/* ckd-tracker. Colours: the dataviz palette (categorical slots 1-8 in fixed
   order, diverging blue-grey-red for the flowsheet, status colours reserved). */
:root {
  color-scheme: light;
  --bg: #f6f6f4; --surface: #ffffff; --ink: #191919; --ink2: #5f5f5f; --ink3: #8a8a8a;
  --rule: #e4e4e0; --grid: #efefec; --band: #e9f3ea; --bandEdge: #cfe5d2; --accent: #257de0;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600; --s5: #ee7fac; --s6: #008a17; --s7: #6a4ce2; --s8: #ec4647;
  --hi: #ec4647; --lo: #257de0; --mid: #efefef;
  --good: #0aac23; --crit: #dc3c3d;
  --betterInk: #006c10; --worseInk: #b3261e; --warn: #fbb315;
  --navh: 0px;
}
/* dark: data-theme on <html>, set by theme.js before the first paint (the
   reader's choice from the header switch, else the system's) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212; --surface: #191919; --ink: #efefef; --ink2: #a8a8a8; --ink3: #7a7a7a;
  --rule: #2c2c2c; --grid: #242424; --band: #1d2e20; --bandEdge: #2c4a31; --accent: #338ced;
  --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23; --s7: #9887ef; --s8: #eb6263;
  --hi: #eb6263; --lo: #338ced; --mid: #383838;
  --betterInk: #53c556; --worseInk: #ff8a80;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, select, input, textarea { font: inherit; color: var(--ink); }
a { color: var(--accent); }
.loading { padding: 40px; text-align: center; color: var(--ink2); }
[hidden] { display: none !important; }

/* header and navigation */
header.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--rule); padding: 8px 16px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
header.top h1 { font-size: 15px; margin: 0; font-weight: 650; display: flex; gap: 8px; align-items: center; }
header.top h1 img { width: 22px; height: 22px; }
.verchip { font-size: 11px; color: var(--ink3); font-weight: 500; text-decoration: none; display: inline-flex; gap: 4px; align-items: center; }
.verchip:hover { color: var(--accent); }
.vernew { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 5px; font-size: 10px; font-weight: 700; }
.tools { display: flex; gap: 6px; align-items: center; }
.ib { width: 32px; height: 32px; border: 1px solid var(--rule); background: var(--surface); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; color: var(--ink); flex: none; }
.ib:hover { border-color: var(--ink3); }
.ib b { font-size: 14px; }
.ib .sun, :root[data-theme="dark"] .ib .moon { display: none; }
:root[data-theme="dark"] .ib .sun { display: block; }
/* ⓘ: opens the help at the topic */
a.hl { color: var(--ink3); text-decoration: none; font-size: 13px; font-weight: 400; padding: 0 3px; cursor: help; }
a.hl:hover { color: var(--accent); }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.pillbtn, nav.tabs button, .seg button { border: 1px solid var(--rule); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
nav.tabs button[aria-current="page"], .seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
nav.tabs button { display: inline-flex; align-items: center; gap: 6px; }
nav.tabs .ico { display: inline-flex; }
nav.tabs .ico svg { width: 16px; height: 16px; }
.sp { flex: 1; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
main { padding: 14px 16px calc(40px + var(--navh)); max-width: 1600px; margin: 0 auto; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--ink2); }
.small { font-size: 12px; }

@media (max-width: 700px) {
  :root { --navh: 66px; }
  header.top { padding: 8px 12px; }
  nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--rule); padding: 6px 2px calc(6px + env(safe-area-inset-bottom)); flex-wrap: nowrap; justify-content: space-around; gap: 0; }
  nav.tabs button { flex: 1 1 0; min-width: 0; border: 0; background: none; border-radius: 0; padding: 0 1px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--ink2); white-space: nowrap; -webkit-tap-highlight-color: transparent; }
  nav.tabs .lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  nav.tabs .ico { width: 52px; max-width: 100%; height: 30px; border-radius: 999px; align-items: center; justify-content: center; transition: background-color .15s; }
  nav.tabs .ico svg { width: 22px; height: 22px; }
  nav.tabs button[aria-current="page"] { background: none; color: var(--accent); font-weight: 600; }
  nav.tabs button[aria-current="page"] .ico { background: color-mix(in srgb, var(--accent) 16%, transparent); }
  main { padding: 10px 8px calc(30px + var(--navh)); }
}
@media (max-width: 360px) {
  nav.tabs button { font-size: 10px; }
  nav.tabs .ico { width: 46px; }
}

/* cards, tiles, tooltip */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 12px; }
.scroll { overflow-x: auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
@media (max-width: 700px) { .tiles { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; } .tile { flex: 0 0 150px; scroll-snap-align: start; } }
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 10px 12px; cursor: pointer; text-align: left; }
.tile .n { font-size: 12px; color: var(--ink2); }
.tile .v { font-size: 23px; font-weight: 650; letter-spacing: -.01em; }
.tile .u { font-size: 12px; color: var(--ink3); margin-left: 3px; font-weight: 400; }
.tile .meta { display: flex; justify-content: space-between; gap: 6px; font-size: 11.5px; color: var(--ink2); margin-top: 2px; }
.tile svg { display: block; width: 100%; height: 28px; margin-top: 4px; }
.tile .n { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.tile .fl { font-size: 12px; vertical-align: 4px; }
.ctrl { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 10px; font-size: 13px; color: var(--ink2); }
select, input[type=text], input[type=email], input[type=date], input[type=number], textarea { border: 1px solid var(--rule); background: var(--surface); border-radius: 8px; padding: 6px 8px; }
svg text { fill: var(--ink2); font-size: 11px; }
svg .lbl { fill: var(--ink); font-size: 12px; font-weight: 600; }
svg .unit { fill: var(--ink3); font-size: 10.5px; }
svg .val { fill: var(--ink); font-size: 12px; font-weight: 600; }
svg .lanelbl { fill: var(--ink); font-size: 11.5px; cursor: pointer; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.14); padding: 8px 10px; font-size: 12.5px; max-width: 320px; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .muted { color: var(--ink2); }
.ev { display: flex; gap: 6px; align-items: center; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink2); margin: 8px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 12px; border: 1px solid var(--rule); color: var(--ink); background: var(--surface); }
button.chip { cursor: pointer; }
.notes { margin-top: 12px; color: var(--ink2); font-size: 12px; padding-left: 18px; }

/* flowsheet */
table.fs { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
table.fs th, table.fs td { padding: 0; text-align: center; }
table.fs th.rowh { position: sticky; left: 0; background: var(--surface); box-shadow: -14px 0 0 var(--surface); text-align: left; padding: 0 10px 0 2px; white-space: nowrap; z-index: 2; }
table.fs th.rowh small { display: block; color: var(--ink3); font-weight: 400; }
table.fs td.cell { min-width: 50px; height: 34px; border-radius: 6px; font-variant-numeric: tabular-nums; }
table.fs thead th.date { font-weight: 500; color: var(--ink2); font-size: 11px; line-height: 1.15; padding-bottom: 4px; }
table.fs td.evs { height: 22px; vertical-align: bottom; }
table.fs td.cell sup { font-size: 9px; font-weight: 700; margin-left: 1px; }
table.fs td.cell.chk { position: relative; }
table.fs td.cell.chk::after { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 11px 11px 0; border-color: transparent var(--warn) transparent transparent; border-top-right-radius: 6px; }
.yearsep { border-left: 2px solid var(--rule); }

/* journal */
.journal { max-width: 640px; }
.day h4 { margin: 12px 2px 6px; font-size: 12px; color: var(--ink2); font-weight: 600; }
.dcard { background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.res { display: flex; flex-wrap: wrap; gap: 6px; }
.res .chip { font-variant-numeric: tabular-nums; }
.fab { position: fixed; right: 18px; bottom: calc(18px + var(--navh)); width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* forms */
.forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 14px; align-items: start; }
.form .fld { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--rule); border-radius: 12px; padding: 8px 12px; margin: 0 0 8px; }
.form .fld .nm { font-weight: 600; }
.form .fld small { display: block; color: var(--ink3); font-weight: 400; }
.form .fld input { width: 130px; text-align: right; font-size: 16px; padding: 8px; }
.form .fld input[type=date] { width: 160px; }
.form .stack { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; }
.form .stack label { font-weight: 600; font-size: 13px; }
.form .stack input, .form .stack textarea, .form .stack select { width: 100%; font-size: 16px; padding: 8px; }
.form .cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.form .cats label { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--rule); border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 13px; background: var(--surface); }
.form .cats input { margin: 0; }
.form .cats label:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.primary { width: 100%; border: 0; border-radius: 12px; background: var(--accent); color: #fff; padding: 12px; font-size: 16px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: .5; cursor: default; }
.secondary { border: 1px solid var(--rule); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.danger { color: var(--crit); }
.err { color: var(--crit); font-size: 13px; margin: 6px 0; }
.row2 { display: flex; gap: 8px; }
.row2 > * { flex: 1; }

/* sign-in */
.signin { max-width: 380px; margin: 12vh auto 0; padding: 24px; }
.signin h1 { font-size: 20px; margin: 0 0 4px; display: flex; gap: 10px; align-items: center; }
.signin h1 img { width: 30px; height: 30px; }
.signin p { color: var(--ink2); }
.signin input { width: 100%; font-size: 17px; padding: 10px 12px; margin: 6px 0 12px; }
.signin input.code { letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }

/* settings tables */
table.list { border-collapse: collapse; width: 100%; font-size: 13px; }
table.list th, table.list td { border-bottom: 1px solid var(--rule); padding: 6px 8px; text-align: left; vertical-align: middle; }
table.list th { color: var(--ink2); font-weight: 600; font-size: 12px; }
table.list input[type=text] { width: 80px; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 14px; align-items: start; }

dialog { border: 1px solid var(--rule); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 16px; width: min(440px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + var(--navh)); z-index: 30; background: var(--ink); color: var(--surface); border-radius: 999px; padding: 8px 16px; font-size: 13px; }

/* help: topics on the left, the topic on the right; on a phone a list, then one topic */
#help { width: min(900px, 94vw); height: min(720px, 90vh); padding: 0; }
#help[open] { display: flex; flex-direction: column; }
.hbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--rule); }
.hbar h2 { font-size: 15px; margin: 0; flex: none; }
.hbar input { flex: 1; min-width: 0; }
.hbar .kbd { font-size: 11.5px; color: var(--ink3); white-space: nowrap; }
kbd { font: 11.5px ui-monospace, Menlo, monospace; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
.hwrap { flex: 1; min-height: 0; display: flex; }
#hnav { width: 200px; flex: none; overflow: auto; border-right: 1px solid var(--rule); padding: 8px; }
#hnav button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 9px; border-radius: 7px; cursor: pointer; }
#hnav button[aria-current="true"] { background: var(--bg); font-weight: 600; }
#hmain { flex: 1; min-width: 0; overflow: auto; padding: 4px 22px 30px; }
#hmain section > h2 { font-size: 18px; margin: 16px 0 4px; }
#hmain article { padding: 2px 0 6px; border-bottom: 1px solid var(--rule); }
#hmain article:last-child { border-bottom: 0; }
#hmain article h3 { font-size: 14.5px; margin: 14px 0 4px; }
#hmain p, #hmain li { max-width: 46em; }
#hmain table { border-collapse: collapse; font-size: 13px; }
#hmain td, #hmain th { border-bottom: 1px solid var(--rule); padding: 4px 10px 4px 0; text-align: left; vertical-align: top; }
#hmain code { font: 12.5px ui-monospace, Menlo, monospace; background: var(--bg); border-radius: 4px; padding: 0 3px; }
#hmain .flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: color-mix(in srgb, var(--accent) 18%, transparent); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { #hmain .flash { animation: none; } nav.tabs .ico { transition: none; } }
#hresults a { display: block; padding: 6px 0; text-decoration: none; }
#hresults mark { background: color-mix(in srgb, var(--s4) 35%, transparent); color: inherit; }
.hback { display: none; }
#help[data-view="list"] .hback { visibility: hidden; }
@media (max-width: 700px) {
  #help { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top); }
  #hnav { width: auto; flex: 1; border-right: 0; }
  #help[data-view="list"] #hmain { display: none; }
  #help:not([data-view="list"]) #hnav { display: none; }
  .hback { display: inline-flex; }
  .hbar .kbd { display: none; }
}
.signin .corner { float: right; display: flex; gap: 6px; }

/* patients */
.ptchip { display: inline-flex; align-items: center; gap: 5px; font: inherit; font-size: 13px; font-weight: 650; letter-spacing: .02em; color: var(--ink); background: var(--grid); border: 1px solid var(--rule); border-radius: 999px; padding: 3px 9px 3px 11px; cursor: pointer; }
.ptchip:hover { border-color: var(--accent); }
.patients { max-width: 640px; }
.patients h2 { font-size: 17px; margin: 4px 0 10px; }
.patients .lead { margin: 4px 0 14px; }
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.pcard { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.pcard.on, .pcard:hover { border-color: var(--accent); }
.pcard .pa { font-size: 18px; font-weight: 650; letter-spacing: .02em; }
.pform { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 0 10px; align-items: end; }
.pform .stack label { font-size: 12px; font-weight: 500; color: var(--ink2); }
.pform > button { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 480px) { .pform { grid-template-columns: 1fr 1fr; } .pform .stack:first-child { grid-column: 1 / -1; } }
.prow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
.prow select { flex: 0 0 auto; }

/* status marks: H / L (the letter counts; the tint helps), change, please check */
.fl { display: inline-block; font-size: 10px; font-weight: 750; line-height: 1.3; margin-left: 3px; padding: 0 3px; border-radius: 4px; color: var(--ink); vertical-align: 1px; }
.fl-high { background: color-mix(in srgb, var(--hi) 22%, transparent); }
.fl-low { background: color-mix(in srgb, var(--lo) 22%, transparent); }
.chg { font-size: 11px; color: var(--ink3); margin-left: 4px; white-space: nowrap; }
.chg.better { color: var(--betterInk); }
.chg.worse { color: var(--worseInk); font-weight: 700; }
.wi { display: inline-flex; vertical-align: -2px; margin-left: 4px; }
.warn { flex: 0 0 auto; }
.tipchk { font-size: 11.5px; color: var(--ink2); margin: 1px 0 4px; }
.tip .warn { vertical-align: -2px; }

/* journal: a card per day; blood and urine in fixed slots, two columns */
.journal { max-width: 720px; }
.day h4 { display: flex; align-items: center; gap: 4px; margin: 14px 2px 6px; font-size: 12px; color: var(--ink2); font-weight: 600; }
.dcard { padding: 8px 8px 8px; gap: 0; }
.blk + .blk { border-top: 1px solid var(--rule); margin-top: 6px; padding-top: 6px; }
.bh { display: flex; align-items: center; gap: 5px; font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink2); font-weight: 650; margin: 0 6px 3px; }
.slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; }
.slot { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; min-width: 0; padding: 4px 6px; border: 0; border-radius: 7px; background: none; font: inherit; font-size: 13.5px; color: var(--ink); text-align: left; }
button.slot { cursor: pointer; }
button.slot:hover, button.obs:hover { background: var(--grid); }
.slot.high { background: color-mix(in srgb, var(--hi) 8%, transparent); }
.slot.low { background: color-mix(in srgb, var(--lo) 8%, transparent); }
.slot .nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink2); font-size: 12.5px; }
.slot .vl { display: flex; align-items: baseline; flex: 0 0 auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.slot .vl .wi { align-self: center; }
.slot.empty .vl { color: var(--ink3); }
.obs { display: flex; align-items: baseline; gap: 7px; width: 100%; padding: 4px 6px; border: 0; border-radius: 7px; background: none; font: inherit; font-size: 13.5px; color: var(--ink); text-align: left; cursor: pointer; }
.obs .dot { flex: 0 0 auto; align-self: center; }
.obs .cat { flex: 0 0 auto; font-size: 11px; color: var(--ink2); }
.obs .ot { flex: 1 1 auto; min-width: 0; }
@media (max-width: 480px) {
  /* phone: name above the value, so neither is cut off */
  .slot { flex-direction: column; align-items: stretch; gap: 0; padding: 4px 7px 5px; }
  .slot .nm { font-size: 11.5px; }
  .slot .vl { font-size: 14.5px; }
  header.top h1 .brand { display: none; }
}
@media (max-width: 380px) { .obs .cat { display: none; } }

/* please check: the bar, the grouped list, the panel in a dialog, hints in Add */
.chkbar, .chkp.open { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; background: color-mix(in srgb, var(--warn) 13%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 50%, var(--rule)); border-radius: 12px; padding: 8px 12px; font-size: 13px; }
.chkbar { margin: 2px 0 6px; }
.chkbar .hl { margin-left: -4px; }
.chkp { margin: 0 0 12px; font-size: 13px; }
.chkhead { display: flex; align-items: flex-start; gap: 8px; flex: 1 1 100%; }
.chkhead .warn { margin-top: 2px; }
.chkhead > span { flex: 1; }
.chkhead > button { flex: 0 0 auto; }
.chkgrp { margin: 10px 0; }
.chkgrp .chkhead { font-weight: 600; margin-bottom: 6px; }
.chkrow { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; padding: 8px 0; border-top: 1px solid var(--rule); font-size: 13.5px; }
.chkrow .row2 > * { flex: 0 0 auto; }
.chkrow .secondary, .chkall { padding: 5px 11px; font-size: 12.5px; }
.chkall { margin: 0 0 8px 23px; }
.vhint { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; color: var(--ink2); margin: -4px 0 8px; }
.vhint:empty { display: none; }
