:root {
  --bg: #f3f5f7; --card: #ffffff; --text: #15202b; --muted: #5b6876; --line: #dde3e9;
  --brand: #0f766e; --brand-ink: #ffffff; --top: #0f766e; --top-ink: #ffffff;
  --input: #ffffff; --danger: #b42318; --danger-bg: #fdecea;
  --warn: #7a4e00; --warn-bg: #fff4d6; --ok: #146c43; --ok-bg: #e3f6ea;
  --fever: #c0261b; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --tab-h: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1419; --card: #18212a; --text: #e8eef3; --muted: #97a5b3; --line: #2a3743;
    --brand: #35bdb0; --brand-ink: #04211e; --top: #0b3a36; --top-ink: #e8f6f4;
    --input: #101820; --danger: #ff8a80; --danger-bg: #3a1c1a;
    --warn: #f5c26b; --warn-bg: #33280f; --ok: #7ddba0; --ok-bg: #12301f;
    --fever: #ff7b6e; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html { background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  /* The extra 1px keeps the page scrollable even when it's short. iOS home-screen apps shrink the
     viewport (leaving a gap under the fixed tab bar) when a page can't scroll. */
  min-height: calc(100lvh + 1px);
  -webkit-touch-callout: none;
}
body.has-tabs { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px); }
a { color: var(--brand); text-decoration: none; }
button, a, label, summary { touch-action: manipulation; }
button, .btn, .tabbar a, .chip, summary { -webkit-user-select: none; user-select: none; }
code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar { background: var(--top); color: var(--top-ink); padding-top: env(safe-area-inset-top); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px max(16px, env(safe-area-inset-left)) 6px max(16px, env(safe-area-inset-right)); }
.topbar h1 { font-size: 1.25rem; flex: 1; font-weight: 700; }
.topbar .back { color: var(--top-ink); font-size: 2rem; line-height: 1; padding: 0 10px 4px 0; margin-left: -4px; }
.wrap { max-width: 720px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) 24px max(16px, env(safe-area-inset-right)); }

/* ---- tab bar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; max-width: 144px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tab-h); color: var(--muted); font-size: .72rem; font-weight: 600; }
.tabbar a.active { color: var(--brand); }
.ico { width: 24px; height: 24px; }

/* ---- cards & lists ---- */
.card { background: var(--card); border-radius: 16px; padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.empty { text-align: center; color: var(--muted); }
.card.empty h2 { color: var(--text); margin-bottom: 6px; }
.card.list { padding: 4px 0; }
.card-title { font-size: 1rem; margin-bottom: 10px; }
.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; }
.row-link { display: flex; align-items: center; gap: 12px; color: var(--text); }
.row-link .grow { display: flex; flex-direction: column; }
.chev { color: var(--muted); font-size: 1.6rem; line-height: 1; }
.archived { opacity: .6; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c, var(--brand)); flex: none; display: inline-block; }
.person { border-left: 5px solid var(--c); display: flex; align-items: flex-start; gap: 12px; }
.person-main { flex: 1; min-width: 0; }
.person-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.person-head h2, .person-head h3 { font-size: 1.15rem; }
.last-temp { margin: 0 0 8px; }
.last-temp .temp { font-size: 1.35rem; }
.person-actions { display: flex; flex-direction: column; gap: 8px; flex: none; align-self: center; }
.person-actions .btn { min-height: 38px; padding: 0 12px; font-size: .85rem; white-space: nowrap; }
.sort-toggle { margin-bottom: 14px; }
.sort-toggle a { padding: 9px 12px; font-size: .9rem; }
.allergy { margin: 0 0 8px; padding: 6px 10px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); font-size: .88rem; }
.mini { list-style: none; margin: 0 0 12px; padding: 0; }
.mini li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: .95rem; }
.mini li:first-child { border-top: 0; }
.act { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); border-top: 1px solid var(--line); }
.act:first-child { border-top: 0; }
.act .grow { display: flex; flex-direction: column; gap: 1px; }
.act .time { width: 64px; flex: none; font-size: .85rem; color: var(--muted); align-self: flex-start; padding-top: 2px; }
.act.static { cursor: default; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font: inherit; font-weight: 650; cursor: pointer; text-align: center; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-secondary { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-light { background: rgba(255,255,255,.18); color: var(--top-ink); border-color: rgba(255,255,255,.35); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.btn:active { transform: scale(.98); opacity: .9; }

/* ---- forms ---- */
.field { margin-bottom: 14px; }
.field > label, .field > .lbl { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=datetime-local], input:not([type]), input[type=number], select, textarea,
input[inputmode], input[list] {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--input); border: 1px solid var(--line); border-radius: 12px; appearance: none; -webkit-appearance: none;
}
input[type=datetime-local], input[type=date] { min-height: 48px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.color-input { padding: 4px; }
.big-input { font-size: 2rem !important; min-height: 64px !important; text-align: center; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; font-size: .95rem; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
details.more { margin: 0 0 16px; }
details.more summary { cursor: pointer; font-weight: 650; color: var(--brand); padding: 8px 0; }

/* person chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 22px; border: 2px solid var(--c); font-weight: 650; color: var(--text); background: transparent; }
.chip input:checked + span { background: var(--c); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }

/* segmented controls */
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.seg label, .seg a { flex: 1; text-align: center; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; }
.seg span, .seg a { display: block; padding: 12px; font-weight: 650; color: var(--muted); }
.seg input:checked + span, .seg a.on { background: var(--brand); color: var(--brand-ink); }
.seg-tabs { margin-bottom: 14px; }

/* saved medicine buttons */
.presets { display: flex; flex-direction: column; gap: 8px; }
.preset { text-align: left; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--input); color: var(--text); font: inherit; display: flex; flex-direction: column; cursor: pointer; }
.preset:active { background: var(--line); }
.preset strong { font-size: 1rem; }
.preset span { color: var(--muted); font-size: .88rem; }

.preset-row > strong { display: block; }
.preset-row > .muted { display: block; margin-bottom: 10px; font-size: .88rem; }

/* family temp rows */
.fam-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.fam-row label { display: flex; flex-direction: column; }
.temp-input { width: 110px !important; text-align: center; font-size: 1.4rem !important; font-weight: 700; }
.fam-row + .btn { margin-top: 12px; }

/* ---- alerts, badges, temps ---- */
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-weight: 550; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.badge { font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 8px; background: var(--line); color: var(--muted); vertical-align: middle; }
.badge-off { background: var(--danger-bg); color: var(--danger); }
.temp { font-weight: 700; font-variant-numeric: tabular-nums; }
.temp-fever { color: var(--fever); }
.temp-danger { color: #fff; background: var(--fever); padding: 0 6px; border-radius: 6px; }

/* ---- login ---- */
.login { max-width: 400px; margin: 0 auto; padding-top: 6vh; }
.login h2 { text-align: center; margin-bottom: 16px; font-size: 1.5rem; }
.login-logo { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 20px; background: var(--top); color: var(--top-ink); display: flex; align-items: center; justify-content: center; font-size: 2.4rem; }
.or { text-align: center; color: var(--muted); margin: 12px 0; }
body.no-tabs .topbar { background: transparent; color: var(--text); }
body.no-tabs .topbar h1 { display: none; }
body.no-tabs .topbar-in { min-height: 8px; }

/* ---- reports ---- */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 14px; }
.sum { margin: 0; border-left: 5px solid var(--c); }
.sum p { margin: 4px 0; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .fever-line { stroke: var(--fever); stroke-width: 1.2; stroke-dasharray: 5 4; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: .85rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.print-title { display: none; }

@media (hover: hover) {
  .btn:hover { opacity: .92; }
  a.act:hover, .preset:hover { background: color-mix(in srgb, var(--line) 50%, transparent); }
}

@media print {
  body { background: #fff; color: #000; padding: 0 !important; min-height: 0; }
  .topbar, .tabbar, .no-print { display: none !important; }
  .print-title { display: block; margin-bottom: 12px; }
  .card { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; }
  .wrap { max-width: none; padding: 0; }
  .act { color: #000; }
  .muted { color: #444; }
}
