/* ──────────────────────────────────────────────────────────────
   Personal Assessment — patient (mobile, large font) + admin
   ────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --ink: #1a2030;
  --ink-soft: #5a6275;
  --ink-faint: #9099ab;
  --line: #e4e7ee;
  --line-soft: #eef0f5;

  --primary: #3a72b8;
  --primary-strong: #2a5790;
  --primary-soft: #e8f0fa;
  --primary-ink: #1d4376;

  --accent: #b88a2f;
  --success: #2c8a55;
  --success-soft: #e6f3ec;
  --warn: #c34a3a;
  --warn-soft: #fbe8e4;

  --shadow-sm: 0 1px 2px rgba(20,28,55,.04), 0 2px 4px rgba(20,28,55,.04);
  --shadow-md: 0 2px 6px rgba(20,28,55,.05), 0 12px 24px rgba(20,28,55,.06);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 20px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: contain;
}

body.flow-body {
  overflow: hidden;
  height: 100dvh;
  height: 100vh;
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

.muted { color: var(--ink-soft); }
.small { font-size: 14px; }

/* ── Hero / index ── */
.hero {
  text-align: center;
  padding: 48px 28px;
  max-width: 480px;
}
.hero h1 { font-size: 30px; margin: 0 0 12px; letter-spacing: -0.01em; }

/* ──────────────────────────────────────────────────────────────
   PATIENT — full-screen swipe flow
   ────────────────────────────────────────────────────────────── */
.flow {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  touch-action: pan-y;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding:
    calc(max(env(safe-area-inset-top), 18px) + 4px)
    24px
    calc(max(env(safe-area-inset-bottom), 18px) + 4px);
  background: var(--bg);
  transition: transform 260ms cubic-bezier(.22, .8, .25, 1);
  will-change: transform;
}
.screen[data-state="active"]  { transform: translateX(0); }
.screen[data-state="past"]    { transform: translateX(-100%); }
.screen[data-state="future"]  { transform: translateX(100%); }

.screen-header {
  flex-shrink: 0;
  padding: 4px 4px 20px;
}
.screen-title {
  font-size: 28px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  color: var(--ink-soft);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}
.progress-part { font-weight: 600; color: var(--ink); font-size: 16px; }
.progress-count { font-variant-numeric: tabular-nums; }
.progress-bar {
  height: 5px;
  background: var(--line-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-strong));
  border-radius: var(--radius-pill);
  transition: width 260ms ease;
}

.screen-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px;
  -webkit-overflow-scrolling: touch;
}
.screen-body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-nav {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  padding-top: 18px;
}
.screen-nav .btn { flex: 1; }

/* ── Buttons ── */
.btn {
  min-height: 56px;
  padding: 0 22px;
  font-size: 18px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 80ms ease, background 140ms ease, opacity 140ms ease;
  letter-spacing: 0.02em;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(58,114,184,0.3);
}
.btn.primary:active:not(:disabled) { background: var(--primary-strong); }

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn.ghost:active { background: var(--primary-soft); color: var(--primary); }

/* ── Consent screen ── */
.consent-body p {
  font-size: 19px;
  line-height: 1.75;
  margin: 14px 0;
  color: var(--ink);
}
.consent-check {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 32px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 19px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.consent-check input[type="checkbox"] {
  width: 28px;
  height: 28px;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.consent-check span { flex: 1; }

/* ── Intake ── */
.intake { display: flex; flex-direction: column; gap: 22px; padding-top: 8px; }
.field { display: flex; flex-direction: column; gap: 10px; }
.field-label {
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
}
.intake input[type="text"], .intake select {
  width: 100%;
  font-size: 22px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.intake input:focus, .intake select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.intake select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'><path d='M3 5l4 4 4-4' stroke='%23777' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 18px center;
  padding-right: 44px;
}
.gender-field { border: none; padding: 0; margin: 0; }
.gender-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.gender-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 20px;
  cursor: pointer;
  transition: all 140ms ease;
}
.gender-option input[type="radio"] {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
}
.gender-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 600;
}

/* ── Tutorial ── */
.lead { font-size: 19px; margin-bottom: 18px; color: var(--ink-soft); }
.scale-legend {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.scale-legend li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  font-size: 18px;
  border-bottom: 1px solid var(--line-soft);
}
.scale-legend li:last-child { border-bottom: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 600;
  border-radius: 50%;
}
.example {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: 18px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.example-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.example-text { font-size: 19px; margin-bottom: 6px; }
.example-text strong { color: var(--primary-strong); font-size: 22px; }
.example-hint { font-size: 15px; color: var(--ink-soft); }

/* ── Question screens ── */
.question-body { display: flex; flex-direction: column; }
.question-text {
  font-size: 26px;
  line-height: 1.5;
  font-weight: 600;
  margin: 12px 4px 28px;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.scale-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.option {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 66px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 19px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease, transform 80ms ease;
  box-shadow: var(--shadow-sm);
}
.option:active { transform: scale(0.99); }
.option-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-weight: 700;
  border-radius: 50%;
  font-size: 19px;
  transition: all 140ms ease;
}
.option-label { flex: 1; }
.option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.option.selected .option-value {
  background: var(--primary);
  color: #fff;
}

/* ── Part-end transitions ── */
.part-end-card {
  text-align: center;
  padding: 32px 16px;
}
.part-end-card h2 {
  font-size: 26px;
  margin: 18px 0 8px;
  font-weight: 600;
}
.check-mark {
  width: 88px;
  height: 88px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(44,138,85,0.25);
}

/* ── Confirm ── */
.confirm-card {
  text-align: center;
  padding: 32px;
  max-width: 360px;
}
.confirm-card h2 { font-size: 26px; margin: 0 0 8px; font-weight: 600; }

/* ── Result ── */
.result-card {
  text-align: center;
  padding: 24px;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}
.result-card.error-card .result-headline { color: var(--warn); }
.result-headline {
  font-size: 24px;
  margin: 0 0 24px;
  color: var(--ink);
  font-weight: 600;
}
.result-scores {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0 0 24px;
}
.score-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 22px;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 16px;
  box-shadow: var(--shadow-sm);
}
.score-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}
.score-percent {
  grid-row: span 2;
  align-self: center;
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.score-raw {
  font-size: 14px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.result-disclaimer {
  font-size: 15px;
  color: var(--ink-soft);
  background: #fcf5e6;
  border: 1px solid #ecdcad;
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: left;
  line-height: 1.7;
}

/* ──────────────────────────────────────────────────────────────
   ADMIN — desktop & mobile friendly
   ────────────────────────────────────────────────────────────── */
body.admin {
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
}
.admin-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}
.admin-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.admin-header h1 {
  font-size: 24px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.admin-header .who {
  color: var(--ink-soft);
  font-size: 14px;
}
.admin-header .who a { color: var(--primary); text-decoration: none; }
.admin-header .who a:hover { text-decoration: underline; }

.role-tag {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin: 0 4px;
  vertical-align: 2px;
  letter-spacing: 0.04em;
}

.admin-nav {
  display: flex;
  gap: 4px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--line);
}
.admin-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 10px 16px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: 15px;
  font-weight: 500;
  transition: color 140ms ease, border-color 140ms ease;
}
.admin-nav a:hover { color: var(--ink); }
.admin-nav a.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.admin-flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.admin-flash.success { background: var(--success-soft); color: #1c6b3d; border: 1px solid #c3e3cf; }
.admin-flash.error { background: var(--warn-soft); color: var(--warn); border: 1px solid #f3c4bd; }

.admin-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.admin-section h2 { font-size: 17px; margin: 0 0 16px; font-weight: 600; }
.section-subhead { font-size: 14px; margin: 20px 0 10px; color: var(--ink-soft); font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }

/* ── Questionnaire grid (doctor dashboard) ── */
.q-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.q-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  text-decoration: none;
  color: inherit;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
  box-shadow: var(--shadow-sm);
}
.q-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}
.q-card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 18px;
  color: var(--ink);
}
.q-card-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
}
.q-card-stats > div { display: flex; flex-direction: column; }
.q-card-stats .num {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.q-card-stats .label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.q-card-meta { font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.q-card-arrow {
  font-size: 14px;
  color: var(--primary);
  font-weight: 500;
}

/* ── QR block ── */
.qr-block {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.qr-svg-wrap {
  width: 220px;
  height: 220px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.qr-svg-wrap img,
.qr-svg-wrap svg { display: block; width: 100%; height: 100%; }
.qr-meta { flex: 1 1 240px; min-width: 0; }
.kv { font-size: 14px; }
.kv-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.kv-row:last-child { border-bottom: 0; }
.kv-k { color: var(--ink-soft); }
.kv-v { word-break: break-all; }
.kv-v code { background: var(--surface-2); padding: 2px 8px; border-radius: 4px; font-size: 13px; }

.qr-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ── Admin buttons ── */
.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: background 140ms ease, transform 80ms ease;
}
.admin-btn:active { transform: scale(0.98); }
.admin-btn.primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(58,114,184,0.2); }
.admin-btn.primary:hover { background: var(--primary-strong); }
.admin-btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.admin-btn.ghost:hover { background: var(--surface-2); }
.admin-btn.danger { background: #fff; color: var(--warn); border-color: var(--warn); }
.admin-btn.danger:hover { background: var(--warn-soft); }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.filter-bar label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-soft);
}
.filter-bar input[type="date"],
.filter-bar select {
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  color: var(--ink);
}
.filter-bar input[type="date"]:focus,
.filter-bar select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ── Admin tables (wrapped for horizontal scroll on mobile) ── */
.card-table {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th, .admin-table td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.admin-table th {
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr:hover td { background: var(--surface-2); }
.admin-table td a { color: var(--primary); text-decoration: none; }
.admin-table td a:hover { text-decoration: underline; }
.admin-table tr.muted td { color: var(--ink-faint); }
.admin-table tr.row-deleted td { color: var(--ink-faint); }
.admin-table tr.row-deleted .r-name { text-decoration: line-through; text-decoration-color: var(--ink-faint); }

.check-inline {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.check-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 16px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 15px;
}

.score-pill {
  display: inline-block;
  padding: 3px 12px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
}
.tag-on { background: var(--success-soft); color: #1c6b3d; }
.tag-off { background: #f0f1f5; color: var(--ink-faint); }

dl.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 22px;
  margin: 0 0 18px;
}
dl.meta dt { color: var(--ink-soft); font-size: 13px; }
dl.meta dd { margin: 0; font-size: 15px; }

.answer-group h3 {
  font-size: 15px;
  margin: 0 0 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.answer-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.answer-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.answer-table tr:last-child td { border-bottom: 0; }
.answer-table td.idx { color: var(--ink-faint); width: 36px; font-variant-numeric: tabular-nums; }
.answer-table td.ans {
  width: 220px;
  color: var(--primary-strong);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ── Form card (manage doctor form) ── */
.form-card { padding: 28px; }
.form-card .field { margin-bottom: 20px; }
.form-card .field label {
  display: block;
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 8px;
  font-weight: 500;
}
.form-card input[type="text"],
.form-card input[type="tel"],
.form-card input[type="password"] {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  color: var(--ink);
}
.form-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 15px;
}
.check-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}

/* ── Login shell ── */
.login-shell {
  max-width: 400px;
  margin: 96px auto 0;
  padding: 36px 32px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
}
.login-shell h1 {
  font-size: 24px;
  margin: 0 0 24px;
  text-align: center;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-shell .field { margin-bottom: 16px; }
.login-shell .field label {
  display: block;
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.login-shell input {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
}
.login-shell input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.login-shell .btn {
  width: 100%;
  margin-top: 8px;
}
.login-shell .flash {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #f3c4bd;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 14px;
  text-align: center;
}

/* ── Misc ── */
code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ── Manage (super admin) — darker accent so it reads differently ── */
body.manage-body {
  background: #f0f2f7;
}
.manage-shell .admin-header {
  border-bottom-color: #d8dce6;
}
.role-tag.dark {
  background: #2a3142;
  color: #e8eaf0;
  font-weight: 500;
}
.manage-login {
  max-width: 420px;
  border-top: 4px solid #2a3142;
}
.manage-brand {
  text-align: center;
  margin-bottom: 26px;
}
.manage-badge {
  display: inline-block;
  background: #2a3142;
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.15em;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  margin-bottom: 14px;
  text-transform: uppercase;
}
.manage-brand h1 {
  font-size: 22px;
  margin: 0 0 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.manage-login .btn.primary {
  background: #2a3142;
  box-shadow: 0 1px 3px rgba(42,49,66,0.3);
}
.manage-login .btn.primary:active:not(:disabled) {
  background: #1c2230;
}

/* ──────────────────────────────────────────────────────────────
   Mobile (≤ 640px): admin → bigger fonts; tables → card list
   ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Base */
  body.admin { font-size: 16px; line-height: 1.6; }
  .admin-shell { padding: 14px 16px 48px; }

  /* Header */
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 0 18px;
  }
  .admin-header h1 { font-size: 22px; }
  .admin-header .who { font-size: 13px; }

  /* Nav */
  .admin-nav a { padding: 10px 12px; font-size: 14px; }

  /* Filter bar — stack on mobile */
  .filter-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-bar > span { display: none; }
  .filter-bar label { width: 100%; justify-content: space-between; }
  .filter-bar input[type="date"],
  .filter-bar select {
    flex: 1;
    font-size: 15px;
    padding: 10px 12px;
    min-height: 40px;
  }
  .filter-bar .admin-btn {
    width: 100%;
    min-height: 42px;
    font-size: 15px;
  }

  /* QR detail page */
  .qr-block { flex-direction: column; align-items: center; gap: 20px; }
  .qr-svg-wrap { width: 100%; height: auto; aspect-ratio: 1; max-width: 320px; }
  .qr-meta { width: 100%; }
  .kv-row { grid-template-columns: 1fr; gap: 4px; padding: 10px 0; }
  .kv-k { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
  .kv-v code { font-size: 12px; word-break: break-all; }

  /* Detail page meta */
  dl.meta {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  dl.meta dt {
    padding-top: 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  dl.meta dt:first-child { padding-top: 0; }

  /* Forms / login */
  .form-card { padding: 20px; }
  .form-card input[type="text"],
  .form-card input[type="tel"],
  .form-card input[type="password"] {
    font-size: 16px;  /* prevent iOS zoom on focus */
    padding: 14px;
    min-height: 48px;
  }
  .form-card .field label { font-size: 13px; }
  .form-actions { flex-direction: column; gap: 8px; }
  .form-actions .admin-btn { width: 100%; min-height: 46px; font-size: 15px; }

  .login-shell {
    margin: 24px 16px 0;
    padding: 28px 22px;
  }
  .login-shell input {
    font-size: 16px;
    padding: 14px;
    min-height: 48px;
  }
  .login-shell .btn { min-height: 50px; }

  /* Doctor dashboard cards */
  .q-grid { grid-template-columns: 1fr; gap: 12px; }
  .q-card { padding: 18px 20px; }
  .q-card-title { font-size: 17px; }
  .q-card-stats { gap: 28px; }
  .q-card-stats .num { font-size: 24px; }

  /* ── Submissions + doctors tables → mobile cards (scoped) ── */
  .submissions-table.card-table,
  .doctors-table.card-table {
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }
  .submissions-table .admin-table,
  .doctors-table .admin-table { font-size: 15px; }
  .submissions-table .admin-table thead,
  .doctors-table .admin-table thead { display: none; }
  .submissions-table .admin-table tbody,
  .doctors-table .admin-table tbody { display: block; }
  .submissions-table .admin-table tr,
  .doctors-table .admin-table tr {
    display: grid;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    gap: 8px 12px;
  }
  .submissions-table .admin-table tr:last-child,
  .doctors-table .admin-table tr:last-child { margin-bottom: 0; }
  .submissions-table .admin-table tr:hover td,
  .doctors-table .admin-table tr:hover td { background: transparent; }
  .submissions-table .admin-table td,
  .doctors-table .admin-table td {
    display: block;
    padding: 0;
    border: 0;
  }

  /* Other admin tables (scores, etc.) stay as tables but with tighter padding. */
  .admin-section .admin-table { font-size: 14px; }
  .admin-section .admin-table th,
  .admin-section .admin-table td { padding: 10px 12px; }

  /* Submissions cards */
  .submissions-table .admin-table tr {
    grid-template-columns: auto auto auto 1fr auto;
    column-gap: 8px;
    row-gap: 6px;
  }
  .submissions-table .r-name {
    grid-column: 1 / 5;
    grid-row: 1;
    font-size: 18px;
    font-weight: 600;
  }
  .submissions-table .r-link {
    grid-column: 5;
    grid-row: 1;
    align-self: center;
  }
  .submissions-table .r-link a {
    display: inline-block;
    padding: 5px 12px;
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
  }
  .submissions-table .r-gender {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 14px;
    color: var(--ink-soft);
  }
  .submissions-table .r-gender::after {
    content: " · " attr(data-age) " 岁";
  }
  .submissions-table .r-gender[data-age=""]::after { content: ""; }
  .submissions-table .admin-table td.r-age { display: none; }
  .submissions-table .r-qid {
    grid-column: 1 / -1;
    grid-row: 3;
    font-size: 13px;
    color: var(--ink-faint);
  }
  .submissions-table .r-s1 { grid-column: 1; grid-row: 4; }
  .submissions-table .r-s2 { grid-column: 2; grid-row: 4; }
  .submissions-table .r-s3 { grid-column: 3; grid-row: 4; }
  .submissions-table .r-s1 .score-pill::before { content: "背 "; opacity: 0.65; }
  .submissions-table .r-s2 .score-pill::before { content: "交 "; opacity: 0.65; }
  .submissions-table .r-s3 .score-pill::before { content: "腹 "; opacity: 0.65; }
  .submissions-table .r-time {
    grid-column: 1 / -1;
    grid-row: 5;
    font-size: 13px;
    color: var(--ink-faint);
    border-top: 1px solid var(--line-soft);
    padding-top: 8px;
    margin-top: 4px;
  }

  /* Manage doctors cards */
  .doctors-table .admin-table tr {
    grid-template-columns: 1fr auto;
    row-gap: 6px;
  }
  .doctors-table .r-name {
    grid-column: 1; grid-row: 1;
    font-size: 17px;
  }
  .doctors-table .r-name strong { font-weight: 600; }
  .doctors-table .r-link {
    grid-column: 2; grid-row: 1;
    align-self: center;
  }
  .doctors-table .r-link a {
    display: inline-block;
    padding: 5px 12px;
    background: var(--surface-2);
    border-radius: 8px;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
  }
  .doctors-table .r-phone {
    grid-column: 1; grid-row: 2;
    font-size: 14px;
    color: var(--ink-soft);
    font-variant-numeric: tabular-nums;
  }
  .doctors-table .r-role {
    grid-column: 2; grid-row: 2;
    align-self: center;
    font-size: 13px;
    color: var(--ink-soft);
  }
  .doctors-table .r-qs {
    grid-column: 1 / -1; grid-row: 3;
    font-size: 14px;
    color: var(--ink-soft);
  }
  .doctors-table .r-qs::before {
    content: "问卷 · ";
    color: var(--ink-faint);
  }
  .doctors-table .r-status {
    grid-column: 1; grid-row: 4;
  }
  .doctors-table .r-created {
    grid-column: 1 / -1; grid-row: 5;
    font-size: 12px;
    color: var(--ink-faint);
    border-top: 1px solid var(--line-soft);
    padding-top: 8px;
    margin-top: 4px;
  }

  /* Answer detail tables stay compact */
  .answer-table { font-size: 14px; }
  .answer-table td { padding: 8px 10px; }
  .answer-table td.ans { width: auto; }

  /* Empty state */
  .empty { padding: 36px 16px; font-size: 14px; }
}

/* ──────────────────────────────────────────────────────────────
   Patient flow tweaks for narrow screens
   ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .screen {
    padding:
      calc(max(env(safe-area-inset-top), 18px) + 4px)
      22px
      calc(max(env(safe-area-inset-bottom), 18px) + 4px);
  }
  .screen-title { font-size: 26px; }

  /* Consent — relax */
  .consent-body p {
    font-size: 18px;
    line-height: 1.85;
    margin: 16px 0;
  }
  .consent-check {
    padding: 18px 18px;
    font-size: 18px;
    margin-top: 24px;
  }

  /* Tutorial — relax */
  .scale-legend li {
    padding: 16px 18px;
    font-size: 17px;
    gap: 14px;
  }
  .badge { width: 36px; height: 36px; font-size: 17px; }
  .example { padding: 16px 18px; }
  .example-text { font-size: 18px; }
  .example-text strong { font-size: 21px; }

  /* Question screens */
  .question-text {
    font-size: 24px;
    line-height: 1.5;
    margin: 12px 4px 24px;
  }
  .scale-options { gap: 14px; }
  .option {
    min-height: 64px;
    padding: 14px 18px;
    font-size: 18px;
  }
  .option-value { width: 40px; height: 40px; font-size: 18px; }

  /* Result — stack score rows vertically per row */
  .result-card { padding: 20px 4px; }
  .result-headline { font-size: 22px; margin-bottom: 20px; }
  .score-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 18px 20px;
    text-align: center;
  }
  .score-label { font-size: 16px; }
  .score-percent {
    font-size: 36px;
    align-self: center;
    line-height: 1.1;
    margin: 4px 0;
  }
  .score-raw { font-size: 13px; align-self: center; }
  .result-disclaimer { font-size: 14px; padding: 14px 16px; line-height: 1.65; }

  /* Intake — slightly bigger inputs */
  .intake input[type="text"], .intake select {
    font-size: 20px;
    padding: 16px;
  }
  .gender-option { padding: 16px; font-size: 19px; }
}
