:root {
  --bg: #f4f7f6; --surface: #fff; --fg: #13262b; --muted: #4b6066; --line: #cfdbd9; --accent: #0e6b68;
  --critical: #a4161a; --high: #b85c00; --medium: #7a6200; --low: #1d6f42; --info: #1d5f8f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; line-height: 1.5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.top { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
       padding: 10px 16px; background: var(--accent); color: #fff; position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 1.15rem; margin: 0; }
.top-controls { display: flex; gap: 8px; align-items: center; }
main, .panel, .banner, .foot { max-width: 860px; margin-inline: auto; }
main { padding: 12px 16px 32px; display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-top: 12px; }
#key-panel { margin-inline: 16px; }
@media (min-width: 892px) { #key-panel { margin-inline: auto; } }
.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: 8px; border: 2px solid; font-weight: 600; }
@media (min-width: 892px) { .banner { margin-inline: auto; } }
.banner.warn { border-color: var(--high); color: var(--high); background: #fff6ea; }
.banner.error { border-color: var(--critical); color: var(--critical); background: #fdeeee; }
.banner.ok { border-color: var(--low); color: var(--low); background: #eef8f1; }

fieldset, details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 0; min-width: 0; }
legend, summary { font-weight: 700; padding: 0 6px; }
summary { cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: .92rem; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 1rem; }
label > span { color: var(--muted); }
fieldset > label, details > label { margin-top: 10px; }
input, select, textarea, button { font: inherit; }
input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--fg); min-height: 42px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; }
input[aria-invalid="true"] { border: 2px solid var(--critical); background: #fdeeee; }
input[type="file"] { padding: 6px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid var(--info); outline-offset: 1px; }
.hint { color: var(--muted); font-size: .88rem; margin: 4px 0 8px; }
.row { display: flex; gap: 8px; }
.row > input { flex: 1; }
.item-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); align-items: end; }
.item-row:first-child { border-top: 0; }

button { padding: 10px 16px; border-radius: 6px; border: 1px solid var(--accent); background: #fff; color: var(--accent); font-weight: 600; cursor: pointer; min-height: 44px; }
button.primary { background: var(--accent); color: #fff; }
button.ghost { border-color: var(--line); color: var(--fg); font-weight: 500; }
.top button.ghost, .top select { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); width: auto; min-height: 38px; }
.top select option { color: var(--fg); }
button:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.actions button { flex: 1 1 200px; }

h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 14px 0 6px; }
ul { margin: 0; padding-left: 20px; }
li { margin: 3px 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > .banner { margin: 0; max-width: none; }

.urgency { padding: 14px 16px; border-radius: 8px; color: #fff; font-size: 1.25rem; font-weight: 800; }
.urgency small { display: block; font-size: .9rem; font-weight: 500; margin-top: 4px; }
.u-Critical { background: var(--critical); } .u-High { background: var(--high); }
.u-Medium { background: var(--medium); } .u-Low { background: var(--low); } .u-none { background: var(--muted); }
.escalate { border: 3px solid var(--critical); color: var(--critical); background: #fdeeee; padding: 12px 14px; border-radius: 8px; font-weight: 800; font-size: 1.1rem; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; border: 1.5px solid currentColor; font-size: .78rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
.b-ok { color: var(--low); } .b-caution { color: var(--medium); } .b-warning { color: var(--high); }
.b-blocked, .b-critical, .b-red, .b-contraindicated { color: var(--critical); }
.b-unchecked, .b-none { color: var(--muted); } .b-severe, .b-amber, .b-avoid { color: var(--high); }
.b-Access { color: var(--low); } .b-Watch { color: var(--high); } .b-Reserve { color: var(--critical); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.muted { color: var(--muted); font-size: .9rem; }
.regimen-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; justify-content: space-between; font-weight: 700; }
.blocked-card { border: 2px solid var(--critical); }
.decide { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.prov { color: var(--muted); font-size: .82rem; word-break: break-word; }
.foot { padding: 12px 16px 24px; color: var(--muted); font-size: .85rem; }

@media print {
  .top, #case-form, #progress, .actions, .no-print, #key-panel { display: none !important; }
  body { background: #fff; } .card, fieldset { break-inside: avoid; }
}
@media (prefers-reduced-motion: no-preference) { button { transition: background-color .15s; } }

/* Personal sign-in */
.auth { max-width: 860px; margin: 0 auto; padding: 0 16px 32px; }
.auth > .banner { margin: 12px 0 0; }
.auth-card { max-width: 440px; margin: 16px auto 0; display: flex; flex-direction: column; gap: 12px; }
.auth-card h2 { margin: 0; font-size: 1.4rem; }
.auth-card p { margin: 0; }
.auth-card .strong { font-weight: 700; overflow-wrap: anywhere; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
button.link { border: 0; background: none; color: var(--accent); padding: 6px 0; text-decoration: underline; font-weight: 600; }
.oauth { display: flex; flex-direction: column; gap: 10px; }
.oauth:empty { display: none; }
.oauth-btn { border-color: var(--line); color: var(--fg); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .88rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.code-input { font-size: 1.15rem; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.steps { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.qr { display: block; width: 200px; height: 200px; margin: 8px 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.secret { display: inline-block; font-size: .95rem; overflow-wrap: anywhere; background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.top-controls { min-width: 0; flex: 1 1 auto; justify-content: flex-end; }
.user-box { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 auto; }
#user-label { font-size: .88rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .user-box button.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); min-height: 38px;
  white-space: nowrap; padding-inline: 12px; }
@media (max-width: 520px) {
  .top-controls { flex-wrap: wrap; }
  .user-box { flex: 1 1 100%; justify-content: space-between; }
}
@media print { #auth, .user-box { display: none !important; } }
