:root {
  --bg: #fff7f2;
  --card: #ffffff;
  --ink: #3b2f2a;
  --muted: #716158;
  --line: #f0e2d9;
  --brand: #b94824;
  --brand-ink: #ffffff;
  --feed: #ffe3d3;
  --poop: #f6e7c1;
  --pee: #d9ecff;
  --glucose: #e7e0ff;
  --bp: #ffdbe4;
  --meal: #dff3dc;
  --warn: #c0392b;
  --ok: #2e7d4f;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(120, 70, 40, 0.08);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid #f5a37f; outline-offset: 2px; }
input:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(239, 125, 87, 0.15); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.err { color: var(--warn); min-height: 1.4em; margin: 6px 0 0; font-size: 0.9rem; }

/* 按钮 */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px;
  background: #f3e7df; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { background: #fde4e1; color: var(--warn); }
.btn.ghost { background: var(--card); border: 1px solid var(--line); font-weight: 500; }
.btn.block { display: block; width: 100%; }
.btn.grow { flex: 1; }
.btn:active { transform: scale(0.98); }
.icon-btn {
  border: 0; background: transparent; font-size: 1.4rem; min-width: 44px; min-height: 44px;
  border-radius: 12px; cursor: pointer; color: var(--muted);
}

/* 登录 */

/* 顶栏 */
main { max-width: 640px; margin: 0 auto; padding: 0 14px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
.tabs { flex: 1; display: flex; background: #f3e7df; border-radius: 14px; padding: 4px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px 0; border-radius: 10px;
  font-weight: 600; color: var(--muted); cursor: pointer; min-height: 42px;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* 概览 */
.summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 6px 0 14px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 0.82rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; line-height: 1.3; }
.stat .sub { color: var(--muted); font-size: 0.8rem; white-space: pre-line; overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }
.stat.alert .value { color: var(--warn); }

/* 快捷按钮 */
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.quick.two { grid-template-columns: repeat(2, 1fr); }
.qbtn {
  border: 0; border-radius: 18px; padding: 16px 6px 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 96px;
  box-shadow: var(--shadow); color: var(--ink);
}
.qbtn .emoji { font-size: 1.7rem; line-height: 1; }
.qbtn .name { font-weight: 700; }
.qbtn .hint { font-size: 0.75rem; color: var(--muted); }
.qbtn:active { transform: scale(0.97); }
.k-feed { background: var(--feed); }
.k-poop { background: var(--poop); }
.k-pee { background: var(--pee); }
.k-glucose { background: var(--glucose); }
.k-bp { background: var(--bp); }
.k-meal { background: var(--meal); }

/* 历史 */
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.history-head h2 { font-size: 1.05rem; margin: 0; }
.day { margin: 14px 0 6px; font-size: 0.85rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px;
  box-shadow: var(--shadow); cursor: pointer; min-height: 56px;
}
.item .badge { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.item .note { display: block; color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .time { color: var(--muted); font-size: 0.9rem; flex: none; white-space: nowrap; padding-left: 4px; font-variant-numeric: tabular-nums; }
.flag { display: inline-block; font-size: 0.72rem; padding: 1px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }
.flag.high { background: #fde4e1; color: var(--warn); }
.flag.low { background: #fff1c9; color: #8a5a00; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* 选项 chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px;
  cursor: pointer; min-height: 40px;
}
.chips button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips.small button { padding: 4px 11px; min-height: 34px; font-size: 0.85rem; }

/* 表单弹层 */
.sheet {
  border: 0; padding: 0; width: 100%; max-width: 640px; margin: auto auto 0; border-radius: 22px 22px 0 0;
  background: var(--card); color: var(--ink); max-height: 92vh;
}
.sheet::backdrop { background: rgba(40, 20, 10, 0.4); }
.sheet form, .sheet > .menu-list, .sheet > p { padding: 0 18px; }
.sheet form { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
.sheet > p { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px 18px; position: sticky; top: 0; background: var(--card); }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-foot {
  display: flex; gap: 10px; margin-top: 8px; position: sticky; bottom: 0; z-index: 1;
  background: var(--card); padding: 10px 0 calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 12px -8px rgba(120, 70, 40, 0.2);
}
.menu-list { display: grid; gap: 10px; }
.field { margin: 14px 0; }
.field > .flabel { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.95rem; }
input[type="number"], input[type="password"], input[type="datetime-local"], textarea, input[type="text"] {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fffdfb;
  min-height: 46px;
}
input[type="tel"], input[type="date"], input[type="time"], input[type="search"], select {
  width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fffdfb;
}
button:disabled { cursor: not-allowed; opacity: 0.65; }
a { color: #8d351a; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
:focus-visible { outline: 3px solid #8d351a; }
textarea { resize: none; min-height: 70px; }
.big-num { font-size: 1.6rem; font-weight: 700; text-align: center; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.unit { color: var(--muted); font-size: 0.85rem; text-align: center; margin-top: 2px; }
.stepper { display: flex; gap: 8px; align-items: stretch; }
.stepper input { flex: 1; }
.stepper button { width: 56px; border: 0; border-radius: 12px; background: #f3e7df; font-size: 1.2rem; font-weight: 700; cursor: pointer; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #3b2f2a; color: #fff; padding: 10px 14px; border-radius: 14px; z-index: 50;
  display: flex; align-items: center; gap: 12px; max-width: 92vw; box-shadow: var(--shadow);
}
.toast button { background: transparent; border: 0; color: #ffcfb8; font-weight: 700; cursor: pointer; min-height: 32px; }

@media (min-width: 560px) {
  .summary { grid-template-columns: repeat(4, 1fr); }
  .stat.wide { grid-column: span 2; }
}
@media (prefers-reduced-motion: reduce) {
  .btn:active, .qbtn:active { transform: none; }
}

.item .note.meal { color: #6b5a9a; white-space: normal; overflow-wrap: anywhere; }
.link-btn { border: 0; background: transparent; color: var(--muted); font-size: 0.85rem; padding: 6px 0; min-height: 32px; cursor: pointer; text-decoration: underline; }

/* 记录/统计切换 */
.views { display: flex; gap: 8px; margin: 2px 0 12px; }
.views button {
  flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 0;
  min-height: 42px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.views button[aria-pressed="true"] { border-color: var(--brand); color: var(--brand); background: #fff1ea; }

/* 中文时间选择器 */
.tp-row { display: flex; gap: 6px; }
.tp select {
  appearance: none; -webkit-appearance: none; border: 1px solid var(--line); border-radius: 12px; background: #fffdfb;
  min-height: 46px; padding: 0 10px; font-size: 1rem; color: var(--ink); text-align: center; text-align-last: center;
}
.tp select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(239, 125, 87, 0.15); }
.tp .tp-date { flex: 1 1 auto; min-width: 0; }
.tp .tp-num { flex: 0 0 76px; font-variant-numeric: tabular-nums; }
.tp-row.is-empty .tp-num { opacity: 0.4; }
.tp-quick { margin-top: 8px; }

/* 统计页 */
.stats-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.stats-head h2 { font-size: 1.05rem; margin: 0; }
#stats-range { margin: 6px 0 10px; }
.chart-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 8px 12px; margin-bottom: 12px; }
.chart-card h3, .chart-card .chart-desc, .chart-card .high-list { margin-left: 4px; margin-right: 4px; }
.chart-card h3 { margin: 0; font-size: 1rem; }
.chart-desc { margin: 2px 0 8px; color: #75665e; font-size: 0.85rem; }
.chart-box { position: relative; width: 100%; }
.chart-empty { color: var(--muted); text-align: center; padding: 26px 0; margin: 0; }
.high-list { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 8px; }
.high-list h4 { margin: 0 0 4px; font-size: 0.9rem; color: var(--warn); }
.high-list p { margin: 8px 0; font-size: 0.88rem; }
.hl-line { display: flex; align-items: baseline; gap: 2px; }
.hl-time { margin-left: auto; color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.hl-val { font-weight: 700; color: var(--warn); }
.hl-meal { display: block; color: #6b5a9a; overflow-wrap: anywhere; }
.stats-foot { margin-top: 4px; }
.ref-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 4px 0; font-size: 0.8rem; color: #75665e; }
.ref-item { display: inline-flex; align-items: center; gap: 5px; }
.ref-dash { display: inline-block; width: 18px; border-top: 3px dashed currentColor; }
.ref-dash[data-c="#e0457b"] { color: #e0457b; }
.ref-dash[data-c="#7c5cff"] { color: #7c5cff; }
.ref-dash[data-c="#9a6a00"] { color: #9a6a00; }
.ref-dash[data-c="#4a90d9"] { color: #4a90d9; }

/* 预估下次喝奶 */
.predict-card {
  grid-column: 1 / -1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  border: 0; border-radius: var(--radius); padding: 12px 14px; cursor: pointer; color: var(--ink);
  background: linear-gradient(135deg, #fff1e8, #ffe3d3); box-shadow: var(--shadow);
}
.predict-card .label { color: #9a5b3f; font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; width: 100%; }
.predict-card .value { font-size: 1.6rem; font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; }
.predict-card .sub { color: #7a5a4a; font-size: 0.85rem; white-space: pre-line; }
.predict-card .hint { color: var(--brand); font-size: 0.8rem; font-weight: 600; margin-top: 2px; }
.predict-card.is-soon { background: linear-gradient(135deg, #fff4d6, #ffe2a8); }
.predict-card.is-due { background: linear-gradient(135deg, #ffe0d1, #ffc3a8); }
.predict-card.is-overdue { background: linear-gradient(135deg, #ffe1e1, #ffc9c9); }
.predict-card.is-overdue .value { color: var(--warn); }
.conf { margin-left: auto; font-size: 0.72rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: rgba(255,255,255,0.7); }
.conf-high { color: var(--ok); }
.conf-medium { color: #9a6a00; }
.conf-low { color: var(--muted); }
.predict-body { padding: 0 18px calc(18px + env(safe-area-inset-bottom)); }
.pd-hero { background: #fff4ee; border-radius: 14px; padding: 12px 14px; margin: 6px 0 10px; }
.pd-time { font-size: 2rem; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.pd-sub { color: #7a5a4a; font-size: 0.88rem; margin-top: 2px; }
.pd-facts { font-size: 0.88rem; margin: 6px 0; }
.pd-h { font-size: 0.95rem; margin: 12px 0 4px; }
.pd-list { margin: 0; padding-left: 1.2em; font-size: 0.88rem; }
.pd-list li { margin: 5px 0; }
.pd-warn { color: #8a4b00; background: #fff6e0; border-radius: 12px; padding: 8px 10px 8px 1.8em; margin-top: 10px; }
#profile form > p.muted { margin: 0 0 4px; }
.field-tip { margin: 6px 0 0; }
.tp .tp-year { flex: 0 0 96px; }
#profile-body input[type="number"] { max-width: 180px; }
.predict-body > .btn { margin-top: 10px; }
.meal-link { color: #6b5a9a; }
.item .time { align-self: flex-start; padding-top: 2px; }
.meal-link { overflow-wrap: anywhere; }

/* 二级页面入口 & 紧急提醒 */
.more-entry {
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 8px; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px dashed #e8c9b8; border-radius: var(--radius); padding: 10px 14px; margin: -6px 0 18px;
}
.more-entry .me-title { font-weight: 700; }
.more-entry .me-sub { grid-column: 1; color: var(--muted); font-size: 0.8rem; }
.more-entry .me-arrow { grid-column: 2; grid-row: 1 / span 2; font-size: 1.6rem; color: var(--brand); }
.flag.danger { background: var(--warn); color: #fff; }
.danger-banner {
  grid-column: 1 / -1; background: #c0392b; color: #fff; border-radius: var(--radius); padding: 12px 14px;
  font-weight: 600; line-height: 1.5;
}
/* 血压表单：高压 / 低压 / 心率 一行三格 */
.bp-row { gap: 8px; }
.bp-row > .field { min-width: 0; margin: 10px 0 4px; }
.bp-row .flabel { text-align: center; }
.bp-row input { width: 100%; min-width: 0; padding-left: 4px; padding-right: 4px; }
.bp-row input { -moz-appearance: textfield; appearance: textfield; }
.bp-row input::-webkit-inner-spin-button, .bp-row input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
