/* ============================================================
   Porcelain design system (docs/04-ARCHITECTURE.md section 6, DR-004)
   Platform: warm porcelain surfaces, ink text, single teal accent.
   Imaging workspaces use the fixed dark stage (.stage) in both themes.
   All components read tokens; no hardcoded colors below the token block.
   ============================================================ */

:root {
  /* surfaces + ink */
  --bg: #FAF9F7;
  --panel: #FFFFFF;
  --panel-2: #F3F1ED;
  --line: #E8E4DE;
  --ink: #1C1E21;
  --muted: #6B6F76;
  --faint: #9CA1A8;

  /* accent + semantics (semantic colors are never decorative) */
  --acc: #0F766E;
  --acc-soft: #E4F0EE;
  --on-acc: #FFFFFF;
  --good: #15803D;
  --warn: #B45309;
  --bad: #B42318;

  /* problem categories, light surfaces (validated 2026-07-11, fixed order:
     skeletal, dental, soft tissue, functional, airway, periodontal, esthetic) */
  --cat-skeletal: #2F6DB0;
  --cat-dental: #0B8A74;
  --cat-soft: #C24358;
  --cat-functional: #7C56C0;
  --cat-airway: #1592CE;
  --cat-perio: #C06430;
  --cat-esthetic: #B84A8F;

  /* dark stage (identical in both themes, DR-004) */
  --stage-bg: #0C1117;
  --stage-panel: #141B23;
  --stage-line: #22303C;
  --stage-ink: #E9EEF3;
  --stage-muted: #8FA1B3;
  --stage-acc: #3FBEDA;

  /* geometry + type */
  --rad: 10px;
  --rad-s: 7px;
  --gap: 12px;
  --pad: 14px;
  --shadow: 0 1px 2px rgba(28, 30, 33, 0.05);
  --fs-0: 13px;
  --fs-1: 15px;
  --fs-2: 18px;
  --fs-3: 24px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --rail-w: 216px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161B;
    --panel: #1B1E25;
    --panel-2: #20242C;
    --line: #2A2E37;
    --ink: #E8E7E3;
    --muted: #9CA1A8;
    --faint: #6B7078;
    --acc: #3AAE9C;
    --acc-soft: #1E2E2C;
    --on-acc: #0B0E12;
    --good: #4ADE80;
    --warn: #E0A24A;
    --bad: #E5695E;
    --cat-skeletal: #4C88CC;
    --cat-dental: #2FA98F;
    --cat-soft: #D9647E;
    --cat-functional: #9D7BE0;
    --cat-airway: #3399BD;
    --cat-perio: #CE7A44;
    --cat-esthetic: #CC6BA6;
    --shadow: none;
  }
}

/* manual override wins over OS preference in both directions */
:root[data-theme='light'] {
  --bg: #FAF9F7; --panel: #FFFFFF; --panel-2: #F3F1ED; --line: #E8E4DE;
  --ink: #1C1E21; --muted: #6B6F76; --faint: #9CA1A8;
  --acc: #0F766E; --acc-soft: #E4F0EE; --on-acc: #FFFFFF;
  --good: #15803D; --warn: #B45309; --bad: #B42318;
  --cat-skeletal: #2F6DB0; --cat-dental: #0B8A74; --cat-soft: #C24358;
  --cat-functional: #7C56C0; --cat-airway: #1592CE; --cat-perio: #C06430; --cat-esthetic: #B84A8F;
  --shadow: 0 1px 2px rgba(28, 30, 33, 0.05);
}
:root[data-theme='dark'] {
  --bg: #14161B; --panel: #1B1E25; --panel-2: #20242C; --line: #2A2E37;
  --ink: #E8E7E3; --muted: #9CA1A8; --faint: #6B7078;
  --acc: #3AAE9C; --acc-soft: #1E2E2C; --on-acc: #0B0E12;
  --good: #4ADE80; --warn: #E0A24A; --bad: #E5695E;
  --cat-skeletal: #4C88CC; --cat-dental: #2FA98F; --cat-soft: #D9647E;
  --cat-functional: #9D7BE0; --cat-airway: #3399BD; --cat-perio: #CE7A44; --cat-esthetic: #CC6BA6;
  --shadow: none;
}

/* ---------- reset-ish ---------- */
* { box-sizing: border-box; }
/* our components set explicit display values, which beat the UA's [hidden]
   rule; this keeps the hidden attribute trustworthy everywhere */
[hidden] { display: none !important; }
html { height: 100%; color-scheme: light dark; }
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-1);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--fs-3); }
h2 { font-size: var(--fs-2); }
h3 { font-size: var(--fs-1); }
p { margin: 0; }
a { color: var(--acc); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--panel); color: var(--ink); padding: 8px 14px;
  border-radius: var(--rad-s); border: 1px solid var(--line);
}
.skip-link:focus { left: 8px; }

/* ---------- app frame ---------- */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }

.rail {
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font-weight: 700; font-size: 18px; letter-spacing: -0.01em;
  padding: 4px 8px;
}
.brand svg { width: 26px; height: 26px; color: var(--acc); flex: none; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); text-decoration: none;
  font-size: 14px; font-weight: 500;
  padding: 9px 10px; border-radius: var(--rad-s);
  transition: background 0.12s, color 0.12s;
}
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a[aria-current='page'] { background: var(--acc-soft); color: var(--acc); font-weight: 600; }
.nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.55; flex: none; }
.nav .nav-group {
  font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--faint); padding: 14px 10px 4px; font-weight: 600;
}

.rail-foot { display: flex; flex-direction: column; gap: 8px; }
.version { font-family: var(--mono); font-size: 11px; color: var(--faint); text-align: center; }

.main { min-width: 0; padding: 26px 30px 60px; }
.main-head {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-hint { font-size: var(--fs-0); color: var(--faint); }
.outlet { max-width: 1100px; }

@media (max-width: 760px) {
  body { overflow-x: clip; }
  .app { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; height: auto; z-index: 40;
    min-width: 0; /* grid item: without this the track inflates to the nav's min-content */
    background: var(--bg);
    border-right: none; border-bottom: 1px solid var(--line);
    flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 10px;
  }
  .brand { flex: none; padding: 4px 2px; }
  .brand span { display: none; }
  .nav {
    flex: 1 1 0; min-width: 0;
    flex-direction: row; overflow-x: auto; padding-bottom: 2px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav .nav-group { display: none; }
  .nav a { white-space: nowrap; padding: 7px 10px; }
  .rail-foot { flex: none; flex-direction: row; }
  .rail-foot .btn { width: auto; font-size: 12px; padding: 7px 10px; }
  .version { display: none; }
  .main { padding: 18px 16px 50px; }
}

/* ---------- components ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  padding: var(--pad);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--gap); }
.card-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--muted); margin: 0 0 10px;
}

.grid { display: grid; gap: var(--gap); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--rad-s);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s, border-color 0.12s;
}
.btn-primary { background: var(--acc); color: var(--on-acc); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--acc); color: var(--acc); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--line); }
.btn-danger:hover { border-color: var(--bad); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  color: var(--acc); background: var(--acc-soft);
  border: 1px solid color-mix(in srgb, var(--acc) 40%, transparent);
  padding: 3px 11px; border-radius: 999px; white-space: nowrap;
}

.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--rad); padding: 12px 14px; box-shadow: var(--shadow);
}
.stat b {
  display: block; font-size: 24px; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat span { font-size: 12px; color: var(--muted); }
.stat.is-warn b { color: var(--warn); }
.stat.is-bad b { color: var(--bad); }

/* category chips: color never appears without the text label */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--on-acc);
  padding: 2.5px 10px; border-radius: 999px; white-space: nowrap;
}
:root[data-theme='dark'] .chip { color: #0B0E12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .chip { color: #0B0E12; } }
.chip-skeletal { background: var(--cat-skeletal); }
.chip-dental { background: var(--cat-dental); }
.chip-soft { background: var(--cat-soft); }
.chip-functional { background: var(--cat-functional); }
.chip-airway { background: var(--cat-airway); }
.chip-perio { background: var(--cat-perio); }
.chip-esthetic { background: var(--cat-esthetic); }

/* tooth picker (FDI odontogram): status color never appears without its
   letter code; the legend repeats code + full label */
.tooth-picker { display: flex; flex-direction: column; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.tooth-row { display: flex; gap: 3px; justify-content: center; min-width: max-content; }
.tooth-row.is-deciduous .tooth { opacity: 0.85; }
.tooth {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 30px; height: 38px; padding: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--rad-s);
  color: var(--ink); font: inherit; cursor: pointer;
}
.tooth:hover { border-color: var(--acc); }
.tooth b { font-size: 12px; font-weight: 600; line-height: 1.2; }
.tooth i { font-size: 10px; font-weight: 700; font-style: normal; line-height: 1.2; min-height: 12px; }
.tooth.is-missing { color: var(--faint); border-style: dashed; }
.tooth.is-missing b { text-decoration: line-through; }
.tooth.is-implant { color: var(--acc); background: var(--acc-soft); border-color: color-mix(in srgb, var(--acc) 40%, transparent); }
.tooth.is-restoration { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.tooth.is-extraction-planned { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.tooth.is-unerupted { color: var(--faint); border-style: dotted; }
.tooth.is-erupting { color: var(--acc); border-style: dotted; }
.tooth.is-impacted { color: var(--bad); border-style: dotted; }
.tooth-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.tooth-key { display: inline-flex; align-items: center; gap: 5px; }
.tooth-key i { font-style: normal; font-weight: 700; }
.tooth-key.is-missing i { color: var(--faint); }
.tooth-key.is-implant i { color: var(--acc); }
.tooth-key.is-restoration i { color: var(--warn); }
.tooth-key.is-extraction-planned i { color: var(--bad); }
.fdi-chip {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 700; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 1.5px 7px; border-radius: 999px; margin-right: 4px;
}

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--gap); }
.field label { font-size: 13px; font-weight: 600; }
.field .help { font-size: 12px; color: var(--faint); }
input[type='text'], input[type='number'], input[type='date'], input[type='email'],
input[type='password'], input[type='search'], input[type='tel'], input[type='url'],
select, textarea {
  font: inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--rad-s); padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--acc); outline: none; }
input:user-invalid { border-color: var(--bad); }

/* checklist row */
.check-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px; border-top: 1px solid var(--line);
  font-size: 14px;
}
.check-row:first-child { border-top: none; }
.check-row input[type='checkbox'] { width: 17px; height: 17px; accent-color: var(--acc); }
.check-row .meta { margin-left: auto; font-size: 12px; color: var(--faint); }

/* measurement tables: monospaced numerals (DR-004) */
.measure-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.measure-table th, .measure-table td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); }
.measure-table thead th {
  border-top: none; font-size: 11px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--muted);
}
.measure-table td.num { font-family: var(--mono); font-size: 13px; text-align: right; }

/* journey spine stepper */
.spine { display: flex; overflow-x: auto; padding: 4px 0 10px; }
.spine-step { flex: 1 0 auto; min-width: 78px; text-align: center; position: relative; font-size: 11px; color: var(--muted); }
.spine-step::before {
  content: ''; position: absolute; top: 8px; left: -50%;
  width: 100%; height: 2px; background: var(--line);
}
.spine-step:first-child::before { display: none; }
.spine-step .knot {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--line);
  font-size: 9px; color: var(--on-acc); margin-bottom: 4px;
}
.spine-step.is-done .knot { background: var(--acc); border-color: var(--acc); }
.spine-step.is-done::before { background: var(--acc); }
.spine-step.is-now .knot { border-color: var(--acc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 25%, transparent); }
.spine-step.is-now::before { background: var(--acc); }
.spine-step.is-now { color: var(--ink); font-weight: 600; }
.spine-step .lbl { display: block; }

/* calendar grid (activation / aligner) */
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { font-size: 10px; color: var(--muted); text-align: center; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.cal-day {
  aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted);
  position: relative; background: var(--panel);
}
.cal-day.is-done { background: color-mix(in srgb, var(--acc) 14%, var(--panel)); border-color: var(--acc); color: var(--ink); }
.cal-day.is-missed { border-color: var(--bad); color: var(--bad); }
.cal-day.is-today { outline: 2px solid var(--ink); outline-offset: -2px; color: var(--ink); font-weight: 700; }

/* dark stage: imaging workspaces, fixed in both themes (DR-004) */
.stage {
  background: var(--stage-bg); color: var(--stage-ink);
  border: 1px solid var(--stage-line); border-radius: var(--rad);
  padding: var(--pad);
}
.stage .card, .stage-panel {
  background: var(--stage-panel); border: 1px solid var(--stage-line);
  border-radius: var(--rad-s); box-shadow: none; color: var(--stage-ink);
}
.stage .card-title { color: var(--stage-muted); }
.stage a { color: var(--stage-acc); }
.model-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--gap); align-items: start; margin-top: var(--gap); }
.model-stage-wrap { position: sticky; top: var(--gap); }
.model-controls { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.model-controls .card { margin: 0; }
.model-overlay { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px; background: rgba(18, 20, 25, 0.92); border: 1px solid var(--stage-line); border-radius: var(--rad-s); z-index: 2; }
.model-overlay .measure-prompt { margin: 0; flex: 1 1 auto; min-width: 140px; color: #E8E4DA; }
@media (max-width: 860px) {
  .model-workspace { grid-template-columns: 1fr; }
  .model-stage-wrap { position: relative; top: auto; }
}
.model-stage { padding: 0; overflow: hidden; }
.model-canvas-wrap { width: 100%; height: min(70vh, 620px); }
.model-canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.mesh-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.tp-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.tp-table th, .tp-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.tp-table th { color: var(--muted); font-weight: 600; }
.tp-num { font-variant-numeric: tabular-nums; text-align: right; }
.measure-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.measure-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.measure-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.measure-name { flex: 1 1 auto; }
.measure-mm { font-variant-numeric: tabular-nums; font-weight: 550; }
.measure-prompt { margin: 8px 0 0; min-height: 1.2em; font-size: 14px; font-weight: 550; color: var(--acc); }
.bolton-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.bolton-chip { font-size: 12px; font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 999px; background: var(--acc-soft); color: var(--acc); }
.bolton-results { display: flex; flex-direction: column; gap: 6px; }
.bolton-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }

/* login screen */
/* "What's new" panel (onboarding) */
.whatsnew-overlay {
  position: fixed; inset: 0; z-index: 100; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 16, 0.55);
}
.whatsnew-card { width: 100%; max-width: 540px; max-height: 82vh; display: flex; flex-direction: column; }
.whatsnew-kicker { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--acc); }
.whatsnew-title { margin: 0 0 14px; font-size: 20px; letter-spacing: -0.01em; }
.whatsnew-body { overflow-y: auto; }
.whatsnew-release { margin-bottom: 14px; }
.whatsnew-rel-title { margin: 0 0 6px; font-weight: 600; }
.whatsnew-list { margin: 0 0 8px; padding-left: 20px; font-size: 14px; }
.whatsnew-list li { margin-bottom: 4px; }
.whatsnew-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}

/* Guided tour: spotlight + coachmark popover */
.tour-spotlight {
  position: fixed; z-index: 200; border-radius: 8px; pointer-events: none;
  border: 2px solid var(--acc); box-shadow: 0 0 0 9999px rgba(10, 12, 16, 0.6);
  transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease;
}
.tour-popover { position: fixed; z-index: 201; width: 320px; max-width: calc(100vw - 16px); }
.tour-title { margin: 0 0 6px; font-weight: 600; font-size: 15px; }
.tour-body { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.tour-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tour-counter { font-size: 12px; color: var(--muted); }
.tour-btns { display: flex; gap: 6px; }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-card { width: 100%; max-width: 380px; padding: 26px 24px; }
.login-brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 4px;
}
.login-brand svg { width: 30px; height: 30px; color: var(--acc); }
.login-sub { text-align: center; font-size: 13px; color: var(--muted); margin: 0 0 20px; }
.login-msg { font-size: 13px; color: var(--bad); min-height: 1.2em; margin: 10px 0 0; }
.login-contact { text-align: center; font-size: 13px; color: var(--muted); margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.login-contact a { color: var(--acc); text-decoration: none; font-weight: 500; }
.login-contact a:hover { text-decoration: underline; }
.login-setup { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.login-setup summary {
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
  padding: 4px 0; list-style-position: inside;
}
.login-setup summary:hover { color: var(--acc); }
.login-setup form { margin-top: 12px; }

/* toolbar + list rows */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: var(--gap); }
.toolbar input[type='search'] { flex: 1 1 200px; min-width: 0; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px; border-top: 1px solid var(--line);
  color: var(--ink); text-decoration: none;
}
.list-row:first-child { border-top: none; }
.list-row:hover { background: var(--panel-2); }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-main b { font-weight: 600; }
.row-sub { font-size: 12px; color: var(--faint); }
.row-side { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* empty / placeholder state */
.empty {
  border: 1px dashed var(--line); border-radius: var(--rad);
  padding: 34px 22px; text-align: center; color: var(--muted);
}
.empty b { display: block; color: var(--ink); font-size: var(--fs-2); margin-bottom: 6px; }
.empty .milestone {
  display: inline-block; margin-top: 12px;
  font-family: var(--mono); font-size: 11px; color: var(--acc);
  background: var(--acc-soft); padding: 3px 10px; border-radius: 999px;
}

/* spine interactivity + stage expectations (M1.1) */
.spine button.knot { cursor: pointer; border-style: solid; padding: 0; font: inherit; font-size: 9px; }
.spine button.knot:hover { border-color: var(--acc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 18%, transparent); }
.stage-expects { margin-top: 6px; }
.stage-expects .check-row { color: var(--muted); }
a.stat { text-decoration: none; color: var(--ink); }
a.stat:hover { border-color: var(--acc); }
.stat b.is-zero { color: var(--faint); }

/* checklist completeness (M1.2) */
.spine-count { display: block; font-size: 9.5px; color: var(--faint); font-variant-numeric: tabular-nums; margin-top: 1px; }
.spine-count.is-complete { color: var(--acc); font-weight: 600; }
.stage-expects-head { display: flex; align-items: center; gap: 14px; }
.stage-expects-head .card-title { margin: 0; flex: none; }
.progress { flex: 1; height: 6px; border-radius: 99px; background: var(--panel-2); overflow: hidden; max-width: 220px; }
.progress i { display: block; height: 100%; background: var(--acc); border-radius: 99px; transition: width 0.2s ease; }

/* settings: about + changelog (M1.2 session) */
.about-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.about-row b { font-size: 17px; }
.changelog { max-width: 68ch; }
.cl-release { font-size: 14px; margin: 16px 0 4px; font-variant-numeric: tabular-nums; }
.cl-release:first-child { margin-top: 0; }
.cl-section { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--acc); font-weight: 700; margin: 8px 0 2px; }
.cl-list { margin: 2px 0 6px; padding-left: 20px; font-size: 13.5px; color: var(--muted); }
.cl-list li { margin: 3px 0; }
.cl-note { font-size: 13px; color: var(--muted); }

/* dashboard (M1.3) */
.dash-two { margin-top: var(--gap); align-items: start; }
.act-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px; border-top: 1px solid var(--line); font-size: 13.5px; }
.act-row:first-child { border-top: none; }
.act-what { min-width: 0; }
.act-when { flex: none; color: var(--faint); font-size: 12px; }
.filter-pill { display: inline-flex; align-items: center; gap: 8px; }
.filter-pill a { color: inherit; text-decoration: none; font-weight: 700; }

/* privacy notice + print (M1.4) */
.notice-p { margin: 4px 0 10px; }
@media print {
  .rail, .toolbar, .btn, .main-head .page-hint { display: none !important; }
  .main { padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; }
  body.print-notice .card:not(:has(.notice-print)) { display: none; }
  body.print-notice .notice-print { display: block; }
}

/* calculators hub (M2 scaffold) */
.tool-card { display: block; text-decoration: none; color: var(--ink); }
.tool-card h3 { margin-bottom: 4px; }
.tool-card:hover { border-color: var(--acc); }
.tool-card.is-locked { opacity: 0.65; }
.tool-card .pill { margin-top: 10px; }

/* activation calendar (M2.3) */
.protocol-card { margin-top: var(--gap); }
.cal-month { font-size: 12px; font-weight: 700; color: var(--muted); margin: 12px 0 4px; letter-spacing: 0.04em; }
.cal-grid { max-width: 420px; }
.cal-head { max-width: 420px; }
button.cal-day { cursor: pointer; font: inherit; font-size: 12px; }
button.cal-day:hover { border-color: var(--acc); }
.cal-day.is-idle { border-color: transparent; color: var(--faint); background: transparent; }
.pill-missed { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
@media print {
  .cal-print { display: block; }
  .cal-grid, .cal-head { max-width: 100%; }
  button.cal-day { border: 1px solid #999; }
}

/* handout instructions (M2.6) */
.handout-instructions { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.instr-text { white-space: pre-wrap; max-width: 68ch; }

/* structured exams (M3.1a) */
.exam-row { display: grid; grid-template-columns: minmax(140px, 1fr) auto minmax(120px, 1fr); gap: 10px; align-items: center; }
.exam-row .row-sub { grid-column: 2 / 4; }
@media (max-width: 640px) { .exam-row { grid-template-columns: 1fr; } .exam-row .row-sub { grid-column: auto; } }

/* knowledge base browser (M3.3) */
.kb-list-title { font-size: 12px; font-weight: 700; color: var(--muted); margin: 8px 0 2px; }
.kb-list { margin: 0 0 6px 18px; padding: 0; }
.kb-list li { font-size: var(--fs-0); margin: 2px 0; }

/* problem list (M3.2) */
.prob-group { margin: 14px 0 6px; }
.ev-chip {
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 600; color: var(--acc);
  background: transparent; border: 1px solid color-mix(in srgb, var(--acc) 40%, transparent);
  padding: 2px 10px; border-radius: 999px; margin: 0 4px 4px 0;
  cursor: pointer; font-family: inherit;
}
.ev-chip:hover { background: var(--acc-soft); }
.card.is-highlight { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }
.case-print { display: none; }
.case-print h3 { margin: 12px 0 4px; }
.issue-box { margin-top: var(--gap); padding-top: var(--gap); border-top: 1px solid var(--line); }
.logo-preview { display: block; max-height: 64px; max-width: 220px; width: auto; margin: 6px 0; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: #FFFFFF; }
/* ---------- Proposal document (M6.5): patient-facing, always paper-white ---------- */
.proposal-doc { position: relative; max-width: 760px; margin: 0 auto; background: #FFFFFF; color: #16181B; border: 1px solid var(--line); border-radius: 8px; padding: 8px 0; }
.doc-section { padding: 40px 48px; border-bottom: 1px dashed #E8E4DE; }
.doc-section:last-child { border-bottom: none; }
.doc-watermark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; font-size: 110px; font-weight: 700; letter-spacing: 0.1em; color: rgba(180, 60, 60, 0.08); transform: rotate(-28deg); z-index: 1; }
.doc-kicker { font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: #0F766E; margin: 0 0 26px; }
.doc-logo { display: block; max-height: 72px; max-width: 260px; width: auto; object-fit: contain; margin: 0 0 26px; }
.doc-title { font-size: 30px; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 34px; color: #16181B; }
.doc-cover-who { border-top: 2px solid #0F766E; padding-top: 18px; }
.doc-patient { font-size: 20px; font-weight: 600; margin: 0 0 10px; }
.doc-meta { font-size: 13px; color: #5F636A; margin: 0 0 4px; }
.doc-heading { font-size: 19px; letter-spacing: -0.01em; margin: 0 0 16px; color: #0F766E; }
.doc-photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.doc-photo-grid figure { margin: 0; }
.doc-photo-grid img { width: 100%; height: auto; border-radius: 4px; }
.doc-photo-grid figcaption { font-size: 12px; color: #5F636A; margin-top: 5px; }
.doc-exam-row { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 7px 0; border-bottom: 1px solid #F0EDE8; font-size: 13.5px; }
.doc-exam-label { flex: 1 1 46%; }
.doc-exam-value { font-weight: 550; }
.doc-exam-row.is-abnormal .doc-exam-value { color: #A14034; }
.doc-exam-note { flex-basis: 100%; font-size: 12.5px; color: #5F636A; }
.doc-goals { margin: 0 0 14px; padding-left: 20px; font-size: 14px; }
.doc-goals li { margin-bottom: 6px; }
.doc-prognosis { font-weight: 600; font-size: 14px; }
.doc-phase { padding: 12px 0; border-bottom: 1px solid #F0EDE8; font-size: 13.5px; }
.doc-phase:last-child { border-bottom: none; }
.doc-phase-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.doc-phase-head b { font-size: 14.5px; }
@media print {
  @page { size: A4; margin: 16mm 14mm; }
  body.print-proposal .app, body.print-proposal .main-head, body.print-proposal .toolbar { display: none; }
  body.print-proposal .proposal-doc { border: none; border-radius: 0; max-width: none; padding: 0; }
  body.print-proposal .doc-section { border-bottom: none; break-before: page; padding: 0; }
  body.print-proposal .doc-section:first-of-type { break-before: auto; }
  body.print-proposal .doc-watermark { position: fixed; }
  .doc-photo-grid img { break-inside: avoid; }
}

.case-print-row { margin: 0 0 10px; }
@media print {
  body.print-case .card, body.print-case .main-head { display: none; }
  body.print-case .case-print { display: block; }
}

/* settings sub-navigation (tabs) */
.subnav { display: flex; gap: 4px; margin-bottom: var(--gap); border-bottom: 1px solid var(--line); }
.subnav a { padding: 8px 14px; font-size: 14px; font-weight: 600; color: var(--muted);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--ink); }
.subnav a[aria-current='page'] { color: var(--acc); border-bottom-color: var(--acc); }

/* photography / records (M4) */
.upload-preview { max-width: 240px; max-height: 180px; border: 1px solid var(--line); border-radius: var(--rad-s); margin-top: 8px; }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--gap); }
.photo-cell { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.photo-cell img { width: 100%; height: 120px; object-fit: cover; border: 1px solid var(--line); border-radius: var(--rad-s); background: var(--panel-2); }
.compare-stage { margin-top: 10px; padding: 10px; }
.compare-side { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare-side img { width: 100%; border-radius: var(--rad-s); }
.compare-slider { position: relative; max-width: 520px; }
.compare-slider > img { width: 100%; display: block; border-radius: var(--rad-s); }
.compare-over { position: absolute; inset: 0; overflow: hidden; border-radius: var(--rad-s); }
.compare-over img { position: absolute; top: 0; left: 0; height: 100%; }
.compare-range { position: absolute; left: 0; right: 0; bottom: 8px; width: 100%; }
