/* Palette: Alabaster Grey #E0E0E2, Pearl Aqua #81D2C7, Pale Slate #B5BAD0, Glaucous #7389AE, Baltic Blue #416788,
   plus one red (not in the palette, owner asked for it) for denied / disabled / destructive things.
   Minimal and modern, sharp corners, but with clear contrast: Alabaster page, white cards, solid badges.
   Contrast (computed): text on page 13.1; muted on page 7.0, on white 9.2; white on Baltic 6.0;
   white on red 6.6; dark teal on Aqua 6.9; dark red on red tint 7.8; red on denied row 5.3.
   Phone layout first; wider screens in the media query at the bottom. */
:root {
  --alabaster: #E0E0E2; --aqua: #81D2C7; --slate: #B5BAD0; --glaucous: #7389AE; --baltic: #416788;
  --baltic-dark: #2F4D66;
  --red: #B42318; --red-dark: #912018; --red-tint: #FDECEA; --red-text: #8F1D15; --red-row: #F6E3E1;
  --text: #141B26; --muted: #3F4859; --page: #EEEEF0;   /* lighter Alabaster: the full #E0E0E2 felt too dark */ --surface: #FFFFFF;
  --border: #C3C7D3; --rule: #DADDE5; --head-bg: #DDE0EA;
  --teal-text: #0F3D37;
  --pad: 1rem;
}
* { box-sizing: border-box; border-radius: 0; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--text); min-height: 100vh; display: flex; flex-direction: column;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased; }
a { color: var(--baltic); text-underline-offset: 2px; font-weight: 500; }
a:hover { color: var(--baltic-dark); }
h1 { font-size: 1.45rem; font-weight: 700; line-height: 1.25; margin: 0; letter-spacing: -.015em; }
h2 { font-size: 1rem; font-weight: 650; margin: 0 0 .9rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); font-weight: 400; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .84rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* --- header + tabs --- */
.bar { background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 1px 3px rgba(20, 27, 38, .06); }
.bar-top, .tabs { max-width: 1040px; margin: 0 auto; padding: 0 var(--pad); }
.bar-top { display: flex; align-items: center; gap: .6rem; min-height: 3.5rem; }
.brand { color: var(--text); text-decoration: none; font-weight: 750; font-size: 1.02rem; letter-spacing: -.01em;
  white-space: nowrap; display: inline-flex; align-items: center; gap: .55rem; }
.brand:hover { color: var(--text); }
.brand::before { content: ""; width: .8rem; height: .8rem; background: var(--baltic); box-shadow: .25rem .25rem 0 var(--aqua); flex: none; }
.who { margin-left: auto; display: flex; align-items: center; gap: .6rem; min-width: 0; font-size: .9rem; }
.who .name { display: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.who .role { white-space: nowrap; color: var(--text); background: var(--slate); font-size: .72rem; font-weight: 700;
  padding: .12rem .5rem; text-transform: uppercase; letter-spacing: .04em; }
.who form { margin: 0; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; padding-bottom: .6rem; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: 1 0 auto; text-align: center; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9rem;
  white-space: nowrap; padding: .45rem .7rem; transition: background .12s, color .12s; }
.tabs a:hover { background: var(--head-bg); color: var(--text); }
.tabs a.on { background: var(--baltic); color: #fff; }
.tabs a:only-child { flex: 0 0 auto; }

/* --- page --- */
main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 1.5rem var(--pad) 3rem; }
footer { font-size: .78rem; color: var(--muted); padding: 1rem var(--pad); border-top: 1px solid var(--border);
  background: var(--surface); text-align: center; }
.head { margin-bottom: 1.25rem; }
.head p { margin: .35rem 0 0; }
.login h1 + p { margin: .35rem 0 1.25rem; }
.back { margin-bottom: .75rem; font-size: .9rem; }
.back a { text-decoration: none; }
.back a:hover { text-decoration: underline; }

.panel { background: var(--surface); border: 1px solid var(--border); padding: var(--pad); margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(20, 27, 38, .06), 0 4px 12px rgba(20, 27, 38, .05); }
.panel.flush { padding: 0; }
.panel.denied { border-top: 4px solid var(--red); }
.panel.denied h1 { font-size: 2.5rem; font-weight: 800; color: var(--red); }
.panel.denied p { color: var(--muted); }
.panel dl:last-child { margin-bottom: 0; }
.login { margin: 1rem auto 0; border-top: 4px solid var(--baltic); }

/* --- forms + buttons --- */
label { display: grid; gap: .35rem; font-weight: 600; font-size: .88rem; }
input { font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  min-height: 44px; padding: .5rem .75rem; border: 1px solid #9DA3B8; background: var(--surface); color: var(--text);
  width: 100%; transition: border-color .15s, box-shadow .15s; }
input:hover { border-color: var(--glaucous); }
input:focus { outline: none; border-color: var(--baltic); box-shadow: 0 0 0 3px rgba(65, 103, 136, .25); }
input::placeholder { color: #6E7689; }
.stack-form { display: grid; gap: 1rem; }
.inline-form { display: flex; flex-direction: column; gap: .6rem; }
.inline-form input { flex: 1; min-width: 0; }

.btn { font: inherit; font-weight: 650; font-size: .92rem; cursor: pointer; min-height: 44px; padding: .5rem 1.15rem;
  border: 1px solid var(--baltic); background: var(--baltic); color: #fff; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; white-space: nowrap; transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--baltic-dark); border-color: var(--baltic-dark); color: #fff; }
.btn:focus-visible { outline: 2px solid var(--baltic); outline-offset: 2px; }
.btn.wide { width: 100%; }
.btn.small { min-height: 34px; padding: .25rem .85rem; font-size: .85rem; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--head-bg); color: var(--text); border-color: var(--glaucous); }
.btn.danger { background: var(--surface); color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn.danger:focus-visible { outline-color: var(--red); }

/* --- messages + badges --- */
.alert, .ok { padding: .65rem .9rem; font-size: .9rem; font-weight: 600; border-left: 4px solid; }
.alert { background: var(--red-tint); color: var(--red-text); border-color: var(--red); }
.ok { background: #E3F5F2; color: var(--teal-text); border-color: #3FA796; }
.badge { display: inline-flex; align-items: center; gap: .4rem; font-size: .72rem; font-weight: 700; padding: .15rem .55rem;
  white-space: nowrap; letter-spacing: .03em; }
.badge::before { content: ""; width: .45rem; height: .45rem; flex: none; }
.badge.on { background: var(--aqua); color: var(--teal-text); }
.badge.on::before { background: var(--teal-text); }
.badge.off { background: var(--red); color: #fff; }
.badge.off::before { border: 1.5px solid #fff; }
.you { font-size: .68rem; font-weight: 700; color: #fff; background: var(--baltic); padding: .05rem .35rem;
  margin-left: .3rem; vertical-align: middle; }

/* --- tables. On phones, .stack tables turn into one card per row with labels. --- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--text); background: var(--head-bg); font-weight: 650; font-size: .78rem; padding: .55rem .65rem;
  border-bottom: 1px solid var(--border); white-space: nowrap; }
td { border-bottom: 1px solid var(--rule); padding: .6rem .65rem; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.is-off td, tr.denied td { background: var(--red-row); }
tr.is-off .uname { color: var(--red-text); text-decoration: line-through; }
tr.empty td { color: var(--muted); }

table.stack thead { display: none; }
table.stack tr { display: block; padding: .75rem 0; border-bottom: 1px solid var(--rule); }
table.stack tr:first-child { padding-top: 0; }
table.stack tr:last-child { border-bottom: 0; padding-bottom: 0; }
table.stack tr.is-off, table.stack tr.denied { background: var(--red-row); box-shadow: inset 4px 0 0 var(--red);
  margin: 0 calc(-1 * var(--pad)); padding: .75rem var(--pad) .75rem calc(var(--pad) + 4px); }
table.stack td { display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .5rem; border: 0;
  padding: .12rem 0 .12rem 6.25rem; position: relative; background: none; }
table.stack td::before { content: attr(data-label); position: absolute; left: 0; top: .2rem; width: 6rem;
  font: 600 .74rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--muted); }
table.stack td.actions, table.stack tr.empty td { display: block; padding: .5rem 0 0; }
table.stack td.actions::before, table.stack tr.empty td::before { content: none; }

table.kv { margin-bottom: 1.25rem; }
table.kv td { padding: .6rem 0; }
table.kv .num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --- patient list + chart --- */
.plist { list-style: none; margin: 0; padding: 0; }
.plist li + li { border-top: 1px solid var(--rule); }
.plist a { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name chev" "meta chev";
  align-items: center; column-gap: 1rem; padding: .8rem var(--pad); text-decoration: none; color: var(--text);
  min-height: 58px; transition: background .12s, box-shadow .12s; }
.plist a:hover, .plist a:focus-visible { background: #F1F3F8; box-shadow: inset 4px 0 0 var(--baltic); outline: none; }
.pname { grid-area: name; font-weight: 600; }
.pmeta { grid-area: meta; font-size: .84rem; color: var(--muted); font-weight: 400; }
.chev { grid-area: chev; font-size: 1.35rem; line-height: 1; color: var(--glaucous); }
.plist a:hover .chev { color: var(--baltic); }

dl { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.5rem; margin: 0 0 1.25rem; font-size: .92rem; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 600; }
.audit .sub { display: block; font-size: .78rem; color: var(--muted); }

/* mid-size phones have room for the username too */
@media (min-width: 420px) and (max-width: 699px) { .who .name { display: inline; max-width: 8rem; } }
@media (max-width: 359px) { .tabs a { font-size: .82rem; padding: .4rem .45rem; } }
@media (max-width: 379px) { .who .role { display: none; } }

/* --- tablets and up --- */
@media (min-width: 700px) {
  :root { --pad: 1.5rem; }
  h1 { font-size: 1.65rem; }
  main { padding-top: 2rem; }
  .who .name { display: inline; }
  .tabs a { flex: 0 0 auto; padding: .45rem 1rem; }
  .panel.narrow { max-width: 520px; }
  .panel.login { margin-top: 3rem; max-width: 420px; }
  .inline-form { flex-direction: row; }
  .plist a { grid-template-columns: 1fr auto auto; grid-template-areas: "name meta chev"; }

  table.stack thead { display: table-header-group; }
  table.stack tr, table.stack tr:first-child, table.stack tr:last-child { display: table-row; padding: 0; border-bottom: 0; }
  table.stack tr.is-off, table.stack tr.denied { margin: 0; padding: 0; background: none; box-shadow: none; }
  table.stack td { display: table-cell; position: static; vertical-align: middle;
    border-bottom: 1px solid var(--rule); padding: .6rem .65rem; }
  table.stack tr:last-child td { border-bottom: 0; }
  table.stack tr.is-off td, table.stack tr.denied td { background: var(--red-row); }
  table.stack tr.is-off td:first-child, table.stack tr.denied td:first-child { box-shadow: inset 4px 0 0 var(--red); }
  table.stack td::before { content: none; }
  table.stack td.actions, table.stack tr.empty td { display: table-cell; padding: .6rem .65rem; }
  table.audit { font-size: .85rem; }
}

/* phones: slightly smaller header so it doesn't feel crowded */
@media (max-width: 699px) {
  .bar-top { min-height: 3.1rem; gap: .5rem; }
  .brand { font-size: .9rem; gap: .45rem; }
  .brand::before { width: .65rem; height: .65rem; box-shadow: .2rem .2rem 0 var(--aqua); }
  .who { gap: .45rem; }
  .who .role { font-size: .64rem; padding: .08rem .4rem; }
  .who .btn.small { min-height: 32px; padding: .2rem .65rem; font-size: .8rem; }
  .tabs { padding-bottom: .5rem; }
  .tabs { gap: .1rem; }
  .tabs a { font-size: .82rem; padding: .38rem .5rem; }
}

/* Tests tab */
.badge.na { background: var(--head-bg); color: var(--muted); }
.badge.na::before { border: 1.5px solid var(--muted); }
.score { font-size: 1.6rem; margin-bottom: .5rem; }
.note { font-size: .84rem; margin: .9rem 0 0; }
.small { font-size: .84rem; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85em; background: var(--head-bg); padding: 0 .3rem; }
.progress { height: 8px; background: var(--head-bg); margin: 0 0 1rem; }
.progress > div { height: 100%; background: var(--baltic); transition: width .4s; }

/* Tests tab: spinner while running, green/red strip when done */
.running-title { display: flex; align-items: center; gap: .7rem; }
.spinner { width: 1.1rem; height: 1.1rem; flex: none; border: 3px solid var(--head-bg); border-top-color: var(--baltic);
  border-right-color: var(--baltic); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress.running > div { background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.25) 0 8px, transparent 8px 16px);
  background-size: 22.6px 22.6px; animation: stripes .8s linear infinite; }
@keyframes stripes { to { background-position: 22.6px 0; } }
.strip { display: flex; align-items: center; gap: .6rem; padding: .85rem 1.1rem; margin-bottom: 1.25rem;
  font-weight: 700; font-size: 1.05rem; color: #fff; }
.strip span { font-size: 1.2rem; line-height: 1; }
.strip.pass { background: #17734A; }   /* white on it: 5.9 */
.strip.fail { background: var(--red); } /* white on it: 6.6 */
@media (prefers-reduced-motion: reduce) { .spinner, .progress.running > div { animation: none; } }

/* Tests tab: plain-language audit check */
.explain { color: var(--muted); max-width: 72ch; }
.score-small { font-size: 1.05rem; margin: .5rem 0 1rem; }
.agroups details { border-top: 1px solid var(--rule); }
.agroups details:last-child { border-bottom: 1px solid var(--rule); }
.agroups summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 1fr auto; gap: .15rem 1rem;
  padding: .7rem .4rem; align-items: center; }
.agroups summary::-webkit-details-marker { display: none; }
.agroups summary:hover { background: #F1F3F8; }
.agroups summary .gtitle::before { content: "\25B8"; display: inline-block; width: 1rem; color: var(--glaucous); }
.agroups details[open] summary .gtitle::before { content: "\25BE"; }
.gtitle { grid-column: 1; }
.gabout { grid-column: 1; font-size: .85rem; color: var(--muted); padding-left: 1rem; }
.gcount { grid-column: 2; grid-row: 1; font-size: .8rem; color: var(--muted); text-align: right; }
.agroups summary .badge { grid-column: 2; grid-row: 2; justify-self: end; }
.alines { list-style: none; margin: 0 0 .6rem; padding: 0 .4rem 0 1.4rem; }
.alines li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .2rem 1rem; padding: .4rem 0;
  border-top: 1px dashed var(--rule); font-size: .9rem; }
.v-ok { color: var(--teal-text); }
.v-no { color: var(--red-text); }
