:root {
  color-scheme: light dark;
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --surface-3: #e9e4db;
  --border: #e6e1d8;
  --text: #211f1c;
  --text-2: #5e5a53;
  --text-3: #938e85;
  --accent: #d8824a;
  --accent-soft: #fbe9dc;
  --accent-text: #ffffff;
  --good: #2f9e62;
  --warn: #d98b2b;
  --bad: #d6453d;
  --over: #e2624a;   /* 奶量超過上限 */
  --grid: #ebe7df;
  /* 紀錄類型色 */
  --c-feed: #e3973b;
  --c-breast: #e07a8a;
  --c-pee: #3d9be9;
  --c-poop: #a7703f;
  --c-both: #5e8fd3;
  --c-weight: #7a63d6;
  --c-height: #2fa58f;
  --c-sleep: #5f6fd6;
  --c-temp: #e2574c;
  --c-note: #7a8a99;
  --c-pump: #d16ba5;
  --c-med: #4a9d8f;
  --c-bath: #3aa6c9;
  --c-age: #d8824a;
  --series-1: var(--c-weight);
  --series-3: var(--c-feed);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .04), 0 8px 24px rgba(40, 30, 10, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --surface: #1f1e1b; --surface-2: #27251f; --surface-3: #33302a; --border: #343129;
    --text: #f1eee8; --text-2: #c2bdb3; --text-3: #8b867c;
    --accent: #e8955e; --accent-soft: #3a2a1f;
    --good: #4db87a; --warn: #e6a04a; --bad: #e46a63; --over: #ef7a62; --grid: #2d2b26; --shadow: none;
    --c-feed: #f0a85a; --c-pee: #5aaef0; --c-poop: #c48a56; --c-weight: #9b86ea; --c-sleep: #8290e8; --c-temp: #ee7a70; --c-note: #93a3b3;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1f1e1b; --surface-2: #27251f; --surface-3: #33302a; --border: #343129;
  --text: #f1eee8; --text-2: #c2bdb3; --text-3: #8b867c;
  --accent: #e8955e; --accent-soft: #3a2a1f;
  --good: #4db87a; --warn: #e6a04a; --bad: #e46a63; --over: #ef7a62; --grid: #2d2b26; --shadow: none;
  --c-feed: #f0a85a; --c-pee: #5aaef0; --c-poop: #c48a56; --c-weight: #9b86ea; --c-sleep: #8290e8; --c-temp: #ee7a70; --c-note: #93a3b3;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", -apple-system, BlinkMacSystemFont, "PingFang TC", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
h1 { font-size: 26px; margin: 0 0 8px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 700; letter-spacing: .01em; }
button { font: inherit; cursor: pointer; color: inherit; }
input, select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 11px 12px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* 圖示 */
.ic { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; vertical-align: -4px; }
.ic.sm { width: 14px; height: 14px; vertical-align: -2px; }
.c-feed { --c: var(--c-feed); } .c-breast { --c: var(--c-breast); } .c-pee { --c: var(--c-pee); } .c-poop { --c: var(--c-poop); }
.c-both { --c: var(--c-both); } .c-weight { --c: var(--c-weight); } .c-height { --c: var(--c-height); } .c-sleep { --c: var(--c-sleep); }
.c-temp { --c: var(--c-temp); } .c-note { --c: var(--c-note); } .c-bath { --c: var(--c-bath); } .c-pump { --c: var(--c-pump); } .c-med { --c: var(--c-med); } .c-age { --c: var(--c-age); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 8px; vertical-align: 1px; }

/* 登入 / 代碼 */
.screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; padding: 32px 24px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.brand { width: 64px; height: 64px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 16px; }
.brand .ic { width: 32px; height: 32px; }
.code-input { text-align: center; font-size: 22px; letter-spacing: .3em; text-transform: uppercase; font-variant-numeric: tabular-nums; }
.msg { min-height: 1.5em; font-size: 14px; color: var(--text-2); margin: 10px 0 0; }
.btn-line {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 20px; padding: 13px 16px; border-radius: var(--radius-sm);
  background: #06c755; color: #fff; font-weight: 700; text-decoration: none;
}
.btn-line .ic { fill: #fff; stroke: none; }
.btn-line:hover { background: #05b34c; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 16px 14px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-head h2 { margin-bottom: 8px; }
main { max-width: 720px; margin: 0 auto; padding-bottom: 40px; }

button.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius-sm); padding: 12px 18px; font-weight: 700;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent);
}
button.primary:disabled { opacity: .6; cursor: default; }
button.link { background: none; border: 0; color: var(--accent); padding: 8px; font-weight: 500; }
button.icon {
  background: var(--surface-2); border: 0; border-radius: 12px; width: 40px; height: 40px; display: grid; place-items: center; color: var(--text-2);
  transition: background .15s;
}
button.icon:hover { background: var(--surface-3); color: var(--text); }
button.icon:disabled { opacity: .35; cursor: default; }

/* 頂部 */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 20px 16px 12px; gap: 10px; }
.baby-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar { width: 48px; height: 48px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.avatar .ic { width: 28px; height: 28px; }
.avatar.girl { background: #fde6ec; color: #d8577a; }
.avatar.boy { background: #e2eefc; color: #3b7dd8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .avatar.girl { background: #3d2530; color: #ef8aa8; } :root:not([data-theme="light"]) .avatar.boy { background: #20304a; color: #7fb0f2; } }
.baby-meta { display: flex; flex-direction: column; min-width: 0; }
.baby-select { width: auto; max-width: 100%; font-size: 22px; font-weight: 700; border: 0; background: transparent; padding: 0; appearance: none; -webkit-appearance: none; line-height: 1.2; letter-spacing: -.01em; }
.baby-select:focus { box-shadow: none; }
.age { color: var(--text-2); font-size: 14px; }
.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* stat tiles */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0 16px 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.stat-icon { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); margin-bottom: 10px; }
.stat-icon .ic { width: 18px; height: 18px; }
.stat-label { font-size: 12px; color: var(--text-2); }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; }
.stat-sub { font-size: 12px; color: var(--text-3); min-height: 1.2em; }
@media (max-width: 420px) { .stat-value { font-size: 17px; } .stat { padding: 12px 10px; } }

/* 當日 */
.day-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.day-nav h2 { margin: 0; font-size: 18px; }
.progress-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 15px; gap: 8px; flex-wrap: wrap; }
.progress-title strong { font-size: 20px; font-variant-numeric: tabular-nums; margin-right: 4px; }
.progress { position: relative; height: 14px; background: var(--surface-2); border-radius: 999px; overflow: visible; }
.progress-bar { height: 100%; width: 0; background: var(--c-feed); border-radius: 999px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.progress-bar.ok { background: var(--good); }
.progress-bar.over { background: var(--over); }
.progress-tick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text-3); border-radius: 2px; }
.progress-foot { margin-top: 6px; display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge .ic { width: 14px; height: 14px; }
.badge.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.day-counts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.day-counts .chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border-radius: 999px; background: var(--surface-2); font-size: 13px; color: var(--text-2); }
.day-counts .chip .ic { width: 16px; height: 16px; color: var(--c); }
.day-counts .chip b { color: var(--text); font-variant-numeric: tabular-nums; }

/* 下一餐預測 */
.next-feed { margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); display: flex; gap: 12px; align-items: center; font-size: 14px; line-height: 1.4; }
.next-feed .nf-icon { width: 40px; height: 40px; border-radius: 12px; background: color-mix(in srgb, var(--c-feed) 16%, transparent); color: var(--c-feed); display: grid; place-items: center; flex-shrink: 0; }
.next-feed .big { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0 6px 0 4px; }
.next-feed .sub { color: var(--text-3); font-size: 12px; }
.next-feed.overdue { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.next-feed.overdue .nf-icon { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.next-feed.overdue .big { color: var(--warn); }

/* 快速記錄 */
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.quick button {
  background: var(--surface-2); border: 1px solid transparent; border-radius: 14px; padding: 12px 4px 10px; font-size: 13px; color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform .1s, background .15s;
}
.quick button:hover { background: var(--surface-3); color: var(--text); }
.quick button:active { transform: scale(.96); }
.qi { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 15%, transparent); }
.qi .ic { width: 22px; height: 22px; }
@media (max-width: 420px) { .quick { grid-template-columns: repeat(3, 1fr); gap: 6px; } .quick button { font-size: 12px; } }
.add-form { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.field-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 8px; align-items: center; }
.field-row label { font-size: 14px; color: var(--text-2); }
.field-row select { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* 當日紀錄 */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .t { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 13px; width: 44px; flex-shrink: 0; }
.timeline .ti { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); flex-shrink: 0; }
.timeline .ti .ic { width: 18px; height: 18px; }
.timeline .d { flex: 1; min-width: 0; font-size: 15px; }
.timeline .d b { font-variant-numeric: tabular-nums; }
.timeline .who { display: block; font-size: 12px; color: var(--text-3); }
.timeline .del { background: none; border: 0; color: var(--text-3); width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; opacity: .6; }
.timeline .del .ic { width: 16px; height: 16px; }
.timeline .del:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); opacity: 1; }
.timeline .empty { color: var(--text-3); justify-content: center; font-size: 14px; }

/* 圖表 */
.chart { position: relative; margin-top: 8px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--text-3); font-size: 11px; font-family: inherit; }
.chart .label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .label.over { fill: var(--over); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .empty { color: var(--text-3); text-align: center; padding: 28px 0; font-size: 14px; }
.chart .band { fill: var(--text-2); opacity: .10; }
.chart .band-edge { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 4; fill: none; }
.chart .who-outer { fill: var(--c-weight); opacity: .07; }
.chart .who-inner { fill: var(--c-weight); opacity: .09; }
.chart .who-median { fill: none; stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .who-label { font-size: 10px; fill: var(--text-3); }
.tooltip {
  position: absolute; transform: translate(-50%, -100%); background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 8px;
  font-size: 12px; pointer-events: none; opacity: 0; transition: opacity .12s; white-space: nowrap; z-index: 2; line-height: 1.4;
}
.tooltip.show { opacity: 1; }

/* 體重分析 */
.analysis { margin-top: 14px; display: grid; gap: 10px; }
.analysis .row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.5; }
.analysis .ai { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); flex-shrink: 0; }
.analysis .ai .ic { width: 16px; height: 16px; }
.analysis .pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); margin-left: 6px; vertical-align: 1px; }
.analysis .pill .ic { width: 12px; height: 12px; }
.analysis .pill.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.analysis .pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.analysis .pill.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.analysis .big { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* 表格 */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; white-space: nowrap; }
th { color: var(--text-3); font-weight: 500; border-bottom: 1px solid var(--border); font-size: 12px; }
td { border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { text-align: left; }
td a { color: var(--accent); text-decoration: none; font-weight: 500; }
td.ok { color: var(--good); font-weight: 600; }
td.over { color: var(--over); font-weight: 600; }

/* LINE 速查 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips span { background: var(--surface-2); border-radius: 8px; padding: 4px 9px; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-2); }
.chips span.cmd { background: var(--accent-soft); color: var(--accent); }

.footer { text-align: center; margin: 8px 16px 0; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.footer .sep { color: var(--text-3); }
.footer .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }
.footer .link { padding: 0 4px; }

/* dialog */
dialog { border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); width: min(420px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 15, 5, .45); backdrop-filter: blur(2px); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 18px; margin-bottom: 4px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
dialog .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
dialog .pair .full { grid-column: 1 / -1; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
