/* Babylog: phone-first. One column, big touch targets, the two log buttons in thumb reach. */
:root {
  --bg: #f7f5f0;
  --card: #fff;
  --ink: #1f2a28;
  --muted: #66706d;
  --line: #e3dfd6;
  --brand: #2f7d6d;
  --brand-ink: #fff;
  --brand-soft: #e2f0ec;
  --green: #2e7d32; --green-bg: #e3f2e4;
  --amber: #8a5a00; --amber-bg: #fdf0cf;
  --red: #b3261e; --red-bg: #fbe3e1;
  --grey-bg: #eeece7;
  --gold: #d49b00; --blue: #2f6fd6;
  --radius: 14px;
  --tabbar: 60px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: .4rem 0 .8rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.loading { padding: 2rem; text-align: center; color: var(--muted); }
.empty { padding: 1.5rem; text-align: center; }
.error, .error-text, .form-error { color: var(--red); }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
#topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .6rem;
  padding: calc(env(safe-area-inset-top) + .5rem) 1rem .5rem; background: var(--brand); color: var(--brand-ink);
}
#topbar .brand { display: flex; align-items: center; gap: .4rem; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
#topbar .brand img { border-radius: 6px; }
#child-pick { flex: 1; text-align: right; }
#child-pick select { font: inherit; padding: .3rem .5rem; border-radius: 8px; border: 0; }
.child-name { font-weight: 600; }
.sync-badge { background: rgba(255,255,255,.2); color: #fff; padding: .25rem .6rem; border-radius: 999px; font-size: .8rem; text-decoration: none; white-space: nowrap; }
.sync-badge.problem { background: #fff; color: var(--red); font-weight: 700; }
.sync-badge.busy { opacity: .75; }
.banner { padding: .55rem 1rem; font-size: .9rem; }
.banner.offline { background: var(--amber-bg); color: var(--amber); }
.banner.warn { background: var(--red-bg); color: var(--red); }
main#main { max-width: 640px; margin: 0 auto; padding: .8rem .9rem calc(var(--tabbar) + 90px + env(safe-area-inset-bottom)); }
main#main.public { padding-bottom: 2rem; }
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar) + env(safe-area-inset-bottom));
}
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .75rem; color: var(--muted); text-decoration: none; }
#tabbar a .ico { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
#tabbar a.active { color: var(--brand); font-weight: 600; }
#tabbar a.active .ico { filter: none; opacity: 1; }

/* ---------- pieces ---------- */
.card { display: block; background: var(--card); border-radius: var(--radius); padding: .9rem 1rem; margin: 0 0 .8rem; border: 1px solid var(--line); color: inherit; text-decoration: none; }
a.card:active { background: #fafaf7; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem; min-height: 44px; padding: .5rem 1rem;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--red); border-color: #f0c4c0; }
.btn.big { min-height: 52px; font-size: 1.05rem; flex: 1; }
.btn.small { min-height: 36px; padding: .3rem .8rem; font-size: .88rem; }
.btn:disabled { opacity: .5; }
.icon { background: none; border: 0; font: inherit; cursor: pointer; min-width: 40px; min-height: 40px; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row .field { flex: 1; }
.actions-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); z-index: 9; display: flex; gap: .6rem;
  padding: .6rem .9rem; background: linear-gradient(to top, var(--bg) 75%, transparent); max-width: 640px; margin: 0 auto;
}
.field { display: block; margin: 0 0 1rem; border: 0; padding: 0; }
.field > .label, .field > legend, label.field { font-weight: 600; font-size: .92rem; }
.label { font-weight: 600; font-size: .92rem; display: block; margin-bottom: .35rem; }
p.label { margin: .6rem 0 .3rem; }
input, select, textarea { font: inherit; }
label.field input, label.field select, label.field textarea, .filters input, .filters select, #fq, .food-search input {
  display: block; width: 100%; margin-top: .3rem; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 1rem;
}
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem .8rem; margin-top: .3rem; }
.check { display: flex; align-items: center; gap: .45rem; min-height: 36px; font-weight: 400; }
.check input { width: 20px; height: 20px; }

/* choice buttons */
.choices { display: flex; flex-wrap: wrap; gap: .35rem; }
.choice {
  flex: 1 0 auto; min-height: 42px; padding: .4rem .7rem; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  font: inherit; font-size: .92rem; color: var(--ink); cursor: pointer; text-decoration: none; text-align: center; display: inline-flex; align-items: center; justify-content: center;
}
.choice[aria-checked="true"] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.choices.small .choice { min-height: 36px; font-size: .82rem; padding: .25rem .5rem; }
.choices.scale .choice { flex: 1 1 0; flex-direction: column; padding: .35rem .2rem; min-width: 0; }
.choices.scale .face { font-size: 1.4rem; line-height: 1.2; }
.choices.scale .num { font-size: 1.1rem; font-weight: 700; }
.choices.scale .small { font-size: .66rem; line-height: 1.15; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { min-height: 38px; padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: .9rem; cursor: pointer; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.tag { display: inline-block; padding: .15rem .6rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: .82rem; margin: 0 .25rem .25rem 0; }
.allergen-badge { display: inline-block; padding: .05rem .4rem; border-radius: 6px; background: #f3ecff; color: #5b3fa0; font-size: .7rem; font-weight: 600; margin-left: .2rem; vertical-align: middle; }
.star { font-size: 1rem; }
.star.gold, .star-btn.gold { color: var(--gold); }
.star.blue, .star-btn.blue { color: var(--blue); }
.star-btn { font-size: 1.7rem; color: var(--muted); }

/* ---------- home ---------- */
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.day-nav h1 { margin: .3rem 0; text-align: center; flex: 1; }
.arrow { font-size: 2rem; line-height: 1; text-decoration: none; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.arrow.disabled { visibility: hidden; }
.stale { text-align: center; color: var(--amber); font-size: .85rem; margin: 0 0 .6rem; }
.allergen-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.allergen { border-radius: 10px; padding: .45rem .5rem; display: flex; flex-direction: column; background: var(--grey-bg); border-left: 5px solid #b9b5ab; }
.allergen .name { font-weight: 600; font-size: .9rem; }
.allergen .days { font-size: .78rem; }
.allergen.recent { background: var(--green-bg); border-color: var(--green); }
.allergen.recent .days { color: var(--green); }
.allergen.due { background: var(--amber-bg); border-color: #d99a00; }
.allergen.due .days { color: var(--amber); font-weight: 600; }
.allergen.overdue { background: var(--red-bg); border-color: var(--red); }
.allergen.overdue .days { color: var(--red); font-weight: 700; }
.allergen.none .days { color: var(--muted); }
.ideas { list-style: none; margin: 0; padding: 0; }
.ideas .btn { white-space: nowrap; flex: none; }
.ideas li { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .55rem 0; border-top: 1px solid var(--line); }
.ideas li:first-child { border-top: 0; }
.note-card .note-text, .note-text { white-space: pre-wrap; }
.big-number { font-size: 1.6rem; font-weight: 700; margin: .1rem 0; }
.big-number .muted { font-size: 1rem; font-weight: 400; }
#timeline h2 { margin: 1rem 0 .5rem; }
.entry-head { display: flex; align-items: baseline; gap: .6rem; }
.entry-head .time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 4.5em; }
.entry-head .oz { margin-left: auto; font-weight: 600; }
.entry.bottle { border-left: 5px solid #8fb8d8; }
.entry.meal { border-left: 5px solid #e2b26b; }
.meal-foods { list-style: none; padding: 0; margin: .4rem 0 0; }
.meal-foods li { display: flex; flex-wrap: wrap; gap: .1rem .6rem; padding: .15rem 0; }
.meal-foods .food-name { font-weight: 600; }
.extras { display: flex; flex-wrap: wrap; gap: .2rem .8rem; font-size: .85rem; margin-top: .3rem; }
.extras:empty { display: none; }
.who { font-size: .75rem; color: var(--muted); margin: .4rem 0 0; }
.pending { color: var(--amber); font-weight: 600; }

/* ---------- logging ---------- */
.log-form { padding-bottom: 1rem; }
.item { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .6rem; margin-bottom: .6rem; }
.item .choices { margin-top: .35rem; }
.item-head { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.item-head .remove { margin-left: auto; color: var(--muted); }
.food-search { position: relative; margin: .2rem 0 .6rem; }
.results { list-style: none; margin: .2rem 0 0; padding: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.results button { display: block; width: 100%; text-align: left; padding: .7rem .8rem; border: 0; border-top: 1px solid var(--line); background: none; font: inherit; cursor: pointer; }
.results li:first-child button { border-top: 0; }
.results .add-new { color: var(--brand); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: .5rem; }
.stepper .step { min-width: 56px; min-height: 52px; font-size: 1.6rem; }
.stepper input { width: 6em; text-align: center; font-size: 1.4rem; font-weight: 700; padding: .5rem; border: 1px solid var(--line); border-radius: 10px; }
.left { font-weight: 600; color: var(--brand); margin: -.4rem 0 1rem; }
.left.bad { color: var(--red); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .4rem 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history li.not_kept { color: var(--muted); }

/* ---------- foods ---------- */
.progress { height: 14px; background: var(--grey-bg); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bars { display: grid; gap: .25rem; }
.bar-row { display: grid; grid-template-columns: 6.5em 1fr 2em; align-items: center; gap: .5rem; font-size: .85rem; }
.bar-row .bar { height: 10px; background: var(--grey-bg); border-radius: 999px; overflow: hidden; }
.bar-row .bar span { display: block; height: 100%; background: #1f8a70; border-radius: 999px; }
.bar-row .count { text-align: right; font-variant-numeric: tabular-nums; }
.iron-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: .25rem; }
.iron-day { display: flex; flex-direction: column; align-items: center; background: var(--grey-bg); border-radius: 8px; padding: .3rem 0; }
.iron-day.ok { background: var(--green-bg); }
.iron-day .count { font-weight: 700; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-bottom: .6rem; }
.filters input { grid-column: 1 / -1; }
.filters input, .filters select { margin-top: 0; }
.food-list { list-style: none; padding: 0; margin: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.food-list a { display: grid; grid-template-columns: 1fr auto; gap: .1rem .5rem; padding: .7rem .9rem; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.food-list li:first-child a { border-top: 0; }
.food-list .muted { grid-column: 1 / -1; }
.food-list li.muted { padding: 1rem; }
.status { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--grey-bg); color: var(--muted); }
.status.trying { background: #e5effb; color: #2b5ea8; }
.status.accepted { background: var(--green-bg); color: var(--green); }
.status.retry { background: var(--amber-bg); color: var(--amber); }
.food-head { display: flex; align-items: center; justify-content: space-between; }
.exposures { padding-left: 1.2rem; }
.exposures li { padding: .2rem 0; }
.exposures li a { margin-right: .5rem; }
.gentle { background: var(--brand-soft); border-radius: 10px; padding: .5rem .7rem; font-size: .9rem; }

/* ---------- trends ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #ebe8e1; stroke-width: 1; }
.chart .tick { font-size: 10px; fill: var(--muted); }
.chart .behind { fill: #d9d6cf; }
.chart .dot { stroke: #fff; stroke-width: 2; }
.chart .note-dot { fill: #5b3fa0; }
.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); margin: 0 0 .3rem; }
.legend { flex-wrap: wrap; gap: .3rem 1rem; }
.legend i.note-key { background: #5b3fa0; border-radius: 50%; width: 9px; height: 9px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; font-size: .8rem; width: 100%; }
table.data th, table.data td { padding: .3rem .4rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
details.card summary { cursor: pointer; font-weight: 600; }
#main > .choices { margin-bottom: .8rem; }

/* ---------- settings, sync ---------- */
.menu-list { list-style: none; padding: 0; margin: 0 0 1rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.menu-list a { display: flex; justify-content: space-between; align-items: center; padding: .95rem 1rem; border-top: 1px solid var(--line); color: inherit; text-decoration: none; font-weight: 600; }
.menu-list li:first-child a { border-top: 0; }
.rows { list-style: none; padding: 0; margin: 0 0 1rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rows li { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .7rem .9rem; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows li.inactive { opacity: .55; }
#fq { margin-bottom: .6rem; }
#tab > .btn.primary { margin-bottom: .8rem; }
.plain { padding-left: 1.1rem; }
.problem { border-color: #f0c4c0; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .4rem 0 .8rem; }
.compare > div { background: var(--bg); border-radius: 10px; padding: .5rem .6rem; }

/* ---------- dialogs, toasts, sign in ---------- */
dialog.modal { border: 0; border-radius: 18px; padding: 0; width: min(560px, 94vw); max-height: 90vh; }
dialog.modal::backdrop { background: rgba(20, 30, 28, .45); }
.dialog-body { padding: 1.1rem; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + 80px); display: flex; flex-direction: column; align-items: center; gap: .4rem; z-index: 50; pointer-events: none; }
.toast { background: #1f2a28; color: #fff; padding: .6rem 1rem; border-radius: 999px; font-size: .9rem; max-width: 92vw; }
.toast.err { background: var(--red); }
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth-brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 1rem; }
.auth-brand img { border-radius: 16px; }
.auth .btn { width: 100%; }
