@font-face { font-family: "Atkinson"; src: url(fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url(fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --bg: #F5F1EA; --surface: #FFFFFF; --surface-2: #EFEAE1; --ink: #1D2926; --muted: #5C6964; --line: #E2DCD1;
  --accent: #2F6B5E; --accent-ink: #FFFFFF; --accent-soft: #DCEBE5;
  --warn: #A9521F; --warn-soft: #F8E6D6; --danger: #B3261E; --danger-soft: #F7DEDC; --ok: #2C7A4B; --ok-soft: #DCEFE2;
  --shadow: 0 1px 2px rgba(29, 41, 38, .06), 0 4px 16px rgba(29, 41, 38, .06);
  --r: 16px; --tap: 48px;
  font-size: 17px;
}
:root.big { font-size: 21px; --tap: 56px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121816; --surface: #1B2320; --surface-2: #232D29; --ink: #EAF1EE; --muted: #A2B0AB; --line: #2E3A36;
    --accent: #6FB8A5; --accent-ink: #0C1A16; --accent-soft: #1F3A33;
    --warn: #E59A62; --warn-soft: #3A2A1D; --danger: #F2827A; --danger-soft: #3D2221; --ok: #7CCB98; --ok-soft: #1E3326;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121816; --surface: #1B2320; --surface-2: #232D29; --ink: #EAF1EE; --muted: #A2B0AB; --line: #2E3A36;
  --accent: #6FB8A5; --accent-ink: #0C1A16; --accent-soft: #1F3A33;
  --warn: #E59A62; --warn-soft: #3A2A1D; --danger: #F2827A; --danger-soft: #3D2221; --ok: #7CCB98; --ok-soft: #1E3326; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: "Atkinson", system-ui, -apple-system, "Segoe UI", sans-serif; line-height: 1.4; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.65rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: .35rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- layout: bottom tabs on phones, side rail on wide screens ---------- */
.app { min-height: 100%; }
.view { padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 760px; margin: 0 auto; outline: none; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px); }
.tabs .brand { display: none; }
.tabs button { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; min-height: var(--tap); color: var(--muted); font-size: .72rem; cursor: pointer; border-radius: 12px; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 700; }
@media (min-width: 900px) {
  .tabs { top: 0; right: auto; width: 220px; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding: 20px 12px; gap: 4px; }
  .tabs .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-size: 1.15rem; }
  .tabs button { flex: 0 0 auto; flex-direction: row; gap: 12px; font-size: .95rem; padding: 10px 12px; justify-content: flex-start; }
  .tabs button[aria-current="page"] { background: var(--accent-soft); }
  .view { margin-left: 220px; margin-right: auto; padding: 28px 40px 60px; max-width: 900px; }
}
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); position: relative; display: inline-block; }
.logo::after { content: ""; position: absolute; inset: 6px 9px; border-radius: 5px; background: var(--accent-ink); opacity: .9; }

/* icons (masks so they follow the text color) */
.ic { width: 24px; height: 24px; display: inline-block; background: currentColor; -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; flex: none; }
.ic-today { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E"); }
.ic-meds { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Crect x='6' y='7' width='12' height='14' rx='2'/%3E%3Cpath d='M5 3h14v4H5zM9 12h6M9 16h4'/%3E%3C/svg%3E"); }
.ic-visit { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-3'/%3E%3Crect x='9' y='2' width='6' height='4' rx='1'/%3E%3Cpath d='M8 12h8M8 16h5'/%3E%3C/svg%3E"); }
.ic-health { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12h4l2-5 4 10 2-5h6'/%3E%3C/svg%3E"); }
.ic-more { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Ccircle cx='5' cy='12' r='2'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Ccircle cx='19' cy='12' r='2'/%3E%3C/svg%3E"); }
.ic-cam { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M4 8h3l2-3h6l2 3h3v11H4z'/%3E%3Ccircle cx='12' cy='13' r='3.5'/%3E%3C/svg%3E"); }
.ic-plus { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.ic-phone { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2z'/%3E%3C/svg%3E"); }
.ic-check { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E"); }

/* ---------- building blocks ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.head .sub { color: var(--muted); font-size: .95rem; }
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px 16px; margin: 10px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn:focus-visible, .tabs button:focus-visible, .chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 700; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.banner { display: flex; align-items: center; gap: 12px; border-radius: var(--r); padding: 12px 14px; margin: 10px 0; background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.banner .btn { margin-left: auto; }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.note { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: .9rem; color: var(--muted); }

/* ---------- Today ---------- */
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); display: grid; place-items: center; flex: none; }
.ring::before { content: attr(data-label); width: 50px; height: 50px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.slot { margin: 18px 0 6px; display: flex; align-items: baseline; gap: 10px; }
.slot h2 { margin: 0; }
.dose { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.dose + .dose { border-top: 1px solid var(--line); }
.dose .pill { width: 44px; height: 44px; border-radius: 12px; flex: none; background: var(--surface-2) center / cover no-repeat; display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.dose .what { flex: 1; min-width: 0; }
.dose .what b { display: block; }
.dose .what .small { color: var(--muted); }
.dose.done .what b { color: var(--muted); }
.dose .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.take { background: var(--accent); color: var(--accent-ink); border: 0; min-height: var(--tap); min-width: var(--tap); padding: 0 16px; border-radius: 999px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.dose.due { background: var(--warn-soft); }
.dose.due .what .when { color: var(--warn); font-weight: 700; }
.group { padding: 0; overflow: hidden; }
.who { font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; }

/* ---------- forms ---------- */
label.f { display: block; margin: 12px 0; }
label.f > span { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 5px; }
label.f > small { display: block; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 10px 12px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; min-height: 42px; cursor: pointer; font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.times { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.times .t { display: flex; align-items: center; gap: 4px; }
.times input { width: 140px; }
.x { border: 0; background: var(--surface-2); border-radius: 50%; width: 34px; height: 34px; cursor: pointer; font-size: 1.1rem; line-height: 1; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 6px 14px 10px; margin: 14px 0; background: var(--surface); }
legend { font-weight: 700; padding: 0 6px; }
.check { border: 2px solid var(--warn); background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-weight: 700; }
.scanbox { display: grid; gap: 10px; }
.scanbox img { width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: var(--surface-2); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 30%; background: var(--accent); animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* ---------- lists ---------- */
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; text-align: left; width: 100%; background: none; border: 0; }
.item + .item { border-top: 1px solid var(--line); }
.item .grow { flex: 1; min-width: 0; }
.item .grow b { display: block; }
.list { padding: 0; overflow: hidden; }
.kv { display: grid; grid-template-columns: minmax(110px, 34%) 1fr; gap: 6px 12px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.hist { display: flex; gap: 4px; flex-wrap: wrap; }
.hist i { width: 14px; height: 14px; border-radius: 4px; background: var(--surface-2); display: inline-block; }
.hist i.t { background: var(--ok); } .hist i.s { background: var(--muted); } .hist i.m { background: var(--danger); }
.chart { width: 100%; height: 160px; }
.chart text { fill: var(--muted); font-size: 11px; }

/* ---------- sheet (full-screen on phones, dialog on wide screens) ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(15, 22, 20, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--bg); width: 100%; max-width: 720px; max-height: calc(100% - env(safe-area-inset-top) - 24px); overflow: auto; border-radius: 20px 20px 0 0; padding: 16px 16px 0; animation: up .22s ease-out; }
.sheet-card > :last-child:not(.sheet-foot):not(form) { margin-bottom: calc(env(safe-area-inset-bottom) + 24px); }
body.sheet-open .tabs { display: none; }
@media (min-width: 900px) { .sheet { align-items: center; } .sheet-card { border-radius: 20px; max-height: 90vh; padding: 22px 26px 0; } body.sheet-open .tabs { display: flex; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 10px; position: sticky; top: -16px; background: var(--bg); padding: 4px 0 10px; z-index: 2; }
.sheet-head h1 { font-size: 1.3rem; flex: 1; }
.sheet-foot { display: flex; gap: 10px; position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 calc(env(safe-area-inset-bottom) + 16px); margin-top: 8px; border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 60; max-width: 92vw; display: flex; gap: 14px; align-items: center; font-weight: 700; box-shadow: var(--shadow); }
.toast button { background: none; border: 0; color: var(--accent-soft); font-weight: 700; cursor: pointer; }
@media (min-width: 900px) { .toast { bottom: 28px; left: calc(50% + 110px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

body.sheet-open .toast { bottom: auto; top: calc(env(safe-area-inset-top) + 12px); }
