/* 小體溫：樣式 */
/* 配色沿用「兩天一夜打包清單」：奶茶米色底、米白卡片、深可可色文字、圓體 Huninn */
:root {
  --bg: #E8DFD5;
  --surface: #F6F1EA;
  --surface-2: #EFE6DC;
  --text: #5B4A40;
  --muted: #968578;
  --line: #DDD0C3;
  --accent: #A88A74;
  --sun: #C2A38A;
  --primary: #5B4A40;
  --on-primary: #F6F1EA;
  --red: #B5563F;
  --red-bg: #F3DED6;
  --yellow: #8E6A1E;
  --yellow-bg: #F2E6C8;
  --fever: #B4602F;
  --fever-bg: #F4E1D2;
  --ok: #5F7F4F;
  --ok-bg: #E3E8D8;
  --toast: #5B4A40;
  --toast-ink: #F6F1EA;
  --toast-hi: #E9CFB4;
  --shadow: none;
  --radius: 16px;
  --child: #A88A74;
  --sans: "Huninn", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #2C2521; --surface: #39302B; --surface-2: #433832; --text: #EDE2D7; --muted: #B2A194; --line: #4A3E37;
    --accent: #B39580; --sun: #C9AB92; --primary: #EDE2D7; --on-primary: #2C2521;
    --red: #E59A86; --red-bg: #4A2E28; --yellow: #E2C27E; --yellow-bg: #463A22; --fever: #E8A57C; --fever-bg: #4A3427;
    --ok: #A9C29A; --ok-bg: #33392B; --toast: #EDE2D7; --toast-ink: #2C2521; --toast-hi: #8A5A3A; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #2C2521; --surface: #39302B; --surface-2: #433832; --text: #EDE2D7; --muted: #B2A194; --line: #4A3E37;
  --accent: #B39580; --sun: #C9AB92; --primary: #EDE2D7; --on-primary: #2C2521;
  --red: #E59A86; --red-bg: #4A2E28; --yellow: #E2C27E; --yellow-bg: #463A22; --fever: #E8A57C; --fever-bg: #4A3427;
  --ok: #A9C29A; --ok-bg: #33392B; --toast: #EDE2D7; --toast-ink: #2C2521; --toast-hi: #8A5A3A; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 18px/1.5 var(--sans);
  min-height: 100vh; padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
a, input, select { touch-action: manipulation; }
a { color: var(--accent); }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px 120px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 15px; }

/* 頂端列 */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  max-width: 640px; margin: 0 auto;
}
.topbar h1 { font-size: 22px; font-weight: 900; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--surface-2); flex: none; }
.back { font-size: 26px; }

/* 按鈕 */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 22px; border-radius: 14px; font-weight: 600; background: var(--surface); border: 1.5px solid var(--line); }
.btn.primary, .btn.child { border: 0; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.child { background: var(--child); color: #fff; }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 21px; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .4; cursor: default; }

/* 孩子卡片 */
.cards { display: grid; gap: 14px; }
.card { background: var(--surface); border-radius: var(--radius); border-left: 8px solid var(--child); overflow: hidden; }
.card-main { display: flex; gap: 14px; padding: 16px; align-items: center; width: 100%; text-align: left; }
.avatar { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; background: color-mix(in srgb, var(--child) 22%, transparent); border: 3px solid var(--child); flex: none; }
.avatar.sm { width: 40px; height: 40px; font-size: 21px; border-width: 2px; }
.card-info { flex: 1; min-width: 0; }
.card-name { font-size: 21px; font-weight: 700; }
.card-age { font-size: 15px; color: var(--muted); }
.card-temp { text-align: right; flex: none; }
.temp-num { font-size: 30px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.temp-meta { font-size: 14px; color: var(--muted); }
.card-foot { display: flex; align-items: center; gap: 10px; padding: 0 16px 14px; }
.card-foot .btn { flex: none; min-height: 48px; }
.card-foot .next { flex: 1; font-size: 15px; color: var(--muted); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 14px; font-weight: 700; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.fever { background: var(--fever-bg); color: var(--fever); }
.badge.normal { background: var(--ok-bg); color: var(--ok); }
.badge.stale, .badge.none { background: var(--surface-2); color: var(--muted); }
.temp-num.fever { color: var(--fever); }

/* 警示 */
.alert { border-radius: 14px; padding: 12px 14px; margin: 0 16px 12px; }
.alert.red { background: var(--red-bg); color: var(--red); }
.alert.yellow { background: var(--yellow-bg); color: var(--yellow); }
.alert.info { background: var(--surface-2); color: var(--muted); }
.alert b { display: block; font-size: 18px; }
.alert p { margin: 2px 0 0; font-size: 16px; color: var(--text); }
.panel .alert { margin: 0 0 12px; }
.disclaimer { font-size: 14px; color: var(--muted); text-align: center; margin: 14px 0 0; }

/* 一般區塊 */
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.panel h2 { font-size: 18px; margin: 0 0 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.spacer { flex: 1; }
.empty { text-align: center; padding: 40px 16px; }
.empty .big-emoji { font-size: 64px; }

/* 孩子切換 */
.child-bar { display: flex; gap: 10px; overflow-x: auto; padding: 4px 16px 12px; max-width: 640px; margin: 0 auto; scrollbar-width: none; }
.child-bar::-webkit-scrollbar { display: none; }
.chip { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 99px; background: var(--surface); border: 3px solid var(--line); flex: none; font-weight: 600; box-shadow: var(--shadow); }
.chip.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, var(--surface)); }
.chip .avatar { --child: var(--c); }

/* 記錄體溫 */
.rec-head { background: var(--child); color: #fff; padding: calc(12px + env(safe-area-inset-top)) 16px 16px; }
.rec-head .inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.rec-head .avatar { background: rgba(255,255,255,.25); border-color: #fff; }
.rec-head .icon-btn { background: rgba(255,255,255,.2); color: #fff; }
.rec-head .who { flex: 1; }
.rec-head .who b { font-size: 24px; display: block; line-height: 1.2; }
.rec-head .who span { font-size: 15px; opacity: .9; }
.rec-body { border-top: 6px solid var(--child); }
.display { text-align: center; font-size: 76px; font-weight: 800; letter-spacing: 1px; font-variant-numeric: tabular-nums; padding: 12px 0 0; line-height: 1.1; }
.display .unit { font-size: 32px; color: var(--muted); }
.display.placeholder { color: var(--line); }
.display.fever { color: var(--fever); }
.display-sub { text-align: center; min-height: 26px; font-size: 16px; color: var(--muted); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin: 12px 0; }
.seg button { min-height: 50px; border-radius: 11px; font-weight: 700; font-size: 19px; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); color: var(--child); outline: 2px solid var(--child); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 14px; }
.keypad button { min-height: 62px; border-radius: 14px; background: var(--surface); font-size: 28px; font-weight: 600; }
.keypad button:active { background: var(--surface-2); }
.time-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 16px; }
.time-row input { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 10px; }
.save-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); z-index: 20; }
.save-bar .inner { max-width: 640px; margin: 0 auto; }

/* 一起量 */
.tg-row { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; padding: 14px; border-radius: var(--radius); background: var(--surface); border-left: 8px solid var(--child); margin-bottom: 12px; }
.tg-row .tg-inputs { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.tg-row input.temp { font-size: 30px; font-weight: 800; min-height: 60px; text-align: center; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); width: 100%; }
.tg-row input.temp:focus { outline: none; border-color: var(--child); }
.tg-row .seg { margin: 0; grid-template-columns: repeat(3, auto); }
.tg-row .seg button { min-height: 52px; font-size: 16px; padding: 0 10px; }
.tg-row .hint { grid-column: 1 / -1; font-size: 15px; }

/* 圖表 */
.range-seg { display: inline-grid; grid-template-columns: repeat(2, auto); background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.range-seg button { padding: 6px 14px; border-radius: 9px; font-weight: 600; font-size: 16px; }
.range-seg button.on { background: var(--surface); box-shadow: var(--shadow); }
.chart-box { position: relative; height: 260px; margin-top: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--muted); margin-top: 8px; }
.legend i { font-style: normal; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.toggle input { width: 22px; height: 22px; }

/* 紀錄列表 */
.rec-list { list-style: none; margin: 0; padding: 0; }
.rec-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rec-list li:last-child { border-bottom: 0; }
.rec-list .t { font-size: 22px; font-weight: 700; width: 80px; font-variant-numeric: tabular-nums; }
.rec-list .t.fever { color: var(--fever); }
.rec-list .meta { flex: 1; font-size: 15px; color: var(--muted); }
.day-head { font-size: 15px; font-weight: 700; color: var(--muted); padding: 10px 0 2px; }

/* 表單 */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field label .req { color: var(--red); }
.field input, .field select { width: 100%; min-height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; }
.colors, .emojis { display: flex; flex-wrap: wrap; gap: 10px; }
.colors button { width: 48px; height: 48px; border-radius: 50%; border: 4px solid transparent; outline: 2px solid transparent; }
.colors button.on { border-color: var(--surface); outline-color: var(--text); }
.emojis button { width: 52px; height: 52px; border-radius: 14px; font-size: 30px; background: var(--surface-2); border: 3px solid transparent; }
.emojis button.on { border-color: var(--text); background: var(--surface); }
.err { color: var(--red); font-size: 16px; min-height: 24px; }
.manage-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.manage-list { list-style: none; margin: 0; padding: 0; }
.manage-list .name { flex: 1; font-weight: 600; }
.manage-list .icon-btn { width: 40px; height: 40px; font-size: 18px; }

/* 浮動按鈕 */
.fab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 15; }
.fab .btn { box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* 提示訊息與復原 */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); max-width: 608px; margin: 0 auto; background: var(--toast); color: var(--toast-ink); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.3); overflow: hidden; }
.toast .msg { flex: 1; font-size: 16px; }
.toast button { color: var(--toast-hi); font-weight: 700; padding: 8px 6px; }
.toast .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--toast-hi); animation: shrink linear forwards; }
@keyframes shrink { from { width: 100%; } to { width: 0; } }
.net { text-align: center; font-size: 14px; padding: 4px; background: var(--yellow-bg); color: var(--yellow); }

/* 登入 */
.auth { max-width: 420px; margin: 0 auto; padding: 48px 16px; }
.auth .logo { font-size: 64px; text-align: center; }
.auth h1 { text-align: center; margin: 0 0 4px; }
.auth .tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 24px 0 16px; }
.auth .tabs button { padding: 10px; border-bottom: 3px solid var(--line); font-weight: 600; color: var(--muted); }
.auth .tabs button.on { border-color: var(--accent); color: var(--text); }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------------- 第二階段 ---------------- */
.btn.sm { min-height: 42px; padding: 0 14px; font-size: 16px; border-radius: 12px; }
.note { background: var(--surface-2); color: var(--muted); border-radius: 14px; padding: 12px 14px; font-size: 15px; margin-bottom: 14px; }
.redtxt { color: var(--red); }
.fever-t { color: var(--fever); }
.link-panel { text-decoration: none; color: inherit; font-weight: 600; }
.source { margin: 10px 0 0; }

/* 首頁：到期提醒 */
.panel.due { border-left: 8px solid var(--sun); }
.due-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.due-row:last-of-type { border-bottom: 0; }
.vax-line, .done-line { margin: -4px 16px 10px; font-size: 15px; border-radius: 10px; padding: 6px 10px; }
.vax-line { background: var(--surface-2); color: var(--text); }
.done-line { color: var(--ok); background: var(--ok-bg); }

/* 孩子頁：功能按鈕 */
.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-bottom: 14px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; background: var(--surface); border-radius: 14px; text-decoration: none; color: var(--text); font-size: 15px; font-weight: 600; text-align: center; }
.act span { font-size: 26px; }
.vax-panel { border-left: 8px solid var(--child); }
.rec-list .t.ico { font-size: 22px; width: 80px; }
.rec-list .meta a { color: var(--text); font-weight: 600; }

/* 選項膠囊 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chipbtn { min-height: 44px; padding: 0 14px; border-radius: 99px; background: var(--surface); border: 1.5px solid var(--line); font-size: 16px; }
.panel .chipbtn { background: var(--bg); }
.chipbtn.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.chipbtn.red { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); color: var(--red); }
.chipbtn.red.on { background: var(--red); color: var(--surface); border-color: var(--red); }

/* 疫苗清單 */
.vx-list { display: grid; gap: 10px; margin-bottom: 14px; }
.vx-item { background: var(--surface); border-radius: 16px; border: 2px solid transparent; }
.vx-item.on { border-color: var(--child); }
.vx-toggle { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; }
.vx-check { width: 30px; height: 30px; flex: none; border-radius: 9px; border: 2px solid var(--muted); display: grid; place-items: center; font-weight: 800; color: var(--on-primary); }
.vx-item.on .vx-check { background: var(--child); border-color: var(--child); color: #fff; }
.vx-detail { padding: 0 14px 14px; }
.vx-detail .field { margin-bottom: 10px; }

/* 注射部位 */
.stepper { display: flex; align-items: center; justify-content: center; gap: 18px; }
.stepper button { width: 60px; height: 60px; border-radius: 50%; background: var(--bg); font-size: 30px; font-weight: 700; }
.stepper span { font-size: 20px; min-width: 110px; text-align: center; }
.stepper b { font-size: 40px; }
.photo-preview { width: 100%; max-height: 320px; object-fit: contain; border-radius: 12px; margin-bottom: 10px; background: var(--bg); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: var(--bg); }
.photos figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* 摘要 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; min-width: 0; }
.stat span { font-size: 13px; color: var(--muted); }
.stat b { font-size: 28px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat b small { font-size: 14px; }
.stat > small { font-size: 12px; color: var(--muted); }
.summary-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.sum-name { font-size: 26px; font-weight: 700; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 6px 4px; }
.tbl td { border-bottom: 1px solid var(--line); padding: 8px 4px; font-variant-numeric: tabular-nums; }
.visit-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; width: 100%; }
.print-head { display: none; }

/* 家庭邀請 */
.invite-out { margin-top: 14px; padding: 14px; background: var(--bg); border-radius: 14px; text-align: center; }
.qr { width: 200px; margin: 0 auto; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { width: 100%; height: auto; display: block; }
.invite-url { width: 100%; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 10px; font-size: 14px; }
.invite-out .row { justify-content: center; }
.manage-list select { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 8px; }
.invite-box { text-align: left; }

/* 列印（就醫摘要、疫苗摘要）：白底黑字，只印內容 */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f3f3f3; --text: #000; --muted: #444; --line: #bbb; }
  body { background: #fff; font-size: 13px; }
  .topbar, .fab, .save-bar, .no-print, .child-bar, #toast-root, #net { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .panel, .stat { border: 1px solid #bbb; break-inside: avoid; }
  .print-head { display: block; }
  .chart-box { height: 220px; }
}
.panel.due .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }
.panel.due .row .btn { white-space: nowrap; padding: 0 8px; }
