/* Baby Tracker — mobile-first, automatic day/night theme */

:root {
  --bg: #f7f4ef;
  --card: #ffffff;
  --ink: #2a2620;
  --ink-soft: #6f675c;
  --line: #e8e2d8;
  --accent: #e8875a;
  --walk: #5aa469;
  --feed: #e8875a;
  --diaper: #9a7fc1;
  --sleep: #5b8dd6;
  --danger: #d6604d;
  --shadow: 0 1px 3px rgba(60, 50, 30, .08);
  --topbar-h: 52px;
  --tabbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120e;
    --card: #201c16;
    --ink: #efe9df;
    --ink-soft: #a39a8b;
    --line: #322c23;
    --accent: #f0976c;
    --walk: #6fbb7f;
    --feed: #f0976c;
    --diaper: #b095d6;
    --sleep: #74a1e4;
    --danger: #e07260;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* App frame: the whole app lives in a viewport-height box. dvh tracks the
   mobile browser toolbar (which collapses on scroll), so the frame — and
   the bars anchored to its edges — resize with it instead of being pushed
   off-screen. The 100vh line is a fallback for browsers without dvh. */
body {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input { font: inherit; color: inherit; }
.muted { color: var(--ink-soft); }
.center { text-align: center; padding: 24px 0; }

/* ---------- topbar ---------- */
.topbar {
  flex: none;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 17px; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  min-width: 40px; min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); font-size: 14px; font-weight: 600;
}

/* ---------- view ----------
   Content scrolls inside the frame (not the document), so scrolling can
   never drag the bars away with it. */
.view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------- tabbar ---------- */
.tabbar {
  flex: none;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background: none; border: 0;
  color: var(--ink-soft);
  font-size: 11px;
  min-height: 44px;
}
.tab.on { color: var(--accent); }
.tab-ic { font-size: 20px; line-height: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.day-head {
  font-size: 13px; font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .04em;
  text-align: center;
  margin: 8px 0;
}

/* ---------- open (in-progress) card ---------- */
.open-cards { display: flex; flex-direction: column; gap: 12px; }
.open-card { border-top: 4px solid var(--accent); }
.open-card.t-walk { border-top-color: var(--walk); }
.open-card.t-feed { border-top-color: var(--feed); }
.open-card.t-sleep { border-top-color: var(--sleep); }
.oc-head { display: flex; align-items: center; gap: 8px; }
.oc-icon { font-size: 20px; }
.oc-title { font-weight: 700; flex: 1; }
.oc-when { color: var(--ink-soft); font-size: 14px; font-variant-numeric: tabular-nums; }
.oc-timer {
  font-size: 40px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin: 8px 0 12px;
  letter-spacing: .01em;
}
.calm-card { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); }
.calm-ic { font-size: 22px; }
.err-card { color: var(--danger); }

/* ---------- dashboard mini cards & stats ---------- */
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.duo.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mini-card { padding: 12px; display: flex; flex-direction: column; }
.mc-lb { font-size: 12px; font-weight: 700; color: var(--ink-soft); margin-bottom: 4px; }
.mc-ago {
  font-size: 18px; font-weight: 700; color: var(--accent);
  margin-top: 2px; font-variant-numeric: tabular-nums;
}
/* fine-print footer: pinned to the card bottom so the row aligns */
.mc-foot { margin-top: auto; }
.mc-sep { border-top: 1px solid var(--line); margin: 6px 0; }
.mc-det {
  font-size: 11px; color: var(--ink-soft); line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { padding: 12px; }
.stat.wide { grid-column: 1 / -1; }
.st-ic { font-size: 18px; }
.st-main { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.st-lb { font-size: 12px; color: var(--ink-soft); }
.st-sub { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.btn.ghost { background: none; color: var(--ink-soft); border-color: var(--line); }
.btn.stop { background: var(--danger); border-color: var(--danger); color: #fff; width: 100%; }
.btn.big { width: 100%; font-size: 17px; padding: 16px 18px; }
.btn.start.t-walk { border-color: var(--walk); color: var(--walk); }
.btn.start.t-feed { border-color: var(--feed); color: var(--feed); }
.btn.start.t-sleep { border-color: var(--sleep); color: var(--sleep); }
.s-ic { font-size: 20px; }
.mini-btn {
  min-width: 40px; min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: none; font-size: 14px;
}
.mini-btn.danger { color: var(--danger); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card);
  font-weight: 600; font-size: 14px;
  color: var(--ink-soft);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- feed card tabs ---------- */
.tabs { display: flex; gap: 8px; margin: 10px 0 12px; }
.tabs .tab-btn {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-weight: 600; font-size: 15px;
  color: var(--ink-soft);
}
.tabs .tab-btn.on { background: var(--feed); border-color: var(--feed); color: #fff; }

/* ---------- per-breast rows (in-progress feed) ---------- */
.feed-side-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.feed-side-row .fs-lb { font-size: 14px; color: var(--ink-soft); }
.feed-side-row .fs-val {
  margin-left: auto;
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.feed-side-row .fs-val.live { color: var(--ink); }

/* ---------- side toggle (in-progress feed) ---------- */
.side-toggle { display: flex; gap: 8px; margin: 12px 0 4px; }
.side-toggle .side-btn {
  flex: 1;
  min-height: 48px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-weight: 600; font-size: 15px;
}
.side-toggle .side-btn.on { background: var(--feed); border-color: var(--feed); color: #fff; }
.chip.diagchip.on { background: var(--diaper); border-color: var(--diaper); }
.fchips .chip { min-height: 38px; }

/* ---------- forms ---------- */
.form-card .fc-title { font-weight: 700; margin-bottom: 10px; }
.ff-lb { font-size: 13px; font-weight: 700; color: var(--ink-soft); margin: 14px 0 8px; }
.qty-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.qty-lb { font-size: 14px; color: var(--ink-soft); flex-shrink: 0; }
.qty-row input {
  flex: 1; min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
.qty-unit { color: var(--ink-soft); font-size: 14px; }
/* Group of number rows sharing one label column: each row dissolves into the
 * grid (display: contents), so the inputs line up at the widest label. */
.qty-rows {
  display: grid; grid-template-columns: max-content 1fr auto;
  gap: 10px 8px; align-items: center; margin-bottom: 10px;
}
.qty-rows .qty-row { display: contents; }
.qty-rows .qty-row.hidden { display: none; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- history ---------- */
.ev-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.ev-top { display: flex; align-items: baseline; gap: 10px; }
.ev-time { font-weight: 700; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.ev-detail { font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.ev-bot {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px;
}
/* History cards: the edit button sits at the true horizontal center of the
   card, independent of how wide the duration/badge on the left is; the
   stop/delete group stays right-aligned. */
.ev-bot.hist {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
}
.ev-bot.hist .ev-edit { grid-column: 2; justify-self: center; }
.ev-bot.hist .ev-acts {
  grid-column: 3;
  display: flex; gap: 8px; justify-content: flex-end;
}
.ev-dur { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.badge {
  font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  color: #fff; background: var(--accent);
}
.open-b.t-walk { background: var(--walk); }
.open-b.t-feed { background: var(--feed); }
.open-b.t-sleep { background: var(--sleep); }
.ev-bot:not(.hist) .mini-btn { margin-left: auto; }
#hist-more { margin-top: 4px; }

/* ---------- login ---------- */
.login-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  text-align: center;
  padding: 28px 22px;
}
.login-icon { font-size: 44px; }
.login-title { margin: 8px 0 4px; font-size: 22px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-form input {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg);
}
.form-err { color: var(--danger); font-size: 14px; min-height: 18px; }

/* ---------- toast ---------- */
/* #toast is just the mount point (Preact renders the pill into it), so the
   pill styles moved to .toast-pill; the pill stays mounted to fade out. */
#toast { position: absolute; inset: 0; pointer-events: none; z-index: 100; }
.toast-pill {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 86vw;
}
.toast-pill.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- edit modal ---------- */
#modal { position: absolute; inset: 0; z-index: 50; pointer-events: none; }
#modal:empty { display: none; }
.modal-bk {
  position: absolute; inset: 0;
  background: rgba(20, 16, 10, .55);
  display: flex; align-items: flex-end; justify-content: center;
  pointer-events: auto;
  opacity: 0; transition: opacity .15s ease;
}
.modal-bk.show { opacity: 1; }
.modal {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 460px;
  max-height: 90dvh; overflow-y: auto;
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal-bk { align-items: center; }
  .modal { border-radius: 16px; max-height: 85dvh; }
}
.md-head { font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.md-lb { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 10px 0 4px; }
.md-check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 10px; }
.md-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.md-foot { display: flex; gap: 10px; margin-top: 18px; }
.md-foot .btn { flex: 1; }
.hidden { display: none; }
/* Chip groups need breathing room after the date widgets; consecutive chip
 * rows are kept apart by .chips' own bottom margin only. */
.modal .chips:not(.chips + .chips) { margin-top: 14px; }

/* ---------- view transitions ---------- */
#view.fade-out { opacity: 0; transition: opacity .14s ease; }
#view.fade-in { animation: viewIn .22s ease; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #view.fade-out { transition: none; }
  #view.fade-in { animation: none; }
}

/* ---------- baby card (home) ---------- */
.baby-card { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.baby-ic { font-size: 30px; }
.baby-info { flex: 1; min-width: 0; }
.baby-name { font-weight: 700; font-size: 15px; }
.baby-age { font-size: 13px; color: var(--ink-soft); }
.baby-edit { color: var(--ink-soft); display: inline-flex; align-items: center; }

/* ---------- inline SVG icons (sprite in index.html) ----------
   Stroke follows currentColor, so icons inherit the text color
   (active tab, danger buttons, white-on-accent chips). */
.ic {
  display: inline-block;
  width: 1.15em; height: 1.15em;
  flex: 0 0 auto;
  vertical-align: -.24em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tab-ic .ic { width: 23px; height: 23px; }
.oc-icon .ic { width: 22px; height: 22px; }
.calm-ic .ic { width: 26px; height: 26px; }
.st-ic .ic { width: 21px; height: 21px; }
.s-ic .ic { width: 23px; height: 23px; }
.login-icon .ic { width: 50px; height: 50px; }
.baby-ic .ic { width: 34px; height: 34px; }
.md-head .ic { width: 19px; height: 19px; }
.icon-btn .ic { width: 19px; height: 19px; }
.mini-btn .ic { width: 17px; height: 17px; }
.baby-edit .ic { width: 17px; height: 17px; }
