[hidden] { display: none !important; }
:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d2422;
  --muted: #5d6865;
  --line: #e2ddd4;
  --brand: #1f5f5b;
  --brand-ink: #ffffff;
  --take: #2f7d4f;
  --take-soft: #e6f2ea;
  --due: #b8641c;
  --due-soft: #fbefe2;
  --late: #a33a2b;
  --late-soft: #f8e4e0;
  --focus: #2a6fdb;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141917; --card: #1d2422; --ink: #ecefed; --muted: #a3ada9; --line: #2e3734;
    --brand: #5fb3aa; --brand-ink: #0d1312; --take: #5cbf83; --take-soft: #1d3326;
    --due: #e5a061; --due-soft: #3a2a1b; --late: #ef8a7a; --late-soft: #3d221e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141917; --card: #1d2422; --ink: #ecefed; --muted: #a3ada9; --line: #2e3734;
  --brand: #5fb3aa; --brand-ink: #0d1312; --take: #5cbf83; --take-soft: #1d3326;
  --due: #e5a061; --due-soft: #3a2a1b; --late: #ef8a7a; --late-soft: #3d221e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 1.6rem; margin: 8px 0 16px; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 0; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Menlo, monospace; letter-spacing: .03em; }
.em { font-weight: 650; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 0;
}
.top .brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; display: block; max-width: 608px; margin: 0 auto; }
.top nav { display: flex; gap: 2px; max-width: 608px; margin: 6px auto 0; overflow-x: auto; }
.top nav a {
  color: inherit; text-decoration: none; padding: 10px 8px; font-size: .92rem; opacity: .8;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.top nav a.on { opacity: 1; border-bottom-color: currentColor; font-weight: 600; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 2px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--card); color: var(--ink);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.take { background: var(--take); color: #fff; min-width: 120px; }
.btn.call { background: var(--brand); color: var(--brand-ink); margin-top: 6px; }
.btn.ghost { border-color: var(--line); background: transparent; }
.btn.link { background: none; color: var(--muted); padding: 10px 8px; min-height: 44px; text-decoration: underline; font-weight: 500; }
.btn.link.warn { color: var(--late); }
.btn.big { width: 100%; min-height: 58px; font-size: 1.1rem; }

.flash { background: var(--take-soft); border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; }
.error { color: var(--late); }

/* today */
.day { display: flex; flex-direction: column; font-size: 1.8rem; }
.day span { font-size: 1rem; font-weight: 500; color: var(--muted); }

.alert { background: var(--due-soft); border-left: 6px solid var(--due); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.alert.urgent { background: var(--late-soft); border-left-color: var(--late); }
.alert p { margin: 0 0 4px; }

.slot { background: var(--card); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; border: 1px solid var(--line); }
.slot > header { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px 8px; }
.slot .state { font-size: .9rem; font-weight: 600; color: var(--muted); }
.slot.due { border: 2px solid var(--due); }
.slot.due .state { color: var(--due); }
.slot.late { border: 2px solid var(--late); }
.slot.late .state { color: var(--late); }
.slot.done .state { color: var(--take); }
.slot.done > header h2 { color: var(--muted); }

.dose { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.dose .what { display: flex; flex-direction: column; min-width: 0; }
.dose .name, .cards .name, .medsheet .name { font-weight: 650; font-size: 1.1rem; }
.detail { color: var(--muted); font-size: .92rem; }
.dose .when { font-size: .9rem; font-weight: 600; color: var(--take); }
.dose.skipped .when { color: var(--muted); }
.dose.taken .name, .dose.skipped .name { color: var(--muted); }
.dose form { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.slot .all { padding: 4px 16px 16px; }

.empty { text-align: center; padding: 32px 0; }

/* lists */
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.cards { list-style: none; margin: 0 0 16px; padding: 0; }
.cards li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.cards li > a, .cards .contact { display: flex; flex-direction: column; padding: 14px 16px; color: inherit; text-decoration: none; }
.cards li.stopped { opacity: .6; }
.supply { font-size: .92rem; margin-top: 2px; }
.supply.low { color: var(--due); font-weight: 600; }
.contact-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.contacts { margin-bottom: 28px; }
.contacts h2 { margin-bottom: 10px; }
details.add summary { cursor: pointer; color: var(--brand); font-weight: 600; padding: 10px 0; }
.signout { text-align: center; margin-top: 24px; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .95rem; }
.form label.choice { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; }
.form input:not([type=radio]):not([type=checkbox]), .form select, .form textarea {
  font: inherit; font-weight: 400; padding: 12px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink); width: 100%; min-height: 48px;
}
.form input[type=radio], .form input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--brand); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 16px 16px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; padding: 0 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.time-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.time-row input { max-width: 180px; }
.hint { margin: 0; font-size: .88rem; color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 8px; }
.danger { margin-top: 28px; text-align: center; }
.inline-form { padding: 14px 16px 0; }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login form { display: flex; flex-direction: column; gap: 10px; text-align: left; margin-top: 16px; }
.login input { font: inherit; padding: 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); }
.login img { border-radius: 18px; }

/* printable list */
.medsheet { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.medsheet h1 { font-size: 1.35rem; margin-top: 0; }
.medsheet .meta { margin: 0 0 8px; }
.medsheet table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .95rem; }
.medsheet th, .medsheet td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.medsheet th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
@media (max-width: 560px) {
  .medsheet thead { display: none; }
  .medsheet tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .medsheet td { display: block; border: 0; padding: 2px 0; }
  .medsheet td:empty { display: none; }
}
@media print {
  :root { --bg: #fff; --card: #fff; --ink: #000; --muted: #444; --line: #bbb; }
  .top, .no-print, .flash { display: none !important; }
  main { max-width: none; padding: 0; }
  .medsheet { border: 0; padding: 0; }
  .medsheet thead { display: table-header-group; }
  .medsheet tr { display: table-row; }
  .medsheet td { display: table-cell; border-bottom: 1px solid #bbb; padding: 8px 6px; }
}
.nw { white-space: nowrap; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 10px; }
.panel h2 { margin-bottom: 2px; }
.panel p { margin: 0; }
.status-line { font-weight: 600; }
.status-line.ok { color: var(--take); }
.status-line.warn { color: var(--due); }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.plain li span { display: flex; flex-direction: column; }
.center { text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.camera { cursor: pointer; }
.shots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shots:empty { display: none; }
.shots figure { margin: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 3/4; }
.shots img { width: 100%; height: 100%; object-fit: cover; display: block; }
.reading { text-align: center; padding: 40px 0; }
.spinner { width: 48px; height: 48px; margin: 0 auto 16px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.checkme { display: inline-block; font-size: .78rem; font-weight: 700; color: var(--due); background: var(--due-soft); border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.scan-note { background: var(--take-soft); border-radius: 10px; padding: 10px 14px; margin: 0 0 14px; }
.scan-cta { margin-bottom: 16px; }
