/* Baby — dark-first, one-handed, 3am-legible.
   No external fonts or assets: system stack only. */

:root {
  color-scheme: dark light;

  --bg: #14161f;
  --surface: #1c1f2b;
  --surface-2: #262a38;
  --line: #333849;
  --text: #eef0f7;
  --muted: #9aa1b8;
  --accent: #7f9cff;
  --accent-ink: #0d1020;
  --danger: #ff6b6b;
  --ok: #52d1a4;

  --breastfeed: #7f9cff;
  --pump: #b98cff;
  --bottle: #ffc46b;
  --note: #8d95ad;

  --tap: 56px;          /* minimum touch target, everywhere */
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #eef0f6;
    --line: #dce0ea;
    --text: #15171f;
    --muted: #5c6379;
    --accent: #3a5bd9;
    --accent-ink: #ffffff;
    --danger: #c62d2d;
    --ok: #12855f;

    --breastfeed: #3a5bd9;
    --pump: #7a45cc;
    --bottle: #b7761a;
    --note: #6a7288;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(96px + var(--safe-b)); }

[hidden] { display: none !important; }

button, input, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); font-weight: 600; }

/* ── Setup ───────────────────────────────────────────────────────────────- */

.setup {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.setup-inner { width: 100%; max-width: 380px; text-align: center; }
.setup-icon { border-radius: 22px; }
.setup h1 { margin: 12px 0 4px; font-size: 30px; }
.setup p { margin: 0 0 24px; }
.setup form { text-align: left; }

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 17px;   /* >=16px stops iOS zooming on focus */
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.btn-primary, .btn-ghost, .btn-danger {
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 17px;
  font-weight: 700;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn-ghost   { background: var(--surface-2); color: var(--text); }
.btn-danger  { background: transparent; color: var(--danger); border-color: var(--line); }
button[disabled] { opacity: 0.5; cursor: default; }

/* ── Top bar ─────────────────────────────────────────────────────────────- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 16px 10px;
}
.brand { font-weight: 800; letter-spacing: 0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.linkish {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 15px;
  padding: 10px 4px;      /* keeps the hit area comfortable without looking big */
  text-decoration: underline;
  text-underline-offset: 3px;
}
/* Gear button: same muted voice as #who so the two sit as one group, but its
   own full --tap box since a glyph alone has no text to pad the hit area. */
.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Banner ──────────────────────────────────────────────────────────────- */

.banner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 4px 16px 20px;
}
.banner-half {
  padding: 18px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  text-align: center;
}
.banner-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.banner-ago {
  /* Sized to fit "2h 14m ago" in half the width without wrapping mid-number. */
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-wrap: balance;
}
.banner-what { margin-top: 6px; font-size: 15px; }
/* Gentle nudge past the 2h mark, more insistent past 4h — each half keeps its
   own clock, so a long feed gap and a long pumping gap show independently. */
.banner-half.warn { border-color: var(--bottle); }
.banner-half.warn .banner-ago { color: var(--bottle); }
.banner-half.error { border-color: var(--danger); }
.banner-half.error .banner-ago { color: var(--danger); }
/* When a type's toggle turns a whole half off (e.g. pump disabled hides
   Expressed), the survivor takes the row instead of sitting alone next to a
   blank column — this is the number a half-asleep parent reads first. */
.banner-half.solo {
  grid-column: 1 / -1;
}
.banner-half.solo .banner-ago {
  font-size: clamp(30px, 10vw, 44px);
}

/* ── Action grid ─────────────────────────────────────────────────────────- */

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 16px 24px;
}
.action {
  min-height: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  font-size: 15px;
  font-weight: 700;
}
.action:active { transform: scale(0.97); background: var(--surface); }
.action-glyph { font-size: 24px; line-height: 1; color: var(--accent); }
.action[data-type="breastfeed"] .action-glyph { color: var(--breastfeed); }
.action[data-type="pump"] .action-glyph { color: var(--pump); }
.action[data-type="bottle"] .action-glyph { color: var(--bottle); }
.action-note { grid-column: span 3; min-height: var(--tap); flex-direction: row; font-size: 18px; }
.action-note .action-glyph { color: var(--note); }

/* ── Log ─────────────────────────────────────────────────────────────────- */

.log { padding: 0 16px; }

.day-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 14px 0 8px;
  background: linear-gradient(var(--bg) 72%, transparent);
}
.day-title { font-size: 15px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.day-sum { font-size: 14px; color: var(--muted); }

.event {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  margin-bottom: 8px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 12px;
}
.event:active { background: var(--surface-2); }
.event[data-type="breastfeed"] { border-left-color: var(--breastfeed); }
.event[data-type="pump"]       { border-left-color: var(--pump); }
.event[data-type="bottle"]     { border-left-color: var(--bottle); }
.event[data-type="note"]       { border-left-color: var(--note); }

.event-time {
  flex: 0 0 auto;
  min-width: 4.6em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.event-body { flex: 1 1 auto; min-width: 0; }
.event-type { font-weight: 600; }
.event-msg {
  color: var(--muted);
  font-size: 15px;
  overflow-wrap: anywhere;
}
.event-author { flex: 0 0 auto; color: var(--muted); font-size: 14px; }
/* An unconfirmed write stays visibly provisional until the POST lands. */
.event.pending { opacity: 0.55; }

/* ── Sheets ──────────────────────────────────────────────────────────────- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
}
.sheet {
  position: fixed;
  z-index: 21;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88svh;
  overflow-y: auto;
  padding: 20px 20px calc(20px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
}
@media (min-width: 640px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: 24px;
    width: 520px;
    transform: translateX(-50%);
    border-radius: 22px;
    border: 1px solid var(--line);
  }
}
.sheet h2 { margin: 0 0 4px; font-size: 22px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: var(--tap);
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 600;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.sheet-actions .btn-primary { flex: 1 1 auto; width: auto; }

/* ── Settings sheet ──────────────────────────────────────────────────────- */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
}
.switch-row-label { font-weight: 600; }

/* The drawn pill is smaller than --tap, but the button's own box is not: it
   owns the full tap target so a half-asleep thumb doesn't need to land on
   the pill exactly, only somewhere in the row. */
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 60px;
  min-height: var(--tap);
  padding: 0;
  background: none;
  border: 0;
}
.switch-track {
  position: absolute;
  top: 50%;
  left: 4px;
  width: 52px;
  height: 30px;
  transform: translateY(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch-knob {
  position: absolute;
  top: 50%;
  left: 7px;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}
.switch[aria-checked="true"] .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}
.switch[aria-checked="true"] .switch-knob {
  transform: translate(22px, -50%);
  background: var(--accent-ink);
}
.switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* At least one type must stay enabled, so app.js renders the last remaining
   one non-interactive instead of letting the tap round-trip to a 400. The
   generic button[disabled] rule already fades it; aria-disabled needs the
   same fade spelled out because it isn't the disabled attribute. Either way
   the dashed track reads as "locked", not "broken" or "loading". */
.switch[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
}
.switch[disabled] .switch-track,
.switch[aria-disabled="true"] .switch-track {
  border-style: dashed;
}

#settings-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

/* ── Snackbar / toast ────────────────────────────────────────────────────- */

.snackbar, .toast {
  position: fixed;
  z-index: 30;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-b));
  padding: 10px 12px;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}
@media (min-width: 640px) {
  .snackbar, .toast { left: 50%; right: auto; width: 520px; transform: translateX(-50%); }
}
.snackbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.snackbar > span { flex: 1 1 auto; font-weight: 600; }
.snack-btn {
  min-height: 44px;              /* inside a transient bar; still thumb-sized */
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}
.toast {
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 16px 12px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .action:active { transform: none; }
}
