/* Little Log. Mobile first, light + dark (night feeds!), safe-area aware. No inline styles anywhere (CSP). */

:root {
  --bg: #f5f2ec;
  --bg-outer: #e8e4db;
  --card: #ffffff;
  --text: #1d2a2e;
  --muted: #5f6d73;
  --line: #e7e2d8;
  --line-strong: #cfc9bc;
  --input: #ffffff;
  --brand: #2b6f77;
  --brand-text: #1f5f67;
  --brand-soft: #e1f0f1;
  --header: #245b62;
  --focus: #1b8fa0;
  --feed: #e08a2c;   --feed-bg: #fdf1e0;   --feed-ink: #8a4a05;
  --diaper: #2f8fd0; --diaper-bg: #e4f2fb; --diaper-ink: #11547f;
  --note: #7a63c9;   --note-bg: #eeeafa;   --note-ink: #4a3a96;
  --wet: #3d9bdc;    --dirty: #a8794a;     --milk: #7aa6d8;
  --danger: #b3261e; --danger-solid: #b3261e;
  --banner-bg: #ffe9b3; --banner-ink: #5a4300;
  --look-bg: #fff6dc;
  --shadow: 0 1px 2px rgba(20, 40, 45, .06), 0 4px 14px rgba(20, 40, 45, .05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1619;
    --bg-outer: #0a0f11;
    --card: #182125;
    --text: #e7eef0;
    --muted: #9bacb2;
    --line: #26333a;
    --line-strong: #36464e;
    --input: #111a1d;
    --brand: #2f7d87;
    --brand-text: #6cc3cd;
    --brand-soft: #1d3a3f;
    --header: #17353a;
    --focus: #6cc3cd;
    --feed: #e69a45;   --feed-bg: #3a2a14;   --feed-ink: #f0b46a;
    --diaper: #4aa3de; --diaper-bg: #13303f; --diaper-ink: #8ec9ee;
    --note: #9a86e0;   --note-bg: #2a2442;   --note-ink: #c3b6f2;
    --wet: #4aa3de;    --dirty: #c1925f;     --milk: #7aa6d8;
    --danger: #ef7d73; --danger-solid: #c9382d;
    --banner-bg: #4a3b12; --banner-ink: #ffe9b3;
    --look-bg: #2a2410;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg-outer); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg-outer);
  -webkit-tap-highlight-color: transparent;
}
body.sheet-open { overflow: hidden; }

button, input, textarea, select { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
a { color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
h3 { font-size: 17px; }
h4 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 28px 12px; }
.gap { margin-top: 12px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.link { color: var(--brand-text); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.hint { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- app shell */
.app-root {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 560px; margin: 0 auto;
  background: var(--bg);
}
@media (min-width: 600px) {
  .app-root { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) 18px 12px;
  background: var(--header); color: #fff;
}
.baby-switch {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 40px; padding: 0; border: 0; background: none; color: #fff;
  font-size: 24px; font-weight: 700; text-align: left;
}
.baby-switch:disabled { opacity: 1; cursor: default; }
.baby-age { margin-top: -2px; font-size: 13px; color: rgba(255, 255, 255, .82); }
.pill { padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, .2); font-size: 13px; font-weight: 700; white-space: nowrap; }
.offline-banner { padding: 8px 16px; background: var(--banner-bg); color: var(--banner-ink); font-size: 13px; text-align: center; }

.main {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 14px 24px;
}
.main > * { flex-shrink: 0; }

.tabbar {
  display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 58px; color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: none;
}
.tab[aria-current="page"] { color: var(--brand-text); }

/* ---------------------------------------------------------------- cards */
.card {
  padding: 16px; border-radius: 16px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.card > h3 + p { margin-top: 2px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.card.center { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 20px; }
.card.center .btn { margin-top: 8px; }
.big-emoji { font-size: 48px; }

.status-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.status-card {
  display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 14px; border-radius: 16px; background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow); text-align: left; color: var(--text);
}
.status-card:disabled { cursor: default; opacity: 1; color: var(--text); }
.status-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.status-ago { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.status-ago.muted { font-size: 18px; font-weight: 600; }
.status-detail { font-size: 13px; color: var(--muted); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 112px; padding: 14px 6px; border-radius: 20px; border: 2px solid transparent;
  font-size: 15px; font-weight: 700;
}
.action-emoji { font-size: 36px; line-height: 1; }
.action.feeding { background: var(--feed-bg); border-color: var(--feed); color: var(--feed-ink); }
.action.diaper { background: var(--diaper-bg); border-color: var(--diaper); color: var(--diaper-ink); }
.action.note { background: var(--note-bg); border-color: var(--note); color: var(--note-ink); }
.action:active { transform: scale(.97); }

.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.quick-btn { padding: 0 4px; font-size: 15px; white-space: nowrap; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.tile { padding: 10px 4px; border-radius: 12px; background: var(--brand-soft); text-align: center; }
.tile-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile-label { margin-top: 2px; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- entry rows */
.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 62px 28px 1fr auto; align-items: start; gap: 8px;
  width: 100%; min-height: 56px; padding: 11px 8px 11px 10px;
  background: none; border: 0; border-left: 4px solid transparent; border-bottom: 1px solid var(--line);
  text-align: left; color: var(--text);
}
.rows .row:last-child { border-bottom: 0; }
.row.t-feeding { border-left-color: var(--feed); }
.row.t-diaper { border-left-color: var(--diaper); }
.row.t-note { border-left-color: var(--note); }
.row-time { padding-top: 2px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-date { display: block; font-weight: 700; color: var(--text); }
.row-icon { font-size: 20px; line-height: 1.3; }
.row-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.row-title { font-weight: 600; }
.row-detail { font-size: 14px; color: var(--muted); }
.row-note {
  font-size: 14px; font-style: italic; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.row-who { padding-top: 3px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.badge {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: var(--banner-bg); color: var(--banner-ink); font-size: 11px; font-weight: 700; vertical-align: middle;
}
.row .badge { margin: 3px 0 0; white-space: nowrap; }

.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 6px 4px 6px; }
.day .rows { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }

/* ---------------------------------------------------------------- buttons, chips, segmented */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
  font-size: 16px; font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger.solid, .btn.danger.armed { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--card); font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips.filter { margin: 0; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.chips.filter .chip { flex-shrink: 0; }

.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: 12px; overflow: hidden; margin-bottom: 4px; }
.seg { flex: 1; min-height: 46px; padding: 0 6px; background: var(--card); border: 0; border-right: 1px solid var(--line-strong); font-size: 15px; font-weight: 600; }
.seg:last-child { border-right: 0; }
.seg[aria-pressed="true"] { background: var(--brand); color: #fff; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.icon-btn.round { width: 52px; height: 52px; flex-shrink: 0; background: var(--brand-soft); color: var(--brand-text); }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: 14px; }
.field label, .lbl { display: block; margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.lbl { margin-top: 16px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"], textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--input); color: var(--text); font-size: 16px;
}
textarea { min-height: 88px; resize: vertical; }
.input-wrap { position: relative; }
.input-wrap input { padding-right: 72px; }
.show-btn { position: absolute; top: 4px; right: 4px; bottom: 4px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--brand-text); font-weight: 700; }
.form-error { min-height: 0; margin: 0 0 10px; color: var(--danger); font-size: 14px; font-weight: 600; }
.form-error:empty { display: none; }
.success { margin: 12px 0; padding: 12px; border-radius: 12px; background: var(--brand-soft); color: var(--text); }

.details .sub { margin-top: 4px; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 88px; border-radius: 16px; border: 2px solid var(--line-strong); background: var(--card);
  font-size: 15px; font-weight: 600;
}
.choice-emoji { font-size: 30px; line-height: 1; }
.choice[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { flex: 1; min-width: 0; text-align: center; font-size: 26px; font-weight: 700; min-height: 56px; }
.unit-btn { min-width: 52px; height: 52px; padding: 0 8px; border-radius: 12px; border: 1px solid var(--line-strong); background: none; font-weight: 700; }
.entry-form > .btn { margin-top: 16px; }
.entry-form > .btn + .btn { margin-top: 10px; }
.entry-form .form-error { margin-top: 10px; }

/* ---------------------------------------------------------------- sheets and toasts */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; justify-content: flex-end; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); animation: fade .15s ease-out; }
.sheet {
  position: relative; width: 100%; max-width: 560px; margin: 0 auto; max-height: 92vh; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--card); color: var(--text); border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25); animation: rise .2s ease-out;
}
.sheet:focus { outline: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 0 18px; }
.sheet-head h2 { font-size: 19px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 18px calc(22px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) {
  .sheet-wrap { justify-content: center; align-items: center; }
  .sheet { border-radius: 22px; max-height: 88vh; }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 14px; max-width: 100%; padding: 12px 16px; border-radius: 12px;
  background: #20292d; color: #fff; font-size: 15px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  pointer-events: auto; animation: rise .18s ease-out;
}
.toast.error { background: #8f2a20; }
.toast-action { padding: 4px 6px; border: 0; background: none; color: #8fd3dc; font-weight: 700; }

/* ---------------------------------------------------------------- signed-out screens */
.auth-root { max-width: 480px; min-height: 100vh; min-height: 100dvh; margin: 0 auto; background: var(--bg); }
.auth-hero {
  padding: calc(env(safe-area-inset-top) + 28px) 24px 56px;
  background: var(--header); color: #fff; text-align: center;
}
.auth-logo { width: 72px; height: 72px; margin-bottom: 10px; border-radius: 18px; }
.auth-hero h1 { font-size: 28px; }
.auth-hero p { margin-top: 4px; font-size: 15px; opacity: .85; }
.auth-card {
  margin: -30px 16px 28px; padding: 22px 20px;
  border-radius: 20px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.auth-card h2 { margin-bottom: 14px; font-size: 22px; }
.auth-card > .muted { margin: -6px 0 14px; }
.auth-card form > .segmented { margin-bottom: 16px; }
.auth-links { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 18px; }

/* ---------------------------------------------------------------- settings */
.kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 56px; padding: 0 4px; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; font-size: 17px;
}
.list-item[aria-pressed="true"] { color: var(--brand-text); }
.member { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.list > .member:last-child { border-bottom: 0; }
.card > .btn { margin-top: 12px; }
.invite { margin: 8px 0; padding: 14px; border-radius: 14px; background: var(--brand-soft); text-align: center; }
.invite-code { font-size: 34px; font-weight: 800; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.invite .muted { margin-top: 6px; }
.danger-zone { border-color: var(--danger); }
.danger-zone h3 { color: var(--danger); }

/* ---------------------------------------------------------------- charts */
.chart { display: block; width: 100%; height: auto; margin-top: 8px; }
.chart-axis { stroke: var(--line-strong); stroke-width: 1; }
.chart-val { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-lbl { fill: var(--muted); font-size: 11px; }
.chart-lbl.today { fill: var(--text); font-weight: 700; }
.bar-feed { fill: var(--feed); }
.bar-wet { fill: var(--wet); }
.bar-dirty { fill: var(--dirty); }
.bar-milk { fill: var(--milk); }
.legend { margin-top: 6px; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; margin-left: 6px; border-radius: 50%; vertical-align: baseline; }
.dot.bar-wet { background: var(--wet); }
.dot.bar-dirty { background: var(--dirty); }

/* ---------------------------------------------------------------- health + units */
.status-row.tight { gap: 8px; margin-top: 8px; }
.status-ago.small { font-size: 18px; }
.status-ago.hot, .big.hot, .row-detail.hot { color: var(--danger); }
.row-detail.hot { font-weight: 700; }
.big-values { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-top: 6px; }
.big { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.big-sub { font-size: 17px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }

.convert { min-height: 1.3em; margin: 6px 0 0; font-size: 14px; font-weight: 600; color: var(--muted); text-align: center; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair .lbl { margin-top: 16px; }
.unit-field { position: relative; }
.unit-field input { padding-right: 48px; }
.unit-field span { position: absolute; top: 50%; right: 12px; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.measure { display: flex; align-items: center; gap: 8px; }
.measure > .unit-field, .measure > .pair { flex: 1; min-width: 0; }
.big-input { font-size: 26px !important; font-weight: 700; text-align: center; min-height: 56px !important; }
.convert.hot { color: var(--danger); }
.owlet-pull { margin: 4px 0 10px; }
.chips.presets { margin: 0 0 8px; }
.chip.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

.chart-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-sub { fill: var(--muted); font-size: 9px; }
.chart-line { fill: none; stroke: var(--brand-text); stroke-width: 2; stroke-linejoin: round; }
.chart-dot { fill: var(--brand-text); }
.chart-dot.hot { fill: var(--danger); }
.chart-ref { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 5 4; }
.chart-ref-lbl { fill: var(--danger); font-size: 10px; font-weight: 600; }
.toast-action + .toast-action { margin-left: -6px; }

/* ---------------------------------------------------------------- doctor report (on screen: a paper-like page) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report-doc {
  --text: #111; --muted: #555; --line: #d9d9d9; --line-strong: #bbb; --card: #fff;
  --brand-text: #1f5f67; --brand-soft: #eef5f6; --danger: #b3261e;
  width: 100%; max-width: 820px; margin: 0 auto; padding: 20px 18px;
  background: #fff; color: #111; border: 1px solid #d9d9d9; border-radius: 12px; font-size: 14px; line-height: 1.4;
}
.report-head { margin-bottom: 14px; padding-bottom: 10px; border-bottom: 2px solid #245b62; }
.report-brand { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #245b62; }
.report-doc h1 { margin: 2px 0 4px; font-size: 26px; }
.report-meta { margin: 0; color: #444; }
.rsection { margin-top: 18px; }
.rsection h2 { margin: 0 0 8px; padding-bottom: 4px; font-size: 16px; border-bottom: 1px solid #d9d9d9; break-after: avoid; }
.kv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }
.kv-item { break-inside: avoid; }
.kv-label { font-size: 12px; color: #555; }
.kv-value { font-weight: 700; }
.rtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.rtable th { padding: 6px 8px; text-align: left; font-weight: 700; background: #f1f4f5; border-bottom: 1px solid #bbb; white-space: nowrap; }
.rtable td { padding: 6px 8px; vertical-align: top; border-bottom: 1px solid #e3e3e3; overflow-wrap: anywhere; }
.rtable td:first-child { white-space: nowrap; }
.rtable tr { break-inside: avoid; }
.rtable thead { display: table-header-group; }
.fine { margin-top: 6px; font-size: 12px; color: #555; }
.report-foot { margin-top: 20px; padding-top: 8px; border-top: 1px solid #d9d9d9; font-size: 12px; color: #555; }
.report-doc .chart { max-width: 520px; }
.standalone-report { padding: 16px; }
@media (max-width: 520px) {
  .kv-grid { grid-template-columns: 1fr; }
  .rtable { font-size: 12px; }
  .rtable th, .rtable td { padding: 5px 6px; }
  .report-doc { padding: 16px 12px; }
}

/* ---------------------------------------------------------------- import from paper or a photo */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 3 / 4; overflow: hidden; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--input); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb.busy { display: flex; align-items: center; justify-content: center; padding: 6px; color: var(--muted); font-size: 13px; text-align: center; }
.thumb-x {
  position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: rgba(0, 0, 0, .7); color: #fff; font-size: 15px; font-weight: 700;
}
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--brand); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.review { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.rv { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.rows .rv:last-child { border-bottom: 0; }
.rv.look { background: var(--look-bg); }
.rv.off .row-icon, .rv.off .row-title, .rv.off .row-detail, .rv.off .row-note { opacity: .62; }   /* (the yellow notes stay at full strength) */
.rv-check { flex: 0 0 50px; display: flex; align-items: center; justify-content: center; margin: 0; cursor: pointer; }
.rv-check input { width: 22px; height: 22px; accent-color: var(--brand); }
.rv .row { flex: 1; min-width: 0; border-bottom: 0; padding-left: 4px; }
.rv-flag { display: block; margin-top: 3px; font-size: 13px; font-weight: 600; color: var(--banner-ink); overflow-wrap: anywhere; }
.rv-flag.bad { color: var(--danger); }
.rv-source { display: block; margin-top: 2px; font-size: 12px; font-style: italic; color: var(--muted); overflow-wrap: anywhere; }
.review-note { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--look-bg); border: 1px solid var(--banner-bg); font-size: 14px; }
.import-bar { position: sticky; bottom: 0; z-index: 2; padding: 10px 0 4px; background: var(--bg); }
.import-bar .form-error { margin-bottom: 8px; }
.banner-note { margin: 2px 0 4px; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); font-size: 14px; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- admin screen */
.person { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.list > .person:last-child { border-bottom: 0; }
.person-main { min-width: 0; flex: 1 1 220px; }
.person-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-hh .card-head h3 { overflow-wrap: anywhere; }
.logrow { display: flex; flex-direction: column; gap: 1px; padding: 9px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.list > .logrow:last-child { border-bottom: 0; }
select option:disabled { color: var(--muted); }

/* ---------------------------------------------------------------- bigger screens
   Phone (under 640px): the layout above, one column with the tab bar at the bottom.
   Tablet (640px and up): the same, in a wider column.
   Computer (960px and up): a menu down the left side and the cards side by side.
   Only for screens; printing keeps its own rules below. */
@media screen and (min-width: 640px) {
  .app-root { max-width: 720px; }
  .auth-root { max-width: 520px; }
}

@media screen and (min-width: 960px) {
  .app-root {
    max-width: 1360px;
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "top top" "banner banner" "nav main";
  }
  .topbar { grid-area: top; padding: calc(env(safe-area-inset-top) + 14px) 32px 14px; }
  .baby-switch { font-size: 26px; }
  .offline-banner { grid-area: banner; }
  .main { grid-area: main; padding: 26px 32px 44px; gap: 16px; }

  /* the tab bar becomes a menu down the left side */
  .tabbar {
    grid-area: nav; flex-direction: column; align-items: stretch; gap: 4px; padding: 18px 14px;
    border-top: 0; border-right: 1px solid var(--line); overflow-y: auto;
  }
  .tab { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 48px; padding: 0 16px; border-radius: 12px; font-size: 16px; }
  .tab[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); }

  /* Home, Trends and Settings: cards side by side */
  .app-root[data-view="app:home"] .main,
  .app-root[data-view="app:trends"] .main,
  .app-root[data-view="app:settings"] .main {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 22px; align-items: stretch; align-content: start;
  }
  .app-root[data-view="app:settings"] .main { align-items: start; }   /* settings cards differ a lot in height, so don't stretch them */
  /* Home: the quick buttons and today's totals on the left, health on the right, the recent list across the bottom */
  .h-quick { grid-column: 1; grid-row: 2; }
  .h-health { grid-column: 2; grid-row: 2 / span 2; }
  .h-today { grid-column: 1; grid-row: 3; }
  .h-recent { grid-column: 1 / -1; }
  .app-root[data-view="app:trends"] .main > .btn.primary.block { grid-column: 1 / -1; }

  /* Log, Import and the doctor report read best as one centered column */
  .app-root[data-view="app:log"] .main > *,
  .app-root[data-view="app:import"] .main > *,
  .app-root[data-view="app:admin"] .main > *,
  .app-root[data-view="app:report"] .main > * { width: 100%; max-width: 780px; align-self: center; }
  .app-root[data-view="app:report"] .main > .report-doc { max-width: 860px; }

  .toasts { bottom: 28px; }
  .sheet { max-width: 620px; }

  /* signed-out screens: the logo and name on the left, the form on the right */
  .auth-root { max-width: none; }
  .auth { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(460px, 1fr); min-height: 100vh; min-height: 100dvh; }
  .auth-hero { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 56px 48px; }
  .auth-logo { width: 112px; height: 112px; margin-bottom: 20px; border-radius: 28px; }
  .auth-hero h1 { font-size: 42px; }
  .auth-hero p { max-width: 26ch; margin-top: 8px; font-size: 19px; }
  .auth-card { align-self: center; justify-self: center; width: min(460px, calc(100% - 64px)); margin: 32px; padding: 28px 26px; }
}

/* things only a mouse needs: show what is clickable */
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { border-color: var(--brand); }
  .btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
  .btn.danger:hover:not(:disabled) { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
  .chip:hover:not([aria-pressed="true"]), .seg:hover:not([aria-pressed="true"]), .choice:hover:not([aria-pressed="true"]) { background: var(--brand-soft); }
  .row:hover, .list-item:hover { background: var(--brand-soft); }
  .status-card:hover:not(:disabled), .action:hover { filter: brightness(.97); transform: translateY(-1px); }
  .tab:hover:not([aria-current="page"]) { background: var(--bg); color: var(--text); }
  .icon-btn:hover, .unit-btn:hover { background: var(--brand-soft); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- printing: only the report, on white, in ink */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff; --bg-outer: #fff; --card: #fff; --text: #111; --muted: #555; --line: #ddd; --line-strong: #bbb;
    --brand-text: #1f5f67; --brand-soft: #eef5f6; --danger: #b3261e;
    --feed: #e08a2c; --wet: #3d9bdc; --dirty: #a8794a; --milk: #7aa6d8;
  }
  html, body { height: auto !important; background: #fff !important; }
  .topbar, .tabbar, .offline-banner, .no-print, .toasts, #sheets { display: none !important; }
  .app-root { display: block !important; height: auto !important; max-width: none !important; border: 0 !important; background: #fff !important; }
  .main { display: block !important; overflow: visible !important; padding: 0 !important; }
  .report-doc { max-width: none; padding: 0; border: 0; border-radius: 0; }
  .table-wrap { overflow: visible; }
  .rsection .chart { break-inside: avoid; }
  a { text-decoration: none; }
  @page { margin: 14mm; }
}
