/* Reset + primitives shared by every LIFF entry, share page, and admin. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  min-height: 100vh;
  min-height: 100dvh;
  /* NOTE: no `transform` here — would make body a containing block for
     position:fixed descendants (like modal-backdrop) and break full-viewport
     overlay. Page-in animation lives on `main` below instead. */
}

/* Page-in animation moved to main so body has no transform → modal backdrop's
   `position: fixed; inset: 0` correctly references the viewport. */
main {
  animation: page-in var(--motion-medium) var(--ease-out) both;
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

img { max-width: 100%; display: block; }
button { font: inherit; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--primary-ink); text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

::selection { background: var(--accent-soft); color: var(--text); }

/* Typography */
h1 { font-size: var(--fs-h1); line-height: var(--lh-tight); margin: 0 0 var(--space-3); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-h2); line-height: var(--lh-tight); margin: var(--space-5) 0 var(--space-2); font-weight: 700; }
h3 { font-size: var(--fs-lg); line-height: var(--lh-tight); margin: var(--space-3) 0 var(--space-1); font-weight: 600; }
p  { margin: 0 0 var(--space-3); }

.muted    { color: var(--text-muted); }
.faint    { color: var(--text-faint); }
.small    { font-size: var(--fs-sm); }
.tiny     { font-size: var(--fs-xs); }
.center   { text-align: center; }
.bold     { font-weight: 600; }
.primary  { color: var(--primary-ink); }
.accent   { color: var(--accent); }
.is-error { color: var(--danger); }
.is-success { color: var(--success); }

/* Layout */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) calc(var(--space-7) + var(--safe-bottom));
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  /* List items fade+rise; staggered via inline delay */
  animation: card-in var(--motion-medium) var(--ease-out) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: var(--surface);
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  min-width: 88px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease),
              opacity var(--motion-fast) var(--ease),
              background var(--motion-fast) var(--ease);
}
.btn:hover,
.btn:focus-visible {
  background: var(--primary-ink);
  outline: none;
  box-shadow: var(--shadow-press);
}
.btn:active { transform: scale(0.97); }
.btn[disabled],
.btn.is-loading {
  opacity: 0.7;
  cursor: progress;
  pointer-events: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover,
.btn-secondary:focus-visible {
  background: var(--surface-2);
  color: var(--primary-ink);
  box-shadow: var(--shadow-press);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); box-shadow: none; }

.btn-danger { background: var(--danger); }
.btn-danger:hover, .btn-danger:focus-visible { background: #b73f3b; }

/* Inputs */
input[type="text"],
input[type="password"],
input[type="email"],
textarea {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--motion-fast) var(--ease),
              box-shadow var(--motion-fast) var(--ease);
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-press);
}

/* Tag / chip */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: var(--radius-pill);
}
.tag-mint   { background: var(--primary-soft); color: var(--primary-ink); }
.tag-peach  { background: var(--accent-soft); color: #a04e2f; }
.tag-warn   { background: var(--warning-soft); color: #8d5618; }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-ok     { background: var(--success-soft); color: #2c7a3f; }

/* Status bar — sits below header, animates text changes */
.status-bar {
  min-height: 24px;
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-warm);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  transition: background var(--motion-medium) var(--ease),
              color var(--motion-medium) var(--ease);
}
.status-bar.is-error   { background: var(--danger-soft); color: var(--danger); }
.status-bar.is-success { background: var(--success-soft); color: #2c7a3f; }
.status-bar.is-busy {
  background: var(--primary-soft);
  color: var(--primary-ink);
}
.status-bar.is-busy::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: var(--space-2);
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 1s var(--ease) infinite;
  vertical-align: middle;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50%      { opacity: 1;   transform: scale(1.2); }
}

/* Skeleton placeholders — shown while data loading. */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--border-soft) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
  border-radius: var(--radius-sm);
  display: block;
}
.skeleton-text  { height: 16px; margin-bottom: var(--space-2); }
.skeleton-line  { height: 12px; margin-bottom: var(--space-2); width: 80%; }
.skeleton-line.short { width: 50%; }
.skeleton-img   { height: 180px; border-radius: var(--radius); margin-bottom: var(--space-3); }
.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* Bottom sheet — slides up from bottom */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(43, 33, 24, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 1000;
  animation: fade-in var(--motion-medium) var(--ease-out) both;
}
.sheet {
  background: var(--surface);
  width: 100%;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4)
           calc(var(--space-6) + var(--safe-bottom));
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -8px 32px rgba(43, 33, 24, 0.2);
  animation: sheet-rise var(--motion-medium) var(--ease-soft) both;
}
.sheet::before {
  content: "";
  display: block;
  width: 36px; height: 4px;
  margin: 0 auto var(--space-4);
  background: var(--border);
  border-radius: var(--radius-pill);
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes sheet-rise {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Hero / mascot helper (img element with optional state class) */
.mascot {
  width: 120px; height: 120px;
  object-fit: contain;
  margin: 0 auto var(--space-3);
  display: block;
  transition: transform var(--motion-slow) var(--ease-soft);
}
.mascot.is-bobbing { animation: mascot-bob 2.5s var(--ease) infinite; }
@keyframes mascot-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* Reveal-on-mount utility for list items (use inline --i counter for stagger) */
.fade-rise {
  animation: card-in var(--motion-medium) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

/* Spinner — used in legacy spots; prefer skeletons */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-muted);
}
.empty-state .hint { font-size: var(--fs-sm); margin-top: var(--space-2); }

/* Visually-hidden (for a11y labels) */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Header (no status bar; modals do all feedback now) ──────────────── */
.feature-header {
  margin-bottom: var(--space-3);
  text-align: center;                  /* centre both title + intro */
}
.feature-header .feature-title {
  margin: 0 0 var(--space-1);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.feature-header .intro {
  margin: 0 0 var(--space-3);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* Feature hero banner — only shown on LIFF main view */
.feature-hero {
  width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
  background: var(--surface-2);        /* placeholder before image loads */
  aspect-ratio: 16 / 9;                /* matches Gemini-generated 16:9 source */
  display: block;
}

/* Full-page LIFF guard — shown when LIFF init fails (e.g. opened outside LINE).
   Replaces the feature UI entirely so it's no longer visible / clickable. */
.liff-guard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 70vh;
  padding: var(--space-5) var(--space-4);
  gap: var(--space-3);
}
.liff-guard-logo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--surface-2);
  display: block;
}
.liff-guard .brand-wordmark {
  font-size: var(--fs-h1);
  letter-spacing: 0.04em;
}
.liff-guard-message {
  max-width: 360px;
  margin: var(--space-2) auto 0;
}
.liff-guard-message h2 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-h2);
  color: var(--primary-ink);
}
.liff-guard-message p {
  margin: 0 0 var(--space-1);
  color: var(--text-muted);
  line-height: 1.6;
}
.liff-guard-err {
  margin-top: var(--space-3) !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  opacity: 0.6;
}

/* Report footer disclaimer — only used at the very bottom of health_report
   output (LIFF result modal + share page). Soft cream card with a quiet info
   icon — looks like part of the report's design language, not a bolt-on. */
.report-disclaimer {
  margin: var(--space-4) 0 0;
  padding: var(--space-3);
  background: var(--surface-2);
  border-radius: var(--radius);
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  font-size: var(--fs-xs);
  line-height: 1.65;
  color: var(--text-muted);
}
.report-disclaimer .disclaimer-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: italic;
  font-family: Georgia, serif;
  font-size: 13px;
  margin-top: 1px;
}
.report-disclaimer p { margin: 0; }

/* Privacy reminder — peach-tinted card above the upload area on medicine /
   exam features, asking users to mask PII before snapping the photo. */
.privacy-notice {
  display: block;
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--text);
  line-height: 1.55;
}
.privacy-notice strong {
  display: block;
  font-weight: 600;
  margin-bottom: var(--space-1);
  color: #8a3f24;                       /* deeper peach for emphasis */
}

/* Brand row — used on share pages for logo + wordmark identification */
.brand-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.brand-logo {
  width: 44px;
  height: 44px;
  display: block;
  flex-shrink: 0;
  background: var(--surface-2);         /* placeholder before image loads */
  border-radius: 50%;
}
.brand-wordmark {
  font-size: var(--fs-xl);
  font-weight: 600;
  letter-spacing: 0.02em;
}
/* 中英文分色對應 logo 兩個圈圈 */
.brand-wordmark .brand-zh {
  color: var(--primary);                /* mint #4fa08c — 綠圈 */
  font-weight: 700;
}
.brand-wordmark .brand-en {
  color: var(--accent);                 /* peach #f2a88f — 桃圈 */
  font-weight: 700;
  margin-left: 0.4em;
}

/* Top action row — 2 prominent buttons side-by-side (歷史 / 分享) */
.top-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.top-action-row .btn { width: 100%; }

/* ── Top-row pill buttons — brand-tokened (mint + peach) ──────────────── */
.btn-history {
  background: var(--primary-soft);
  color: var(--primary-ink);
  border: 2px solid var(--primary);
  box-shadow: none;
}
.btn-history:hover, .btn-history:focus-visible {
  background: #c5e2d8;       /* slightly deeper mint */
  color: var(--primary-ink);
}

.btn-share {
  background: var(--accent-soft);
  color: #8a3f24;            /* deep peach for legibility on accent-soft */
  border: 2px solid var(--accent);
  box-shadow: none;
}
.btn-share:hover, .btn-share:focus-visible {
  background: #fbd5c2;       /* slightly deeper peach */
  color: #8a3f24;
}

.btn-generate {
  background: linear-gradient(135deg, #EDE7FE, #DDD2FA);   /* soft pastel purple */
  color: #5B3B9B;
  border: 1px solid #C4B5FD;
  width: 100%;
  padding: var(--space-3) var(--space-4);
}
.btn-generate:hover, .btn-generate:focus-visible {
  background: linear-gradient(135deg, #DDD2FA, #C8B7F4);
  color: #4C2E87;
}

/* Upload zone — brand-tokened (warm cream + dashed peach / mint borders) */
.upload-zone-camera {
  background: var(--surface-warm);
  border: 2px dashed var(--accent);
  color: var(--primary-ink);
}
.upload-zone-camera:hover, .upload-zone-camera:focus-visible {
  background: var(--accent-soft);
  border-color: #de8865;
}
.upload-zone-gallery {
  background: var(--surface-2);
  border: 2px dashed var(--primary);
  color: var(--primary-ink);
}
.upload-zone-gallery:hover, .upload-zone-gallery:focus-visible {
  background: var(--primary-soft);
  border-color: var(--primary-ink);
}

/* ── Progress: spinner + message ──────────────────────────────────────── */
.progress-spinner {
  width: 48px;
  height: 48px;
  margin: var(--space-3) auto;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-message { color: var(--text); margin: var(--space-2) 0 var(--space-3); }

/* ── Centered floating modal ──────────────────────────────────────────── */
/* Lock body scroll while modal open so the underlying page doesn't jump */
body.modal-open { overflow: hidden; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-start;            /* modal sticks to top of safe area */
  justify-content: center;
  /* Top padding clears LIFF / iOS notch / Android status bar so × is visible.
     Bottom padding accounts for iOS home indicator. */
  padding-left: var(--space-3);
  padding-right: var(--space-3);
  padding-top:    max(64px, env(safe-area-inset-top, 0px) + 48px);
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px) + 12px);
  /* No overflow — modal-body handles internal scroll so × stays sticky on modal */
  animation: modal-fade var(--motion-fast) var(--ease-out);
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 480px;
  /* Exact fit: viewport minus same padding as backdrop. dvh accounts for iOS
     dynamic URL bar; falls back to vh on older browsers. */
  max-height: calc(100vh
    - max(64px, env(safe-area-inset-top, 0px) + 48px)
    - max(20px, env(safe-area-inset-bottom, 0px) + 12px)
  );
  max-height: calc(100dvh
    - max(64px, env(safe-area-inset-top, 0px) + 48px)
    - max(20px, env(safe-area-inset-bottom, 0px) + 12px)
  );
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modal-rise var(--motion-medium) var(--ease-out);
}
@keyframes modal-rise {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* × close button — absolute on modal so it stays put while body scrolls */
.modal-close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: background var(--motion-fast) var(--ease-out),
              transform var(--motion-fast) var(--ease-out);
}
.modal-close-btn:hover, .modal-close-btn:focus-visible {
  background: var(--surface-2);
  transform: scale(1.05);
}
.modal-close-btn:active { transform: scale(0.95); }
.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4);
  -webkit-overflow-scrolling: touch;
}
.modal-title {
  margin: 0 32px var(--space-2) 0;  /* leave room on right for × */
  font-size: var(--fs-lg);
}
.modal-title.center { margin: 0 0 var(--space-2); padding-right: 0; }
.modal-footer-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.modal-footer-actions .btn { flex: 1 1 auto; }

/* Centered backdrop variant: short modals (progress / warning) sit in the
   vertical middle instead of clinging to the safe-area top. */
.modal-backdrop.is-center { align-items: center; }

/* Bare modal variant: no white frame — spinner + label float directly on
   the dim backdrop. Used for the upload "分析中" progress state. */
.modal.is-bare {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  max-height: none;
  overflow: visible;
  animation: none;
}
.modal.is-bare .modal-close-btn { display: none; }
.modal.is-bare .modal-body {
  padding: var(--space-3);
  overflow: visible;
  text-align: center;
}
.modal.is-bare .progress-spinner {
  width: 56px;
  height: 56px;
  border-color: rgba(255, 255, 255, 0.25);
  border-top-color: #ffffff;
}
.modal.is-bare .progress-message {
  color: #ffffff;
  font-size: var(--fs-lg);
  font-weight: 500;
  margin: var(--space-2) 0 0;
}

/* ── View navigation (history list / records list) ───────────────────── */
.view-header {
  /* 3-column grid: 1fr (back btn) | auto (title) | 1fr (spacer)
     — title 永遠在 viewport 正中央，跟返回鈕無關 */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.view-header .btn-back { justify-self: start; }
.btn-back {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-back:hover, .btn-back:focus-visible {
  background: var(--surface-2);
}
.btn-back:active { transform: scale(0.96); }
.view-title {
  margin: 0;
  font-size: var(--fs-h2);
  grid-column: 2;                       /* 中欄 */
  text-align: center;
  color: var(--primary-ink);            /* 跟 LIFF 首頁 feature-title 同色 */
  min-width: 0;
}
.view-loading {
  text-align: center;
  padding: var(--space-5) 0;
}

/* ── Upload zones (camera + gallery) ──────────────────────────────────── */
.upload-area { margin-bottom: var(--space-4); }
.upload-zones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.upload-zone {
  appearance: none;
  border: 2px dashed var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out),
              transform var(--motion-fast) var(--ease-out);
}
.upload-zone:hover, .upload-zone:focus-visible {
  border-color: var(--accent);
  background: var(--surface-2);
}
.upload-zone:active { transform: scale(0.98); }
.upload-zone .zone-icon { font-size: 2rem; line-height: 1; }
.upload-zone .zone-label { font-weight: 600; font-size: var(--fs-base); }
.upload-zone .zone-hint  { font-size: var(--fs-xs); color: var(--text-muted); }

/* ── In-sheet button row ─────────────────────────────────────────────── */
.sheet-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.sheet-actions .btn { flex: 1 1 auto; }
.sheet-title { margin-top: 0; }

/* Detail sheet image */
.detail-img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
  background: var(--surface-2);
}
.detail-body { margin-top: var(--space-2); }

/* ── Share URL readonly input ────────────────────────────────────────── */
.share-url-box {
  width: 100%;
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  word-break: break-all;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: var(--space-2) 0;
}

/* ── History list (compact rows: thumb + meta) ───────────────────────── */
.section-h2 {
  font-size: var(--fs-h2);
  margin: 0 0 var(--space-2);
}
.history-area.is-hidden { display: none; }
.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.history-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out),
              transform var(--motion-fast) var(--ease-out);
}
.history-row:hover, .history-row:focus-visible {
  background: var(--surface-2);
}
.history-row:active { transform: scale(0.99); }
.history-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  flex-shrink: 0;
}
.history-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-time {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.history-summary {
  font-size: var(--fs-sm);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-chevron {
  color: var(--text-faint);
  font-size: 1.5rem;
  flex-shrink: 0;
  line-height: 1;
}

/* Skeleton variants for the compact row */
.skeleton-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* Larger primary action button (for health_report Generate) */
.btn-large { padding: var(--space-3) var(--space-4); font-size: var(--fs-base); }

/* Feature title accent */
.feature-title { color: var(--primary-ink); }

/* ── Status badges (oval) — exam / measure ────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.4;
  vertical-align: middle;
}
.status-badge.status-ok      { background: #DCFCE7; color: #15803D; }
.status-badge.status-warn    { background: #FEF3C7; color: #92400E; }
.status-badge.status-danger  { background: #FEE2E2; color: #B91C1C; }
.status-badge.status-unknown { background: var(--surface-2); color: var(--text-muted); }

/* ── Score badge (health_report) — solid colored oval with number ──── */
.score-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  font-weight: 700;
  color: white;
  font-size: var(--fs-sm);
  line-height: 1.4;
  min-width: 48px;
  text-align: center;
  vertical-align: middle;
}
.score-badge.score-excellent { background: #059669; }
.score-badge.score-good      { background: #10B981; }
.score-badge.score-fair      { background: #F59E0B; }
.score-badge.score-poor      { background: #EF4444; }
.score-badge.score-unknown   { background: #94A3B8; }

/* ── Accordion (drug / exam item) ─────────────────────────────────────── */
.drug-accordion,
.exam-accordion {
  margin: var(--space-2) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.drug-accordion > summary,
.exam-accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  user-select: none;
}
.drug-accordion > summary::-webkit-details-marker,
.exam-accordion > summary::-webkit-details-marker { display: none; }
.drug-accordion > summary::after,
.exam-accordion > summary::after {
  content: "▸";
  margin-left: auto;
  color: var(--text-faint);
  transition: transform var(--motion-fast);
  flex-shrink: 0;
}
.drug-accordion[open] > summary::after,
.exam-accordion[open] > summary::after { transform: rotate(90deg); }
.drug-accordion > dl,
.exam-accordion > dl {
  margin: 0;
  padding: 0 var(--space-3) var(--space-3);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px var(--space-3);
  border-top: 1px solid var(--border);
}
.drug-accordion dt,
.exam-accordion dt {
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  padding-top: 6px;
}
.drug-accordion dd,
.exam-accordion dd {
  margin: 0;
  padding-top: 6px;
  font-size: var(--fs-sm);
}

.drug-summary { flex-wrap: wrap; }
.drug-summary .drug-name { font-weight: 600; }
.drug-summary .drug-use { flex-basis: 100%; }

.exam-summary-row { gap: var(--space-2); }
.exam-summary-row .exam-item-name {
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Chart container ──────────────────────────────────────────────────── */
.chart-container {
  margin: var(--space-3) 0;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.chart-title { margin-bottom: var(--space-1); }
.chart-svg { display: block; }
.chart-legend {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  margin-top: var(--space-1);
  flex-wrap: wrap;
}
.chart-legend-item { display: inline-flex; align-items: center; gap: 4px; }
.chart-legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
}

.chart-stats {
  margin: var(--space-2) 0;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.chart-stats table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.chart-stats th, .chart-stats td {
  text-align: center;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.chart-stats thead th { color: var(--text-muted); font-weight: 500; }
.chart-stats tbody th { text-align: left; color: var(--text-muted); font-weight: 500; }
.chart-stats tbody tr:last-child th,
.chart-stats tbody tr:last-child td { border-bottom: none; }

.history-extras { margin-bottom: var(--space-4); }

/* ── Measure split (Level 1: 血壓 / 血糖) ─────────────────────────────── */
.measure-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
/* Single-category fallback: stretch the lone card across both columns */
.measure-split:has(> .measure-category-card:only-child) {
  grid-template-columns: 1fr;
}
.measure-split.is-single { grid-template-columns: 1fr; }   /* JS fallback */

.measure-category-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-4);
  min-height: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  transition: background var(--motion-fast), transform var(--motion-fast);
}
.measure-category-card:hover, .measure-category-card:focus-visible {
  background: var(--surface-2);
}
.measure-category-card:active { transform: scale(0.98); }
.measure-category-card.blood-pressure { border-left: 5px solid #EF4444; }
.measure-category-card.blood-glucose  { border-left: 5px solid #10B981; }
.measure-category-card .cat-title {
  font-size: 1.15rem;
  font-weight: 600;
}
.measure-category-card .cat-count { margin: 0; }
.measure-category-card .history-chevron {
  position: absolute;
  bottom: var(--space-2);
  right: var(--space-2);
}

.measure-chart-wrap { margin-bottom: var(--space-2); }
.measure-section { margin-bottom: var(--space-4); }
.subsection-h3 {
  font-size: var(--fs-sm);
  margin: var(--space-3) 0 var(--space-1);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Share button — LINE 好友 (cross-brand colour, kept intentionally) ── */
.btn-line-share {
  background: #06C755;
  color: white;
  border: 2px solid white;            /* white separator from brand palette */
  outline: 1px solid #06C755;         /* keeps LINE green outer edge */
  outline-offset: -1px;
  box-shadow: none;
}
.btn-line-share:hover, .btn-line-share:focus-visible {
  background: #04A648;
  color: white;
}

/* ── Share page header (general browser context) ─────────────────────── */
.share-header {
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}
.share-header h1 { margin: 0 0 var(--space-1); }
.share-header .share-meta { margin: 0 0 var(--space-2); }

/* Section title visual lift — clear separator between extras / list / etc */
.section-h2 {
  margin: var(--space-4) 0 var(--space-2);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.history-extras > .section-h2:first-child { margin-top: 0; }

/* Empty-state visual (when no records yet) */
.empty-state {
  padding: var(--space-5) var(--space-3);
}
.empty-icon {
  margin: 0 auto var(--space-3);
  opacity: 0.7;
}
