:root {
  --bg: #f6f3ee; --surface: #ffffff; --surface-2: #efebe4; --line: #e2ddd4;
  --text: #22252b; --muted: #6d7078;
  --accent: #c2653d; --accent-ink: #ffffff; --accent-soft: #f6e3d9;
  --feed: #c2653d; --diaper: #3d8a8a; --sleep: #5b5fb3; --health: #a5487a;
  --alert: #c0392b; --alert-soft: #fbe5e2; --watch: #b7791f; --watch-soft: #fbf0dc;
  --good: #2f855a; --good-soft: #e1f3e8; --info: #3b6ea8; --info-soft: #e3edf8;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --surface: #1d2028; --surface-2: #262a34; --line: #2f3440;
    --text: #e9e7e3; --muted: #9a9ea8;
    --accent: #e08a62; --accent-ink: #1a1410; --accent-soft: #3a2a22;
    --feed: #e08a62; --diaper: #5fb3b3; --sleep: #8f93e6; --health: #d47aa8;
    --alert: #ef6f60; --alert-soft: #3a2220; --watch: #e0a64a; --watch-soft: #352b1a;
    --good: #5cc08a; --good-soft: #1d3127; --info: #6fa3e0; --info-soft: #1d2a3a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.4rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--alert); min-height: 1.2em; margin: .4rem 0; font-size: .9rem; }

.screen.center { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.narrow { width: 100%; max-width: 380px; }
.logo { font-size: 2.4rem; }

label { display: block; font-size: .85rem; color: var(--muted); margin: .7rem 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem;
  min-height: 48px;
}
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: .6rem; color: var(--text); font-size: 1rem; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: .6rem 1rem; min-height: 44px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; margin-top: .5rem; }
.btn.danger { color: var(--alert); }
.btn:active { transform: scale(.98); }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 1.4rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: .4rem; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.baby-name { font-weight: 700; font-size: 1.15rem; }
main { padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 680px; margin: 0 auto; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: .72rem; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabbar button span { font-size: 1.25rem; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* status */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.stat .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 1.35rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: .85rem; color: var(--muted); }
.stat.feed { border-left: 4px solid var(--feed); }
.stat.diaper { border-left: 4px solid var(--diaper); }
.stat.sleep { border-left: 4px solid var(--sleep); }
.stat.today { border-left: 4px solid var(--muted); }

.live {
  margin-top: 10px; border-radius: var(--radius); padding: 14px; display: flex; align-items: center; gap: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent);
}
.live.sleeping { background: var(--info-soft); border-color: var(--sleep); }
.live .timer { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.live .grow { flex: 1; }

/* when chips */
.when { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.when::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: .45rem .8rem; font: inherit; font-size: .88rem; min-height: 36px; cursor: pointer;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip input[type="time"] { display: inline; width: auto; min-height: 0; padding: 0; margin: 0 0 0 .3rem; border: 0; background: none; }

/* quick actions */
.group { margin-top: 6px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; }
.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.action {
  text-align: left; font: inherit; color: var(--text); background: var(--surface); cursor: pointer;
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-height: 58px; box-shadow: var(--shadow);
}
.action .hint { display: block; font-size: .75rem; color: var(--muted); }
.action.feed { border-left: 4px solid var(--feed); }
.action.diaper { border-left: 4px solid var(--diaper); }
.action.sleep { border-left: 4px solid var(--sleep); }
.action.meds { border-left: 4px solid var(--health); }
.action.more { border-style: dashed; color: var(--muted); }
.action:active { transform: scale(.98); }

/* insights */
.insight { display: flex; gap: 10px; border-radius: 14px; padding: 12px; margin-bottom: 8px; border: 1px solid var(--line); background: var(--surface); }
.insight .ic { font-size: 1.3rem; line-height: 1.2; }
.insight .t { font-weight: 600; }
.insight .d { font-size: .88rem; color: var(--muted); }
.insight.alert { background: var(--alert-soft); border-color: var(--alert); }
.insight.watch { background: var(--watch-soft); border-color: var(--watch); }
.insight.good { background: var(--good-soft); border-color: var(--good); }
.insight.info { background: var(--info-soft); border-color: transparent; }
.disclaimer { font-size: .75rem; color: var(--muted); margin-top: 6px; }

/* history */
.filters { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 8px; }
.day-head { position: sticky; top: 64px; background: var(--bg); padding: 8px 0 4px; font-weight: 700; z-index: 1; }
.event { display: grid; grid-template-columns: 48px 28px 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.event .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.event .title { font-weight: 600; }
.event .detail { font-size: .85rem; color: var(--muted); }
.event .del { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* stats */
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.chart h4 { margin: 0 0 6px; font-size: .9rem; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 9px; font-family: inherit; }
.bar-feed { fill: var(--feed); } .bar-diaper { fill: var(--diaper); } .bar-sleep { fill: var(--sleep); } .bar-health { fill: var(--health); }
.axis { stroke: var(--line); }
.line-w { stroke: var(--accent); fill: none; stroke-width: 2; }
.dot-w { fill: var(--accent); }
.ref { stroke: var(--muted); stroke-dasharray: 3 3; }
.heat { fill: var(--feed); }
.seg { display: flex; gap: 6px; margin-bottom: 10px; }

/* more */
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu .action { min-height: 64px; }
.qa { padding: 10px 0; border-bottom: 1px solid var(--line); }
.qa .q { font-weight: 600; }
.qa .a { color: var(--muted); font-size: .9rem; }

/* sheet */
dialog#sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
dialog#sheet::backdrop { background: rgba(0,0,0,.45); }
#sheet-form { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); border-radius: 999px; padding: .5rem .6rem .5rem 1rem; z-index: 20;
  display: flex; align-items: center; gap: 10px; width: max-content; max-width: calc(100% - 32px);
  white-space: nowrap; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast #toast-text { overflow: hidden; text-overflow: ellipsis; }
.toast .link { color: var(--accent-soft); }
