/* ==========================================================================
   Sonus — design system (Spec/design/UI-LANGUAGE.md)
   Jane-inspired: calm white cards on a grey canvas, hairline borders,
   thin grey page titles, one blue accent, small airy controls, dark mode.
   Self-contained: no external fonts, no CDNs.
   ========================================================================== */

/* --- 1. Tokens (light) ---------------------------------------------------- */
:root {
  /* Surfaces */
  --bg:        #F7F7F7;   /* sidebar / near-white chrome background */
  --canvas:    #EFEFEF;   /* content canvas — a hair darker so cards float */
  --surface:   #FFFFFF;   /* cards, panels, topbar */
  --surface-2: #F3F4F6;   /* read-only inputs, table headers */
  --border:    #E0E0E0;   /* hairline */
  --shadow:    0 1px 2px rgba(16, 24, 40, .04);
  --shadow-pop:0 6px 24px rgba(16, 24, 40, .12);

  /* Accent — Sonus blue (single swappable token) */
  --accent:       #2563eb;
  --accent-hover: #3b82f6;
  --accent-press: #1d4ed8;
  --accent-tint:        rgba(37, 99, 235, .08);
  --accent-tint-strong: rgba(37, 99, 235, .14);
  --row-select:  #E7EFFD;
  --on-accent:   #ffffff;

  /* Text */
  --text:  #2C2C2C;
  --muted: #6B6B6B;
  --title: #4A4A4A;       /* Jane's big light-grey page titles */

  /* Status (never the accent — §4c) */
  --error:        #E53935;
  --error-tint:   rgba(229, 57, 53, .10);
  --success:      #43A047;
  --success-tint: rgba(76, 175, 80, .12);
  --warning:      #EF9A1D;
  --warning-tint: rgba(255, 167, 38, .14);
  --neutral-pill: #757575;

  /* Charts (fixed clinical convention: Pre = red, Post = blue) */
  --chart-pre:  #e34948;
  --chart-post: #2a78d6;
  --chart-cs:   #008300;
  --chart-ahry: #eda100;

  /* Shape & type */
  --radius:      4px;
  --radius-pill: 6px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --fs-base: 14px;
  --fs-small: 12px;
  --fs-caption: 11px;
  --fs-title: 28px;
  --fw-title: 300;

  /* Shell metrics */
  --topbar-h: 52px;
  --subnav-w: 220px;

  color-scheme: light;
}

/* --- 1b. Tokens (dark) — derived, soft charcoal, not pure black ----------- */
:root[data-theme="dark"] {
  --bg:        #16181D;
  --canvas:    #101216;
  --surface:   #1B1E23;
  --surface-2: #22262D;
  --border:    #2C3038;
  --shadow:    0 1px 2px rgba(0, 0, 0, .25);
  --shadow-pop:0 6px 24px rgba(0, 0, 0, .5);

  --accent:       #3b82f6;
  --accent-hover: #60a5fa;
  --accent-press: #2563eb;
  --accent-tint:        rgba(59, 130, 246, .14);
  --accent-tint-strong: rgba(59, 130, 246, .24);
  --row-select:  rgba(59, 130, 246, .16);

  --text:  #E6E8EB;
  --muted: #9BA1AA;
  --title: #B8BEC6;

  --error:        #EF5350;
  --error-tint:   rgba(239, 83, 80, .16);
  --success:      #66BB6A;
  --success-tint: rgba(102, 187, 106, .16);
  --warning:      #FFB74D;
  --warning-tint: rgba(255, 183, 77, .16);
  --neutral-pill: #8A9099;

  --chart-pre:  #ef6b6a;
  --chart-post: #5b9be0;
  --chart-cs:   #3fbf3f;
  --chart-ahry: #ffb84d;

  color-scheme: dark;
}

/* --- 2. Base -------------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--canvas);
  font: var(--fs-base)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; }
::placeholder { color: var(--muted); opacity: .8; }

/* Thin accent scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(37, 99, 235, .35) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(37, 99, 235, .3); border-radius: 4px; min-height: 20px; }

/* --- 3. App shell ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: stretch; gap: .25rem;
  height: var(--topbar-h);
  padding: 0 1rem 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  align-self: center;
  color: var(--accent); font-weight: 700; font-size: 1.05rem;
  letter-spacing: 1px; text-decoration: none; margin-right: 1.25rem;
}
.top-tabs { display: flex; align-items: stretch; }
.top-tabs a {
  display: flex; align-items: center; padding: 0 .9rem;
  color: var(--muted); text-decoration: none; font-size: .95rem;
  border-bottom: 3px solid transparent; border-top: 3px solid transparent;
}
.top-tabs a:hover { background: var(--accent-tint); color: var(--text); text-decoration: none; }
.top-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.topbar-right .who { color: var(--muted); font-size: var(--fs-small); white-space: nowrap; }
.topbar-right .who strong { color: var(--text); font-weight: 600; }

.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); align-items: stretch; }
.subnav {
  flex: 0 0 var(--subnav-w); width: var(--subnav-w);
  background: var(--bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.canvas { flex: 1 1 auto; min-width: 0; padding: 0 1.5rem 3rem; }

/* Grouped link-list left panel (Reports / Settings) */
.subnav-group { padding: .9rem .6rem .25rem; }
.subnav-group h3 {
  margin: 0 0 .3rem .5rem; font-size: var(--fs-caption); font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
.subnav-link {
  display: block; padding: .42rem .7rem; margin: 1px 0;
  border-radius: var(--radius-pill);
  color: var(--muted); text-decoration: none; font-size: .95rem;
}
.subnav-link:hover { background: var(--accent-tint); color: var(--text); text-decoration: none; }
.subnav-link.active { background: var(--accent-tint-strong); color: var(--accent); font-weight: 600; }

/* Patient-list left panel */
.subnav-search { padding: .75rem .6rem .4rem; }
.subnav-search input {
  width: 100%; padding: .45rem .6rem; font: inherit; font-size: .9rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.subnav-search input:focus { outline: none; border-color: var(--accent); }
.subnav-list { flex: 1 1 auto; overflow-y: auto; padding: 0 .4rem .5rem; }
.subnav-patient {
  display: block; padding: .42rem .7rem; margin: 1px 0;
  border-radius: var(--radius-pill); color: var(--text);
  text-decoration: none; font-size: .95rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subnav-patient strong { font-weight: 600; }   /* last name bold — Jane */
.subnav-patient:hover { background: var(--accent-tint); text-decoration: none; }
.subnav-patient.active { background: var(--accent-tint-strong); color: var(--accent); }
.subnav-footer {
  padding: .6rem; border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--bg);
}
.subnav-empty { padding: .6rem .9rem; color: var(--muted); font-size: var(--fs-small); }

/* --- 4. Page head — big light grey title strip (the Jane tell) ------------- */
.page-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem;
  padding: 1.1rem 0 .8rem; margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.page-head h1 {
  margin: 0; font-size: var(--fs-title); font-weight: var(--fw-title);
  color: var(--title); letter-spacing: -.01em; line-height: 1.2;
}
.page-head .head-meta { color: var(--muted); font-size: var(--fs-small); }
.page-head .head-actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* Patient sub-tabs, under the title strip */
.sub-tabs { display: flex; gap: .35rem; flex-wrap: nowrap; overflow-x: auto; margin: -0.35rem 0 1.1rem; padding-bottom: 2px; }
.sub-tabs a {
  padding: .32rem .85rem; border-radius: 999px; white-space: nowrap;
  color: var(--accent); text-decoration: none; font-size: .92rem;
}
.sub-tabs a:hover { background: var(--accent-tint); text-decoration: none; }
.sub-tabs a.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* --- 5. Cards & dense responsive grid -------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .9rem 1.1rem; margin-bottom: 1rem;
}
.card > h2, .card > h3 {
  margin: 0 0 .6rem; font-size: .82rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.card .meta { margin-bottom: 0; }

.dash-grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
}
.dash-grid .card { margin-bottom: 0; min-width: 0; }
.w-3 { grid-column: span 3; }
.w-4 { grid-column: span 4; }
.w-6 { grid-column: span 6; }
.w-8 { grid-column: span 8; }
.w-12 { grid-column: span 12; }
@media (max-width: 1400px) {
  .w-3 { grid-column: span 4; }
}
@media (max-width: 1100px) {
  .w-3, .w-4 { grid-column: span 6; }
  .w-6, .w-8 { grid-column: span 12; }
}
@media (max-width: 700px) {
  .w-3, .w-4, .w-6, .w-8, .w-12 { grid-column: span 12; }
}

.scroll-x { overflow-x: auto; }
.scroll-y { max-height: 20rem; overflow-y: auto; }

/* --- 6. Tables — airy hairline rows, no zebra ------------------------------ */
table.listing { width: 100%; border-collapse: collapse; background: transparent; }
table.listing th, table.listing td {
  text-align: left; padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
}
table.listing thead th {
  color: var(--muted); font-weight: 600; font-size: var(--fs-small);
  text-transform: uppercase; letter-spacing: .04em;
  background: transparent; border-bottom: 1px solid var(--border);
}
table.listing tbody tr:last-child td { border-bottom: none; }
table.listing tbody tr:hover td { background: var(--accent-tint); }
table.listing tbody tr.selected td { background: var(--row-select); }
table.compact th, table.compact td { padding: .3rem .6rem; font-size: .9rem; }
table.factors td, table.factors th[scope="row"] { white-space: nowrap; }
table.vectors td { font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Full-bleed list card: table touches the card edges; a too-wide table
   scrolls inside the card, never widens the page. */
.card.card-table { padding: 0; overflow-x: auto; }
.card.card-table > h2 { padding: .8rem 1.1rem 0; }
.card.card-table table.listing th:first-child,
.card.card-table table.listing td:first-child { padding-left: 1.1rem; }
.card.card-table table.listing th:last-child,
.card.card-table table.listing td:last-child { padding-right: 1.1rem; }

/* --- 7. Pills — the only non-accent color (§4c) ----------------------------- */
.pill {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: var(--fs-caption); font-weight: 600; line-height: 1.6;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill-accent { background: var(--accent-tint-strong); color: var(--accent); }
.pill-success { background: var(--success); color: #fff; }
.pill-warning { background: var(--warning); color: #fff; }
.pill-error { background: var(--error); color: #fff; }
.pill-soft-success { background: var(--success-tint); color: var(--success); }
.pill-soft-warning { background: var(--warning-tint); color: var(--warning); }
.pill-soft-error { background: var(--error-tint); color: var(--error); }
/* legacy alias */
.badge, .badge-muted {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: var(--fs-caption); font-weight: 600; line-height: 1.6;
  background: var(--accent-tint-strong); color: var(--accent); white-space: nowrap;
}
.badge-muted { background: var(--surface-2); color: var(--muted); }

/* --- 8. Buttons — small, airy, understated ---------------------------------- */
button, .btn { font: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .38rem 1rem; min-height: 34px;
  border-radius: var(--radius); border: 1px solid transparent;
  font-size: .92rem; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-press); }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--accent); background: var(--accent-tint); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--surface-2); color: var(--muted); border-color: transparent;
  cursor: not-allowed; filter: none;
}
.btn-sm { padding: .2rem .7rem; min-height: 28px; font-size: .85rem; }
.linklike {
  background: none; border: none; padding: 0; color: var(--accent);
  cursor: pointer; font: inherit;
}
.linklike:hover { text-decoration: underline; }
.inline { display: inline; }

/* Icon button (theme toggle) */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 999px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: .95rem;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
:root[data-theme="dark"] .theme-icon-dark { display: none; }
:root:not([data-theme="dark"]) .theme-icon-light { display: none; }

/* --- 9. Forms ---------------------------------------------------------------- */
input[type="text"], input[type="search"], input[type="number"], input[type="date"],
input[type="password"], input[type="email"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem .65rem; min-height: 34px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[readonly], .readonly-box { background: var(--surface-2); color: var(--muted); }

.field { display: flex; flex-direction: column; gap: .22rem; min-width: 0; }
.field > label, .field > .field-label {
  font-size: var(--fs-small); color: var(--muted); font-weight: 400;
}
.field .required-mark { color: var(--error); }
.field-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: .8rem 1.4rem;
}
.field-hint { color: var(--muted); font-size: var(--fs-caption); font-style: italic; }
ul.errorlist { margin: .2rem 0 0; padding-left: 1.1rem; font-size: .85rem; color: var(--error); }

/* Icon-gutter form sections (Jane §4b) */
.form-section { display: grid; grid-template-columns: 2.4rem 1fr; gap: 0 .4rem; padding: 1rem 0; border-bottom: 1px solid var(--border); }
.form-section:last-of-type { border-bottom: none; }
.form-section .gutter-icon {
  color: var(--muted); font-size: 1.05rem; line-height: 1.4; text-align: center;
  opacity: .75; filter: grayscale(1);   /* emoji glyphs render as quiet grey marks (Jane) */
}
.form-section h3 { margin: 0 0 .6rem; font-size: .95rem; font-weight: 600; color: var(--text); grid-column: 2; }
.form-section .field-grid { grid-column: 2; }
.form-section .section-body { grid-column: 2; min-width: 0; }

/* Sticky action footer */
.form-footer {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem 1.25rem; margin: 1.25rem -1.5rem 0;
  background: var(--surface); border-top: 1px solid var(--border);
}
.form-footer .spacer { flex: 1 1 auto; }

/* --- 10. Touch-select — big tap targets (§4e) -------------------------------- */
.touch-select { display: flex; flex-wrap: wrap; gap: .4rem; }
.ts-opt { position: relative; display: block; }
.ts-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.ts-opt span {
  display: flex; align-items: center; justify-content: center;
  min-height: 46px; min-width: 58px; padding: .35rem .8rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  font-size: .95rem; font-weight: 500; cursor: pointer;
  transition: background .1s, border-color .1s, color .1s;
  user-select: none; text-align: center;
}
.ts-opt:hover span { border-color: var(--accent); color: var(--accent); }
.ts-opt input:checked + span {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); font-weight: 600;
}
.ts-opt input:focus-visible + span { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.touch-select.ts-small .ts-opt span { min-height: 38px; min-width: 46px; font-size: .88rem; }
.touch-select.ts-xs { gap: .3rem; }
.touch-select.ts-xs .ts-opt span { min-height: 34px; min-width: 38px; font-size: .82rem; padding: .2rem .5rem; }

/* Numeric stepper — big touch number entry */
.stepper { display: inline-flex; align-items: stretch; }
.stepper input[type="number"] {
  width: 5.2rem; min-height: 46px; text-align: center;
  border-radius: 0; border-left: none; border-right: none;
  font-size: 1.05rem; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper button {
  min-width: 44px; min-height: 46px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
  font-size: 1.2rem; font-weight: 600; cursor: pointer;
}
.stepper button:hover { color: var(--accent); border-color: var(--accent); z-index: 1; }
.stepper button:first-child { border-radius: var(--radius-pill) 0 0 var(--radius-pill); }
.stepper button:last-child { border-radius: 0 var(--radius-pill) var(--radius-pill) 0; }

/* Factor row: label + side buttons + magnitude stepper on one line */
.factor-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .8rem;
  padding: .55rem 0; border-bottom: 1px solid var(--border);
}
.factor-row:last-child { border-bottom: none; }
.factor-label { flex: 0 0 5.5rem; font-weight: 600; font-size: .95rem; }
.factor-label small { display: block; font-weight: 400; color: var(--muted); font-size: var(--fs-caption); }
.factor-derived {
  display: inline-flex; align-items: center; min-height: 46px;
  padding: .35rem .9rem; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--muted);
  border: 1px dashed var(--border); font-size: .95rem;
}

/* Derived/read-only chip with a value */
.derived-chip { font-variant-numeric: tabular-nums; }
.chip-key { color: var(--muted); font-size: .78rem; margin-right: .4rem; text-transform: uppercase; letter-spacing: .04em; }

/* Fast-entry alignment (§4e-R2): side/direction toggles stay LEFT after the
   label; the number input is pushed RIGHT so all numbers form one scannable
   column down the card. */
.factor-row > .stepper,
.factor-row > input,
.factor-row > .field,
.factor-item > .stepper,
.factor-item > .num-derived { margin-left: auto; }
/* Stepper + derived chip travel as one right-aligned unit (cFAC after FCAb). */
.num-derived { display: inline-flex; align-items: center; gap: .5rem .8rem; }
.factor-row .field.tp-field { flex: 0 1 11rem; }

/* Paired factor line (§4e-R2): FAC+FCAb / HAC+HCAb share a row on wide
   screens, with the derived chip inline after the second factor. Items keep
   their natural width and wrap as whole units, so a tight card stacks
   "FAC …" / "FCAb … chip" as clean full rows instead of scrambling. */
.factor-pair { align-items: center; }
.factor-item {
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .8rem;
  flex: 1 0 auto; min-width: 0;
}

/* Reference points — compact container (§4e-R2) */
.ref-cap {
  display: block; margin: .5rem 0 .1rem; color: var(--muted);
  font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: .05em;
}
.ref-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .6rem;
  padding: .3rem 0; border-bottom: 1px solid var(--border);
}
.ref-row:last-child { border-bottom: none; }
.ref-row .ref-label { flex: 1 1 7rem; min-width: 0; line-height: 1.15; }
.ref-row .ref-label b { font-size: .95rem; }
.ref-row .ref-label small { display: block; color: var(--muted); font-size: var(--fs-caption); }
.ref-row .touch-select { margin-left: auto; }

/* Two-column section inside a wide card (Degeneration) */
.grid-2col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(21rem, 100%), 1fr)); gap: .4rem 2rem; }

/* Post "None — no post film" state: measurement rows grey out */
[data-post-fields].fields-off, input.fields-off { opacity: .45; }

/* Advanced mensuration preview (storage slice pending) */
fieldset.adv-preview { border: none; margin: 0; padding: 0; min-width: 0; }
fieldset.adv-preview h3 {
  margin: 1rem 0 .45rem; font-size: .8rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
fieldset.adv-preview h3:first-child { margin-top: .2rem; }
fieldset.adv-preview input { background: var(--surface-2); color: var(--muted); }

/* --- 11. Drop zones (Jane's dashed upload tile) ------------------------------- */
.drop-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .3rem; min-height: 7rem; padding: 1rem;
  border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: var(--fs-small); text-align: center;
  background: transparent;
}
.drop-zone .dz-icon {
  width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 999px;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.drop-zone.disabled { opacity: .65; }
.dz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .6rem; }

/* --- 12. Messages / banners ----------------------------------------------------- */
.messages { list-style: none; padding: 0; margin: 1rem 0 0; }
.msg {
  padding: .55rem .9rem; border-radius: var(--radius); margin-bottom: .5rem;
  border: 1px solid var(--border); background: var(--surface); font-size: .92rem;
}
.msg.success { background: var(--success-tint); border-color: transparent; color: var(--success); }
.msg.warning { background: var(--warning-tint); border-color: transparent; color: var(--warning); }
.msg.error { background: var(--error-tint); border-color: transparent; color: var(--error); }
.issues {
  background: var(--error-tint); border: 1px solid var(--error);
  border-radius: var(--radius); padding: .75rem 1rem .75rem 2rem; margin-bottom: 1rem;
  color: var(--text);
}
.issue-critical { color: var(--error); }

/* Info banner (soft accent) */
.banner-info {
  background: var(--accent-tint); border-radius: var(--radius);
  padding: .55rem .9rem; color: var(--text); font-size: .92rem; margin-bottom: 1rem;
}

/* --- 13. Summary lists, stats, misc ------------------------------------------- */
dl.summary { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.25rem; margin: 0; }
dl.summary dt { color: var(--muted); font-size: .92rem; }
dl.summary dd { margin: 0; font-weight: 600; font-size: .92rem; }
.meta { color: var(--muted); font-size: var(--fs-small); }

/* Big light stat numbers (Jane profile band) */
.stat-band { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; }
.stat { min-width: 5rem; }
.stat .stat-value { font-size: 30px; font-weight: 300; color: var(--title); line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .stat-label { color: var(--muted); font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: .05em; }

/* Donut / ring gauges */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: .35rem; min-width: 0; }
.donut-wrap .fig-donut { max-width: 13rem; }   /* Jane-sized ring, not card-filling */
.donut-row { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-around; }
.gauge-caption { color: var(--muted); font-size: var(--fs-caption); text-align: center; }

/* Empty states */
.empty-state {
  text-align: center; color: var(--muted); padding: 3rem 1rem;
}
.empty-state .empty-glyph { font-size: 2.2rem; opacity: .45; display: block; margin-bottom: .5rem; filter: grayscale(1); }
.empty-state p { margin: .25rem 0; }

/* Figures */
.fig { display: block; width: 100%; max-width: 26rem; height: auto; margin: 0 auto; }
.fig-stick, .fig-mastoid { max-width: 17rem; }
.stick-pair { display: flex; flex-wrap: wrap; gap: 1.25rem; justify-content: center; }
.stick-pair figure { margin: 0; text-align: center; flex: 1 1 14rem; min-width: 0; }
.stick-pair figcaption { color: var(--muted); font-size: var(--fs-small); margin-bottom: .25rem; }
.chart-legend { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.chip { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; }
.chip-pre { background: var(--chart-pre); }
.chip-post { background: var(--chart-post); }

.corrections { margin: 0; padding-left: 1.2rem; }
.corrections li { margin-bottom: .35rem; }
.verdict-good { color: var(--success); font-weight: 700; font-size: 1.05rem; margin: .25rem 0; }
.degeneration-note {
  border-top: 1px solid var(--border); margin: .6rem 0 0; padding-top: .5rem;
  color: var(--warning); font-size: .92rem;
}

/* Collapsible advanced panel */
details.adv-panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
details.adv-panel > summary {
  cursor: pointer; list-style: none; padding: .8rem 1.1rem;
  color: var(--accent); font-weight: 600; font-size: .95rem;
  display: flex; align-items: center; gap: .5rem;
}
details.adv-panel > summary::before { content: "+"; font-size: 1.1rem; }
details.adv-panel[open] > summary::before { content: "−"; }
details.adv-panel > .adv-body { padding: 0 1.1rem 1rem; }

/* Type-filter chips (Charts tab) */
.filter-chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.filter-chips a, .filter-chips span.chip-disabled {
  padding: .25rem .8rem; border-radius: 999px; font-size: .88rem;
  border: 1px solid var(--border); color: var(--muted); text-decoration: none;
  background: var(--surface);
}
.filter-chips a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.filter-chips a.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.filter-chips span.chip-disabled { opacity: .55; cursor: not-allowed; }

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--canvas); padding: 1rem;
}
.login-card { width: 100%; max-width: 23rem; padding: 1.6rem 1.75rem 1.75rem; }
.login-card .brand-mark {
  color: var(--accent); font-weight: 700; letter-spacing: 1px; font-size: 1.3rem;
  margin-bottom: .2rem;
}
.login-card h1 { font-size: 1.1rem; font-weight: 400; color: var(--muted); margin: 0 0 1.1rem; }
.login-card .field { margin-bottom: .8rem; }
.login-card input { width: 100%; }

/* --- 14. Responsive shell -------------------------------------------------------- */
.subnav-toggle { display: none; }
@media (max-width: 900px) {
  .shell { display: block; }
  .subnav {
    position: static; width: 100%; height: auto; max-height: 45vh;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .canvas { padding: 0 .9rem 3rem; }
  .form-footer { margin-left: -.9rem; margin-right: -.9rem; padding-left: .9rem; padding-right: .9rem; }
  .topbar { padding: 0 .5rem; overflow-x: auto; }
  .topbar .brand { margin-right: .5rem; }
  .top-tabs a { padding: 0 .6rem; font-size: .88rem; }
  .topbar-right .who { display: none; }
  .page-head h1 { font-size: 22px; }
  .page-head .head-actions { margin-left: 0; flex-basis: 100%; }
  .form-footer { flex-wrap: wrap; }
  .form-footer .meta { display: none; }
  .factor-label { flex-basis: 100%; }
  .factor-item { flex-basis: 100%; }
  .factor-pair .factor-derived { margin-left: auto; }
}

/* --- 15. Settings admin pages (users / audit / compliance) ------------------ */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem;
}
.filter-bar .field { flex: 0 1 11rem; }
.filter-bar .filter-actions { display: flex; gap: .4rem; margin-left: auto; }
.pager { display: flex; align-items: center; gap: .8rem; margin: -.25rem 0 .75rem; }

.check-row {
  display: flex; align-items: flex-start; gap: .9rem;
  padding: .75rem 0; border-bottom: 1px solid var(--border);
}
.check-row:last-child { border-bottom: none; padding-bottom: .2rem; }
.check-status { flex: 0 0 6.5rem; padding-top: .1rem; }
.check-body { min-width: 0; }
.check-title { font-weight: 600; font-size: .95rem; }
.check-text { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; }
@media (max-width: 700px) {
  .check-row { flex-direction: column; gap: .3rem; }
  .check-status { flex-basis: auto; }
  .filter-bar .filter-actions { margin-left: 0; }
}

/* Widget-customization affordances (Phase D) */
.dash-toolbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  justify-content: flex-end; margin-bottom: .5rem;
}
.dash-toolbar .editing-only { display: none; }
.dash-toolbar.editing .editing-only { display: inline-flex; }
.dash-toolbar.editing [data-edit-grid] { display: none; }
.dash-toolbar.editing .meta.editing-only { display: inline; margin-right: auto; }
.dash-grid.editing [data-widget] { outline: 2px dashed var(--accent-tint-strong); cursor: grab; position: relative; }
.dash-grid.editing [data-widget].dragging { opacity: .5; }
.dash-grid.editing [data-widget].widget-off { opacity: .45; outline-style: dotted; }
.widget-hidden { display: none !important; }
.widget-controls {
  display: flex; gap: .3rem; justify-content: flex-end;
  margin: -.3rem -.3rem .4rem 0;
}

/* --- Rapid Entry (Spec/design/rapid-entry.md) — keyboard-only loop ------- */
.rapid-card { max-width: 780px; padding: 0 0 .5rem; }
.rapid-row {
  display: flex; align-items: center; gap: .9rem;
  padding: .5rem 1rem; border-bottom: 1px solid var(--border);
}
.rapid-row:last-child { border-bottom: none; }
.rapid-row.rapid-focus {
  background: var(--accent-tint);
  box-shadow: inset 3px 0 0 var(--accent);
}
.rapid-label { flex: 0 0 140px; line-height: 1.15; }
.rapid-label b { display: block; font-size: .95rem; }
.rapid-label small { color: var(--muted); font-size: var(--fs-caption); }
.rapid-enum { display: flex; flex-wrap: wrap; gap: .3rem; border-radius: var(--radius); }
.rapid-enum:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.rp-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 52px; min-height: 30px; padding: .15rem .55rem;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  font-size: .85rem; color: var(--muted); background: var(--surface);
  user-select: none;
}
.rp-pill.rp-s { min-width: 34px; padding: .15rem .3rem; }
.rp-pill.selected {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); font-weight: 600;
}
.rapid-num {
  width: 96px; text-align: right;
  font-size: 1.05rem; font-variant-numeric: tabular-nums;
}
.rapid-warn { color: var(--warning); font-size: var(--fs-small); margin-left: auto; }
.rapid-input-wrap { position: relative; flex: 1 1 auto; max-width: 340px; }
.rapid-input-wrap .rapid-text { width: 100%; }
.rapid-hint { color: var(--muted); font-size: var(--fs-caption); }
.rapid-pt-list {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  max-height: 260px; overflow-y: auto;
}
.rapid-pt { padding: .45rem .6rem; font-size: .9rem; cursor: pointer; }
.rapid-pt.active, .rapid-pt:hover { background: var(--row-select); }
:root[data-theme="dark"] .rapid-pt.active,
:root[data-theme="dark"] .rapid-pt:hover { background: var(--accent-tint-strong); }
.rapid-foot {
  display: flex; align-items: center; gap: .8rem;
  padding: .8rem 1rem .3rem; border-top: 1px solid var(--border);
}
.rapid-foot .spacer { flex: 1 1 auto; }
.rapid-foot.rapid-ready .btn-primary {
  box-shadow: 0 0 0 3px var(--accent-tint-strong);
}
.rp-key {
  font-family: inherit; font-size: .68rem; font-weight: 600;
  padding: 0 .28rem; margin-right: .35rem; border-radius: 3px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); line-height: 1.4;
}
.rp-pill.selected .rp-key {
  background: rgba(255, 255, 255, .22); border-color: transparent;
  color: var(--on-accent);
}
.rapid-keys { display: none; }
.rapid-row.rapid-focus .rapid-keys {
  display: inline; margin-left: auto;
  color: var(--muted); font-size: var(--fs-caption); white-space: nowrap;
}
.rapid-row.rapid-focus .rapid-warn:not([hidden]) ~ .rapid-keys { display: none; }
.rapid-warn { margin-left: auto; }
.rapid-wrap { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.rapid-wrap .rapid-card { flex: 1 1 560px; }
.rapid-legend {
  flex: 0 0 250px; position: sticky; top: calc(var(--topbar-h) + 1rem);
  padding: .9rem 1rem; font-size: var(--fs-small);
}
.rapid-legend h2 { margin: 0 0 .6rem; }
.rl-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .6rem; padding: .22rem 0;
}
.rl-row small { color: var(--muted); text-align: right; }
.rl-row .rp-key { margin-right: .15rem; }
.rl-save .rp-key { border-color: var(--accent); color: var(--accent); }
.rl-sep { border: 0; border-top: 1px solid var(--border); margin: .45rem 0; }
.rp-sgrid { display: flex; flex-direction: column; gap: .3rem; }
.rp-srow { display: flex; gap: .3rem; }
.rl-opt {
  display: flex; align-items: center; gap: .4rem;
  padding: .18rem 0; font-size: var(--fs-small); cursor: pointer;
}
.rapid-legend .btn { margin-top: .45rem; }
[data-rapid-defaults-msg] { color: var(--success); font-size: var(--fs-caption); }
.preview-strip {
  display: flex; flex-wrap: wrap; gap: .35rem 1rem;
  margin: -.35rem 0 .6rem; min-height: 1.1em;
}
.preview-strip:empty { display: none; }
.preview-strip strong { color: var(--text); font-weight: 600; }
