:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --line: #e2e8ef;
  --accent: #0ea5e9;
  --accent-deep: #0284c7;
  --accent-soft: #e0f2fe;
  --accent-glow: rgba(14, 165, 233, 0.16);
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  /* Relative tokens so chrome scales with base / Dynamic Type */
  --radius: 0.875rem;
  --shadow: 0 0.5rem 1.75rem rgba(26, 35, 50, 0.06);
  --tap: 3.25rem; /* ~52px at 16px root; grows with text size */
  --header-h: 4.5rem;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC",
    "Microsoft JhengHei", "Helvetica Neue", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* Readable floor for secondary labels (scales with rem root) */
  --text-xs: 0.8125rem; /* ~13–15px depending on root */
  --text-sm: 0.9375rem;
  --text-md: 1rem;
  --text-lg: 1.125rem; /* ~18px at 16px root; ~20px at 112.5% */
  --text-xl: 1.25rem; /* ~20–22px */
  --text-2xl: 1.375rem; /* ~22–24px section titles */
  --medical-blue: #0284c7;
  --medical-slate: #475569;
  --region-default-fill: #f1f5f9;
  --region-default-stroke: #94a3b8;
  --region-hover-fill: #bae6fd;
  --region-hover-stroke: #0284c7;
  --region-selected-fill: #3b82f6;
  --region-selected-stroke: #0284c7;
}

* {
  box-sizing: border-box;
}

/*
  Base type: ~18px (112.5% of typical 16px) for all-age readability.
  On iOS/iPadOS, -apple-system-body respects Settings → Display → Text Size
  (Dynamic Type / Larger Text). font-family is re-applied so CJK faces remain.
*/
html {
  font-size: 112.5%;
  line-height: 1.5;
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@supports (font: -apple-system-body) {
  html {
    font: -apple-system-body;
    font-family: var(--font);
  }
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

body {
  font-size: 1rem;
  line-height: 1.5;
  font-weight: 400;
  font-family: var(--font);
  padding-bottom: calc(1.5rem + var(--safe-bottom));
  /* iPad / touch: reduce accidental selection; still allow form fields */
  touch-action: manipulation;
}

.app-shell.single-page {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell.single-page .main {
  max-width: 45rem;
  margin: 0 auto;
}

/* Four-tab navigation */
.tab-bar {
  position: sticky;
  top: var(--header-h, 4.5rem);
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  padding: 0.65rem 0.9rem;
  background: rgba(244, 246, 248, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.follow-up-student {
  font-weight: 800;
  font-size: 1.05rem;
  margin: 0 0 6px;
  color: var(--ink);
}

.follow-up-summary {
  margin: 0 0 14px;
}

.modal-follow-up {
  max-width: 440px;
}

.follow-up-pills {
  margin-top: 8px;
}

.record-item-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.record-item .btn-sm {
  min-height: 2.75rem; /* ≥44px touch target */
  padding: 0.4rem 0.85rem;
  font-size: 0.9rem;
}

.tag-pending-follow {
  background: #fef3c7;
  color: #b45309;
}

.tag-done-follow {
  background: #d1fae5;
  color: #047857;
}

/* Carry-over: registered on a previous day, still pending follow-up */
.tag-not-today {
  background: #ffedd5;
  color: #c2410c;
  border: 1px solid #fdba74;
  font-weight: 700;
}

.record-item-carryover {
  border-color: #fb923c;
  background: linear-gradient(135deg, #fff7ed 0%, #ffffff 55%);
  box-shadow: 0 0 0 1px rgba(251, 146, 60, 0.35), var(--shadow);
}

.record-item-carryover .record-item-meta {
  color: #9a3412;
  font-weight: 600;
}

/* History cards — full medical summary + print */
.record-item-history {
  cursor: default;
}

.history-student {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  display: block;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.35;
}

html[lang='en'] .history-student {
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.history-card-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-row {
  display: grid;
  /* Chinese labels are short (2–3 chars); English needs more room */
  grid-template-columns: minmax(4.5em, max-content) 1fr;
  gap: 10px 12px;
  font-size: 0.92rem;
  line-height: 1.4;
  align-items: start;
}

html[lang='en'] .history-row {
  grid-template-columns: minmax(6.75rem, max-content) 1fr;
}

.history-k {
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

html[lang='en'] .history-k {
  letter-spacing: 0.01em;
}

.history-v {
  font-weight: 700;
  color: var(--ink);
  /* Prefer natural CJK/Latin wrapping; avoid mid-word English breaks */
  overflow-wrap: break-word;
  word-break: normal;
  min-width: 0;
}

.detail-dl-medical dt {
  min-width: 5.5em;
}

html[lang='en'] .detail-dl-medical dt {
  min-width: 7.5em;
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: var(--text-xs);
}

.tab-btn {
  min-height: 3rem; /* ≥48px at default root */
  padding: 0.4rem 0.35rem;
  border-radius: 0.75rem;
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.2;
  color: var(--muted);
  background: var(--surface);
  border: 1.5px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tab-btn .tab-count {
  flex-shrink: 0;
}

.tab-btn.active {
  color: var(--accent-deep);
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.tab-count {
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #e2e8ef;
  color: var(--ink);
  font-size: var(--text-xs);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab-btn.active .tab-count {
  background: var(--accent);
  color: #fff;
}

.tab-panel {
  animation: fadeIn 0.16s ease;
}

.tab-panel[hidden] {
  display: none !important;
}

.panel-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.panel-head-actions a.btn {
  text-decoration: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.panel-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.panel-head-actions a.btn {
  text-decoration: none;
}

.panel-head h2 {
  margin: 0;
}

.btn-sm {
  min-height: 2.75rem; /* ≥44px */
  padding: 0 0.85rem;
  font-size: 0.9rem;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.wizard-panel {
  animation: fadeIn 0.16s ease;
  /* Keep step content below sticky header + tab bar when scrolling into view */
  scroll-margin-top: calc(var(--header-h, 72px) + 64px + var(--safe-top));
}

#manualCard {
  scroll-margin-top: calc(var(--header-h, 72px) + 64px + var(--safe-top));
}

.wizard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  /* Keep nav buttons reachable while keyboard is open (later steps) */
  position: sticky;
  bottom: calc(8px + var(--safe-bottom));
  z-index: 2;
  padding: 10px 0 2px;
  background: linear-gradient(
    to top,
    var(--surface) 70%,
    rgba(255, 255, 255, 0)
  );
}

/*
  Search step: do NOT sticky “Next” — sticky bottom sat on top of the
  roster/medical card while the virtual keyboard was open, so staff
  tapped Next without reading student info.
*/
.wizard-step-search .wizard-actions,
.wizard-actions-search {
  position: static;
  background: none;
  padding: 0;
  margin-top: 14px;
}

.wizard-actions .btn {
  min-height: var(--tap);
}

.wizard-actions .btn-primary {
  flex: 1 1 auto;
}

/* Follow-up modal: three clear questions */
.fu-step {
  margin: 0 0 14px;
  padding: 12px 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: #f8fafb;
}

.fu-step-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.fu-step-num {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  background: var(--accent);
  line-height: 1;
}

.fu-step-titles {
  min-width: 0;
}

.fu-step-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.25;
}

.fu-note-field {
  margin-top: 4px;
}

.modal-follow-up .fu-step .follow-up-pills {
  margin: 0;
}

.confirm-summary {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #f8fafb;
  font-size: 0.95rem;
}

.confirm-summary .row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
}

.confirm-summary .k {
  color: var(--muted);
  font-weight: 600;
}

.lookup-preview {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.45;
  border: 1.5px solid var(--line);
  background: #f8fafb;
  /* Scroll target stays clear of sticky header/tabs */
  scroll-margin-top: calc(var(--header-h, 72px) + 72px + var(--safe-top));
  scroll-margin-bottom: 24px;
}

.lookup-preview.ok {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.lookup-preview.ok .lookup-preview-line {
  font-size: 1.15rem;
  margin-bottom: 2px;
}

.lookup-preview.err {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.lookup-preview .btn-manual-entry {
  margin-top: 10px;
}

/* Offline / connectivity banner (iPad Wi‑Fi drop) */
.connectivity-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  font-size: var(--text-sm);
  font-weight: 600;
  background: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fcd34d;
  z-index: 20;
}

.connectivity-banner.is-offline {
  background: #fee2e2;
  color: #991b1b;
  border-bottom-color: #fecaca;
}

.connectivity-banner.is-syncing {
  background: #e0f2fe;
  color: #075985;
  border-bottom-color: #7dd3fc;
}

.connectivity-banner.is-pending {
  background: #fef3c7;
  color: #92400e;
}

.connectivity-banner[hidden] {
  display: none !important;
}

.manual-entry-panel {
  margin-top: 12px;
  padding: 14px;
  border-radius: 12px;
  border: 1.5px dashed var(--accent);
  background: #f8fafc;
}

.manual-entry-panel[hidden] {
  display: none !important;
}

.manual-entry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin: 10px 0;
}

@media (max-width: 480px) {
  .manual-entry-grid {
    grid-template-columns: 1fr;
  }
}

.manual-entry-panel .hint.muted {
  color: var(--muted);
  font-size: var(--text-xs);
  margin-bottom: 10px;
}

.tag-pending-upload {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.tag-unmatched-roster {
  background: #f3e8ff;
  color: #6b21a8;
  border: 1px solid #d8b4fe;
}

.record-item.is-local-pending {
  border-left: 3px solid var(--warn);
}

/* Compact sticky name strip while keyboard may still be open (before blur) */
.lookup-preview-sticky-name {
  position: sticky;
  top: calc(var(--header-h, 4.5rem) + 3.5rem + var(--safe-top));
  z-index: 3;
  margin: -4px -6px 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-soft) 92%, #fff);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.12);
}

/* Section label only — not the student name line */
.lookup-preview > strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.lookup-preview-line {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: break-word;
}

.lookup-preview-line strong {
  font-weight: 800;
}

.lookup-medical {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed color-mix(in srgb, var(--accent) 35%, transparent);
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--accent-deep);
}

.lookup-medical-row {
  display: grid;
  grid-template-columns: minmax(11rem, auto) 1fr;
  gap: 4px 10px;
  align-items: start;
}

.lookup-medical-k {
  font-weight: 700;
  white-space: normal;
  opacity: 0.9;
  line-height: 1.35;
}

.lookup-medical-v {
  font-weight: 600;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

@media (max-width: 420px) {
  .lookup-medical-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

.reason-field {
  margin-top: 14px;
}

.reason-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 520px) {
  .reason-options {
    grid-template-columns: repeat(3, 1fr);
  }
}

.reason-chip {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 4.25rem;
  width: 100%;
  padding: 1rem 0.9rem;
  border-radius: 0.875rem;
  border: 2px solid var(--line);
  background: #f8fafb;
  font-weight: 700;
  font-size: 1.12rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    border-color 0.15s,
    background 0.15s,
    color 0.15s,
    box-shadow 0.15s,
    transform 0.12s;
}

.reason-chip-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.reason-chip-emoji {
  font-size: 1.15em;
  line-height: 1;
}

.reason-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* 覆診/病 — rose / medical */
.reason-chip.reason-medical {
  border-color: #fca5a5;
  background: linear-gradient(180deg, #fff5f5 0%, #fee2e2 100%);
  color: #b91c1c;
}
.reason-chip.reason-medical:has(input:checked) {
  border-color: #dc2626;
  background: linear-gradient(180deg, #fecaca 0%, #fca5a5 100%);
  color: #7f1d1d;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.35);
}

/* 家事 — sky / personal */
.reason-chip.reason-family {
  border-color: #7dd3fc;
  background: linear-gradient(180deg, #f0f9ff 0%, #e0f2fe 100%);
  color: #0369a1;
}
.reason-chip.reason-family:has(input:checked) {
  border-color: #0284c7;
  background: linear-gradient(180deg, #bae6fd 0%, #7dd3fc 100%);
  color: #0c4a6e;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.35);
}

/* 其他 — amber */
.reason-chip.reason-other {
  border-color: #fcd34d;
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  color: #b45309;
}
.reason-chip.reason-other:has(input:checked) {
  border-color: #d97706;
  background: linear-gradient(180deg, #fde68a 0%, #fcd34d 100%);
  color: #78350f;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.35);
}

.reason-chip:active {
  transform: scale(0.98);
}

.reason-chip:has(input:focus-visible) {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.reason-other {
  margin-top: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 1rem;
}

.reason-other:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Medical room: visit type — tap to advance */
.visit-type-hint {
  margin: 4px 0 10px;
}

.visit-type-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.visit-type-btn {
  border: none;
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.visit-type-btn.visit-type-both {
  grid-column: 1 / -1;
  min-height: 4.5rem;
  flex-direction: column;
  gap: 0.25rem;
}

.visit-type-sub {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  opacity: 0.85;
}

.detail-section {
  margin-top: 16px;
  padding: 1.25rem 1.25rem 1.1rem;
  border-radius: 1rem; /* rounded-2xl-ish */
  border: 1px solid #e2e8f0;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.detail-section + .detail-section {
  margin-top: 18px;
  padding-top: 1.25rem;
  border-top: 1px solid #e2e8f0;
}

.detail-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: var(--text-2xl);
  line-height: 1.3;
  margin-bottom: 14px;
  color: var(--ink);
}

.detail-section-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 800;
  background: #fee2e2;
  color: #b91c1c;
}

/* Form labels / buttons — all-age iPad friendly (18–20px) */
.wizard-panel .field > label,
.wizard-panel .field > .label,
.detail-section .field > label,
#sectionInjury .field > label,
#sectionDiscomfort .field > label {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--medical-slate);
}

.wizard-panel .btn,
.wizard-panel .symptom-pill,
.wizard-panel .visit-type-btn {
  font-size: var(--text-lg);
}

.injury-location-field {
  margin: 0 0 14px;
  padding: 1rem 1.1rem 0.9rem;
  border-radius: 1rem;
  border: 1px solid color-mix(in srgb, var(--medical-blue) 28%, #e2e8f0);
  background: color-mix(in srgb, var(--accent-soft) 55%, #fff);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.injury-location-field > label {
  font-weight: 700;
  font-size: var(--text-lg);
  display: block;
  margin-bottom: 8px;
  color: var(--medical-slate);
}

.injury-location-field .hint {
  margin: 0 0 10px;
}

.injury-location-pills {
  margin-bottom: 0;
}

#injuryLocationOtherText {
  margin-top: 10px;
  width: 100%;
}

.detail-section-badge.badge-injury {
  background: #e0f2fe;
  color: #0369a1;
}

/* ── Interactive anatomical body map (外傷) ── */
.body-map-mount {
  position: relative;
  margin: 8px 0 12px;
  padding: 0;
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  background:
    radial-gradient(120% 80% at 50% 0%, #f0f9ff 0%, transparent 55%),
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  overflow: visible;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.body-map {
  position: relative;
  padding: 14px 12px 16px;
}

.body-map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 2px;
}

/* Prominent selected-part badge */
.body-map-selection {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.4rem;
  min-height: 2rem;
  padding: 0.4rem 0.85rem;
  border-radius: 0.75rem;
  background: #e0f2fe;
  border: 1.5px solid #7dd3fc;
  color: #0c4a6e;
  font-size: 1.25rem; /* 20px / text-xl */
  line-height: 1.3;
  max-width: min(100%, 28rem);
}

.body-map-selection.is-empty {
  background: #f8fafc;
  border-color: #e2e8f0;
  border-style: dashed;
  color: var(--muted);
  font-size: var(--text-lg);
  font-weight: 600;
}

.body-map-selection-label {
  font-weight: 700;
  color: #0369a1;
}

.body-map-selection-value {
  font-weight: 800;
  color: #0c4a6e;
  font-size: 1.25rem;
}

.body-map-orient-line {
  margin: 0 0 10px;
  padding: 0 2px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: #64748b;
  line-height: 1.4;
}

.body-map-clear {
  flex-shrink: 0;
  min-height: 3rem; /* 48px */
  padding: 0.5rem 1rem;
  font-size: var(--text-lg);
  font-weight: 700;
  border-radius: 0.75rem;
  border: 1.5px solid #cbd5e1;
  background: #fff;
  color: var(--medical-slate);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.body-map-clear:hover {
  border-color: var(--medical-blue);
  color: var(--medical-blue);
  background: #f0f9ff;
}

/* 2-column: Front | Back */
.body-map-views,
.body-map-views-anatomical,
.body-map-views-simplified {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
}

.body-map-view {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: center;
  border-radius: 1rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  padding: 12px 8px 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.body-map-view-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 8px;
  line-height: 1.15;
}

.body-map-view-label span {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--ink);
}

.body-map-view-label small {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.body-map-canvas {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  min-height: 0;
}

.body-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.body-svg-face {
  max-width: 320px;
  width: 100%;
}

.body-svg-body,
.body-svg-back {
  max-width: 220px;
  width: 100%;
}

/* Floating callout label (18px) — no text inside SVG regions */
.body-map-tooltip {
  position: absolute;
  z-index: 90;
  transform: translate(-50%, -100%);
  pointer-events: none;
  padding: 0.45rem 0.85rem;
  border-radius: 0.65rem;
  background: #0f172a;
  color: #fff;
  font-size: 1.125rem; /* 18px / text-lg */
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.28);
}

.body-map-tooltip::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #0f172a;
  border-bottom-width: 0;
}

/* Face detail modal */
.body-face-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, var(--safe-top));
  padding-bottom: max(1rem, var(--safe-bottom));
}

.body-face-modal[hidden] {
  display: none !important;
}

.body-face-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.body-face-modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 28rem);
  max-height: min(92vh, 40rem);
  overflow: auto;
  border-radius: 1.25rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22);
  padding: 1rem 1.1rem 1.15rem;
}

.body-face-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.body-face-modal-head h3 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--ink);
  line-height: 1.3;
}

.body-face-modal-close {
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  min-height: 3rem;
  padding: 0;
  font-size: 1.75rem;
  line-height: 1;
  border-radius: 0.75rem;
  color: var(--medical-slate);
}

.body-face-modal-selection {
  margin-bottom: 12px;
}

.body-face-modal-selection .body-map-selection {
  max-width: 100%;
}

.body-face-modal-canvas {
  display: flex;
  justify-content: center;
  padding: 8px 4px 12px;
  border-radius: 1rem;
  background:
    radial-gradient(80% 70% at 50% 20%, #f0f9ff 0%, transparent 60%),
    #f8fafc;
  border: 1px solid #e2e8f0;
}

.body-face-modal-actions {
  margin-top: 14px;
  display: flex;
  justify-content: stretch;
}

.body-face-modal-done {
  width: 100%;
  min-height: 3rem;
  font-size: var(--text-lg);
  font-weight: 700;
  border-radius: 0.75rem;
}

/* Non-interactive silhouette underlay */
.body-silhouette {
  fill: #eef2f6;
  stroke: #c5d0dc;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}

.body-silhouette-face {
  fill: #f4f7fa;
  stroke: #c9d4e0;
  stroke-width: 1.8;
}

.body-silhouette-body {
  fill: #eef2f6;
}

/* Side markers (右/左) — medical orientation */
.body-side-marker {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 800;
  fill: #94a3b8;
  pointer-events: none;
  user-select: none;
}

/* Clickable SVG regions */
.body-region {
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* Invisible expanded hit target (≥ ~48px when map is large enough) */
.body-region-hit {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}

/* Default: light gray/blue fill, subtle border */
.body-region-path {
  fill: var(--region-default-fill);
  stroke: var(--region-default-stroke);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition:
    fill 0.14s ease,
    stroke 0.14s ease,
    filter 0.14s ease,
    opacity 0.1s ease;
  /* Slightly widen stroke hit without visual bulk via paint-order */
  paint-order: stroke fill;
}

/* Face zoom head — dashed ring cue */
.body-region-face-zoom .body-region-path {
  fill: #e0f2fe;
  stroke: #38bdf8;
  stroke-width: 1.8;
  stroke-dasharray: 4 2.5;
}

.body-region-check-bg {
  fill: rgba(255, 255, 255, 0.95);
  stroke: none;
  pointer-events: none;
  filter: drop-shadow(0 0 2px rgba(2, 132, 199, 0.45));
}

.body-region-check {
  fill: none;
  stroke: #0284c7;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Hover / keyboard active: medium blue */
@media (hover: hover) and (pointer: fine) {
  .body-region:hover:not(.is-selected) .body-region-path {
    fill: var(--region-hover-fill);
    stroke: var(--region-hover-stroke);
    stroke-width: 2;
  }

  .body-region-face-zoom:hover:not(.is-selected) .body-region-path {
    fill: #bae6fd;
    stroke: #0284c7;
    stroke-dasharray: none;
  }
}

.body-region:active:not(.is-selected) .body-region-path {
  fill: var(--region-hover-fill);
  stroke: var(--region-hover-stroke);
  stroke-width: 2;
}

/* Selected: vibrant primary + white glow */
.body-region.is-selected .body-region-path {
  fill: var(--region-selected-fill);
  stroke: var(--region-selected-stroke);
  stroke-width: 2.2;
  stroke-dasharray: none;
  filter: drop-shadow(0 0 5px rgba(59, 130, 246, 0.65));
}

/* Keyboard focus */
.body-region:focus-visible .body-region-path {
  stroke: #0284c7;
  stroke-width: 2.6;
  filter: drop-shadow(0 0 0 2px #fff) drop-shadow(0 0 0 4px #38bdf8);
}

.body-region:focus-visible.is-selected .body-region-path {
  stroke: #0369a1;
  stroke-width: 2.6;
  filter:
    drop-shadow(0 0 5px rgba(59, 130, 246, 0.65))
    drop-shadow(0 0 0 2px #fff)
    drop-shadow(0 0 0 4px #0ea5e9);
}

.body-parts-bar {
  margin-bottom: 12px;
}

.injury-pairs-bar {
  gap: 8px;
}

.injury-pair-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: #e0f2fe;
  border: 1.5px solid #0ea5e9;
  color: #0369a1;
  font-weight: 800;
  font-size: var(--text-lg);
  line-height: 1.2;
  min-height: 2.75rem;
}

.injury-pair-text {
  max-width: 12em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.injury-pair-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #0369a1;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.injury-pair-remove:hover {
  background: rgba(3, 105, 161, 0.12);
}

.injury-pair-pending {
  font-size: var(--text-lg);
  font-weight: 700;
  color: #0369a1;
}

.injury-kinds-field {
  margin-top: 8px;
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.injury-kinds-field > label {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--ink);
}

.injury-kinds {
  margin-top: 12px;
  gap: 0.65rem;
}

/* Injury type pill buttons — modern, 48px min, rounded-xl */
button.injury-kind-btn {
  font: inherit;
  appearance: none;
  -webkit-appearance: none;
  min-height: 3rem; /* 48px */
  padding: 0.6rem 1.1rem;
  border-radius: 0.75rem; /* rounded-xl */
  font-size: 1.125rem; /* 18px */
  font-weight: 700;
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

button.injury-kind-btn:hover {
  border-color: #f97316;
  background: #fff7ed;
  color: #c2410c;
}

button.injury-kind-btn:active,
button.injury-kind-btn.is-active {
  transform: scale(0.97);
  border-color: #ea580c;
  background: #ffedd5;
  color: #9a3412;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.injury-kind-for {
  font-weight: 700;
  color: var(--medical-blue);
  margin-left: 4px;
  font-size: var(--text-lg);
}

.injury-other-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.injury-other-row .symptom-other-input {
  flex: 1 1 160px;
  margin-top: 0;
  min-height: 3rem;
  font-size: var(--text-lg);
}

/* Phone: stack Front/Back */
@media (max-width: 520px) {
  .body-map-views,
  .body-map-views-anatomical,
  .body-map-views-simplified {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .body-map-view {
    padding: 12px 10px 14px;
  }

  .body-svg-body,
  .body-svg-back {
    max-width: 240px;
  }

  .body-map-toolbar {
    flex-wrap: wrap;
  }

  .body-map-clear {
    margin-left: auto;
  }

  .body-map-selection,
  .body-map-selection-value {
    font-size: 1.125rem;
  }
}

@media (min-width: 521px) {
  .body-svg-body,
  .body-svg-back {
    max-width: 260px;
  }
}

/* Medical room: grouped symptom pills (easier to scan) */
.symptom-field {
  margin-top: 4px;
}

.symptom-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.symptom-head > label {
  margin: 0;
}

.symptom-selected-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  border: 1.5px dashed var(--line);
  background: #f8fafb;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--muted);
}

.symptom-selected-bar:not(.is-empty) {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
}

.symptom-selected-bar .symptom-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
}

.symptom-groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.symptom-group {
  margin: 0;
  padding: 12px 12px 10px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #fcfdfe 0%, #f7f9fb 100%);
}

.symptom-group legend {
  padding: 0 0.5rem;
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: none;
}

.symptom-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.symptom-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem; /* 48px touch */
  padding: 0.55rem 1rem;
  border-radius: 0.75rem; /* rounded-xl pills */
  border: 1.5px solid #e2e8f0;
  background: #fff;
  font-weight: 700;
  font-size: var(--text-lg); /* 18px */
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition:
    border-color 0.12s,
    background 0.12s,
    color 0.12s,
    box-shadow 0.12s,
    transform 0.1s;
}

.symptom-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.symptom-pill:active {
  transform: scale(0.97);
}

.symptom-pill:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.symptom-pill:has(input:checked) {
  border-color: var(--accent-deep);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.symptom-pill.symptom-other-pill {
  border-style: dashed;
}

.symptom-pill.symptom-other-pill:has(input:checked) {
  border-style: solid;
}

.symptom-other-input {
  margin-top: 10px;
}

.empty-list,
.empty-next {
  padding: 20px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.empty-next .hint {
  margin-top: 8px;
}

.detail-dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

.detail-dl > div {
  display: grid;
  gap: 2px;
}

.detail-dl dt {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-dl dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.ok-text {
  color: var(--ok);
}

.tag {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 0.25rem;
}

.tag-selfgo {
  background: #fef3c7;
  color: #b45309;
}

.tag-feed {
  background: #e0f2fe;
  color: #0369a1;
}

.tag-manual {
  background: #f3e8ff;
  color: #7e22ce;
}

/* Split: 系統 / 手動 sections */
.record-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.record-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
}

.record-section-head h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--ink);
}

.record-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: var(--text-xs);
  font-weight: 700;
}

.section-hint {
  margin: 0 0 0.65rem;
  font-size: var(--text-sm);
}

.records-hint {
  margin-top: -6px;
}

.empty-section {
  padding: 20px 14px;
  font-size: 0.9rem;
}

.detail-extra-actions {
  margin-top: 12px;
}

.modal-actions {
  margin-top: 16px;
  justify-content: flex-end;
}

.modal-actions .btn-danger {
  margin-right: auto;
}

.modal-compact {
  max-width: 400px;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.75rem + var(--safe-top)) 1.25rem 0.9rem;
  min-height: var(--header-h);
  background: linear-gradient(135deg, #0369a1 0%, #0ea5e9 55%, #38bdf8 100%);
  color: #fff;
  box-shadow: 0 0.25rem 1.125rem rgba(14, 165, 233, 0.28);
}

.header-auth {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  max-width: 72%;
  /* Order: NAME · language · login/logout */
}

.header-staff-name {
  order: 1;
  font-size: 0.95rem;
  font-weight: 700;
  opacity: 0.95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 8em;
}

.btn-lang {
  order: 2;
  min-width: 2.75rem;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  padding-left: 0.65rem;
  padding-right: 0.65rem;
}

#btnAuth {
  order: 3;
}

/* Keep tab bar stuck under header height approx */
.app-shell.single-page {
  --header-h: 4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 3rem;
  min-width: 3rem;
  height: 3rem;
  padding: 0;
  border-radius: 0.875rem;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1;
  letter-spacing: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
  user-select: none;
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand p {
  margin: 0.15rem 0 0;
  font-size: var(--text-sm);
  opacity: 0.9;
}

.btn-header-icon {
  flex-shrink: 0;
  min-height: 2.75rem; /* ≥44px */
  min-width: 2.75rem;
  padding: 0.5rem 0.9rem;
  border-radius: 0.75rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.btn-header-icon:active {
  background: rgba(255, 255, 255, 0.28);
}

/* Login required: keep main content readable but non-interactive under the modal */
body.is-logged-out .main,
body.is-logged-out .tab-bar {
  pointer-events: none;
  user-select: none;
  filter: grayscale(0.15);
  opacity: 0.55;
}

.print-method-field {
  margin: 12px 0 0;
  padding: 0;
  border: none;
}

.print-method-field legend {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
  padding: 0;
}

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

.radio-row:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.radio-row input {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.radio-row span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.radio-row strong {
  font-size: 0.95rem;
}

.radio-row small {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.settings-hint {
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.85rem;
  border-radius: 0.65rem;
  background: #f1f5f9;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.settings-hint.warn {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}

.settings-hint.ok {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
}

.settings-meta {
  margin: 0.65rem 0 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

.settings-actions {
  flex-wrap: wrap;
  gap: 8px;
}

.settings-actions .btn-secondary {
  margin-right: auto;
}

.main {
  max-width: 57.5rem;
  margin: 0 auto;
  padding: 1rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  text-align: center;
}

.stat-card .n {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-deep);
  line-height: 1.1;
}

.stat-card .l {
  margin-top: 0.25rem;
  font-size: var(--text-xs);
  color: var(--muted);
}

.card {
  background: #fff;
  border-radius: 1rem; /* rounded-2xl */
  padding: 1.35rem 1.5rem; /* p-6-ish */
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  border: 1px solid #e2e8f0;
  margin-bottom: 0.9rem;
}

.card h2 {
  margin: 0 0 0.9rem;
  font-size: var(--text-2xl);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
}

.card h2::before {
  content: "";
  width: 4px;
  height: 1.1em;
  border-radius: 4px;
  background: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}

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

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
}

.field label .req {
  color: var(--danger);
  margin-left: 2px;
}

.field label .temperature-unit {
  margin-left: 0.35rem;
  font-weight: 500;
  color: var(--muted);
  opacity: 0.85;
}

.field input,
.field select,
.field textarea {
  min-height: var(--tap);
  border: 1.5px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: #fafbfc;
  /* ≥16px prevents iOS zoom-on-focus; scales with root/Dynamic Type */
  font-size: max(1rem, 16px);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field textarea {
  min-height: 5.5rem;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px var(--accent-glow);
}

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

.btn {
  min-height: var(--tap);
  padding: 0 1.15rem;
  border-radius: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-deep);
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.btn-ghost {
  background: #eef2f6;
  color: var(--ink);
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
}

.btn-block {
  width: 100%;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input,
.toolbar select {
  min-height: 2.75rem; /* ≥44px */
  border: 1.5px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  flex: 1 1 8.75rem;
  font-size: max(1rem, 16px);
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.record-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  min-height: 4.5rem;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: center;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.record-item:active {
  background: #f8fafb;
}

.record-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.record-item .name {
  font-weight: 700;
  font-size: 1.1rem;
}

.record-item .meta {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-pending {
  background: #fff7ed;
  color: var(--warn);
}

.badge-verified {
  background: #ecfdf5;
  color: var(--ok);
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--line);
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(26, 35, 50, 0.05);
}

.nav button {
  min-height: 56px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.nav button .ico {
  font-size: 1.15rem;
  line-height: 1;
}

.nav button.active {
  color: var(--accent-deep);
  background: var(--accent-soft);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  z-index: 50;
  max-width: min(92vw, 420px);
  padding: 14px 18px;
  border-radius: 12px;
  background: #1a2332;
  color: #fff;
  font-size: 0.95rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: #991b1b;
}

.toast.ok {
  background: var(--accent-deep);
}

/* Full-screen print progress overlay (above modals; paint before print on iPad) */
.print-loading {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
  background: rgba(15, 23, 32, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  pointer-events: all;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.print-loading.is-on,
.print-loading:not([hidden]) {
  display: flex !important;
}

.print-loading[hidden] {
  display: none !important;
}

.print-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-width: min(78vw, 240px);
  padding: 28px 32px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  text-align: center;
}

.print-loading-card p {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.print-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3.5px solid var(--line);
  border-top-color: var(--accent);
  animation: printSpin 0.75s linear infinite;
}

@keyframes printSpin {
  to {
    transform: rotate(360deg);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 32, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  /* Closed modal must never intercept clicks */
  pointer-events: none;
  visibility: hidden;
}

.modal-backdrop.open {
  display: flex;
  pointer-events: auto;
  visibility: visible;
}

.modal {
  width: min(100%, 520px);
  max-height: min(86vh, 720px);
  overflow: auto;
  background: var(--surface);
  border-radius: 18px 18px 14px 14px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(16px);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.modal h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.detail-grid {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
  font-size: 0.95rem;
}

.detail-grid .row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
}

.detail-grid .k {
  color: var(--muted);
  font-weight: 600;
}

.hint {
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 0.75rem;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  min-height: var(--tap);
  align-items: center;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  min-height: 2.75rem;
  padding: 0.55rem 0.85rem;
  border-radius: 0.75rem;
  background: #f8fafb;
  border: 1.5px solid var(--line);
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.choice input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.choice-locked {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
  cursor: default;
  opacity: 1;
}

.choice-locked input {
  display: none;
}

.choice-hint {
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--muted);
}

.preview-slip {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: var(--text-xs);
  white-space: pre-wrap;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 0.75rem;
  padding: 0.9rem;
  line-height: 1.5;
}

/* ── Tablet / iPad (portrait & landscape, classic + Pro widths) ── */
@media (min-width: 768px) and (max-width: 1366px) {
  /*
    Slightly larger root when Dynamic Type is unavailable.
    On iOS, -apple-system-body already tracks system text size.
  */
  html {
    font-size: 118.75%; /* ~19px if browser default is 16px */
  }

  :root {
    --tap: 3.5rem; /* ~48–56px depending on root */
    --header-h: 4.75rem;
  }

  .main {
    padding: 1.35rem 1.75rem;
  }

  .tab-bar {
    gap: 0.5rem;
    padding: 0.75rem 1rem;
  }

  .tab-btn {
    min-height: 3.25rem;
    font-size: 1.05rem;
    padding: 0.5rem 0.4rem;
  }

  .btn,
  .btn-sm,
  .btn-header-icon,
  .record-item .btn-sm {
    min-height: 3rem;
  }

  .btn {
    padding: 0 1.25rem;
    font-size: 1.05rem;
  }

  .field input,
  .field select,
  .field textarea,
  .toolbar input,
  .toolbar select {
    min-height: 3rem;
    font-size: max(1.05rem, 16px);
    padding: 0.7rem 1rem;
  }

  .reason-chip {
    min-height: 4.75rem;
    font-size: 1.2rem;
    padding: 1.1rem 1rem;
  }

  .record-item {
    min-height: 5rem;
    padding: 1.15rem 1.25rem;
  }

  .record-item .name {
    font-size: 1.15rem;
  }

  .record-item .meta {
    font-size: 1rem;
  }

  .card {
    padding: 1.25rem 1.35rem;
  }

  .card h2 {
    font-size: 1.15rem;
  }

  .field label {
    font-size: 1rem;
  }

  .choice {
    min-height: 3rem;
    font-size: 1.05rem;
    padding: 0.65rem 1rem;
  }

  .brand h1 {
    font-size: 1.4rem;
  }

  .brand p {
    font-size: 1rem;
  }
}

/* Re-apply Dynamic Type after tablet root bump so system preference wins on Apple */
@supports (font: -apple-system-body) {
  @media (min-width: 768px) and (max-width: 1366px) {
    html {
      font: -apple-system-body;
      font-family: var(--font);
    }
  }
}

@media (min-width: 768px) {
  .main {
    padding: 1.35rem 1.75rem;
  }

  .modal-backdrop {
    align-items: center;
  }

  .modal {
    border-radius: 1.125rem;
    width: min(100%, 35rem);
  }

  .stats {
    gap: 0.9rem;
  }

  .stat-card .n {
    font-size: 1.85rem;
  }

  .reason-chip {
    min-height: 4.75rem;
    font-size: 1.18rem;
    padding: 1.1rem 1rem;
  }

  .toolbar input,
  .toolbar select,
  .toolbar .btn {
    min-height: 3rem;
  }
}

@media (min-width: 900px) {
  .app-shell.single-page .main {
    max-width: 50rem;
  }

  .tab-bar {
    max-width: 50rem;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
  }

  .tab-btn {
    min-height: 3.25rem;
    font-size: 1.08rem;
  }

  .record-item {
    min-height: 4.75rem;
    padding: 1.125rem 1.25rem;
  }

  .record-item .name {
    font-size: 1.12rem;
  }

  .record-item .meta {
    font-size: 0.95rem;
  }

  .btn {
    min-height: 3.25rem;
    padding: 0 1.35rem;
    font-size: 1.05rem;
  }

  .field input,
  .field select,
  .field textarea {
    font-size: max(1.05rem, 16px);
  }

  /* Prevent iOS zoom on focus: ≥16px, still scales with root */
  input,
  select,
  textarea {
    font-size: max(1rem, 16px);
  }
}

/* Coarse pointer (finger): larger hit targets */
@media (pointer: coarse) {
  :root {
    --tap: 3.5rem;
  }

  .reason-chip {
    min-height: 4.75rem;
    font-size: 1.16rem;
    padding: 1.1rem 0.9rem;
  }

  .record-item {
    min-height: 5rem;
  }

  .btn,
  .btn-sm,
  .btn-header-icon,
  .tab-btn,
  .choice {
    min-height: 3rem;
  }

  a,
  button,
  .record-item,
  .radio-row {
    /* Prefer comfortable finger spacing */
    touch-action: manipulation;
  }
}

/* iPad landscape: slightly wider content column, avoid cramped side gutters */
@media (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
  .app-shell.single-page .main {
    max-width: min(52rem, 92vw);
  }

  .tab-bar {
    max-width: min(52rem, 92vw);
  }

  .main {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

/* Legacy bottom-nav hidden (single-page app) */
.nav {
  display: none !important;
}

@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .modal-actions .btn-danger {
    margin-right: 0;
  }
}
