:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1f1e1c;
  --muted: #74716b;
  --line: #e4e1db;
  --accent: #2f5d62;
  --accent-text: #ffffff;
  --feed: #a35d6e;
  --diaper: #9a7a3a;
  --sleep: #55609c;
  --pump: #3f7f79;
  --growth: #557d52;
  --danger: #b03a2e;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1d;
    --surface-2: #262627;
    --text: #ebe9e5;
    --muted: #9a968f;
    --line: #2e2e30;
    --accent: #7fb3b0;
    --accent-text: #0f1f20;
    --feed: #d495a3;
    --diaper: #cdb071;
    --sleep: #9aa4e0;
    --pump: #7cc0b8;
    --growth: #92bb8e;
    --danger: #e0786c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }

.i { width: 20px; height: 20px; flex: none; display: block; }

.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }

/* ---- login ---- */
.login {
  max-width: 340px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14vh) 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login img { border-radius: 18px; width: 64px; height: 64px; }
.login h1 { margin: 4px 0 10px; font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; }
.login label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--muted); }
.error { color: var(--danger); margin: 0; font-size: .9rem; }

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px; /* prevents iOS zoom on focus */
}
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ---- layout ---- */
#app { min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 1.3rem; font-weight: 650; letter-spacing: -.01em; display: flex; align-items: center; gap: 4px; }
#baby-age { font-size: .82rem; }
.baby-switch { border: 0; background: none; padding: 0; text-align: left; color: inherit; min-width: 0; }
.baby-switch h1 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#baby-chevron .i { width: 18px; height: 18px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; flex: none; }

main {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 92px);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 4px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  border: 0;
  background: none;
  font-size: .7rem;
  font-weight: 500;
  color: var(--muted);
}
.tabbar button .i { width: 22px; height: 22px; }
.tabbar button.active { color: var(--accent); }

h2 {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 26px 4px 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 550;
  text-decoration: none;
  color: var(--text);
}
.btn:active, .tile:active, .segmented button:active { opacity: .7; }
.btn .i { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.link { border: 0; background: none; padding: 0; color: var(--muted); font-size: .85rem; text-decoration: underline; text-underline-offset: 2px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
}
.icon-btn.quiet { background: none; color: var(--muted); }

/* Small tinted square holding a type icon. */
.badge {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--c, var(--muted)) 13%, transparent);
  color: var(--c, var(--muted));
  flex: none;
}
.badge .i { width: 19px; height: 19px; }

/* ---- today ---- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.status { padding: 12px 14px; min-width: 0; }
.status + .status { border-left: 1px solid var(--line); }
.status .label { font-size: .72rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status .label::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.status .value { font-size: 1.05rem; font-weight: 650; white-space: nowrap; margin-top: 2px; font-variant-numeric: tabular-nums; }
.status .sub { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.timer {
  margin-top: 12px;
  padding: 14px 16px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
}
.timer-head { display: flex; align-items: center; gap: 10px; }
.timer-head .what { flex: 1; font-weight: 600; }
.timer .clock { font-size: 2.6rem; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.01em; line-height: 1.15; margin-top: 8px; }
.timer-actions { display: flex; gap: 10px; margin-top: 12px; }
.timer-actions .btn { flex: 1; }
.timer .stop { background: var(--c); border-color: var(--c); color: var(--surface); }

.quick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}
.tile.active { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.tile-title { display: block; font-weight: 600; font-size: .95rem; }
.tile-hint { display: block; font-size: .76rem; color: var(--muted); }

.diaper-row {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.diaper-label { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: .95rem; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-weight: 550;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chips button.on { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---- entry list ---- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.entry {
  display: grid;
  grid-template-columns: 44px 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
}
.entry:last-child { border-bottom: 0; }
.entry .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.entry .title { font-weight: 550; }
.entry .detail { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .right { display: flex; align-items: center; gap: 8px; font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.entry .who {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: .66rem;
  line-height: 20px;
  text-align: center;
  text-transform: uppercase;
}
.running-badge { color: var(--c); font-weight: 600; }
.empty { padding: 18px; text-align: center; color: var(--muted); font-size: .9rem; }

.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.day-head .stats { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: .76rem; }

.more { display: flex; justify-content: center; margin: 18px 0; }

/* ---- summary ---- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; margin-top: 8px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; font-weight: 550; font-size: .88rem; color: var(--muted); }
.seg .on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 8%); }

.avg-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 8px; }
.avg .num { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.avg .lbl { font-size: .74rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.avg .lbl::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

.day-table { width: 100%; border-collapse: collapse; font-size: .86rem; font-variant-numeric: tabular-nums; }
.day-table th, .day-table td { padding: 9px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.day-table th:first-child, .day-table td:first-child { text-align: left; }
.day-table th { font-size: .7rem; color: var(--muted); font-weight: 600; }
.day-table tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 64px; margin-top: 4px; }
.bars div { flex: 1; background: var(--c); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .75; }
.bars-labels { display: flex; gap: 4px; font-size: .64rem; color: var(--muted); margin-top: 4px; }
.bars-labels span { flex: 1; text-align: center; }

/* ---- growth ---- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--c); stroke-width: 2; }
.chart .latest { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart .latest b { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.footer-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 26px 0 8px; }
.version { text-align: center; }

/* ---- sheet (dialog) ---- */
dialog {
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--bg);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 35%); }
@media (min-width: 600px) {
  dialog { margin: auto; border-radius: 18px; }
}
#sheet-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
}
#sheet-form h3 { margin: 0; font-size: 1.15rem; font-weight: 650; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .8rem; color: var(--muted); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.row input { min-width: 0; }
@media (max-width: 420px) { .row.times { grid-template-columns: minmax(0, 1fr); } }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices label { position: relative; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span {
  display: inline-block;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 550;
  font-size: .92rem;
}
.choices input:checked + span { background: var(--text); border-color: var(--text); color: var(--bg); }
.choices input:focus-visible + span { outline: 2px solid var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.danger { flex: 0 0 auto; }

/* ---- toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 80px);
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: 12px;
  background: #1f1e1c;
  color: #f6f5f2;
  font-size: .92rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 22%);
}
#toast button { border: 0; background: none; color: #9fd0cb; font-weight: 650; padding: 0; }

/* ---- settings & baby sheets ---- */
.sheet-section { display: flex; flex-direction: column; gap: 8px; }
.sheet-section > h4 { margin: 6px 2px 0; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.rows { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rows > * {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  color: var(--text);
  text-decoration: none;
}
.rows > :last-child { border-bottom: 0; }
.rows .sub { color: var(--muted); font-size: .85rem; }
.rows .on { font-weight: 650; }
.rows .check { color: var(--accent); }
.rows > button:focus:not(:focus-visible) { outline: none; }
.sheet-section > h4 .link { font-size: inherit; text-transform: none; letter-spacing: 0; }
.invite-box { display: flex; flex-direction: column; gap: 8px; }
.invite-box input { font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1; }
