/* ==========================================================
   新手家醫看診助手 — 介面樣式
   調性：安靜、紙感、編輯式排版；主題色由主題名稱雜湊而來（--hue）
   ========================================================== */

:root {
  --paper: #f5f3ee;
  --surface: #ffffff;
  --ink: #16232c;
  --ink-2: #3a4a55;
  --muted: #5f6b74;      /* 4.9:1 on paper */
  --faint: #66717a;      /* 4.5:1 on paper：最弱的文字層級 */
  --mark: #a3acb2;       /* 非文字的裝飾線條與圖示 */
  --line: #e4dfd5;
  --line-2: #eeeae2;
  --accent: #1f5e8c;
  --accent-ink: #164a70;
  --accent-soft: #e6eef5;
  --ok: #2a7262;
  --ok-soft: #e5f2ee;
  --warn: #93600f;
  --warn-soft: #fbf0dc;
  --danger: #b4432f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(22, 35, 44, .05);
  /* 靜止的紙頁：一層貼近的邊緣陰影＋一層柔和的落影，讓卡片平時就看得出疊在紙上 */
  --shadow-rest: 0 1px 1px rgba(22, 35, 44, .04), 0 2px 4px -1px rgba(22, 35, 44, .05), 0 8px 18px -10px rgba(22, 35, 44, .16);
  --shadow: 0 1px 2px rgba(22, 35, 44, .04), 0 12px 32px -12px rgba(22, 35, 44, .18);
  --serif: "Noto Serif TC", "Songti TC", serif;
  /* Source Sans 3 與 Noto Sans TC（即思源黑體）是同一家族，中英混排筆畫一致 */
  --sans: "Source Sans 3", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.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; }

/* ---------- 版面外框 ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  flex: 0 0 232px; display: flex; flex-direction: column;
  padding: 28px 16px 22px; border-right: 1px solid var(--line); background: #fbfaf7;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 32px; color: var(--ink); text-decoration: none; }
.brand-mark { display: block; width: 38px; height: 38px; }
.brand-text { display: grid; font-size: 12px; color: var(--muted); line-height: 1.3; }
.brand-text strong { color: var(--ink); font-family: var(--serif); font-size: 18px; letter-spacing: .04em; }
.nav-list { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500; transition: background .2s;
}
.nav-item em { font-style: normal; }
.nav-item:hover { background: rgba(22, 35, 44, .04); }
.nav-item.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: grid; gap: 14px; padding: 0 6px; }
.ai-status {
  justify-self: start; display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px 5px 8px; border-radius: 999px;
  background: var(--ok-soft); color: var(--ok); font-size: 12px; font-weight: 600;
}
.ai-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgba(47, 125, 107, .15); }
.ai-status.demo { background: var(--warn-soft); color: var(--warn); }
.privacy-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.privacy-note b { display: block; color: var(--ink-2); font-weight: 600; }

main { flex: 1; min-width: 0; }
.content { max-width: 1280px; margin: 0 auto; padding: 56px 56px 96px; }

/* ---------- 按鈕 ---------- */
.primary-button, .secondary-button, .danger-button, .link-button {
  border-radius: 999px; font-weight: 600; font-size: 14px; transition: transform .15s var(--ease), background .2s, box-shadow .2s;
}
.primary-button { border: 0; padding: 11px 20px; background: var(--ink); color: #fff; }
.primary-button:hover { background: #24343f; }
.primary-button:active { transform: scale(.98); }
.primary-button:disabled { background: #e3e0d8; color: var(--ink-2); cursor: not-allowed; }
.secondary-button { border: 1px solid var(--line); padding: 10px 18px; background: var(--surface); color: var(--ink); }
.secondary-button:hover { border-color: #cfc8bb; }
.danger-button { border: 1px solid #ecc9c1; padding: 10px 18px; background: var(--surface); color: var(--danger); }
.link-button { border: 0; padding: 4px 8px; background: none; color: var(--accent); font-size: 13px; }
.link-button:hover { background: var(--accent-soft); }
.full-button { width: 100%; margin-top: 12px; padding: 13px; }

/* ---------- 學習庫：開頭 ---------- */
.library-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.library-hero h1 { margin: 0; font-family: var(--serif); font-size: clamp(30px, 3.4vw, 44px); line-height: 1.22; letter-spacing: .01em; font-weight: 700; }
.hero-meta { margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.hero-meta b { color: var(--ink); font-weight: 600; }
.mobile-break { display: none; }
.add-button { display: inline-flex; align-items: center; gap: 8px; padding: 13px 22px; box-shadow: var(--shadow); }
.add-button span { font-size: 18px; line-height: 1; }

.library-search {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 18px; margin-bottom: 40px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-sm);
  transition: border-color .2s, box-shadow .2s;
}
.library-search:focus-within { border-color: #c9d6e0; box-shadow: 0 0 0 4px var(--accent-soft); }
.library-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 10px 4px; font-size: 15px; }
.library-search input::placeholder { color: var(--faint); }

/* ---------- 學習庫：主題索引 ---------- */
.library-layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); gap: 48px; align-items: start; }
.topic-index { position: sticky; top: 32px; }
.topic-index-head { display: flex; justify-content: space-between; align-items: center; padding: 0 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.topic-index-head span { font-size: 12px; font-weight: 600; letter-spacing: .14em; color: var(--muted); }
.topic-list { display: grid; gap: 1px; max-height: calc(100vh - 140px); overflow: auto; padding-right: 4px; }
.topic-link {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 12px;
  padding: 9px 10px; border: 0; border-radius: var(--radius-sm); background: none; text-align: left; color: var(--ink-2); font-size: 14px;
  transition: background .2s;
}
.topic-link:hover { background: rgba(22, 35, 44, .04); }
.topic-link.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line); }
.topic-link .dot { width: 8px; height: 8px; border-radius: 50%; background: hsl(var(--hue, 210) 40% 52%); }
.topic-link.all .dot { background: var(--ink); }
.topic-link small { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- 學習庫：主題書架 ---------- */
.shelf { margin-bottom: 56px; }
.shelf-head { display: flex; align-items: baseline; gap: 14px; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.shelf-head h2 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 700; letter-spacing: .01em; }
.shelf-head h2::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 12px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); vertical-align: 3px; }
.shelf-count { color: var(--muted); font-size: 13px; }
.shelf-head .link-button { margin-left: auto; }

.topic-hero { padding: 8px 0 28px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.topic-hero h2 { margin: 0; font-family: var(--serif); font-size: clamp(28px, 3vw, 38px); font-weight: 700; line-height: 1.25; }
.topic-hero-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.results-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 20px; }
.results-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; }
.results-head span { color: var(--muted); font-size: 13px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 20px; }
.note-card {
  position: relative; display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink);
  box-shadow: var(--shadow-sm); transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .35s;
  animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms);
}
.note-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: #d9d2c5; }
.note-card:hover .cover img { transform: scale(1.04); }
.cover { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: hsl(var(--hue) 35% 94%); }
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; transition: transform .6s var(--ease); }
.cover-text { position: absolute; inset: 0; padding: 22px 20px; display: flex; flex-direction: column; justify-content: space-between; }
.cover-text blockquote {
  margin: 0; font-family: var(--serif); font-size: 15px; line-height: 1.7; color: hsl(var(--hue) 30% 22%);
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.cover-text blockquote::before { content: "“"; display: block; height: 22px; font-size: 40px; line-height: 1; color: hsl(var(--hue) 40% 52%); }
.wave { display: flex; align-items: center; gap: 3px; height: 54px; }
.wave i { flex: 1; max-width: 4px; border-radius: 2px; background: hsl(var(--hue) 40% 48%); opacity: .75; }
.cover-kind {
  position: absolute; left: 12px; bottom: 12px; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px); border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.card-body { display: grid; gap: 8px; padding: 16px 18px 18px; }
.card-topic { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.card-topic::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); }
.card-body b { font-size: 15px; font-weight: 600; line-height: 1.45; }
.card-body p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; justify-content: space-between; gap: 10px; padding-top: 10px; margin-top: 2px; border-top: 1px solid var(--line-2); color: var(--faint); font-size: 12px; }
.card-meta span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta span:last-child { flex: none; font-variant-numeric: tabular-nums; }

.empty-state { padding: 72px 24px; text-align: center; border: 1px dashed #d6cfc1; border-radius: var(--radius); background: rgba(255, 255, 255, .5); }
.empty-state .empty-mark { font-family: var(--serif); font-size: 44px; color: #c8bfae; }
.empty-state h3 { margin: 8px 0 6px; font-family: var(--serif); font-size: 22px; }
.empty-state p { max-width: 380px; margin: 0 auto 20px; color: var(--muted); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- 對話框 ---------- */
.app-dialog {
  width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: 22px;
  background: var(--surface); color: var(--ink); box-shadow: 0 40px 100px -20px rgba(22, 35, 44, .45);
}
.app-dialog[open] { animation: pop .3s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.app-dialog::backdrop { background: rgba(22, 35, 44, .38); backdrop-filter: blur(3px); }
.wide-dialog { width: min(920px, calc(100% - 32px)); }
.app-dialog form, .dialog-body, .viewer { padding: 28px 32px 26px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.dialog-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; line-height: 1.3; }
.dialog-intro { margin: 10px 0 0; color: var(--muted); }
.close-button { flex: none; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--paper); color: var(--muted); font-size: 20px; line-height: 1; }
.close-button:hover { color: var(--ink); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.notice { margin: 16px 0 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--paper); color: var(--muted); font-size: 13px; }
.form-error { min-height: 20px; margin: 14px 0 0; color: var(--danger); font-size: 13px; }

.app-dialog label { display: grid; gap: 6px; margin-top: 16px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.app-dialog input:not([type="checkbox"]):not([type="file"]), .app-dialog textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fdfcfa;
  font-size: 14px; font-weight: 400; color: var(--ink); transition: border-color .2s, box-shadow .2s, background .2s;
}
.app-dialog input:focus, .app-dialog textarea:focus { outline: 0; border-color: #b9cad8; background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.app-dialog textarea { resize: vertical; line-height: 1.65; }

/* ---------- 新增筆記：步驟 ---------- */
.step { margin-top: 20px; }
.mode-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin-bottom: 18px; background: var(--paper); border-radius: 14px; }
.mode-tab { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 11px; border: 0; border-radius: 11px; background: none; color: var(--muted); font-size: 14px; font-weight: 600; transition: background .2s, color .2s, box-shadow .2s; }
.mode-tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.dropzone {
  display: grid !important; place-items: center; align-content: center; gap: 6px; min-height: 240px; margin: 0 !important; padding: 24px;
  border: 1.5px dashed #d3cbbd; border-radius: var(--radius); background: #fcfbf8; text-align: center; cursor: pointer; transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone b { color: var(--ink); font-size: 16px; }
.dropzone small { max-width: 360px; color: var(--muted); font-size: 13px; font-weight: 400; }
.ai-note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
#textInput { min-height: 200px; }
.recorder { display: flex; align-items: center; gap: 18px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: #fcfbf8; }
.record-button { flex: 0 0 68px; width: 68px; height: 68px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); }
.record-button span { width: 26px; height: 26px; border-radius: 50%; background: var(--danger); transition: border-radius .2s, transform .2s var(--ease); }
.record-button.recording { animation: pulse 1.4s infinite; }
.record-button.recording span { border-radius: 6px; transform: scale(.85); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(180, 67, 47, .3); } 50% { box-shadow: 0 0 0 12px rgba(180, 67, 47, 0); } }
.recorder b { display: block; font-size: 14px; }
.record-timer { font-family: var(--sans); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.or-divider { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--faint); font-size: 12px; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.file-button { display: grid !important; place-items: center; margin-top: 0 !important; cursor: pointer; }
.loading-step { display: grid; justify-items: center; gap: 6px; padding: 64px 20px; text-align: center; }
.loading-step b { font-size: 16px; }
.loading-step p { margin: 0; color: var(--muted); font-size: 13px; }
.spinner { width: 40px; height: 40px; margin-bottom: 10px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ai-result { margin: 0 0 18px; padding: 11px 14px; border-radius: var(--radius-sm); background: var(--ok-soft); color: var(--ok); font-size: 13px; font-weight: 500; }
.ai-result.warn { background: var(--warn-soft); color: var(--warn); }
.library-form-grid { display: grid; grid-template-columns: 300px 1fr; gap: 28px; }
.library-form-grid.single { grid-template-columns: 1fr; }
.preview-column { position: sticky; top: 0; align-self: start; }
.preview-column img { display: block; width: 100%; max-height: 440px; object-fit: contain; border-radius: var(--radius-sm); background: var(--paper); }
.audio-preview { display: grid; justify-items: center; gap: 10px; padding: 28px 14px; border-radius: var(--radius-sm); background: var(--paper); }
.audio-preview span { font-size: 28px; color: var(--danger); }
.audio-preview audio, .viewer-audio { width: 100%; }
.field-column > label:first-child { margin-top: 0; }
.topic-field { margin-top: 16px; }
.topic-field > label { margin-top: 0 !important; display: flex !important; align-items: center; gap: 8px; }
.topic-field input { margin-top: 6px; }
.topic-badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.topic-badge.existing { background: var(--ok-soft); color: var(--ok); }
.topic-badge.new { background: var(--accent-soft); color: var(--accent-ink); }
.related-topics { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.related-topics button {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 12px; color: var(--ink-2);
}
.related-topics button::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); }
.related-topics button:hover { border-color: var(--accent); color: var(--accent); }
.source-fields { margin: 18px 0 0; padding: 4px 14px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.source-fields legend { padding: 0 6px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.source-fields legend em { margin-left: 6px; color: var(--muted); font-style: normal; font-weight: 400; }
.two-col { display: grid; grid-template-columns: 1fr 96px; gap: 12px; }
.back-button { margin-right: auto; }

/* ---------- 檢視筆記 ---------- */
.viewer-image { display: block; margin-top: 20px; overflow: hidden; border-radius: var(--radius-sm); background: var(--paper); text-align: center; }
.viewer-image img { display: block; max-width: 100%; max-height: 62vh; margin: 0 auto; object-fit: contain; }
.viewer-audio { margin-top: 20px; }
.viewer-source { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--paper); font-size: 13px; }
.viewer-source a { margin-left: auto; font-weight: 600; text-decoration: none; }
.viewer-block { margin-top: 18px; font-size: 14px; }
.viewer-block > b, .viewer-block summary b { font-size: 13px; color: var(--ink-2); }
.viewer-block summary { cursor: pointer; }
.viewer-block p { margin: 8px 0 0; color: var(--ink-2); line-height: 1.75; white-space: pre-wrap; }
.ai-label { margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: 11px; font-weight: 600; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.card-tags span { padding: 3px 10px; border-radius: 999px; background: var(--paper); color: var(--ink-2); font-size: 12px; }
.viewer .dialog-actions .danger-button { margin-right: auto; }

/* ---------- AI 整理主題 ---------- */
.reorganize-body { margin-top: 18px; }
.reorganize-loading { display: grid; justify-items: center; gap: 10px; padding: 40px; color: var(--muted); }
.reorganize-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.reorganize-table th { padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
.reorganize-table td { padding: 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.reorganize-table td.old { color: var(--faint); text-decoration: line-through; text-decoration-color: #d0c8ba; }
.reorganize-table input { padding: 8px 11px !important; }
.reorganize-groups { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.reorganize-groups span { padding: 4px 10px; border-radius: 999px; background: hsl(var(--hue) 35% 94%); color: hsl(var(--hue) 30% 28%); font-size: 12px; font-weight: 600; }

/* ---------- 提示訊息 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50; padding: 12px 18px; border-radius: 999px; background: var(--ink); color: #fff;
  font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: .25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 響應式 ---------- */
@media (max-width: 1080px) {
  .library-layout { grid-template-columns: 1fr; gap: 24px; }
  .topic-index { position: static; }
  .topic-index-head { border: 0; margin: 0; padding: 0 0 8px; }
  .topic-list { display: flex; gap: 6px; max-height: none; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
  .topic-list::-webkit-scrollbar { display: none; }
  .topic-link { flex: none; grid-template-columns: 8px auto auto; gap: 8px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
  .topic-link.active { background: var(--ink); color: #fff; box-shadow: none; border-color: var(--ink); }
  .topic-link.active small { color: rgba(255, 255, 255, .7); }
  .topic-link.all.active .dot { background: #fff; }
}
@media (max-width: 860px) {
  .sidebar { flex-basis: 76px; padding: 24px 12px; }
  .brand { justify-content: center; padding: 0 0 28px; }
  .brand-text, .nav-item em, .privacy-note { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .sidebar-foot { padding: 0; justify-items: center; }
  .ai-status { font-size: 0; padding: 6px; }
  .ai-status::before { margin: 0; }
  .content { padding: 40px 28px 80px; }
  .library-form-grid { grid-template-columns: 1fr; }
  .preview-column { position: static; }
}
@media (max-width: 640px) {
  .sidebar { position: fixed; inset: auto 0 0 0; z-index: 20; height: auto; flex-direction: row; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); background: rgba(251, 250, 247, .94); backdrop-filter: blur(12px); }
  .brand, .sidebar-foot { display: none; }
  .nav-list { display: flex; width: 100%; justify-content: space-around; }
  .nav-item { flex-direction: column; gap: 2px; padding: 6px 14px; font-size: 11px; }
  .nav-item em { display: block; }
  .nav-item.active { box-shadow: none; background: none; color: var(--accent); }
  .content { padding: 28px 16px 110px; }
  .library-hero { flex-direction: column; align-items: stretch; gap: 20px; }
  .mobile-break { display: inline; }
  .add-button { justify-content: center; }
  .library-search { border-radius: var(--radius); padding: 8px 8px 8px 14px; margin-bottom: 28px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
  .card-body { padding: 12px 13px 14px; }
  .card-body p, .card-meta span:first-child { display: none; }
  .cover-text { padding: 14px; }
  .cover-text blockquote { font-size: 13px; -webkit-line-clamp: 4; }
  .shelf { margin-bottom: 40px; }
  .app-dialog { width: 100%; max-width: none; max-height: 92vh; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  .app-dialog form, .dialog-body, .viewer { padding: 22px 18px 20px; }
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- 學習庫：主題卡 ---------- */
.shelf-head.plain h2::before { display: none; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.topic-tile {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .35s;
  animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms);
}
.topic-tile:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: #d9d2c5; }
.tile-cover { position: relative; height: 150px; overflow: hidden; background: linear-gradient(135deg, hsl(var(--hue) 38% 93%), hsl(var(--hue) 30% 86%)); }
.tile-cover img { position: absolute; width: 62%; height: 120%; object-fit: cover; object-position: top; border-radius: 10px; box-shadow: 0 8px 24px -8px rgba(22, 35, 44, .35); transition: transform .5s var(--ease); }
.tile-cover.stack-1 img { left: 50%; top: 18px; width: 72%; transform: translateX(-50%); }
.tile-cover.stack-2 img:nth-child(1) { left: 10%; top: 26px; transform: rotate(-5deg); }
.tile-cover.stack-2 img:nth-child(2) { right: 10%; top: 16px; transform: rotate(4deg); }
.tile-cover.stack-3 img:nth-child(1) { left: 4%; top: 30px; width: 50%; transform: rotate(-7deg); }
.tile-cover.stack-3 img:nth-child(2) { left: 25%; top: 14px; width: 50%; z-index: 2; }
.tile-cover.stack-3 img:nth-child(3) { right: 4%; top: 30px; width: 50%; transform: rotate(7deg); }
.topic-tile:hover .tile-cover.stack-1 img { transform: translateX(-50%) translateY(-4px); }
.tile-glyph { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--serif); font-size: 64px; font-weight: 700; color: hsl(var(--hue) 30% 40% / .55); }
.tile-body { display: grid; gap: 10px; padding: 18px 20px 18px; }
.tile-body b { font-family: var(--serif); font-size: 19px; font-weight: 700; line-height: 1.35; }
.tile-body ul { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.tile-body li { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.tile-body li::before { content: "—"; margin-right: 8px; color: var(--faint); }
.tile-meta { display: flex; justify-content: space-between; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line-2); color: var(--faint); font-size: 12px; }
.tile-kinds { display: flex; gap: 10px; }
@media (max-width: 640px) { .topic-grid { grid-template-columns: 1fr 1fr; gap: 12px; } .tile-cover { height: 110px; } .tile-body { padding: 12px 13px 14px; } .tile-body b { font-size: 16px; } .tile-body ul, .tile-kinds { display: none; } }
.card-grid.row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1240px) and (min-width: 1081px) { .card-grid.row-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .card-grid.row-4 .note-card:nth-child(4) { display: none; } }
@media (max-width: 640px) { .card-grid.row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
.cover-text { padding-bottom: 50px; }
.cover-text blockquote { -webkit-line-clamp: 4; }
.card-grid.row-4 .cover-text blockquote { -webkit-line-clamp: 3; font-size: 14px; }
.topic-grid { grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); }
.tile-cover { height: 140px; }
@media (max-width: 1080px) { .library-layout { grid-template-columns: minmax(0, 1fr); } .topic-index, .library-main { min-width: 0; } }
@media (max-width: 640px) { .library-search input::placeholder { font-size: 14px; } }
@media (max-width: 640px) { .cover-text { padding-bottom: 44px; } .cover-text blockquote, .card-grid.row-4 .cover-text blockquote { -webkit-line-clamp: 2; } }

/* ==========================================================
   病歷與開藥
   ========================================================== */
.rx-hero { margin-bottom: 32px; }
.rx-switcher { display: flex; align-items: center; gap: 10px; }
.rx-switcher button { white-space: nowrap; }
.rx-switcher select {
  max-width: 300px; padding: 12px 38px 12px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font-size: 14px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.rx-layout { display: grid; grid-template-columns: minmax(380px, 5fr) minmax(0, 7fr); gap: 32px; align-items: start; }
.rx-card { padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.rx-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.rx-card-head h3 { margin: 0; font-family: var(--serif); font-size: 18px; }
.rx-card-head h3 small { margin-left: 6px; color: var(--muted); font-family: var(--sans); font-size: 13px; font-weight: 500; }
.rx-card label { display: grid; gap: 6px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.rx-card input, .rx-card textarea, .rx-card select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fdfcfa; font-size: 14px; font-weight: 400;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.rx-card input:focus, .rx-card textarea:focus, .rx-card select:focus { outline: 0; border-color: #b9cad8; background: #fff; box-shadow: 0 0 0 4px var(--accent-soft); }
.rx-card textarea { resize: vertical; line-height: 1.65; }
.muted-text { color: var(--faint); font-size: 13px; }

.patient-row { display: grid; grid-template-columns: 1.4fr .7fr .8fr; gap: 12px; }
.allergy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.field-label { margin-right: 4px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.allergy-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.allergy-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px 4px 12px; border-radius: 999px; background: #fbe9e5; color: var(--danger); font-size: 13px; font-weight: 600; }
.allergy-chip button, .condition-chip button { width: 32px; height: 32px; margin: -4px -4px -4px 0; border: 0; border-radius: 50%; background: none; color: inherit; font-size: 15px; line-height: 1; opacity: .6; }
.allergy-chip button:hover, .condition-chip button:hover { opacity: 1; background: rgba(0, 0, 0, .06); }
.allergy-add { position: relative; margin-left: auto; }
.chip-button { padding: 6px 12px; border: 1px dashed #cfc7b9; border-radius: 999px; background: none; color: var(--ink-2); font-size: 13px; }
.chip-button:hover { border-color: var(--accent); color: var(--accent); }
.chip-button.selected { border-style: solid; border-color: var(--danger); background: #fbe9e5; color: var(--danger); }
.allergy-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 10; width: 340px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pop-title { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .08em; }
.pop-title:not(:first-child) { margin-top: 14px; }
.allergen-options { display: flex; flex-wrap: wrap; gap: 6px; }
.search-results { display: grid; margin-top: 6px; max-height: 240px; overflow: auto; }
.search-results button { display: grid; gap: 2px; padding: 9px 10px; border: 0; border-radius: 8px; background: none; text-align: left; }
.search-results button:hover { background: var(--paper); }
.search-results b { font-size: 14px; }
.search-results span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.soap-card { display: grid; gap: 14px; }
.soap-card label span { font-family: var(--serif); font-size: 15px; color: var(--ink); }
.soap-hint { margin: -2px 0 0; color: var(--faint); font-size: 12px; }

.condition-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.condition-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: hsl(var(--hue) 35% 94%); color: hsl(var(--hue) 35% 24%); font-size: 14px;
}
.condition-chip small { color: hsl(var(--hue) 30% 26%); font-size: 11px; font-variant-numeric: tabular-nums; }
.condition-chip em { padding: 1px 7px; border-radius: 999px; background: rgba(255, 255, 255, .7); font-size: 11px; font-style: normal; font-weight: 600; }
.condition-add { margin-top: 12px; }
.condition-add select { width: auto; padding: 7px 12px; border-style: dashed; border-radius: 999px; color: var(--ink-2); font-size: 13px; background: none; }
.ai-other { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

.save-state { color: var(--faint); font-size: 12px; }
.rx-list { display: grid; gap: 10px; }
.rx-empty { margin: 0; padding: 18px; border: 1px dashed #d6cfc1; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; text-align: center; }
.rx-item { position: relative; display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: start; padding: 14px; border: 1px solid var(--line-2); border-radius: 14px; background: #fdfcfa; }
.rx-thumb { width: 56px; height: 56px; display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: var(--paper); color: var(--faint); font-family: var(--serif); font-size: 20px; }
.rx-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.rx-main { display: grid; gap: 6px; min-width: 0; }
.rx-main > b { font-size: 15px; }
.rx-main > b small { margin-left: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.rx-product { justify-self: start; max-width: 100%; padding: 0; border: 0; background: none; color: var(--accent); font-size: 13px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rx-dose { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rx-dose select { width: auto; padding: 7px 10px; font-size: 13px; }
.rx-dose input.rx-dose-amount, .rx-dose input.rx-custom { width: 7.5em; padding: 7px 10px; font-size: 13px; }
.rx-dose input[type="number"].rx-custom { width: 5em; }
.rx-custom-days { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.rx-hint { color: var(--muted); font-size: 12px; }
.rx-hint.warn { color: var(--warn); font-weight: 600; }
.rx-for { justify-self: start; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.rx-for::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); }
.rx-remove { width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; color: var(--faint); font-size: 18px; }
.rx-remove:hover { background: #fbe9e5; color: var(--danger); }
.product-picker { grid-column: 1 / -1; display: grid; gap: 4px; max-height: 280px; overflow: auto; padding: 6px; margin-top: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.product-picker button { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; padding: 6px 8px; border: 0; border-radius: 8px; background: none; text-align: left; }
.product-picker button:hover, .product-picker button.selected { background: var(--accent-soft); }
.product-picker img, .product-picker .no-img { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: var(--paper); display: grid; place-items: center; color: var(--faint); font-size: 11px; }
.product-picker b { display: block; font-size: 13px; }
.product-picker small { color: var(--muted); font-size: 12px; }
.rx-search { position: relative; margin-top: 14px; }
.rx-search .search-results { position: absolute; left: 0; right: 0; z-index: 5; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.rx-search .search-results:empty { display: none; }

/* 推薦欄 */
.rx-recs { position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow: auto; padding: 4px 4px 24px; scrollbar-width: thin; }
.recs-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.recs-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; }
.recs-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.recs-empty { padding: 56px 24px; text-align: center; border: 1px dashed #d6cfc1; border-radius: var(--radius); color: var(--muted); }
.recs-empty .empty-mark { font-family: var(--serif); font-size: 40px; color: #c8bfae; }

.rec-row { margin-bottom: 28px; }
.rec-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.rec-row-head h3 { margin: 0; font-family: var(--serif); font-size: 19px; }
.rec-row-head h3::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 10px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); vertical-align: 2px; }
.because { margin-right: 8px; color: var(--muted); font-family: var(--sans); font-size: 13px; font-weight: 500; }
.rec-row-head > span { color: var(--faint); font-size: 12px; }
.rec-rail { display: grid; grid-auto-flow: column; grid-auto-columns: 196px; gap: 14px; overflow-x: auto; padding: 4px 4px 14px; margin: 0 -4px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.rec-none { margin: 0; }
.rec-card {
  position: relative; display: flex; flex-direction: column; overflow: visible; scroll-snap-align: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: transform .3s var(--ease), box-shadow .3s var(--ease); animation: rise .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms);
}
.rec-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.rec-card.adopted { border-color: #9fcabd; box-shadow: 0 0 0 3px var(--ok-soft); }
.rec-open { display: flex; flex-direction: column; padding: 0; border: 0; background: none; text-align: left; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.rec-cover { height: 118px; display: grid; place-items: center; background: linear-gradient(140deg, hsl(var(--hue) 30% 95%), hsl(var(--hue) 28% 89%)); }
.rec-cover img { max-width: 86%; max-height: 98px; object-fit: contain; border-radius: 8px; mix-blend-mode: multiply; }
.pill-glyph { font-family: var(--serif); font-size: 44px; font-weight: 700; color: hsl(var(--hue) 30% 40% / .5); }
.rec-body { display: grid; gap: 4px; padding: 12px 14px 6px; min-height: 92px; }
.rec-body b { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.rec-class { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-reason { padding: 2px 8px; border-radius: 999px; background: var(--paper); color: var(--ink-2); font-size: 12px; font-weight: 600; }
.rec-warning { color: var(--warn); font-size: 12px; font-weight: 600; }
.rec-actions { display: flex; gap: 6px; padding: 8px 12px 12px; }
.adopt-button { flex: 1; padding: 8px; border: 1px solid #cfd8df; border-radius: 999px; background: var(--surface); color: var(--accent-ink); font-size: 13px; font-weight: 600; transition: background .2s, border-color .2s, color .2s; }
.adopt-button:hover { border-color: var(--accent); background: var(--accent); color: #fff; }
.adopt-button:disabled { border-color: transparent; background: var(--ok-soft); color: var(--ok); cursor: default; }
.rec-more { width: 34px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 16px; line-height: 1; }
.rec-menu { position: absolute; top: 8px; right: 8px; z-index: 6; display: grid; min-width: 168px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.rec-menu button { padding: 9px 12px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: 13px; }
.rec-menu button:hover { background: var(--paper); }
.rec-menu [data-never] { color: var(--danger); }

.excluded { margin-top: 8px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .6); }
.excluded summary { cursor: pointer; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.excluded ul { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.excluded li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; }
.excluded-name { font-weight: 600; }
.excluded-why { color: var(--muted); font-size: 12px; }
.excluded-why.allergy { color: var(--danger); }
.excluded li .link-button { margin-left: auto; }

/* 藥品資訊卡 */
.drug-zh { margin-left: 8px; color: var(--muted); font-family: var(--sans); font-size: 16px; font-weight: 500; }
.drug-gallery { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 10px; overflow-x: auto; margin-top: 18px; padding-bottom: 6px; }
.drug-gallery figure { margin: 0; }
.drug-gallery img { width: 132px; height: 96px; object-fit: contain; border-radius: 10px; background: var(--paper); }
.drug-gallery figcaption { margin-top: 4px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drug-summary { margin-top: 20px; padding: 18px 20px; border-radius: var(--radius); background: #f8f6f1; }
.summary-purpose { margin: 0 0 14px; font-family: var(--serif); font-size: 18px; line-height: 1.55; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.summary-grid span, .drug-facts span { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.summary-grid p, .summary-grid ul { margin: 4px 0 0; font-size: 14px; line-height: 1.65; }
.summary-grid ul { padding-left: 18px; }
.summary-empty { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.summary-empty p { flex: 1 1 260px; margin: 0; color: var(--muted); font-size: 14px; }
.ai-label-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0 0; color: var(--faint); font-size: 12px; }
.ai-label-line .ai-label { margin: 0; }
.drug-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-2); }
.drug-facts b { display: block; margin-top: 4px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.drug-facts .wide { grid-column: 1 / -1; }
.drug-facts p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.65; }
.drug-products { margin-top: 18px; }
.drug-products summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.drug-products table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 13px; }
.drug-products th { padding: 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: left; }
.drug-products td { padding: 8px; border-bottom: 1px solid var(--line-2); }
.drug-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 18px; font-size: 13px; }
.drug-links span { color: var(--muted); font-weight: 600; }
.drug-links a { font-weight: 600; text-decoration: none; }
.drug-links a:hover { text-decoration: underline; }
.drug-source { margin: 14px 0 0; color: var(--faint); font-size: 12px; }

@media (max-width: 860px) { .rx-layout { grid-template-columns: 1fr; } .rx-recs { position: static; max-height: none; overflow: visible; } }
@media (max-width: 640px) {
  .rx-switcher { flex-direction: column; align-items: stretch; }
  .rx-switcher select { max-width: none; }
  .patient-row { grid-template-columns: 1fr 1fr; }
  .patient-row label:first-child { grid-column: 1 / -1; }
  .allergy-add { margin-left: 0; }
  .allergy-pop { left: 0; right: auto; width: min(340px, calc(100vw - 48px)); }
  .recs-head { flex-direction: column; align-items: flex-start; }
  .rec-rail { grid-auto-columns: 168px; }
  .summary-grid, .drug-facts { grid-template-columns: 1fr 1fr; }
  .drug-products { display: none; }
}
.rec-cover img, .rx-thumb img, .drug-gallery img, .product-picker img { opacity: 0; transition: opacity .4s var(--ease); }
.rec-cover img.loaded, .rx-thumb img.loaded, .drug-gallery img.loaded, .product-picker img.loaded { opacity: 1; }
@media (max-width: 860px) { .rx-layout { grid-template-columns: minmax(0, 1fr); } }


/* ==========================================================
   Polish pass（/impeccable polish）
   ========================================================== */

/* 瀏覽器原生表面也套用手札配色 */
::selection { background: #d6e3ee; color: var(--ink); }
html { scrollbar-color: #cfc7b9 transparent; scrollbar-width: thin; }
input, textarea { caret-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--ink); }
a { text-underline-offset: 3px; text-decoration-thickness: 1px; }
table, .record-timer, .topic-link small, .card-meta, .tile-meta, .condition-chip small { font-variant-numeric: tabular-nums; }

/* 圖示（Lucide，線寬一致） */
.icon { width: 1.1em; height: 1.1em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.18em; }
.primary-button, .secondary-button, .danger-button, .link-button, .chip-button, .adopt-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.add-button .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.nav-item .icon { width: 18px; height: 18px; color: var(--mark); transition: color .2s; }
.nav-item.active .icon { color: var(--accent); }
.search-icon { width: 18px; height: 18px; color: var(--faint); }
.close-button { display: grid; place-items: center; }
.close-button .icon { width: 18px; height: 18px; }
.mode-tab .icon { width: 17px; height: 17px; }
.dropzone-icon { width: 30px; height: 30px; color: var(--faint); stroke-width: 1.6; }
.empty-mark .icon { width: 36px; height: 36px; color: #b7ad9c; stroke-width: 1.5; }
.cover-kind .icon { width: 13px; height: 13px; }
.tile-kinds span { display: inline-flex; align-items: center; gap: 4px; }
.tile-kinds .icon { width: 13px; height: 13px; }
.rec-warning { display: inline-flex; align-items: flex-start; gap: 5px; }
.rec-warning .icon { width: 13px; height: 13px; margin-top: 1px; }
.rx-thumb .icon { width: 22px; height: 22px; color: var(--mark); }
.rx-product { display: inline-flex; align-items: center; gap: 4px; }
.rx-product span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rx-product .icon { width: 14px; height: 14px; }
.rx-remove, .rec-more { display: grid; place-items: center; }
.rx-remove .icon { width: 16px; height: 16px; }
.rec-more .icon { width: 16px; height: 16px; }
.allergy-chip button, .condition-chip button { display: grid; place-items: center; }
.allergy-chip button .icon, .condition-chip button .icon { width: 13px; height: 13px; stroke-width: 2.2; }
.ai-result { display: flex; align-items: flex-start; gap: 8px; }
.ai-result .icon { margin-top: 2px; }
.save-state { display: inline-flex; align-items: center; gap: 5px; }
.save-state .icon { width: 13px; height: 13px; color: var(--ok); }
.audio-preview .icon { width: 30px; height: 30px; color: var(--danger); }
.viewer-source a, .drug-links a { display: inline-flex; align-items: center; gap: 4px; }
.viewer-source a .icon, .drug-links a .icon { width: 13px; height: 13px; }
.link-button .icon { width: 15px; height: 15px; }
#aiDetectButton:disabled { opacity: .7; cursor: progress; }

/* 標題下方的資訊列（取代標題上方的小標） */
.dialog-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.dialog-meta span { display: inline-flex; align-items: center; gap: 6px; }
.dialog-meta .icon { width: 14px; height: 14px; }
.topic-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); }
.topic-hero .topic-title::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 14px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); vertical-align: 0.15em; }

/* 主題就地改名 */
.topic-rename { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.topic-rename input { flex: 1 1 280px; padding: 10px 14px; border: 1px solid #b9cad8; border-radius: var(--radius-sm); background: #fff; font-family: var(--serif); font-size: clamp(22px, 2.4vw, 30px); font-weight: 700; color: var(--ink); box-shadow: 0 0 0 4px var(--accent-soft); outline: 0; }
.topic-rename p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }

/* 兩段式刪除 */
.danger-button { transition: background .2s, color .2s, border-color .2s; }
.danger-button:hover { border-color: var(--danger); }
.danger-button.confirming { background: var(--danger); border-color: var(--danger); color: #fff; }

/* 有層次的立體感：卡片靜止時就浮在紙上，懸停再上一層 */
.note-card, .topic-tile, .rec-card, .rx-card { box-shadow: var(--shadow-rest); }
.note-card:hover, .topic-tile:hover, .rec-card:hover { box-shadow: var(--shadow); }
.library-search { box-shadow: var(--shadow-rest); }
.rec-card.adopted { box-shadow: var(--shadow-rest), 0 0 0 3px var(--ok-soft); }

/* 載入中骨架 */
.skeleton { aspect-ratio: 3 / 4; border-radius: var(--radius); background: linear-gradient(100deg, #eeeae2 30%, #f7f5f0 50%, #eeeae2 70%) 0 0 / 250% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* 觸控裝置：放大小按鈕的觸控範圍 */
@media (pointer: coarse) {
  .allergy-chip button, .condition-chip button { width: 32px; height: 32px; }
  .rec-more { width: 42px; }
  .rx-remove { width: 40px; height: 40px; }
  .adopt-button { padding: 11px; }
  .link-button { padding: 8px 10px; }
}

/* 標題階層：病歷卡片標題改為 h2，外觀維持 */
.rx-card-head .rx-card-title { margin: 0; font-family: var(--serif); font-size: 18px; }
.rx-card-head .rx-card-title small { margin-left: 6px; color: var(--muted); font-family: var(--sans); font-size: 13px; font-weight: 500; }

/* 卡片以浮起表達邊界，不再同時使用髮絲邊框 */
.note-card, .topic-tile, .rec-card, .rx-card { border-color: transparent; }
.note-card:hover, .topic-tile:hover { border-color: transparent; }

/* 開藥區：改為以分隔線區隔的清單列，避免卡片中再放卡片 */
.rx-list { gap: 0; }
.rx-item { padding: 14px 2px; border: 0; border-radius: 0; background: none; border-bottom: 1px solid var(--line-2); }
.rx-item:first-child { padding-top: 4px; }
.rx-item:last-child { border-bottom: 0; }
.library-search, .allergy-pop, .rec-menu { border-color: transparent; }
.library-search:focus-within { border-color: #c9d6e0; }
.rx-empty { padding: 6px 0 2px; border: 0; text-align: left; }

/* 所有內容圖片：載入後淡入；失敗時保留占位底色 */
.cover img, .tile-cover img, .viewer-image img { opacity: 0; transition: opacity .4s var(--ease), transform .6s var(--ease); }
.cover img.loaded, .tile-cover img.loaded, .viewer-image img.loaded { opacity: 1; }
.drug-gallery figure.img-failed { display: none; }

/* ---------- 病歷與開藥：critique 修正（本次處方、可比較的卡片、鍵盤與響應式） ---------- */

/* 頁首在中等寬度就改成上下排，避免標題被擠成直排 */
@media (max-width: 860px) {
  .library-hero { flex-direction: column; align-items: stretch; gap: 20px; }
  .rx-switcher { flex-wrap: wrap; }
  .rx-switcher select { flex: 1 1 220px; max-width: none; }
}

/* 自動儲存狀態放在 SOAP 旁邊 */
.soap-foot { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.soap-foot .soap-hint { margin: 0; }

/* 已移除的病灶：看得到，也能復原 */
.removed-conditions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.restore-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 3px 10px; border: 1px dashed #cdc5b6; border-radius: 999px; background: none; color: var(--ink-2); font-size: 12px; }
.restore-chip span { color: var(--accent); font-weight: 600; }
.restore-chip:hover { border-color: var(--accent); }

/* 本次處方：採用的結果與過敏排除固定在推薦上方 */
.tray-safety { display: flex; align-items: flex-start; gap: 8px; margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--paper); color: var(--ink-2); font-size: 13px; line-height: 1.55; }
.tray-safety .icon { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--muted); }
.tray-safety.has-allergy { background: #fbe9e5; }
.tray-safety.has-allergy .icon, .tray-safety.has-allergy b { color: var(--danger); }
.tray-safety .link-button { padding: 0 4px; font-size: 13px; }
.rx-hint { display: inline-flex; align-items: center; gap: 4px; }
.rx-hint .icon { width: 13px; height: 13px; }
@media (min-width: 861px) {
}

/* 推薦卡：理由與市售資訊分開；不再推薦需要確認 */
.rec-cover, .rec-body { display: grid; }
.rec-reasons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.rec-reason.mine { background: var(--ok-soft); color: var(--ok); }
.rec-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.rec-menu [data-never].confirming { background: #fbe9e5; font-weight: 600; }

/* 橫向列表：桌機加左右箭頭，鍵盤用方向鍵 */
.rail-wrap { position: relative; }
.rail-nav { position: absolute; top: 46px; z-index: 3; display: none; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); transition: opacity .2s; }
.rail-nav .icon { width: 17px; height: 17px; }
.rail-nav.prev { left: -6px; }
.rail-nav.next { right: -6px; }
.rail-wrap.at-start .rail-nav.prev, .rail-wrap.at-end .rail-nav.next { opacity: 0; pointer-events: none; }
@media (hover: hover) and (pointer: fine) { .rail-nav { display: grid; } }

/* 藥品卡對話框：主要動作固定在底部 */
.dialog-actions.sticky-actions { position: sticky; bottom: 0; margin: 24px -32px -26px; padding: 14px 32px 18px; background: linear-gradient(to bottom, rgba(255, 255, 255, .85), var(--surface) 40%); }
#drugTitle:focus { outline: 0; }

/* 提示訊息可帶「復原」 */
.toast.has-action { display: flex; align-items: center; gap: 14px; padding-right: 8px; pointer-events: auto; }
.toast:not(.show) { pointer-events: none; }
.toast button { padding: 6px 12px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .16); color: #fff; font-size: 13px; font-weight: 600; }
.toast button:hover { background: rgba(255, 255, 255, .28); }
@media (max-width: 640px) { .toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); } }
.toast span { min-width: 0; }
.toast button { flex: none; white-space: nowrap; }
/* 選單蓋在外觀圖上，不遮住藥名 */
.rec-menu { padding: 5px; }
.rec-menu button { padding: 7px 12px; line-height: 1.45; }
@media (max-width: 640px) { .rx-switcher select { flex: none; } }
@media (max-width: 640px) {
  .rec-row-head { flex-wrap: wrap; }
}

/* ---------- 健保給付（健保署健保用藥品項） ---------- */
.nhi-tag { display: inline-block; margin-right: 6px; padding: 1px 7px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-size: 11px; font-weight: 700; line-height: 18px; }
.nhi-tag.self-pay { background: var(--paper); color: var(--muted); }
.rec-meta.no-nhi { color: var(--muted); }
.rx-nhi { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.rx-nhi.self-pay, .self-pay { color: var(--muted); }
.picker-nhi { color: var(--ok); font-variant-numeric: tabular-nums; }
.picker-nhi.self-pay { color: var(--muted); }
.nhi-cell { display: block; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nhi-cell small { display: block; color: var(--warn); font-size: 11px; }
.recs-head { flex-wrap: wrap; }
.picker-nhi { display: block; margin-top: 2px; }
.drug-products { overflow-x: auto; }
.drug-products table { min-width: 760px; }
.drug-products td:nth-child(2), .drug-products td:nth-child(3), .drug-products th { white-space: nowrap; }
/* 推薦列表可用滑鼠拖曳捲動 */
@media (hover: hover) and (pointer: fine) { .rec-rail { cursor: grab; } }
.rec-rail.dragging { cursor: grabbing; scroll-snap-type: none; user-select: none; }
.rec-rail.dragging .rec-card { pointer-events: none; }
.rec-rail img { -webkit-user-drag: none; user-select: none; }

/* ---------- critique 2026-10-04 修正 ---------- */

/* 中等寬度（並排視窗、筆電）：側欄改成圖示、病歷與推薦維持左右兩欄，採用結果留在畫面內 */
@media (min-width: 641px) and (max-width: 1180px) {
  .sidebar { flex-basis: 76px; padding: 24px 12px; }
  .brand { justify-content: center; padding: 0 0 28px; }
  .brand-text, .nav-item em, .privacy-note { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .sidebar-foot { padding: 0; justify-items: center; }
  .ai-status { font-size: 0; padding: 6px; }
  .ai-status::before { margin: 0; }
  .content { padding: 40px 28px 80px; }
}
@media (min-width: 861px) and (max-width: 1180px) {
  .rx-layout { grid-template-columns: minmax(320px, 5fr) minmax(0, 6fr); gap: 24px; }
  .rec-rail { grid-auto-columns: 176px; }
}
.add-button { flex: none; white-space: nowrap; }
@media (max-width: 640px) {
  .rx-switcher { flex-wrap: nowrap; }
  .rx-switcher select, #recordSelect { width: 100%; min-width: 0; }
}

/* 推薦卡：成分、劑型與健保在同一行資訊；病史風險為琥珀提醒 */
.rec-components { color: var(--ink-2); font-size: 12px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rec-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 0; }
.rec-warning { padding: 6px 8px; margin-top: 2px; border-radius: 8px; background: var(--warn-soft); line-height: 1.45; }
.rec-warning span { min-width: 0; }

/* 健保標籤：中性墨水外框，綠色保留給「已採用／已確認」 */
.nhi-tag { border: 1px solid #c9d1d7; background: transparent; color: var(--ink-2); font-weight: 600; }
.nhi-tag.self-pay { border-style: dashed; border-color: #d3cbbd; background: transparent; color: var(--muted); }


/* 病灶列可收起 */
.rec-row-toggle { display: inline-flex; align-items: baseline; gap: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; }
.rec-row-toggle .icon { width: 16px; height: 16px; margin-right: 6px; color: var(--muted); align-self: center; transition: transform .25s var(--ease); }
.rec-row.collapsed .rec-row-toggle .icon { transform: rotate(-90deg); }
.rec-row.collapsed { margin-bottom: 14px; }
.rec-row-head h3::before { display: none; }
.rec-row-toggle .because::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 10px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); vertical-align: 1px; }

/* 安全資訊：過敏、病史風險、系統能力範圍各一行 */
.tray-safety div { display: grid; gap: 4px; }
.tray-safety p { margin: 0; }
.tray-safety .safety-risk b { color: var(--warn); }
.tray-safety .safety-scope { color: var(--muted); font-size: 12px; }

/* 窄螢幕：回到本次處方 */
.tray-fab { position: fixed; right: 16px; bottom: calc(156px + env(safe-area-inset-bottom)); z-index: 30; display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; border: 0; border-radius: 999px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); }
.tray-fab[hidden] { display: none; }
.tray-fab .icon { width: 17px; height: 17px; }
@media (min-width: 641px) { .tray-fab { bottom: 96px; } }

/* 被排除清單補上類別；藥品卡外部連結加大點擊區 */
.excluded-class { color: var(--ink-2); font-size: 12px; }
.drug-links a { display: inline-flex; align-items: center; min-height: 32px; }
.toast kbd { margin-left: 8px; padding: 1px 6px; border-radius: 6px; background: rgba(255, 255, 255, .16); font: inherit; font-size: 12px; opacity: .85; }
/* 列表改用 flex：卡片固定寬度，「其他 n 個」較窄，前 3 張旁邊就看得到 */
.rec-rail { display: flex; --card-w: 176px; }
.rec-rail > .rec-card { flex: 0 0 var(--card-w); }
@media (min-width: 861px) and (max-width: 1180px) { .rec-rail { --card-w: 164px; } }
@media (max-width: 640px) { .rec-rail { --card-w: 168px; } }
/* 提示訊息：寬度依內容、不被置中定位壓窄；多行時改用圓角矩形；手機放在浮動按鈕上方 */
.toast { width: max-content; max-width: min(560px, calc(100vw - 32px)); line-height: 1.5; }
.toast.has-action { border-radius: 16px; }
@media (max-width: 640px) { .toast { bottom: calc(150px + env(safe-area-inset-bottom)); } }
.drug-components { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; line-height: 1.55; }

/* 病灶列標題右側：候選數＋看全部 */
.rec-row-side { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; justify-content: flex-end; }
.rec-row-side > span { color: var(--faint); font-size: 12px; }
.rec-row-side .link-button { padding: 4px 8px; font-weight: 600; }

/* 看全部彈窗：所有推薦排成格狀，一次查看與操作 */
.row-dialog { width: min(1080px, calc(100% - 32px)); }
.row-dialog .dialog-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; }
.row-dialog .dialog-head h2:focus { outline: 0; }
.row-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(188px, 1fr)); gap: 16px; margin-top: 20px; }
.row-grid .rec-card { animation: none; }
.row-grid .rec-card:hover { transform: none; }
@media (max-width: 640px) { .row-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }

/* ---------- 衛教單（F-08／F-09） ---------- */
.edu-hero { margin-bottom: 28px; }
.edu-new { display: flex; align-items: center; gap: 10px; }
.edu-new select { min-width: 200px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; }

.edu-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 32px; align-items: start; }
.edu-list { position: sticky; top: 24px; }
#eduList { display: grid; gap: 6px; }
.edu-list-title { margin: 0 0 6px; font-family: var(--serif); font-size: 17px; }
.edu-list-item { display: grid; gap: 2px; padding: 12px 14px 12px 18px; border-radius: 12px; color: var(--ink); text-decoration: none; position: relative; transition: background .2s; }
.edu-list-item::before { content: ""; position: absolute; left: 6px; top: 18px; width: 6px; height: 6px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); }
.edu-list-item:hover { background: rgba(255, 255, 255, .7); }
.edu-list-item.active { background: var(--surface); box-shadow: var(--shadow-rest); }
.edu-list-item b { font-size: 15px; line-height: 1.4; }
.edu-list-item span { color: var(--ink-2); font-size: 13px; }
.edu-list-item small { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.edu-list-item small .icon { width: 12px; height: 12px; color: var(--ok); }
.edu-list-empty { margin: 0; font-size: 13px; line-height: 1.6; }

.edu-empty, .edu-generating { display: grid; justify-items: center; gap: 10px; padding: 72px 24px; border: 1px dashed #d6cfc1; border-radius: var(--radius); color: var(--muted); text-align: center; }
.edu-empty h2 { margin: 6px 0 0; color: var(--ink); font-family: var(--serif); font-size: 22px; }
.edu-empty p { max-width: 46ch; margin: 0; line-height: 1.7; }
.edu-empty .empty-mark .icon { width: 40px; height: 40px; color: #c8bfae; }
.edu-generating b { color: var(--ink); font-size: 16px; }

/* 工具列：狀態、產生圖、確認、交付 */
.edu-toolbar { display: grid; gap: 10px; margin-bottom: 18px; }
.edu-status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--ink-2); font-size: 14px; font-weight: 600; }
.edu-status .icon { width: 16px; height: 16px; }
.edu-status.ok { color: var(--ok); }
.edu-status span { color: var(--muted); font-size: 12px; font-weight: 500; }
.edu-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.edu-confirm { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer; }
.edu-confirm input { width: 18px; height: 18px; accent-color: var(--ok); }
.edu-confirm:has(input:checked) { border-color: #9fcabd; background: var(--ok-soft); color: var(--ok); }
.edu-delete { display: grid; place-items: center; width: 42px; height: 42px; margin-left: auto; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.edu-delete .icon { width: 18px; height: 18px; }
.edu-delete:hover, .edu-delete.confirming { background: #fbe9e5; color: var(--danger); }
.edu-hint { margin: 0; color: var(--muted); font-size: 13px; }

/* 衛教單本體：給長輩看的紙本，大字、高對比、圖片優先 */
.edu-sheet { max-width: 780px; padding: 44px 48px 32px; border-radius: 18px; background: #fff; color: #17222a; box-shadow: var(--shadow-rest), 0 30px 60px -40px rgba(22, 35, 44, .35); font-size: 20px; line-height: 1.75; }
.edu-sheet-head { margin-bottom: 22px; }
.edu-sheet-topics { margin: 0 0 6px; color: hsl(var(--hue) 35% 32%); font-size: 15px; font-weight: 700; letter-spacing: .04em; }
.edu-sheet-head h2 { margin: 0; font-family: var(--serif); font-size: 34px; line-height: 1.3; }
.edu-figure { margin: 0 0 28px; overflow: hidden; border-radius: 14px; background: linear-gradient(140deg, hsl(var(--hue) 30% 96%), hsl(var(--hue) 26% 90%)); aspect-ratio: 3 / 2; }
.edu-figure img { display: block; width: 100%; height: 100%; object-fit: cover; }
.edu-figure-empty { display: grid; place-items: center; align-content: center; gap: 12px; height: 100%; padding: 24px; color: var(--muted); font-size: 15px; line-height: 1.6; text-align: center; }
.edu-figure-empty .icon { width: 34px; height: 34px; color: hsl(var(--hue) 25% 60%); }
.edu-block { margin-top: 26px; }
.edu-block h3 { margin: 0 0 10px; padding-bottom: 8px; border-bottom: 2px solid hsl(var(--hue) 30% 88%); font-family: var(--serif); font-size: 25px; }
.edu-block > p { margin: 0; }
.edu-points { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.edu-points li { position: relative; display: flex; align-items: flex-start; gap: 6px; padding-left: 26px; }
.edu-points li::before { content: ""; position: absolute; left: 4px; top: .7em; width: 10px; height: 10px; border-radius: 50%; background: hsl(var(--hue) 40% 52%); }
.edu-warn h3 { color: #8c3a29; border-bottom-color: #f2d4cc; }
.edu-warn .edu-points li::before { background: var(--danger); }
.edu-meds { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.edu-med { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 18px; align-items: start; padding: 16px; border-radius: 14px; background: #faf8f4; }
.edu-med-photo { display: grid; place-items: center; width: 104px; height: 104px; overflow: hidden; border-radius: 12px; background: #fff; }
.edu-med-photo img { width: 100%; height: 100%; object-fit: contain; }
.edu-med-photo .icon { width: 30px; height: 30px; color: var(--mark); }
.edu-med-body p { margin: 0; }
.edu-med-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.edu-med-name b { font-size: 24px; }
.edu-med-name small { color: var(--muted); font-size: 15px; }
.edu-med-purpose { color: #2c3a44; }
.edu-med-schedule { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px !important; padding: 4px 14px 4px 10px; border-radius: 999px; background: hsl(var(--hue) 35% 93%); color: #17222a; font-weight: 700; }
.edu-med-schedule .icon { width: 18px; height: 18px; color: hsl(var(--hue) 40% 38%); }
.edu-med-tip { margin-top: 6px !important; color: #4a5660; font-size: 18px; }
.edu-note { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.edu-sheet-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; margin-top: 34px; padding-top: 14px; border-top: 1px solid #ece8e0; color: var(--muted); font-size: 13px; }

/* 可直接修改的文字：滑過或聚焦時才顯示外框 */
.edu-edit { border-radius: 6px; outline: 0; transition: background .15s, box-shadow .15s; }
.edu-edit:hover { background: #f7f4ee; }
.edu-edit:focus { background: #fffbea; box-shadow: 0 0 0 2px #ead9a6; }
.edu-edit:empty::before { content: attr(data-placeholder); color: #a3acb2; }
.edu-remove { flex: none; display: grid; place-items: center; width: 32px; height: 32px; margin-left: auto; border: 0; border-radius: 50%; background: none; color: var(--faint); opacity: 0; transition: opacity .15s; }
.edu-points li:hover .edu-remove, .edu-remove:focus-visible { opacity: 1; }
.edu-remove:hover { background: #fbe9e5; color: var(--danger); }
.edu-remove .icon { width: 15px; height: 15px; }
.edu-add { margin-top: 8px; }
.edu-sheet.exporting .edu-edit:empty { display: none; }

@media (max-width: 1080px) {
  .edu-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .edu-list { position: static; }
  #eduList { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .edu-list-title { display: none; }
  .edu-list-item { flex: 0 0 220px; background: rgba(255, 255, 255, .6); }
}
@media (max-width: 640px) {
  .edu-new { flex-direction: column; align-items: stretch; }
  .edu-new select { min-width: 0; width: 100%; }
  .edu-sheet { padding: 26px 20px 22px; font-size: 18px; }
  .edu-sheet-head h2 { font-size: 27px; }
  .edu-block h3 { font-size: 22px; }
  .edu-med { grid-template-columns: 76px minmax(0, 1fr); gap: 12px; padding: 12px; }
  .edu-med-photo { width: 76px; height: 76px; }
  .edu-med-name b { font-size: 21px; }
  .edu-remove { opacity: 1; }
  .edu-delete { margin-left: 0; }
}
.edu-med.no-photo { grid-template-columns: minmax(0, 1fr); }
.edu-med-schedule { display: flex; width: fit-content; max-width: 100%; align-items: flex-start; line-height: 1.5; padding-top: 6px; padding-bottom: 6px; }
.edu-med-schedule .icon { flex: none; margin-top: .2em; }
.edu-sheet .icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* 匯出圖片：沒有衛教圖時不留空白框 */
.edu-sheet.exporting .edu-figure.empty { display: none; }
/* 匯出前先移除編輯用的按鈕，讓版面重新排列；排程膠囊不換行（轉圖時字寬略有差異） */
.edu-sheet.exporting .edu-ui { display: none; }
.edu-sheet.exporting .edu-med-schedule .edu-edit { white-space: nowrap; }

/* ==========================================================
   病歷 SOAP（Modified POMR）、病歷管理、語音看診、完成病歷
   ========================================================== */
.compact-button { padding: 8px 14px; font-size: 13px; }
.icon-button { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.icon-button:hover { background: var(--paper); color: var(--ink); }
.icon-button .icon { width: 18px; height: 18px; }
.danger-icon:hover { background: #fbe9e5; color: var(--danger); }
.danger-icon.confirming { background: var(--danger); color: #fff; }

/* 病人資料列：動作在上、資料在下 */
.record-status { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }
.record-status.done { color: var(--ok); }
.record-status.changed { color: var(--warn); }
.record-status:empty { display: none; }
.patient-row { grid-template-columns: 1.2fr .6fr .7fr 1.1fr; }

/* S／O／A/P 標題：大寫字母當段落記號 */
.soap-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 700; }
.soap-title b { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 7px; border-radius: 9px; background: var(--ink); color: #fff; font-family: var(--sans); font-size: 14px; letter-spacing: .02em; transform: translateY(-2px); }
.soap-title small { flex-basis: 100%; color: var(--faint); font-family: var(--sans); font-size: 12px; font-weight: 500; }
.problems-card .rx-card-head { align-items: flex-start; }
.problem-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px; }

/* A/P：問題清單（精簡列）＋統整的評估與計畫 */
.field-title { margin: 4px 0 8px; color: var(--ink-2); font-size: 13px; font-weight: 700; }
.problem-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.problem { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-left: 4px solid hsl(var(--hue) 45% 62%); border-radius: var(--radius-sm); background: hsl(var(--hue) 40% 98.5%); }
.problem-no { color: hsl(var(--hue) 35% 34%); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.problem b { font-family: var(--serif); font-size: 15px; }
.problem small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.problem em { padding: 1px 8px; border-radius: 999px; background: #fff; color: var(--muted); font-size: 11px; font-style: normal; font-weight: 600; }
.problem em.no-recs { background: var(--warn-soft); color: var(--warn); }
.problem-move { display: inline-flex; margin-left: auto; }
.problem-move button { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.problem-move button:not(.problem-remove) .icon { transform: rotate(90deg); }
.problem-move button:hover:not(:disabled) { background: rgba(0, 0, 0, .06); color: var(--ink); }
.problem-move button:disabled { opacity: .3; cursor: default; }
.problem-empty { padding: 14px; border: 1px dashed #d6cfc1; border-radius: var(--radius-sm); color: var(--muted); font-size: 14px; text-align: center; }
.rx-card .ap-field { margin-top: 16px; }
.ap-field > span { display: flex; align-items: center; gap: 8px; color: var(--ink); font-family: var(--serif); font-size: 15px; }
.ap-field > span b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 12px; }
.plan-rx { display: flex; gap: 8px; margin: 8px 0 0; color: var(--ink-2); font-size: 13px; line-height: 1.6; }
.plan-rx > span:first-child { flex: none; color: var(--faint); font-weight: 600; }

/* AI 參考計畫：預設模糊遮住，醫師寫完再偷看 */
.ai-plan { margin-top: 12px; padding: 10px 12px; border: 1px dashed #c7d3dd; border-radius: var(--radius-sm); background: #fff; }
.ai-plan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--accent); font-size: 12px; font-weight: 700; }
.ai-plan-head > span:first-child { display: inline-flex; align-items: center; gap: 5px; }
.ai-plan-head em { margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: 11px; font-style: normal; }
.ai-plan-actions { display: inline-flex; gap: 2px; }
.ai-plan-hint { margin: 4px 0 0; color: var(--faint); font-size: 12px; }
.ai-plan-body { display: grid; gap: 4px; margin: 8px 0 0; filter: blur(5px); opacity: .55; user-select: none; transition: filter .3s var(--ease), opacity .3s var(--ease); }
.ai-plan.shown .ai-plan-body { filter: none; opacity: 1; user-select: text; }
.ai-plan-body div { display: grid; grid-template-columns: 36px 1fr; gap: 6px; font-size: 13px; line-height: 1.6; }
.ai-plan-body dt { color: var(--faint); font-weight: 600; }
.ai-plan-body dd { margin: 0; color: var(--ink-2); }

/* 語意偵測的「可能的問題」 */
.semantic-suggest { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); }
.semantic-suggest > span { display: inline-flex; align-items: center; gap: 5px; color: var(--accent); font-size: 12px; font-weight: 700; }
.suggest-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 12px; border: 1px solid #b9cad8; border-radius: 999px; background: #fff; color: var(--ink); font-size: 13px; font-weight: 600; }
.suggest-chip small { color: var(--faint); font-size: 11px; font-weight: 500; }
.suggest-chip .icon { width: 14px; height: 14px; color: var(--accent); }
.suggest-chip:hover { border-color: var(--accent); }

.condition-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.custom-problem { display: flex; flex: 1 1 260px; gap: 6px; }
.rx-card .custom-problem input { flex: 1; min-width: 0; padding: 7px 12px; border-style: dashed; border-radius: 999px; font-size: 13px; }
.custom-problem .chip-button { display: inline-flex; align-items: center; gap: 4px; }

/* 衛教單入口：放在開藥區最後，開完藥接著做 */
#rxTitle:focus { outline: none; }

/* 病歷頁版面：病人資料滿版；S｜O；左 A/P＋開藥區、右推薦藥品 */
.rx-layout {
  grid-template-columns: minmax(380px, 5fr) minmax(0, 7fr); grid-template-rows: auto auto auto 1fr;
  grid-template-areas: "patient patient" "s o" "ap recs" "rx recs"; gap: 20px 28px;
}
.rx-layout > * { min-width: 0; }
.patient-card { grid-area: patient; }
.soap-s { grid-area: s; align-self: stretch; }
.soap-o { grid-area: o; align-self: stretch; display: flex; flex-direction: column; }
.soap-o label { flex: 1; grid-template-rows: auto 1fr; }
.soap-o textarea { min-height: 160px; }
.problems-card { grid-area: ap; }
.rx-section { grid-area: rx; align-self: start; }
.rx-recs { grid-area: recs; align-self: start; }
.patient-body { display: grid; grid-template-columns: minmax(0, 620px) minmax(0, 1fr); gap: 12px 28px; align-items: end; }
.patient-body .allergy-row { margin-top: 0; padding-top: 0; border-top: 0; }
.recs-safety { margin: 0 0 18px; }
@media (max-width: 1180px) {
  .patient-body { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .rx-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "patient" "s" "o" "ap" "recs" "rx"; }
}

/* 病歷管理 */
.records-dialog { width: min(1080px, calc(100% - 32px)); }
.records-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 12px; margin: 18px 0 14px; }
.records-filters label { margin-top: 0; display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.records-filters input, .records-filters select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink); font-size: 14px; }
.records-filters .filter-search { flex: 1 1 240px; }
.records-table-wrap { max-height: min(60vh, 560px); overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.records-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.records-table th { position: sticky; top: 0; z-index: 1; padding: 10px 12px; background: var(--paper); color: var(--muted); font-size: 12px; text-align: left; white-space: nowrap; }
.records-table td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; line-height: 1.55; }
.records-table tr.current { background: var(--accent-soft); }
.records-table .nowrap { white-space: nowrap; }
.mini-problems { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.mini-assessment { display: block; margin-top: 4px; color: var(--muted); }
.status-done { display: inline-flex; align-items: center; gap: 3px; color: var(--ok); font-weight: 600; }
.status-draft { color: var(--faint); }
.row-actions { display: flex; align-items: center; gap: 4px; }
.records-empty { padding: 28px !important; color: var(--muted); text-align: center; }

/* 語音看診 */
.voice-stage { display: grid; justify-items: center; gap: 12px; padding: 26px 8px 8px; text-align: center; color: var(--ink-2); }
.voice-stage p { margin: 0; max-width: 46ch; line-height: 1.65; }
.voice-record { display: grid; place-items: center; gap: 4px; width: 132px; height: 132px; border: 0; border-radius: 50%; background: var(--accent); color: #fff; font-size: 14px; font-weight: 700; box-shadow: 0 10px 28px -10px rgba(31, 94, 140, .6); transition: transform .2s var(--ease); }
.voice-record .icon { width: 34px; height: 34px; }
.voice-record:hover { transform: scale(1.03); }
.voice-record.stop { background: var(--danger); box-shadow: 0 0 0 0 rgba(180, 67, 47, .45); animation: voice-pulse 1.6s ease-out infinite; }
@keyframes voice-pulse { to { box-shadow: 0 0 0 22px rgba(180, 67, 47, 0); } }
.voice-timer { font-family: var(--serif); font-size: 30px; font-variant-numeric: tabular-nums; color: var(--ink); }
.voice-upload { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.voice-privacy { display: flex; gap: 6px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 12px; text-align: left; }
.voice-privacy .icon { flex: none; margin-top: 2px; }
.voice-preview { display: grid; gap: 10px; margin-top: 16px; }
.voice-item { display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.voice-item:has(input:checked) { border-color: #b9cad8; background: var(--accent-soft); }
.voice-item input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.voice-item b { margin-right: 8px; font-size: 13px; }
.voice-item em { color: var(--warn); font-size: 11px; font-style: normal; font-weight: 600; }
.voice-item span span { display: block; margin-top: 4px; color: var(--ink-2); font-size: 14px; line-height: 1.6; white-space: pre-line; }
.voice-transcript summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.voice-transcript p { margin: 8px 0 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--paper); font-size: 13px; line-height: 1.7; }
.voice-note { margin: 0; color: var(--faint); font-size: 12px; }

/* 完成病歷：中文／英文 */
.note-tabs { display: inline-flex; gap: 4px; margin: 16px 0 10px; padding: 4px; border-radius: 999px; background: var(--paper); }
.note-tabs button { padding: 6px 16px; border: 0; border-radius: 999px; background: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.note-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.note-text { max-height: 58vh; overflow: auto; margin: 0; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fffefa; color: var(--ink); font-family: "SF Mono", Menlo, Consolas, var(--sans); font-size: 13px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }


@media (max-width: 640px) {
  .records-dialog { width: 100%; }
  .patient-row { grid-template-columns: 1fr 1fr; }
  .rx-switcher { flex-wrap: wrap; }
  .rx-switcher select { flex: 1 1 100%; }
  .records-table thead { display: none; }
  .records-table tr { display: grid; grid-template-columns: 1fr auto; padding: 10px 12px; border-top: 1px solid var(--line); }
  .records-table td { padding: 2px 0; border: 0; }
  .records-table td:nth-child(4), .records-table td:nth-child(5) { grid-column: 1 / -1; }
  .problem em { display: none; }
}
.dialog-head h2[tabindex="-1"]:focus { outline: none; }
.voice-stage .voice-upload { display: inline-flex; flex-direction: row; align-items: center; gap: 5px; }
.voice-item { margin: 0; font-weight: 400; }
.voice-item span span { font-weight: 400; }
.rx-card-head .link-button { white-space: nowrap; flex: none; }

/* 衛教單：病人熟悉的說法（俗稱、台語）；沒有內容時匯出圖片不顯示 */
.edu-aka { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 10px 0 0; font-size: 19px; color: #2b3a44; }
.edu-aka > span:first-child { padding: 2px 10px; border-radius: 999px; background: hsl(var(--hue) 35% 93%); color: hsl(var(--hue) 35% 28%); font-size: 14px; font-weight: 700; }
.exporting .edu-aka:has(.edu-edit:empty) { display: none; }
.edu-source { flex-basis: 100%; font-size: 12px; }

/* 現病史症狀：S 欄下方的症狀標籤，推薦區的症狀列 */
.symptom-strip { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.symptom-label { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin: 0 0 8px; color: var(--ink-2); font-size: 12px; font-weight: 700; }
.symptom-label .icon { width: 14px; height: 14px; align-self: center; color: var(--accent); }
.symptom-label small { color: var(--faint); font-weight: 500; }
.symptom-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.symptom-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 3px 4px 3px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface, #fff); color: var(--ink); font-size: 13px; font-weight: 600; }
.symptom-chip small { max-width: 12em; overflow: hidden; color: var(--faint); font-size: 11px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.symptom-chip button { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.symptom-chip button:hover { background: var(--accent-soft); color: var(--ink); }
.symptom-chip button .icon { width: 13px; height: 13px; }
.symptom-row .because { color: var(--accent); font-weight: 600; }
.symptom-row .rec-row-side span { max-width: 16em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.symptom-covered { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

/* 病歷動作列：固定在畫面下方中間（sticky，跟著病歷頁內容欄置中） */
.record-bar { position: sticky; bottom: 20px; z-index: 25; display: flex; align-items: center; gap: 8px; width: fit-content; max-width: 100%; margin: 28px auto 0; padding: 8px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, .96); box-shadow: 0 2px 4px rgba(22, 35, 44, .06), 0 14px 36px -12px rgba(22, 35, 44, .28); backdrop-filter: blur(10px); }
.record-bar-status { display: flex; align-items: center; gap: 10px; margin: 0 6px 0 10px; }
.record-bar-status:has(.record-status:empty):has(.save-state:empty) { display: none; }
.record-bar-status .save-state { white-space: nowrap; }
.bar-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 0 18px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease); }
.bar-button[hidden] { display: none; }
.bar-button .icon { width: 17px; height: 17px; }
.bar-button:hover { border-color: var(--ink-2); }
.bar-button:disabled { opacity: .6; cursor: progress; }
.bar-button.primary { border-color: var(--ink); background: var(--ink); color: #fff; }
.bar-button.primary:hover { background: var(--ink-2); }
.bar-button.education { border-color: var(--ok); background: var(--ok); color: #fff; }
.bar-button.education:hover { background: #215b4e; }
.bar-button.danger { border-color: transparent; background: none; color: var(--muted); }
.bar-button.danger:hover { background: #fbe9e5; color: var(--danger); }
.bar-button.danger.confirming { background: var(--danger); color: #fff; }
@media (max-width: 640px) {
  .record-bar { bottom: calc(84px + env(safe-area-inset-bottom)); gap: 6px; padding: 6px; }
  .record-bar-status { display: none; }
  .record-bar.done .bar-button.danger span { display: none; }
  .bar-button { min-height: 44px; padding: 0 14px; font-size: 13px; }
  .bar-button.danger { padding: 0 12px; }
}

/* 新病歷：手動輸入／語音看診 */
.new-record-dialog { width: min(560px, calc(100vw - 32px)); }
.new-record-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.new-record-option { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); text-align: left; cursor: pointer; transition: border-color .15s var(--ease), box-shadow .15s var(--ease), transform .15s var(--ease); }
.new-record-option:hover { border-color: var(--ink-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.new-record-option b { font-family: var(--serif); font-size: 18px; }
.new-record-option > span:last-child { color: var(--muted); font-size: 13px; line-height: 1.55; }
.option-icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 4px; border-radius: 12px; background: var(--line-2); color: var(--ink); }
.option-icon .icon { width: 20px; height: 20px; }
.new-record-option.voice .option-icon { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 480px) { .new-record-options { grid-template-columns: 1fr; } }
/* 病歷頁有下方動作列：提示訊息往上移，避免蓋住按鈕 */
body:has(#view-records:not([hidden])) .toast { bottom: 100px; }
@media (max-width: 640px) { body:has(#view-records:not([hidden])) .toast { bottom: calc(158px + env(safe-area-inset-bottom)); } }

/* ---------- 圖卡式衛教單（version 2）：每個重點一張插圖＋5–10 字標語 ---------- */
.edu-sheet.cards .edu-sheet-head { margin-bottom: 8px; text-align: center; }
.edu-sheet.cards .edu-sheet-head h2 { font-size: 38px; color: hsl(var(--hue) 40% 26%); }
.edu-sheet.cards .edu-sheet-head > p.edu-edit { margin: 8px auto 0; max-width: 30em; color: #3a4852; font-size: 19px; line-height: 1.6; }
.edu-sheet.cards .edu-aka { justify-content: center; }
.edu-sheet.cards .edu-block h3 { border: 0; padding: 0; margin-bottom: 14px; text-align: center; font-size: 26px; }
.edu-sheet.cards .edu-block h3::after { content: ""; display: block; width: 44px; height: 4px; margin: 8px auto 0; border-radius: 4px; background: hsl(var(--hue) 40% 62%); }
.edu-cards { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.edu-card { position: relative; display: grid; justify-items: center; align-content: start; gap: 10px; padding: 0 0 14px; overflow: hidden; border-radius: 16px; background: hsl(var(--hue) 35% 96%); text-align: center; }
.edu-card > b { padding: 0 8px; font-size: 21px; line-height: 1.35; text-wrap: balance; }
.edu-card-art { position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 1; overflow: hidden; background: hsl(var(--hue) 30% 92%); }
.edu-card-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.edu-progress { width: min(320px, 80%); height: 6px; overflow: hidden; border-radius: 6px; background: var(--line); }
.edu-progress span { display: block; height: 100%; border-radius: inherit; background: var(--ink); transition: width .4s ease; }
.edu-card-emoji { font-size: 64px; line-height: 1; }
.edu-card-art.loading::after { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, .7) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ccircle cx='20' cy='20' r='16' fill='none' stroke='%23d9d3c7' stroke-width='3'/%3E%3Cpath d='M20 4a16 16 0 0 1 16 16' fill='none' stroke='%2317222a' stroke-width='3'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 20 20' to='360 20 20' dur='.8s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E") center / 36px no-repeat; }
.edu-card-redraw { position: absolute; right: 6px; bottom: 6px; display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .92); color: var(--ink-2); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); opacity: 0; transition: opacity .15s; }
.edu-card-redraw .icon { width: 16px; height: 16px; }
.edu-card .edu-remove { position: absolute; top: 4px; right: 4px; background: rgba(255, 255, 255, .92); }
.edu-card:hover .edu-remove, .edu-card:hover .edu-card-redraw, .edu-card-redraw:focus-visible { opacity: 1; }
.edu-warn .edu-card { background: #fdf0ec; }
.edu-warn .edu-card > b { color: #8c3a29; }
.edu-sheet.cards .edu-warn h3 { color: #a63f2b; }
.edu-sheet.cards .edu-warn h3::after { background: #e0806b; }
.edu-urgent { margin: 14px 0 0; padding: 12px 16px; border-radius: 12px; background: #b5462f; color: #fff; font-size: 20px; font-weight: 700; text-align: center; }
.edu-urgent .edu-edit:hover { background: rgba(255, 255, 255, .12); }
.edu-urgent .edu-edit:focus { background: rgba(255, 255, 255, .18); box-shadow: 0 0 0 2px rgba(255, 255, 255, .5); color: #fff; }
.edu-med.compact { grid-template-columns: 76px minmax(0, 1fr); gap: 14px; align-items: center; padding: 12px 14px; }
.edu-med.compact.no-photo { grid-template-columns: minmax(0, 1fr); }
.edu-med.compact .edu-med-photo { width: 76px; height: 76px; }
.edu-med.compact .edu-med-name { gap: 2px 12px; }
.edu-med.compact .edu-med-name b { font-size: 22px; }
.edu-med.compact .edu-med-name > span { color: hsl(var(--hue) 40% 32%); font-weight: 700; }
.edu-med.compact .edu-med-schedule { margin-top: 4px !important; }
.edu-med.compact .edu-med-tip { margin-top: 2px !important; font-size: 17px; }
.edu-sheet.cards.exporting .edu-card-emoji:empty { display: none; }
@media (max-width: 640px) {
  .edu-sheet.cards .edu-sheet-head h2 { font-size: 29px; }
  .edu-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .edu-card > b { font-size: 18px; }
  .edu-card-redraw { opacity: 1; }
  .edu-med.compact { grid-template-columns: 60px minmax(0, 1fr); }
  .edu-med.compact .edu-med-photo { width: 60px; height: 60px; }
}

/* ---------- 病人歸檔：新病歷先選病人、第幾次就診、過去就診 ---------- */
.new-record-question { margin: 18px 0 0; color: var(--ink-2); font-size: 15px; font-weight: 600; }
.new-record-step .new-record-options { margin-top: 12px; }
.new-record-back { margin-top: 14px; }
.patient-search { width: 100%; margin-top: 16px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font: inherit; font-size: 15px; }
.patient-search:focus { outline: 0; border-color: #c9d6e0; box-shadow: 0 0 0 4px var(--accent-soft); }
.patient-list { display: grid; gap: 8px; max-height: min(52vh, 440px); margin: 12px 0 0; padding: 2px; overflow-y: auto; list-style: none; }
.patient-row-button { display: grid; gap: 4px; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.patient-row-button:hover, .patient-row-button:focus-visible { border-color: var(--ink-2); box-shadow: var(--shadow); }
.patient-row-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.patient-row-main b { font-size: 16px; }
.patient-row-main span { color: var(--ink-2); font-size: 14px; }
.patient-row-main small { margin-left: auto; color: var(--muted); font-size: 12px; }
.patient-row-problems { color: var(--ink-2); font-size: 14px; line-height: 1.5; }
.patient-row-allergy { display: inline-flex; align-items: center; gap: 4px; width: fit-content; padding: 1px 8px; border-radius: 999px; background: #fbe9e5; color: var(--danger); font-size: 12px; font-weight: 700; }
.patient-row-allergy .icon { width: 13px; height: 13px; }
.patient-empty { padding: 20px; color: var(--muted); font-size: 14px; text-align: center; }

.label-line { display: flex; align-items: center; gap: 8px; min-height: 1lh; }
.visit-badge { padding: 0 8px; border-radius: 999px; background: var(--line-2, #eee); color: var(--muted); font-size: 11px; font-weight: 700; line-height: 18px; }
.visit-badge.return { background: var(--accent-soft); color: var(--accent); }
#pCode[readonly] { background: var(--paper); color: var(--ink-2); cursor: default; }
.allergy-since { margin-left: 6px; font-size: 11px; font-weight: 500; opacity: .75; }

.past-row { grid-column: 1 / -1; display: flex; align-items: flex-start; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line-2); }
.past-row[hidden] { display: none; }
.past-visits { flex: 1; min-width: 0; padding-top: 6px; }
.past-visits summary { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; font-weight: 700; cursor: pointer; list-style: none; }
.past-visits summary::-webkit-details-marker { display: none; }
.past-visits summary::after { content: "▾"; font-size: 11px; transition: transform .15s; }
.past-visits:not([open]) summary::after { transform: rotate(-90deg); }
.past-visits summary .icon { width: 16px; height: 16px; }
.past-visit-list { display: grid; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.past-visit-list li { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 8px 12px; border-radius: 10px; background: var(--paper); font-size: 14px; }
.past-visit-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.past-visit-body { display: grid; gap: 2px; }
.past-visit-body small { margin-left: 4px; color: var(--muted); font-weight: 500; }
.past-visit-body > span { color: var(--ink-2); font-size: 13px; }
.pmh-button { flex: none; }
.code-filter { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.visit-no { display: block; color: var(--muted); font-size: 12px; }
@media (max-width: 640px) {
  .past-visit-list li { grid-template-columns: minmax(0, 1fr) auto; }
  .past-visit-date { grid-column: 1 / -1; }
  .past-row { flex-direction: column; }
}
