:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea,
select {
  font: inherit;
}

.admin-shell {
  min-height: 100vh;
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  flex-direction: column;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav a {
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
}

.nav a:hover,
.nav a.active {
  color: var(--primary);
  background: #eff6ff;
}

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 22px auto 56px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.page-head h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

.page-head p,
.subtle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-body {
  padding: 18px;
}

.stat {
  padding: 18px;
}

.stat-link {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.stat-link:hover,
.stat-link:focus-visible,
.stat-link.active {
  border-color: #bfdbfe;
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.12);
  transform: translateY(-1px);
}

.stat-link.active {
  background: #f8fbff;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  line-height: 1;
}

.dashboard-status-panel {
  margin-top: 14px;
}

.dashboard-list-head {
  margin-bottom: 10px;
}

.dashboard-actions {
  margin-top: 0;
}

.dashboard-empty {
  margin: 12px 0 0;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.quick-entry-list {
  display: grid;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.quick-entry-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) minmax(120px, 1fr) minmax(120px, 1fr) 42px;
  gap: 10px;
  align-items: end;
  min-width: 760px;
}

.quick-entry-row + .quick-entry-row .field label {
  display: none;
}

.quick-submit {
  margin-top: 12px;
  min-width: 150px;
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.compact-textarea {
  min-height: 72px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  color: #374151;
  font-size: 13px;
  font-weight: 600;
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.danger {
  color: var(--red);
}

.btn.ok {
  border-color: var(--green);
  background: #f0fdf4;
  color: var(--green);
}

.btn.small {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #fafafa;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 12px;
}

.badge.blue {
  color: #1d4ed8;
  background: #eff6ff;
}

.badge.green {
  color: #15803d;
  background: #f0fdf4;
}

.badge.amber {
  color: #b45309;
  background: #fffbeb;
}

.badge.red {
  color: #b91c1c;
  background: #fef2f2;
}

.flash {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
}

.flash.success {
  color: var(--green);
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.flash.error {
  color: var(--red);
  background: #fef2f2;
  border-color: #fecaca;
}

.cards {
  display: grid;
  gap: 12px;
}

.employee-card {
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.employee-card .card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.employee-card h3 {
  margin: 0;
  font-size: 17px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.qr-box {
  width: 180px;
  max-width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-box img {
  display: block;
  width: 100%;
  height: auto;
}

.question-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  background: #fff;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.sortable-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sortable-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.question-sort-panel {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #f8fbff;
}

.sort-mode-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.compact-question-list {
  display: grid;
  gap: 8px;
}

.compact-question-item {
  display: grid;
  grid-template-columns: 44px 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.compact-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #eef2ff;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 700;
}

.compact-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-meta {
  color: var(--muted);
  font-size: 12px;
}

.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f9fafb;
  color: #6b7280;
  cursor: grab;
  font-size: 18px;
  line-height: 1;
  touch-action: none;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle:hover {
  color: var(--primary);
  border-color: #bfdbfe;
  background: #eff6ff;
}

.sortable-ghost {
  opacity: 0.35;
  background: #eff6ff;
}

.sortable-chosen {
  border-color: #93c5fd;
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.16);
}

.sortable-drag {
  opacity: 0.96;
  transform: rotate(0.2deg);
}

.question-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 0;
}

.option-grid,
.rule-grid {
  display: grid;
  grid-template-columns: 44px 90px 1fr 120px 72px;
  gap: 8px;
  align-items: end;
  margin: 8px 0;
}

.option-grid {
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.option-label-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  color: #374151;
  font-size: 13px;
  font-weight: 600;
}

.option-label-auto {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  min-height: 40px;
  border: 1px solid #bfdbfe;
  border-radius: 7px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 15px;
}

.option-handle {
  align-self: end;
}

.rule-grid {
  grid-template-columns: 70px 110px 110px 1fr 1fr 120px 72px;
}

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
}

.login-card {
  width: min(400px, 100%);
  padding: 26px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.survey-page {
  min-height: 100vh;
  padding: 28px 16px 44px;
  background: #f4f6f8;
}

.survey-card {
  width: min(760px, 100%);
  margin: 0 auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(17, 24, 39, 0.08);
  overflow: hidden;
}

.survey-header {
  padding: 28px 28px 20px;
  border-bottom: 1px solid #eef0f3;
}

.survey-header h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.35;
}

.survey-header p {
  margin: 14px 0 0;
  color: #4b5563;
  font-size: 15px;
  white-space: pre-line;
}

.survey-note {
  margin-top: 14px;
  padding: 12px;
  border-radius: 7px;
  background: #f9fafb;
  color: #4b5563;
  font-size: 14px;
  white-space: pre-line;
}

.survey-body {
  padding: 10px 28px 28px;
}

.public-question {
  padding: 22px 0;
  border-bottom: 1px solid #eef0f3;
}

.public-question:last-child {
  border-bottom: 0;
}

.public-question h2 {
  margin: 0 0 14px;
  font-size: 17px;
  line-height: 1.45;
}

.required-dot {
  color: var(--red);
}

.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 7px;
  cursor: pointer;
}

.choice:hover {
  border-color: #bfdbfe;
  background: #f8fbff;
}

.choice input {
  margin-top: 4px;
}

.submit-row {
  padding-top: 22px;
}

.submit-btn {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 7px;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.submit-btn:hover {
  background: #1d4ed8;
}

.public-error {
  padding: 12px;
  margin: 0 0 12px;
  border-radius: 7px;
  background: #fef2f2;
  color: #b91c1c;
}

@media (max-width: 820px) {
  .admin-topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .nav {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .nav a {
    flex: 0 0 auto;
    min-height: 38px;
    white-space: nowrap;
  }

  .container {
    width: calc(100% - 22px);
    margin-top: 14px;
  }

  .page-head {
    flex-direction: column;
  }

  .toolbar,
  .toolbar form.toolbar,
  .toolbar form {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .toolbar .input,
  .toolbar .select,
  .toolbar .btn {
    width: 100% !important;
  }

  .btn {
    min-height: 44px;
  }

  .btn.small {
    min-height: 38px;
  }

  .grid.cols-4,
  .grid.cols-3,
  .form-row {
    grid-template-columns: 1fr;
  }

  .quick-entry-list {
    overflow-x: visible;
  }

  .quick-entry-row {
    min-width: 0;
    grid-template-columns: 1fr;
  }

  .quick-entry-row + .quick-entry-row .field label {
    display: block;
  }

  .icon-btn {
    width: 100%;
  }

  .quick-submit {
    width: 100%;
  }

  .desktop-table {
    display: none;
  }

  .mobile-cards {
    display: grid;
  }

  .employee-card {
    padding: 14px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .actions > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .actions .btn,
  .actions form,
  .actions form .btn {
    width: 100%;
  }

  .qr-box {
    width: 210px;
    margin: 0 auto;
  }

  .question-block {
    padding: 12px;
  }

  .question-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .question-tools .btn {
    width: 100%;
  }

  .option-grid {
    grid-template-columns: 44px 1fr;
    align-items: start;
  }

  .rule-grid {
    grid-template-columns: 1fr 1fr;
  }

  .option-grid .wide,
  .rule-grid .wide {
    grid-column: 1 / -1;
  }

  .option-grid > .option-label-box,
  .option-grid > .field:not(.wide),
  .option-grid > .btn {
    grid-column: 2;
  }

  .option-grid > .btn,
  .rule-grid > .btn {
    width: 100%;
  }

  .rule-grid > .btn {
    grid-column: 1 / -1;
  }

  .drag-handle {
    width: 42px;
    height: 42px;
  }

  .sort-mode-top {
    flex-direction: column;
  }

  .compact-question-item {
    grid-template-columns: 42px 32px minmax(0, 1fr);
    align-items: start;
  }

  .compact-title {
    overflow: visible;
    line-height: 1.45;
    text-overflow: clip;
    white-space: normal;
  }

  .compact-meta {
    grid-column: 3;
  }

  .survey-page {
    padding: 12px 10px 28px;
  }

  .survey-header {
    padding: 22px 18px 16px;
  }

  .survey-header h1 {
    font-size: 22px;
  }

  .survey-body {
    padding: 6px 18px 22px;
  }

  .public-question {
    padding: 18px 0;
  }
}

@media (min-width: 821px) {
  .mobile-cards {
    display: none;
  }
}
