/* Frostbite Chart Audit — entry helper. Clean clinical UI. */
:root{
  --bg:#eef2f7; --card:#ffffff; --ink:#1b2733; --muted:#5b6776; --line:#dde4ec; --line-strong:#767f8c;
  --primary:#1769aa; --primary-d:#115089; --primary-soft:#e7f0f8;
  --ok:#137a4d; --ok-bg:#e6f6ee; --warn:#b45309; --warn-bg:#fdf3e3;
  --focus:#2684ff; --danger:#c0392b;
  --radius:10px; --shadow:0 1px 3px rgba(16,40,70,.08),0 4px 16px rgba(16,40,70,.06);
  --maxw:900px; --appbar-h:56px;
}
*{box-sizing:border-box}
/* The [hidden] attribute must win over component display rules (e.g. .gate sets
   display:grid, which would otherwise keep the unlocked overlay visible). */
[hidden]{display:none !important}
html,body{margin:0;padding:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  color:var(--ink); background:var(--bg); line-height:1.45;
  -webkit-font-smoothing:antialiased; padding-bottom:84px;
}
strong{font-weight:600}

/* Buttons */
.btn{
  font:inherit; font-weight:600; cursor:pointer; border:1px solid var(--line);
  background:#fff; color:var(--ink); padding:.55rem .9rem; border-radius:8px;
  transition:background .12s,border-color .12s,box-shadow .12s; line-height:1;
}
.btn:hover{background:#f6f9fc; border-color:#c4d0dd}
.btn:focus-visible{outline:none; box-shadow:0 0 0 3px rgba(38,132,255,.4)}
.btn:disabled{opacity:.45; cursor:default}
.btn-primary{background:var(--primary); border-color:var(--primary); color:#fff}
.btn-primary:hover{background:var(--primary-d); border-color:var(--primary-d)}
.btn-ghost{background:transparent; border-color:transparent; color:var(--primary)}
.btn-ghost:hover{background:var(--primary-soft)}
.btn-sm{padding:.35rem .6rem; font-size:.85rem}
.btn-block{width:100%; padding:.7rem; margin-top:.4rem}

/* Gate */
.gate{position:fixed; inset:0; display:grid; place-items:center; padding:1.5rem;
  background:linear-gradient(160deg,#e7eef6,#dde7f1)}
.gate-card{background:var(--card); width:100%; max-width:380px; padding:2rem 1.8rem;
  border-radius:14px; box-shadow:var(--shadow); text-align:center}
.gate-logo{font-size:2.4rem; color:var(--primary)}
.gate-title{font-size:1.4rem; margin:.3rem 0 .2rem}
.gate-sub{color:var(--muted); margin:0 0 1.2rem; font-size:.92rem}
.gate-label{display:block; text-align:left; font-size:.82rem; font-weight:600; color:var(--muted); margin-bottom:.25rem}
.gate-input{width:100%; padding:.65rem .75rem; font:inherit; border:1px solid var(--line);
  border-radius:8px; background:#fbfdff}
.gate-input:focus{outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(38,132,255,.25)}
.gate-err{color:var(--danger); font-size:.85rem; margin:.6rem 0 0}
.gate-note{color:var(--muted); font-size:.76rem; margin:1.2rem 0 0; line-height:1.5}

/* App bar */
.appbar{position:sticky; top:0; z-index:30; background:#fff; border-bottom:1px solid var(--line);
  display:flex; align-items:center; gap:1rem; height:var(--appbar-h); padding:0 1.1rem; box-shadow:0 1px 2px rgba(16,40,70,.04)}
.appbar-title{font-size:1.05rem; font-weight:700}
.appbar-sub{font-size:.8rem; color:var(--muted)}
.appbar-status{margin-left:auto; font-size:.76rem; color:var(--muted); display:flex; align-items:center; gap:.4rem; white-space:nowrap}
.appbar-status .dot{width:8px; height:8px; border-radius:50%; background:var(--ok); box-shadow:0 0 0 3px var(--ok-bg)}

/* Tabs */
.tabs{position:sticky; top:var(--appbar-h); z-index:20; background:#fff; border-bottom:1px solid var(--line);
  display:flex; gap:.15rem; padding:0 .6rem; overflow-x:auto; scrollbar-width:thin}
.tab{border:none; background:none; font:inherit; cursor:pointer; padding:.7rem .8rem; color:var(--muted);
  border-bottom:2.5px solid transparent; white-space:nowrap; display:flex; align-items:center; gap:.4rem; font-weight:600}
.tab:hover{color:var(--ink)}
.tab.active{color:var(--primary); border-bottom-color:var(--primary)}
.tab-badge{min-width:18px; height:18px; padding:0 5px; border-radius:9px; font-size:.7rem; font-weight:700;
  display:inline-flex; align-items:center; justify-content:center; color:#fff; background:transparent}
.tab-badge.warn{background:var(--warn)}
.tab-badge.done{background:var(--ok)}

/* Progress */
.progress{max-width:var(--maxw); margin:1rem auto 0; padding:0 1.1rem}
.progress-meta{display:flex; align-items:center; gap:.6rem; font-size:.85rem; color:var(--muted); margin-bottom:.35rem}
.progress-meta .btn{margin-left:auto}
.progress-text strong{color:var(--ink)}
.progress-track{height:7px; background:#e2e8f0; border-radius:5px; overflow:hidden}
.progress-fill{height:100%; width:0; background:linear-gradient(90deg,var(--primary),#3a93d4); transition:width .3s}

/* Panels & sections */
.panels{max-width:var(--maxw); margin:0 auto; padding:1rem 1.1rem}
.panel[hidden]{display:none}
.section-group{background:var(--card); border:1px solid var(--line); border-radius:var(--radius);
  box-shadow:var(--shadow); padding:1.1rem 1.2rem; margin-bottom:1rem}
.section{font-size:.78rem; font-weight:700; letter-spacing:.04em; text-transform:uppercase;
  color:var(--primary); margin:.1rem 0 1rem; padding-bottom:.6rem; border-bottom:1px solid var(--line)}

/* Field */
.field{margin:0 0 1.15rem; padding:0; border:none}
.field:last-child{margin-bottom:.2rem}
.field[hidden]{display:none}
.field-label{display:block; font-weight:600; font-size:.92rem; margin-bottom:.4rem}
.field-label .req{color:var(--danger); margin-left:.2rem}
.input,textarea.input{width:100%; padding:.55rem .7rem; font:inherit; color:var(--ink);
  border:1px solid var(--line); border-radius:8px; background:#fbfdff}
.input:focus,textarea.input:focus{outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(38,132,255,.22)}
input[type=date].input,input[type=datetime-local].input,input[type=number].input{max-width:320px}
textarea.input{resize:vertical; min-height:2.4rem}
.hint{font-size:.76rem; color:var(--muted); margin-top:.3rem}
.field-warn{font-size:.78rem; color:var(--warn); margin-top:.3rem; font-weight:500}
.field-warn[hidden]{display:none}
.date-row{display:flex; gap:.5rem; align-items:center; flex-wrap:wrap}
.auto-btn{font:inherit; font-size:.82rem; font-weight:600; cursor:pointer; border:1px solid var(--line-strong);
  background:#fff; color:var(--primary-d); padding:.45rem .75rem; border-radius:8px; min-height:38px; white-space:nowrap}
.auto-btn:hover{background:var(--primary-soft); border-color:var(--primary)}
.auto-btn:focus-visible{outline:none; box-shadow:0 0 0 3px rgba(38,132,255,.4)}

/* Options (radio / checkbox / yesno) */
fieldset.options{border:none; margin:0; padding:0; min-width:0}
fieldset.options legend{padding:0; font-weight:600; font-size:.92rem; margin-bottom:.45rem}
fieldset.options legend .req{color:var(--danger); margin-left:.2rem}
.opts{display:flex; flex-wrap:wrap; gap:.45rem}
.opt{display:inline-flex; align-items:center; gap:.45rem; padding:.45rem .7rem; border:1px solid var(--line);
  border-radius:8px; cursor:pointer; background:#fbfdff; font-size:.9rem; transition:background .1s,border-color .1s}
.opt:hover{border-color:#bcccdd; background:#f4f8fc}
.opt input{accent-color:var(--primary); margin:0; width:16px; height:16px}
.opt:has(input:checked){border-color:var(--primary); background:var(--primary-soft); color:var(--primary-d); font-weight:600}
.opt:focus-within{box-shadow:0 0 0 3px rgba(38,132,255,.22)}
.clear{margin-top:.5rem; font-size:.78rem; color:var(--muted); background:none; border:none; cursor:pointer; padding:0; text-decoration:underline}
.clear:hover{color:var(--primary)}

/* Action bar */
.actionbar{position:fixed; bottom:0; left:0; right:0; z-index:25; background:#fff; border-top:1px solid var(--line);
  box-shadow:0 -2px 10px rgba(16,40,70,.06); display:flex; align-items:center; gap:.5rem; padding:.6rem 1.1rem}
.actionbar-spacer{flex:1}
.actionbar{flex-wrap:wrap}
.cb-review{display:flex; align-items:center; gap:.35rem; font-size:.82rem; color:var(--muted); white-space:nowrap; cursor:pointer}
.cb-review input{accent-color:var(--primary); width:16px; height:16px; margin:0}
.submit-status{font-size:.82rem; max-width:46ch}
.submit-status.busy{color:var(--muted)}
.submit-status.ok{color:var(--ok); font-weight:600}
.submit-status.err{color:var(--danger); font-weight:600}
@media (max-width:560px){
  .actionbar #btn-open{flex:1; text-align:center}
  .appbar-status{display:none}
}

/* Review drawer */
.review{position:fixed; right:1rem; bottom:74px; z-index:40; width:min(420px,calc(100vw - 2rem));
  max-height:60vh; overflow:auto; background:#fff; border:1px solid var(--line); border-radius:12px; box-shadow:var(--shadow)}
.review-head{display:flex; align-items:center; justify-content:space-between; padding:.8rem 1rem; border-bottom:1px solid var(--line);
  position:sticky; top:0; background:#fff}
.review-list{list-style:none; margin:0; padding:.4rem}
.review-item{margin:0}
.review-empty{padding:1rem; color:var(--ok); font-weight:600}
.review-link{width:100%; text-align:left; border:none; background:none; font:inherit; cursor:pointer;
  padding:.55rem .6rem; border-radius:8px; display:flex; flex-direction:column; gap:.15rem}
.review-link:hover{background:var(--primary-soft)}
.review-tab{font-size:.72rem; text-transform:uppercase; letter-spacing:.03em; color:var(--muted); font-weight:700}
.review-q{font-size:.9rem}

/* Flash highlight when jumping to a field */
.flash{animation:flash 2s ease-out}
@keyframes flash{0%{box-shadow:0 0 0 3px rgba(38,132,255,.5)}100%{box-shadow:0 0 0 3px rgba(38,132,255,0)}}
.field.flash{border-radius:8px}

/* ---- accessibility & polish (from audit) ---- */
.sr-only{position:absolute!important; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden;
  clip:rect(0,0,0,0); white-space:nowrap; border:0}

/* Accessible tablist: visible keyboard focus + adequate target size */
.tab{min-height:44px}
.tab:focus-visible{outline:none; box-shadow:inset 0 0 0 2px var(--focus)}

/* Stronger non-text contrast on control boundaries (>=3:1) */
.input,textarea.input,.gate-input{border-color:var(--line-strong)}
.opt{border-color:var(--line-strong); min-height:44px}

/* Comfortable touch targets */
.btn{min-height:38px}
.btn-sm{min-height:32px}
.clear{padding:.45rem .2rem; min-height:32px}

/* Long option labels read better as full-width rows than as chips */
.opts-vertical{flex-direction:column; align-items:stretch}
.opts-vertical .opt{width:100%}

/* Matrix rows grouped into one tidy block (shared option set) */
.matrix-block{border:1px solid var(--line); border-radius:9px; background:#fcfdfe; margin:.2rem 0 1rem; overflow:hidden}
.matrix-block .field.is-matrix{margin:0; padding:.6rem .85rem; border-top:1px solid var(--line)}
.matrix-block .field.is-matrix:first-child{border-top:none}
.field.is-matrix legend{font-size:.88rem}
.field.is-matrix .opts{margin-top:.35rem}

/* Matrix chips: lighter & denser (the same option set repeats on each row) */
.field.is-matrix .opt{min-height:36px; padding:.32rem .55rem; font-size:.85rem; background:#fff}
.field.is-matrix .opts{gap:.35rem}

/* Long vertical option lists: cap width and separate rows for readability */
.opts-vertical{max-width:640px}
.opts-vertical .opt{min-height:40px; border-color:var(--line)}
.opts-vertical .opt + .opt{margin-top:-1px}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{animation-duration:.001ms!important; animation-iteration-count:1!important;
    transition-duration:.001ms!important; scroll-behavior:auto!important}
}

/* ===== Top-level form switcher (Frostbite | Hennepin calculator) ===== */
.formswitch{background:#0e2336; display:flex; gap:.3rem; padding:.45rem .6rem; overflow-x:auto; scrollbar-width:thin}
.formswitch .sw{border:none; background:transparent; color:#c4d2e0; font:inherit; font-weight:600; font-size:.9rem;
  cursor:pointer; padding:.5rem 1rem; border-radius:8px; white-space:nowrap; min-height:40px; transition:background .12s,color .12s}
.formswitch .sw:hover{background:rgba(255,255,255,.10); color:#fff}
.formswitch .sw.active{background:#fff; color:var(--primary-d)}
.formswitch .sw:focus-visible{outline:none; box-shadow:0 0 0 3px rgba(38,132,255,.55)}

/* ===== Hennepin Frostbite Score calculator ===== */
.hhr-livetotal{margin-left:auto; display:flex; align-items:center; gap:.5rem; background:var(--primary-soft);
  border:1px solid var(--primary); color:var(--primary-d); padding:.28rem .75rem; border-radius:999px; white-space:nowrap}
.hhr-livetotal-label{font-size:.7rem; text-transform:uppercase; letter-spacing:.04em; font-weight:700; opacity:.85}
.hhr-livetotal-val{font-size:1.2rem; font-weight:800; font-variant-numeric:tabular-nums}
.hhr-intro{font-size:.85rem; color:var(--muted); line-height:1.55; margin:.1rem 0 0}
.hhr-figure{margin:1rem 0 0}
.hhr-diagram{display:block; width:100%; max-width:560px; height:auto; border:1px solid var(--line-strong); border-radius:8px; background:#fff}
.hhr-figure figcaption{margin-top:.45rem}

.hhr-scorebox{background:linear-gradient(160deg,#eef6ff,#e3eefa); border-color:var(--primary)}
.hhr-total{display:flex; align-items:baseline; justify-content:space-between; gap:1rem; padding-bottom:.7rem; border-bottom:1px solid var(--line)}
.hhr-total-label{font-weight:700; font-size:1rem}
.hhr-total-val{font-size:2.4rem; font-weight:800; color:var(--primary-d); line-height:1; font-variant-numeric:tabular-nums}
.hhr-score-grid{display:grid; grid-template-columns:1fr auto; gap:.05rem 1rem; margin-top:.7rem; font-size:.88rem}
.hhr-score-row{display:contents}
.hhr-score-name{color:var(--muted); padding:.18rem 0}
.hhr-score-num{font-weight:700; text-align:right; font-variant-numeric:tabular-nums; padding:.18rem 0; color:var(--ink)}
.hhr-score-row.major .hhr-score-name{color:var(--ink); font-weight:700; margin-top:.45rem}
.hhr-score-row.major .hhr-score-num{color:var(--primary-d); margin-top:.45rem}

/* Vertical bullet-point option lists (Hennepin calculator only; the checkbox is the bullet).
   Scoped to #app-hhr so the frostbite form's chip-style options are untouched. */
#app-hhr .opts-bullets{display:flex; flex-direction:column; gap:.05rem; max-width:680px}
#app-hhr .opts-bullets .opt{border:none; background:none; border-radius:6px; width:100%; min-height:36px;
  margin:0; padding:.35rem .5rem; justify-content:flex-start; text-align:left; gap:.6rem; font-size:.88rem}
#app-hhr .opts-bullets .opt .opt-text{flex:1}
#app-hhr .opts-bullets .opt:hover{background:#f1f6fb}
#app-hhr .opts-bullets .opt:has(input:checked){background:var(--primary-soft); color:var(--primary-d); font-weight:600}
/* Long section-code lists (16+) wrap into columns of bullets instead of one tall wall */
#app-hhr .opts-bullets.opts-bullets-multi{display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr));
  gap:.05rem 1.25rem; max-width:none}

@media (max-width:560px){
  .hhr-livetotal{padding:.2rem .55rem}
  .hhr-total-val{font-size:2rem}
  #app-hhr .opts-bullets.opts-bullets-multi{grid-template-columns:repeat(auto-fill,minmax(116px,1fr)); gap:0 .8rem}
}
