:root {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --border: #34332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --primary: #3987e5; --primary-ink: #ffffff;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2c2b28;
  --good: #34b07a; --good-bg: #13261d; --warn: #e0a020; --warn-bg: #2b220d;
  --bad: #e66767; --bad-bg: #2d1515;
  --radius: 14px; --tap: 52px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f1ed; --surface: #fcfcfb; --surface-2: #ecebe6; --border: #d9d8d2;
  --text: #0b0b0b; --text-2: #3d3c39; --muted: #6b6a65;
  --primary: #2a78d6; --series-1: #2a78d6; --series-2: #eb6834; --grid: #e6e5e0;
  --good: #1d7f52; --good-bg: #e2f3ea; --warn: #8a5a00; --warn-bg: #fdf1d6;
  --bad: #c03434; --bad-bg: #fbe5e5;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: calc(env(safe-area-inset-top) + 64px) 16px calc(env(safe-area-inset-bottom) + 84px);
  max-width: 640px; margin: 0 auto; min-height: 100vh;
}
body.noscroll { overflow: hidden; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 20px; } h3 { font-size: 17px; }
h2.sec { margin: 22px 4px 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
small, .small { font-size: 14px; } .muted { color: var(--muted); }
.center { text-align: center; } .grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; } .between { justify-content: space-between; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.err { color: var(--bad); }
.ok-t { color: var(--good); font-weight: 600; } .late-t { color: var(--bad); font-weight: 600; }

/* Header & nav */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex-direction: column; } .brand .name { font-weight: 700; font-size: 19px; }
.sync { font-size: 12px; color: var(--muted); } .sync::before { content: "●"; margin-right: 4px; }
.sync.ok::before { color: var(--good); } .sync.wait::before { color: var(--warn); } .sync.bad { color: var(--bad); } .sync.bad::before { color: var(--bad); } .sync.demo::before { color: var(--muted); }
.who { min-height: 44px; padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; }
.lbl-sm { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border: 0; color: var(--muted); font: 12px system-ui; padding: 8px 0 10px; min-height: 60px; }
.tabs button .ic { display: block; font-size: 22px; } .tabs button.on { color: var(--text); font-weight: 700; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card.muted-card { opacity: .8; }
.bignum { font-size: 44px; font-weight: 800; letter-spacing: -.02em; margin: 4px 0; }
.bignum .unit { font-size: 20px; font-weight: 500; color: var(--muted); }
.progress { height: 16px; background: var(--surface-2); border-radius: 8px; overflow: hidden; margin: 6px 0 8px; }
.progress div { height: 100%; background: var(--primary); border-radius: 8px; transition: width .3s; }
.next { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.banner { display: flex; gap: 10px; align-items: flex-start; background: var(--bad-bg); border: 1px solid var(--bad); color: var(--text); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.banner .bi { font-size: 20px; }
.timer { border-color: var(--warn); } .timer.go { border-color: var(--good); background: var(--good-bg); } .timer.late { border-color: var(--bad); background: var(--bad-bg); }
.countdown { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.stats b { display: block; font-size: 20px; } .stats small { color: var(--muted); }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .35; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--bad); }
.btn.xl { min-height: 60px; font-size: 19px; width: 100%; }
.btn.sm { min-height: 44px; padding: 6px 12px; font-size: 15px; }
.btn.wide { width: 100%; margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.grid3 .btn { padding: 8px; font-size: 14px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 4px 0 8px; }
.act { min-height: 84px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 15px; }
.act span { display: block; font-size: 28px; margin-bottom: 2px; }
.act.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* Slots */
.slot { padding: 0; overflow: hidden; }
.slot.done { border-color: var(--good); } .slot.due { border-color: var(--warn); } .slot.bad { border-color: var(--bad); }
.slot-head { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 64px; padding: 10px 14px; background: none; border: 0; color: var(--text); font: inherit; text-align: left; }
.slot-time { font-weight: 800; font-size: 20px; min-width: 84px; } .slot-g { flex: 1; }
.plus { font-size: 26px; color: var(--primary); }
.pill { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; font-weight: 600; }
.pill.done { background: var(--good-bg); color: var(--good); } .pill.partial, .pill.later, .pill.due { background: var(--warn-bg); color: var(--warn); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.entry, .medrow { display: flex; gap: 10px; align-items: center; width: 100%; min-height: 56px; padding: 8px 14px; background: none; border: 0; border-top: 1px solid var(--border); color: var(--text); font: inherit; font-size: 15px; text-align: left; }
.card > .entry:first-child { border-top: 0; }
.ei { font-size: 20px; } .when { text-align: right; font-size: 14px; color: var(--text-2); white-space: nowrap; }
.medrow small { color: var(--muted); } .medrow .tap { font-size: 12px; color: var(--primary); white-space: nowrap; }
.check { width: 32px; height: 32px; flex: none; border-radius: 9px; border: 2px solid var(--muted); display: grid; place-items: center; font-weight: 800; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.medrow.given .grow { color: var(--text-2); }

/* Forms */
.fld { display: block; margin: 0 0 14px; } .fld > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.big-input { font-size: 22px; min-height: 56px; } .big-input.huge { font-size: 34px; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; } .chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
.chip { min-height: 46px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px; white-space: nowrap; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; min-height: 46px; border: 0; background: none; color: var(--text-2); font: inherit; font-weight: 600; border-radius: 9px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px #0005; }
.seg.sm { margin: 0; } .seg.sm button { min-height: 36px; padding: 0 12px; font-size: 14px; }
.timefield { display: flex; gap: 6px; align-items: center; } .timefield input { flex: 1; min-width: 0; }
.calc { min-height: 28px; margin: -4px 0 12px; font-size: 18px; }
.hint { background: var(--warn-bg); color: var(--text); padding: 10px 12px; border-radius: 10px; }
.daynav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.daynav .btn { min-width: 56px; font-size: 22px; } .daynav.sm { font-size: 15px; } .daynav.sm .btn { min-width: 44px; }
.srow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.srow input[type=time] { flex: 1; } .inl { display: flex; align-items: center; gap: 4px; width: 110px; } .w5 { width: 80px; }
.medcard { border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 10px; } .medcard.paused { opacity: .65; }
.toggle { display: flex; align-items: center; gap: 6px; white-space: nowrap; } .toggle input { width: 24px; min-height: 24px; height: 24px; }
.savebar { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 64px); z-index: 11; display: flex; gap: 10px; padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--border); max-width: 640px; margin: 0 auto; }
.savebar .btn { flex: 1; }

/* Sheet (bottom modal) */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: #000a; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 94vh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0; max-width: 640px; margin: 0 auto; padding-bottom: env(safe-area-inset-bottom); overscroll-behavior: contain; }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.sheet-head h2 { margin: 0; }
.x { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); font-size: 20px; }
.sheet-body { padding: 16px; }
.sheet-foot { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; padding-bottom: 12px; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 60; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; max-width: 600px; margin: 0 auto; box-shadow: 0 6px 20px #0006; }
.toast button { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 0; background: var(--primary); color: #fff; font: inherit; font-weight: 700; }

/* Login */
.login { max-width: 420px; margin: 10vh auto 0; text-align: center; }
.login .logo { font-size: 64px; } .login form { text-align: left; margin-top: 24px; }
.login .btn { margin-top: 16px; }
.lbl { display: block; color: var(--muted); margin-bottom: 6px; }

/* Charts */
.chart { position: relative; margin: 6px 0; touch-action: pan-y; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--muted); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; } .chart .axis.strong { fill: var(--text-2); font-weight: 600; }
.chart .bar { fill: var(--series-1); } .chart .bar.low { fill: var(--series-1); opacity: .55; }
.chart .target { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); } .chart .line.s2 { stroke: var(--series-2); }
.chart .dot { stroke: var(--surface); stroke-width: 2; } .chart .dot.s1 { fill: var(--series-1); } .chart .dot.s2 { fill: var(--series-2); }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart .tip { position: absolute; top: -6px; transform: translateY(-100%); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 13px; white-space: nowrap; pointer-events: none; z-index: 3; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); } .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 4px; border-bottom: 1px solid var(--border); text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; } .tbl tr[data-edit] { cursor: pointer; }
.card .tbl { display: block; overflow-x: auto; }

@media (max-width: 370px) { .actions { grid-template-columns: repeat(2, 1fr); } .grid3 { grid-template-columns: 1fr; } }

/* Print: only the vet summary, black on white */
@media print {
  :root { --text: #000; --muted: #444; --border: #bbb; --surface: #fff; --bg: #fff; }
  body { padding: 0; max-width: none; font-size: 12pt; background: #fff; color: #000; }
  .top, .tabs, .no-print, .toast, .sheet-wrap, .savebar { display: none !important; }
  .print-area { border: 0; padding: 0; }
  .card .tbl { display: table; } .tbl { font-size: 10pt; }
  h3 { margin-top: 14px; }
}

/* Keep grids inside the phone width (date/time inputs have large intrinsic widths on iOS). */
.grid2 > *, .grid3 > *, .fld, .timefield > * { min-width: 0; }
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; min-width: 0; }
html, body { overflow-x: hidden; }
.timefield input { font-size: 19px; padding: 8px; } .timefield .btn.sm { padding: 6px 10px; }
:root { accent-color: var(--primary); }
