/* 의원 수가 시뮬레이터 — layout and components. Tokens live in tokens.css.
   Mobile first; >= 900px switches to the two-column workspace (input 360px | results). */

/* ===== base ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* `hidden` must win over any display rule below; until-found panels are handled per layout. */
[hidden]:not([hidden="until-found"]) { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-block-start: var(--sp-4);
}

body {
  margin: 0;
  min-block-size: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  /* Korean: break lines between words (at spaces), never inside a word such as 진료영역; a
     word longer than its whole line still wraps (break-word keeps table min-content widths) */
  word-break: keep-all;
  overflow-wrap: break-word;
}

h1, h2, h3, h4, p { margin: 0; }
h1, h2 { font-family: var(--font-serif); font-weight: 700; letter-spacing: -0.01em; }
small { font-size: max(0.82em, var(--fs-2xs)); } /* never under 12px, also inside 12.5px table cells */
a { color: var(--brand); text-underline-offset: 2px; }
strong { font-weight: 750; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--sp-3);
  inset-block-start: -100px;
  z-index: 100;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 700;
}
.skip-link:focus { inset-block-start: var(--sp-3); }

.noscript-note {
  margin: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 650;
}

.icon {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
  vertical-align: -0.2em;
}

/* ===== buttons ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-block-size: var(--tap);
  padding: 0 0.85rem;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { background: var(--soft); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn small { font-weight: 550; color: var(--ink2); }

.btn-quiet { background: transparent; border-color: transparent; color: var(--ink2); }
.btn-quiet:hover { background: var(--soft); border-color: transparent; color: var(--ink); }

.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 86%, var(--ink)); border-color: transparent; color: var(--on-brand); }

.btn-sm { padding: 0 0.7rem; font-size: var(--fs-xs); }
.btn.active-preset { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.btn.active-preset small { color: var(--brand); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  inline-size: var(--tap);
  block-size: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.icon-btn .icon { inline-size: 20px; block-size: 20px; }

/* ===== header ========================================================== */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-4);
  max-inline-size: 1600px;
  margin-inline: auto;
  padding: var(--sp-3) var(--sp-4);
  border-block-end: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: var(--sp-3); min-inline-size: 0; }
.brand-mark { inline-size: 40px; block-size: 40px; flex: none; }
.mark-base { fill: var(--mark-base); }
.mark-cut { fill: var(--mark-cut); }
.brand-text { min-inline-size: 0; }
.brand-name { font-size: var(--fs-xl); line-height: 1.2; }
.brand-sub { margin-block-start: 2px; font-size: var(--fs-xs); color: var(--ink2); }

.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); }

#btn-theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] #btn-theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] #btn-theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #btn-theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) #btn-theme-toggle .icon-moon { display: none; }
}

/* Phones: header actions become one row of 44px icon buttons; "링크 복사" keeps its label. */
@media (max-width: 639.98px) {
  .app-header { padding: var(--sp-3); }
  .brand-name { font-size: var(--fs-lg); }
  .header-actions { inline-size: 100%; justify-content: space-between; gap: 2px; }
  .header-actions .btn { padding: 0; min-inline-size: var(--tap); }
  .header-actions .btn:not(#btn-share) .btn-label {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  #btn-share { padding: 0 0.8rem; }
}

/* ===== layout ========================================================== */
.app-layout {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  max-inline-size: 1600px;
  margin-inline: auto;
  padding: var(--sp-4);
}

.side-col, .main-col {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-inline-size: 0;
}
.main-col:focus { outline: none; }

@media (min-width: 900px) {
  .app-layout {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    align-items: start;
    gap: var(--sp-5);
    padding: var(--sp-5);
  }
  .side-col {
    position: sticky;
    inset-block-start: var(--sp-4);
    max-block-size: calc(100dvh - 2 * var(--sp-4));
    overflow-y: auto;
    /* no overscroll containment: at the top of the page the column's tail sits below the fold,
       and the wheel must be able to chain to the page to bring it into view */
    scrollbar-width: thin;
    scrollbar-gutter: stable;
    padding-inline-end: var(--sp-1);
  }
  .main-col { gap: var(--sp-4); }
}

@media (max-width: 899.98px) {
  .app-layout { padding: var(--sp-3); gap: var(--sp-3); }
}

/* ===== cards and phone step headings ================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--sp-4);
}
.card-title { font-size: var(--fs-lg); line-height: 1.3; }
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-block-end: var(--sp-3);
}

.m-step {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-block-start: var(--sp-3);
  font-size: var(--fs-lg);
  color: var(--brand);
}
.m-step:first-child { margin-block-start: var(--sp-1); }
.m-step-num { color: var(--accent-ink); font-size: 1.15em; line-height: 1; }
@media (min-width: 900px) {
  /* ①-④ guide only the phone scroll */
  .m-step, #btn-open-settings { display: none; }
}

/* ===== core card ======================================================= */
.scale-badge {
  padding: 0.15rem 0.55rem;
  border-radius: var(--r-pill);
  background: var(--brand-soft);
  color: var(--brand);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}

.core-fields { display: flex; flex-direction: column; gap: var(--sp-4); }
.core-slot:empty { display: none; }

.quick-chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); align-items: center; }
.core-fields > .quick-chips { margin-block-start: calc(-1 * var(--sp-2)); }

.chip-btn {
  min-block-size: var(--tap);
  padding: 0 0.7rem;
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 650;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink2);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chip-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.chip-btn.is-active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

.preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-block-start: var(--sp-4);
  padding-block-start: var(--sp-3);
  border-block-start: 1px dashed var(--line);
}
.preset-label { font-size: var(--fs-xs); font-weight: 700; color: var(--ink2); }
.preset-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-1); flex: 1 1 15rem; }
.btn-seg { flex-direction: column; gap: 0; padding: 0.3rem 0.4rem; font-size: var(--fs-sm); white-space: normal; line-height: 1.15; }
.btn-seg small { font-size: var(--fs-2xs); }

.btn-settings {
  justify-content: flex-start;
  inline-size: 100%;
  min-block-size: 52px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-lg);
  font-size: var(--fs-md);
  font-weight: 750;
  box-shadow: var(--shadow);
}
.btn-settings .icon-end { margin-inline-start: auto; rotate: -90deg; }

/* ===== field: slider + number pair (rendered by app.js) ================ */
.field-group, .field { display: flex; flex-direction: column; gap: var(--sp-1); }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.field-head label, .field-label { font-size: var(--fs-sm); font-weight: 650; color: var(--ink); }
.field-val { font-size: var(--fs-sm); font-weight: 800; color: var(--brand); white-space: nowrap; }
.field-hint { font-size: var(--fs-xs); color: var(--ink3); line-height: 1.45; }
.delta-note { font-size: var(--fs-2xs); font-weight: 700; color: var(--accent-ink); white-space: nowrap; }

.slider-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3); }
.range-wrap { position: relative; }
.range-wrap > input[type="range"] { position: relative; z-index: 1; }
/* default-value tick: app.js sets --def-n (0..1) on .range-wrap */
.def-tick {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: calc(11px + (100% - 22px) * var(--def-n, 0));
  inline-size: 2px;
  block-size: 16px;
  translate: -1px -50%;
  border-radius: 1px;
  background: var(--accent);
  pointer-events: none;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  inline-size: 100%;
  block-size: var(--tap);
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}
/* app.js may set --fill (e.g. "40%") for the filled part of the track in WebKit/Blink */
input[type="range"]::-webkit-slider-runnable-track {
  block-size: 6px;
  border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--brand) 0 var(--fill, 0%), var(--muted) var(--fill, 0%) 100%);
}
input[type="range"]::-moz-range-track { block-size: 6px; border-radius: var(--r-pill); background: var(--muted); }
input[type="range"]::-moz-range-progress { block-size: 6px; border-radius: var(--r-pill); background: var(--brand); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  inline-size: 22px;
  block-size: 22px;
  margin-block-start: -8px;
  border-radius: 50%;
  border: 2px solid var(--brand);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
  inline-size: 22px;
  block-size: 22px;
  border-radius: 50%;
  border: 2px solid var(--brand);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--brand); outline-offset: 2px; }
input[type="range"]:focus-visible::-moz-range-thumb { outline: 2px solid var(--brand); outline-offset: 2px; }

.num-box {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--soft);
}
.num-box:focus-within { border-color: var(--brand); outline: 2px solid var(--brand); outline-offset: 1px; }
.num-box input {
  inline-size: 5.2rem;
  min-block-size: var(--tap);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 800;
  text-align: right;
}
.num-box input:focus { outline: none; }
.num-box .unit, .num-box span { font-size: var(--fs-xs); font-weight: 650; color: var(--ink2); white-space: nowrap; }

.revert-btn {
  display: inline-grid;
  place-items: center;
  inline-size: var(--tap);
  block-size: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink2);
  cursor: pointer;
}
.revert-btn:hover { background: var(--soft); color: var(--ink); }
.revert-btn .icon { inline-size: 16px; block-size: 16px; }

/* ===== variable panel: value chips by group (rendered by app.js) ======= */
.var-home { display: flex; flex-direction: column; gap: var(--sp-2); }
.var-home-head { padding-inline: var(--sp-1); }
.var-home-hint { margin-block-start: 2px; font-size: var(--fs-xs); color: var(--ink2); }
.var-panel { display: flex; flex-direction: column; gap: var(--sp-3); }
@media (max-width: 899.98px) {
  /* #var-panel lives in #settings-drawer on phones (app.js moves the node there and back). */
  .var-home { display: none; }
}

.var-group {
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.var-group.is-policy { background: var(--policy); }
.var-group-head { display: flex; align-items: center; gap: var(--sp-2); margin-block-end: var(--sp-2); }
.var-group-title { font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: 800; }
.var-count {
  min-inline-size: 1.4rem;
  padding: 0 0.4rem;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-2xs);
  font-weight: 800;
  line-height: 1.4rem;
  text-align: center;
}
.var-count:empty, .var-count[data-n="0"] { display: none; }
.var-group-actions { margin-inline-start: auto; display: flex; gap: var(--sp-1); }
.var-group-actions .btn { padding: 0 0.55rem; font-size: var(--fs-2xs); }

.chip-list { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-inline-size: 100%;
  min-block-size: var(--tap);
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-xs);
  line-height: 1.3;
  text-align: start;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip:hover { border-color: var(--line-strong); }
.chip-name { color: var(--ink2); font-weight: 600; overflow-wrap: anywhere; }
.chip-val { font-weight: 800; white-space: nowrap; }
.chip.is-changed { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: var(--accent-soft); }
.chip.is-changed .chip-val { color: var(--accent-ink); }
.chip.is-changed::before {
  content: "";
  inline-size: 6px;
  block-size: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.chip[aria-expanded="true"] { border-color: var(--brand); background: var(--brand-soft); }
.chip input[type="checkbox"], .chip input[type="radio"] { inline-size: 16px; block-size: 16px; margin: 0; accent-color: var(--brand); flex: none; }
.chip:has(input:checked) { border-color: var(--brand); }
/* switch chips: the ring goes on the whole chip, not on the small native checkbox */
.chip:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.chip input:focus-visible { outline: none; }

.chip-editor {
  flex: 1 0 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.var-group.is-policy .chip-editor { background: var(--surface); }

/* radio/checkbox rows inside editors (legacy .choice-item, kept for the patient tab too) */
.radio-stack, .check-grid { display: grid; gap: var(--sp-1); }
.check-grid.two-col { grid-template-columns: 1fr 1fr; }
.choice-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  min-block-size: var(--tap);
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.4;
  cursor: pointer;
}
.choice-item:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice-item input { flex: none; margin: 0.15rem 0 0; inline-size: 16px; block-size: 16px; accent-color: var(--brand); }

/* ===== KPI strip ======================================================= */
.kpi-strip { display: flex; flex-direction: column; gap: var(--sp-3); container-type: inline-size; }
.kpi-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-3); }
.kpi-tag {
  margin-inline-start: 0.3rem;
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--ink2);
  white-space: nowrap;
}

.segmented-radios {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0;
  padding: 3px;
  min-inline-size: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--soft);
}
.segmented-radios label {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-block-size: var(--tap);
  padding: 0.2rem 0.7rem;
  border-radius: var(--r-sm);
  color: var(--ink2);
  font-size: var(--fs-xs);
  font-weight: 650;
  line-height: 1.25;
  cursor: pointer;
}
.segmented-radios label span { display: inline-flex; flex-direction: column; }
.segmented-radios label small { font-size: var(--fs-2xs); font-weight: 550; }
.segmented-radios label:has(input:checked) { background: var(--surface); color: var(--brand); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.segmented-radios label:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 1px; }
.segmented-radios input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
}
.metric-switch { padding: 3px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); }
.kpi-tile {
  min-inline-size: 0;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
}
.kpi-tile.is-loss { background: var(--loss-soft); border-color: color-mix(in srgb, var(--loss) 30%, transparent); }
.kpi-tile.is-gain { background: var(--gain-soft); border-color: color-mix(in srgb, var(--gain) 30%, transparent); }
.kt-label { font-size: var(--fs-xs); font-weight: 650; color: var(--ink2); }
.kt-val {
  margin-block-start: 0.2rem;
  font-family: var(--font-serif);
  /* never wraps, so it scales with the KPI strip (the query container): 4 columns here */
  font-size: clamp(1.05rem, 2.6cqi, var(--fs-kpi));
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: color var(--dur) var(--ease);
}
.kpi-tile.is-loss .kt-val { color: var(--loss-ink); }
.kpi-tile.is-gain .kt-val { color: var(--gain-ink); }
.kt-sub { margin-block-start: 0.15rem; font-size: var(--fs-2xs); color: var(--ink3); line-height: 1.4; }

@container (max-width: 820px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kt-val { font-size: clamp(1.05rem, 4.6cqi, var(--fs-kpi)); }
}
@container (max-width: 460px) {
  /* phone: the month change leads, full width and large */
  #tile-month-diff { grid-column: 1 / -1; order: -1; }
  #tile-year-diff { grid-column: 1 / -1; }
  .kpi-tile .kt-val { font-size: clamp(1rem, 5.2cqi, 1.3rem); }
  #tile-month-diff .kt-val { font-size: clamp(1.6rem, 8cqi, 2.2rem); }
}
@container (max-width: 290px) {
  /* very narrow phones (~320px): one tile per row so "−4억 7,948만원" never spills */
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
}

.kpi-after {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-4);
  padding: 0.6rem 0.85rem;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: var(--r-md);
  background: var(--accent-soft);
  font-size: var(--fs-sm);
}
.kpi-after .icon { color: var(--accent-ink); }
.kpi-after strong { font-family: var(--font-serif); font-size: var(--fs-lg); white-space: nowrap; }

.cohort-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  padding-block-start: var(--sp-2);
  border-block-start: 1px dashed var(--line);
  font-size: var(--fs-xs);
  color: var(--ink2);
}
.cohort-line strong { color: var(--ink); font-weight: 750; white-space: nowrap; }

.warn-banner {
  padding: 0.5rem 0.75rem;
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-xs);
  font-weight: 650;
}

/* ===== tabs, panels, phone folds ======================================= */
.tabs-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: clip;
}
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: var(--sp-2);
  border-block-end: 1px solid var(--line);
  background: var(--soft);
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-block-size: var(--tap);
  padding: 0 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.tab-btn:hover { color: var(--ink); background: var(--muted); }
.tab-btn[aria-expanded="true"] {
  background: var(--surface);
  border-color: var(--line);
  color: var(--brand);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.tab-btn-key .icon { color: var(--accent-ink); }

/* Panels carry no box of their own so a hidden="until-found" panel collapses to nothing. */
.tab-panel { min-inline-size: 0; }
/* Without hidden="until-found" support app.js marks the other panels .is-inactive instead.
   Desktop screens only: phones read every panel, and print.css prints every panel. */
@media screen and (min-width: 900px) {
  .tab-panel.is-inactive { display: none; }
}
.tab-panel-inner { display: flex; flex-direction: column; gap: var(--sp-6); padding: var(--sp-5); min-inline-size: 0; }
.tab-panel-inner > * { min-inline-size: 0; }
.domain-main { gap: var(--sp-6); }

.m-fold > .m-fold-sum { display: none; }
.m-fold-sum {
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-block-size: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-md);
  font-weight: 800;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.m-fold-sum::-webkit-details-marker { display: none; }
.m-fold-sum .icon { color: var(--ink2); transition: rotate var(--dur) var(--ease); }
.m-fold[open] > .m-fold-sum .icon { rotate: 180deg; }

@media (min-width: 900px) {
  /* folds are always open on desktop; a fold left closed from the phone layout can still be reopened */
  .m-fold:not([open]) > .m-fold-sum { display: flex; }
  .plan-detail > .m-fold-sum { display: none; }
  .plan-detail:not([open]) > .m-fold-sum { display: flex; }
}

@media (max-width: 899.98px) {
  .tab-bar { display: none; }
  .tabs-card { display: flex; flex-direction: column; gap: var(--sp-3); background: none; border: 0; box-shadow: none; overflow: visible; }
  /* phones read every panel in one scroll */
  .tab-panel, .tab-panel[hidden] { display: block; content-visibility: visible; }
  .tab-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    overflow: clip;
  }
  .m-fold > .m-fold-sum { display: flex; }
  .m-fold[open] > .m-fold-sum { border-block-end: 1px solid var(--line); }
  .tab-panel-inner { padding: var(--sp-4) var(--sp-3); gap: var(--sp-5); }
  .plan-detail { margin-inline: calc(-1 * var(--sp-3)); border-block-start: 1px solid var(--line); }
  .plan-detail[open] > .m-fold-sum { border-block-end: 1px solid var(--line); }
  .plan-detail-body { padding: var(--sp-4) var(--sp-3) 0; }
}

/* ===== result components (legacy render markup, restyled) ============== */
.section-h3 {
  margin: 0 0 var(--sp-3);
  font-size: var(--fs-md);
  font-weight: 800;
  line-height: 1.4;
}
/* title + hint/button pairs sit on one line; plain titles with inline values stay as text */
.section-h3:has(> .field-hint, > .btn) {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-1) var(--sp-3);
}
.section-h3 .field-hint { font-weight: 500; }
.section-desc { max-inline-size: 75ch; margin: 0 0 var(--sp-3); font-size: var(--fs-sm); color: var(--ink2); }

.txt-gain { color: var(--gain-ink); }
.txt-loss { color: var(--loss-ink); }
.txt-brand { color: var(--brand); }

.modality-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-2); }
.mod-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
}
/* the share pill drops under a long title instead of squeezing it to three lines */
.mod-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-1); }
.mod-title { font-size: var(--fs-sm); font-weight: 800; }
.mod-share {
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink2);
  font-size: var(--fs-2xs);
  font-weight: 700;
  white-space: nowrap;
}
.mod-vals { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-1); font-size: var(--fs-xs); color: var(--ink2); }
.mod-vals strong { font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 700; color: var(--ink); white-space: nowrap; }
.mod-bar-track { block-size: 6px; border-radius: var(--r-pill); background: var(--muted); overflow: clip; }
.mod-bar-fill { block-size: 100%; inline-size: var(--mod-pct, 0%); border-radius: var(--r-pill); background: var(--mod-color, var(--brand)); transition: inline-size var(--dur) var(--ease); }
.mod-foot { display: flex; justify-content: space-between; gap: var(--sp-1); font-size: var(--fs-xs); font-weight: 700; }
.mod-count { color: var(--ink3); }

.waterfall-list { display: flex; flex-direction: column; gap: var(--sp-1); container-type: inline-size; }
.wf-row {
  display: grid;
  grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) 8.5rem;
  align-items: center;
  gap: var(--sp-3);
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-md);
  background: var(--bg);
  font-size: var(--fs-sm);
}
.wf-label { min-inline-size: 0; font-weight: 700; }
.wf-label small { display: block; font-size: var(--fs-2xs); font-weight: 500; color: var(--ink3); }
.wf-track { position: relative; block-size: 1.1rem; border-radius: var(--r-sm); background: var(--muted); overflow: clip; }
.wf-zero { position: absolute; inset-block: 0; inset-inline-start: 50%; inline-size: 1px; background: var(--ink2); opacity: 0.5; }
.wf-fill {
  position: absolute;
  inset-block: 2px;
  inset-inline-start: var(--wf-start, 50%);
  inline-size: var(--wf-width, 0%);
  border-radius: 3px;
  transition: inline-size var(--dur) var(--ease), inset-inline-start var(--dur) var(--ease);
}
.wf-fill.pos { background: var(--gain); }
.wf-fill.neg { background: var(--loss); }
.wf-delta { text-align: end; font-weight: 750; white-space: nowrap; }
/* rows follow their list's width (summary and planner), not the viewport: the results
   column is only ~440-640px wide between 900 and 1100px viewports */
@container (max-width: 640px) {
  .wf-row { grid-template-columns: minmax(0, 1fr) auto; }
  .wf-track { grid-column: 1 / -1; grid-row: 2; }
}

.range-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--sp-2); }
.rc-item { padding: 0.75rem 0.9rem; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); font-size: var(--fs-sm); }
.rc-head { display: flex; justify-content: space-between; gap: var(--sp-2); margin-block-end: 0.25rem; font-weight: 750; }
.rc-head > span:last-child { white-space: nowrap; }
.rc-nums { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 var(--sp-2); color: var(--ink2); font-size: var(--fs-xs); white-space: nowrap; }

.mini-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-2); }
.mini-kpi { min-inline-size: 0; padding: 0.75rem 0.85rem; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.mk-label { font-size: var(--fs-xs); font-weight: 700; color: var(--ink2); }
.mk-val { margin-block-start: 0.2rem; font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 700; line-height: 1.25; }
.mk-sub { margin-block-start: 0.15rem; font-size: var(--fs-2xs); color: var(--ink3); line-height: 1.4; }

.badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: var(--r-sm); font-size: var(--fs-2xs); font-weight: 700; white-space: nowrap; }
.badge-cut { background: var(--loss-soft); color: var(--loss-ink); }
.badge-keep { background: var(--soft); color: var(--ink2); }
.badge-up { background: var(--gain-soft); color: var(--gain-ink); }

/* tables: wide ones scroll inside their own container; number columns never wrap */
.table-scroller {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
table.data-table { inline-size: 100%; min-inline-size: 700px; border-collapse: collapse; font-size: var(--fs-xs); }
table.data-table th, table.data-table td {
  padding: 0.5rem 0.65rem;
  border-block-end: 1px solid var(--line);
  text-align: end;
  vertical-align: middle;
}
table.data-table th:first-child, table.data-table td:first-child,
table.data-table th.align-left, table.data-table td.align-left { text-align: start; }
table.data-table td:not(:first-child):not(.align-left) { white-space: nowrap; }
table.data-table thead th {
  background: var(--soft);
  color: var(--ink2);
  font-size: var(--fs-2xs);
  font-weight: 750;
  white-space: nowrap;
}
table.data-table tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 55%, transparent); }
table.data-table tbody tr.group-header-row td {
  border-block-start: 2px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 800;
}
table.data-table tbody tr.sub-item-row td:first-child { padding-inline-start: 1.3rem; color: var(--ink2); }
table.data-table tfoot td { border-block-end: 0; background: var(--soft); font-size: var(--fs-sm); font-weight: 800; }
table.data-table .row-highlight, table.data-table tr.row-highlight td { background: var(--brand-soft); font-weight: 700; }
tr.is-selected-case td { background: var(--brand-soft) !important; }
table.data-table.plan-solve-table { min-inline-size: 520px; } /* beats the 700px data-table floor */

.chart-box { padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); margin-block-end: var(--sp-2); font-size: var(--fs-xs); font-weight: 650; color: var(--ink2); }
.legend-dot { display: inline-block; inline-size: 0.65rem; block-size: 0.65rem; margin-inline-end: 0.3rem; border-radius: 50%; vertical-align: middle; }
.legend-dot.dot-26 { background: var(--series-26); }
.legend-dot.dot-27 { background: var(--series-27); }
.legend-dot.dot-diff { background: var(--series-diff); }
/* tabs.js draws the curve in CSS pixels (viewBox width = rendered width), so its 11-unit axis
   text is 11px on screen; under 560px the chart keeps that width and scrolls sideways */
.chart-scroller { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
svg.scale-svg { display: block; inline-size: 100%; min-inline-size: 560px; block-size: auto; max-block-size: 300px; color: var(--ink2); }
/* series hooks for the scaling chart (app.js: class="s-26|s-27|s-diff") */
.scale-svg .s-26 { stroke: var(--series-26); }
.scale-svg .s-27 { stroke: var(--series-27); }
.scale-svg .s-diff { stroke: var(--series-diff); }
.scale-svg circle.s-26 { fill: var(--series-26); stroke: none; }
.scale-svg circle.s-27 { fill: var(--series-27); stroke: var(--surface); }
.scale-svg circle.s-diff { fill: var(--series-diff); stroke: none; }
.be-title { margin-block-end: 0.35rem; font-size: var(--fs-md); font-weight: 800; }
.be-body { font-size: var(--fs-sm); color: var(--ink2); line-height: 1.65; }

details.sub-disclosure { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: clip; }
details.sub-disclosure > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-block-size: var(--tap);
  padding: 0.55rem 0.8rem;
  font-size: var(--fs-sm);
  font-weight: 700;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
details.sub-disclosure > summary::-webkit-details-marker { display: none; }
/* Lucide chevron-down as a mask, so no text glyph is needed */
details.sub-disclosure > summary::after {
  content: "";
  flex: none;
  inline-size: 18px;
  block-size: 18px;
  background: var(--ink2);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: rotate var(--dur) var(--ease);
}
details.sub-disclosure[open] > summary { border-block-end: 1px solid var(--line); background: var(--soft); }
details.sub-disclosure[open] > summary::after { rotate: 180deg; }
.sub-disclosure-body { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-3); }

/* patient tab (legacy markup kept verbatim) */
.reconcile-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-1) var(--sp-3);
  padding: 0.65rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--gain) 35%, transparent);
  border-radius: var(--r-md);
  background: var(--gain-soft);
  color: var(--gain-ink);
  font-size: var(--fs-sm);
  font-weight: 750;
}
.receipt-inspector { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg); }
.receipt-chip-bar { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.receipt-chip {
  min-block-size: var(--tap);
  padding: 0.35rem 0.7rem; /* long type names wrap to two lines on phones */
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink2);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
}
.receipt-chip:hover { color: var(--ink); border-color: var(--line-strong); }
.receipt-chip.is-active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.case-filter-bar { display: flex; flex-direction: column; gap: var(--sp-2); margin-block-end: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.case-filter-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.search-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-inline-size: 0;
  padding: 0 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.search-input-wrap:focus-within { border-color: var(--brand); outline: 2px solid var(--brand); outline-offset: 1px; }
.search-input-wrap label { font-size: var(--fs-xs); font-weight: 700; color: var(--ink2); white-space: nowrap; }
.search-input-wrap input[type="search"] { min-inline-size: 0; inline-size: 14rem; max-inline-size: 100%; min-block-size: var(--tap); border: 0; background: transparent; color: var(--ink); font: inherit; font-size: var(--fs-sm); }
.search-input-wrap input[type="search"]:focus { outline: none; }

.user-type-badge, .ext-type-badge {
  display: inline-flex;
  align-items: center;
  margin-inline-end: 0.35rem;
  padding: 0.08rem 0.42rem;
  border-radius: var(--r-sm);
  font-size: var(--fs-2xs);
  font-weight: 800;
  vertical-align: middle;
  white-space: nowrap;
}
.user-type-badge { background: var(--brand); color: var(--on-brand); }
.ext-type-badge { background: var(--soft); color: var(--ink2); font-weight: 700; }
.case-row-btn { inline-size: 100%; min-block-size: var(--tap); padding: 0; border: 0; background: transparent; color: inherit; font: inherit; line-height: 1.4; text-align: start; cursor: pointer; }
.case-row-btn:hover strong { color: var(--brand); text-decoration: underline; }
/* type-summary column: without a floor it shrinks to one syllable per line beside the nowrap number columns */
.case-row-btn[data-type-n] { min-inline-size: 9.5rem; }

/* Phones: the 23-type summary becomes a card list (spec 5.5). Each row is a card: name and
   definition, then the cells with their column name (data-label from tabs.js), three to a
   line as ’26 · ’27 · 증감. Screens only, so print keeps the table. */
@media screen and (max-width: 639.98px) {
  .type-summary-scroller { overflow: visible; border: 0; border-radius: 0; background: none; }
  table.data-table.type-summary-table { display: block; min-inline-size: 0; }
  table.data-table.type-summary-table thead { display: none; }
  table.data-table.type-summary-table :is(tbody, tfoot) { display: flex; flex-direction: column; gap: var(--sp-2); }
  table.data-table.type-summary-table tfoot { margin-block-start: var(--sp-2); }
  table.data-table.type-summary-table tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--sp-2);
    padding: var(--sp-3);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
  }
  table.data-table.type-summary-table tr:not(.sub-item-row) { border-color: var(--line-strong); background: var(--soft); }
  table.data-table.type-summary-table tbody tr.group-header-row:not(:first-child) { margin-block-start: var(--sp-3); }
  table.data-table.type-summary-table tr.is-selected-case { border-color: var(--brand); background: var(--brand-soft); }
  table.data-table.type-summary-table :is(tbody, tfoot) tr td,
  table.data-table.type-summary-table tbody tr:hover td {
    display: block;
    min-inline-size: 0;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: start;
  }
  /* (0,3,3): beats the nowrap rule for number cells, so a long cell wraps between words */
  table.data-table.type-summary-table tr td:not(.align-left) { white-space: normal; }
  table.data-table.type-summary-table tbody tr.sub-item-row td:first-child { padding: 0; color: inherit; }
  table.data-table.type-summary-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-block-end: 2px;
    font-size: var(--fs-2xs);
    font-weight: 700;
    color: var(--ink2);
  }
  /* type cards: name, definition, [월 인원 (2 columns) | 유형 평균 1인 ’27],
     월 매출 ’26 · ’27 · 증감, 대표 1인 ’26 · ’27 · 증감 */
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(-n+2) { grid-column: 1 / -1; }
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(2) { color: var(--ink2); }
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(3) { order: 1; grid-column: span 2; }
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(7) { order: 2; }
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(n+8) { order: 3; }
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(n+4):nth-child(-n+6) { order: 4; }
  table.data-table.type-summary-table tr.sub-item-row > td:nth-child(10) { font-size: var(--fs-sm); font-weight: 800; }
  table.data-table.type-summary-table .case-row-btn strong { font-size: var(--fs-sm); }
  /* subtotal and total cards, same grid: label, [월 인원 (2 columns) | 유형 평균 1인 ’27],
     월 매출 ’26 · ’27 · 증감, then the 평균 1인 ’26 → ’27 line */
  table.data-table.type-summary-table tr:not(.sub-item-row) > td { font-size: var(--fs-xs); }
  table.data-table.type-summary-table tr:not(.sub-item-row) > td:first-child { grid-column: 1 / -1; font-size: var(--fs-sm); }
  table.data-table.type-summary-table tr:not(.sub-item-row) > td:nth-child(2) { order: 1; grid-column: span 2; }
  table.data-table.type-summary-table tr:not(.sub-item-row) > td:nth-child(4) { order: 2; }
  table.data-table.type-summary-table tr:not(.sub-item-row) > td:nth-child(n+5) { order: 3; }
  table.data-table.type-summary-table tr:not(.sub-item-row) > td:nth-child(3) { order: 4; grid-column: 1 / -1; color: var(--ink2); }
}
/* 320px screens: a little more room per column so 7-digit amounts stay on one line */
@media screen and (max-width: 359.98px) {
  table.data-table.type-summary-table tr { padding-inline: var(--sp-2); }
}

.custom-builder-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--sp-3); }
fieldset { min-inline-size: 0; margin: 0; padding: 0; border: 0; }
.builder-box { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
legend.sr-legend { margin-block-end: var(--sp-1); padding: 0; font-size: var(--fs-xs); font-weight: 700; color: var(--ink2); }
.inline-num-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: 0.35rem 0.6rem; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.inline-num-row label { font-size: var(--fs-sm); font-weight: 600; }
.inline-num-row input[type="number"] {
  inline-size: 6rem;
  min-block-size: var(--tap);
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 750;
  text-align: end;
}
.builder-result-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--brand); border-radius: var(--r-md); background: var(--brand-soft); }
.builder-result-nums { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-5); font-size: var(--fs-sm); font-weight: 750; }

/* ===== planner (rendered by app.js) ==================================== */
.plan-intro .section-h3 { align-items: center; }
.plan-intro .section-desc { margin-block-end: 0; }
.plan-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-2); }
.plan-kpis:empty, .plan-levers:empty, .plan-waterfall:empty { display: none; }
.plan-levers { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--sp-3) var(--sp-4); }
.lever { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
.lever.is-active { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: var(--accent-soft); }
.lever-gain { font-size: var(--fs-xs); font-weight: 750; white-space: nowrap; }

/* coverage bar: app.js sets --cover (0%..100%+) */
.cover-bar { display: flex; flex-direction: column; gap: var(--sp-1); grid-column: 1 / -1; }
.cover-track { position: relative; block-size: 14px; border-radius: var(--r-pill); background: var(--muted); overflow: clip; }
.cover-fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  inline-size: min(100%, var(--cover, 0%));
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: inline-size var(--dur) var(--ease);
}
.cover-bar.is-met .cover-fill { background: var(--gain); }
.cover-label { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--ink2); }
.cover-label strong { color: var(--ink); white-space: nowrap; }

/* #plan-note: app.js status text (empty until written). .plan-disclaimer: fixed cost caveat. */
.plan-note { font-size: var(--fs-sm); color: var(--ink2); }
.plan-note:empty { display: none; }
.plan-disclaimer { display: flex; align-items: flex-start; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--ink2); }
.plan-disclaimer .icon { margin-block-start: 1px; color: var(--ink2); }
.plan-detail-body { display: flex; flex-direction: column; gap: var(--sp-6); }
.plan-waterfall { display: flex; flex-direction: column; gap: var(--sp-1); container-type: inline-size; }

/* lever cards and contribution rows (Task 9; rows reuse the summary .wf-row styles) */
.lever .field-head { align-items: center; }
.lever-gain:empty { display: none; }
.plan-waterfall .wf-zero { inline-size: 2px; translate: -1px 0; background: var(--accent-ink); opacity: 0.8; }
.wf-fill.level { background: var(--ink2); }
.wf-fill.gap { background: transparent; border: 2px dashed var(--loss); }
.wf-fill.gap.is-over { border-color: var(--gain); }
/* lever track fill runs from Δ = 0 to the thumb (app.js sets --fill-a / --fill-b), so a
   lever that can go negative shows no fill at 0 */
.lever input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(to right, var(--muted) 0 var(--fill-a, 0%), var(--brand) var(--fill-a, 0%) var(--fill-b, 0%), var(--muted) var(--fill-b, 0%) 100%);
}
/* Firefox: the same gradient on the track; its native progress bar would start at min */
.lever input[type="range"]::-moz-range-track {
  background: linear-gradient(to right, var(--muted) 0 var(--fill-a, 0%), var(--brand) var(--fill-a, 0%) var(--fill-b, 0%), var(--muted) var(--fill-b, 0%) 100%);
}
.lever input[type="range"]::-moz-range-progress { background: transparent; }
.plan-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 899.98px) {
  .plan-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-kpis > [data-pk="gap"] { grid-column: 1 / -1; }
}

/* patients: the count table has its own fold below the case-structure fold */
details.sub-disclosure + details.sub-disclosure { margin-block-start: var(--sp-3); }
.sub-disclosure-body > .case-filter-bar { margin-block-end: 0; }

/* ===== dialogs ========================================================= */
dialog {
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  inline-size: min(720px, calc(100vw - 2rem));
  max-inline-size: calc(100vw - 2rem);
  max-block-size: min(86dvh, 920px);
}
dialog[open] { display: flex; flex-direction: column; animation: dialog-in var(--dur) var(--ease); }
dialog::backdrop { background: rgba(24, 18, 8, 0.45); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-5);
  border-block-end: 1px solid var(--line);
}
.dialog-body { flex: 1 1 auto; min-block-size: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-4) var(--sp-5) var(--sp-5); }

.drawer[open] { inline-size: min(560px, calc(100vw - 2rem)); }
.drawer-body { padding: var(--sp-3); background: var(--bg); }
@media (max-width: 899.98px) {
  /* bottom sheet */
  .drawer[open] {
    inline-size: 100%;
    max-inline-size: 100%;
    max-block-size: 88dvh;
    margin: auto 0 0;
    border-block-end: 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    animation-name: sheet-in;
  }
  .drawer-body { padding-block-end: max(var(--sp-4), env(safe-area-inset-bottom)); }
}
/* share fallback (app.js creates it when the clipboard is unavailable) */
.share-dialog[open] { inline-size: min(560px, calc(100vw - 2rem)); }
.share-note { margin-block-end: var(--sp-3); font-size: var(--fs-sm); color: var(--ink2); }
.share-url-field {
  inline-size: 100%;
  min-block-size: var(--tap);
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-sm);
}
.share-url-field:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
@keyframes dialog-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
@keyframes sheet-in { from { translate: 0 100%; } to { translate: 0 0; } }

.ev-section + .ev-section { margin-block-start: var(--sp-5); }
.ev-title { margin-block-end: var(--sp-2); font-size: var(--fs-md); font-weight: 800; color: var(--brand); }
.ev-note { margin-block-end: var(--sp-2); font-size: var(--fs-xs); color: var(--ink2); }
.ev-list { display: flex; flex-direction: column; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.ev-list li { display: flex; flex-direction: column; padding: 0.6rem 0.8rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); font-size: var(--fs-sm); }
.ev-list li span { font-size: var(--fs-xs); color: var(--ink2); }
.ev-defs { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: var(--sp-2) var(--sp-4); margin: 0; font-size: var(--fs-sm); }
.ev-defs dt { font-weight: 800; }
.ev-defs dd { margin: 0; color: var(--ink2); line-height: 1.6; }
.ev-defs dd strong { color: var(--ink); }
@media (max-width: 560px) {
  .ev-defs { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .ev-defs dd { margin-block-end: var(--sp-3); }
  .dialog-head { padding-inline-start: var(--sp-4); }
  .dialog-body { padding-inline: var(--sp-4); }
}

/* ===== footer, toast =================================================== */
.site-footer {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-inline-size: 1600px;
  margin: var(--sp-4) auto 0;
  padding: var(--sp-4) var(--sp-4) var(--sp-8);
  border-block-start: 1px solid var(--line);
  font-size: var(--fs-xs);
  color: var(--ink2);
}
@media (min-width: 900px) { .site-footer { padding-inline: var(--sp-5); } }
.site-footer p { max-inline-size: 75ch; }

.toast {
  position: fixed;
  inset-inline: 0;
  inset-block-end: max(var(--sp-5), env(safe-area-inset-bottom));
  z-index: 50;
  inline-size: max-content;
  max-inline-size: calc(100vw - 2rem);
  margin-inline: auto;
  padding: 0.65rem 1rem;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--fs-sm);
  font-weight: 650;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  translate: 0 8px;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), translate var(--dur) var(--ease);
}
.toast.is-shown { opacity: 1; translate: 0 0; }

/* ===== density (must stay after the component rules) =================== */
@media (min-width: 900px) and (pointer: fine) and (not (any-pointer: coarse)) {
  /* denser controls with a mouse on a wide screen; phones, tablets and touch-screen
     laptops (any coarse pointer) keep 44px targets */
  .chip { min-block-size: 34px; }
  .revert-btn { inline-size: 32px; block-size: 32px; }
  .var-group-actions .btn, .btn-sm { min-block-size: 34px; }
  .receipt-chip { min-block-size: 36px; }
  .case-row-btn { min-block-size: 32px; }
  .segmented-radios label { min-block-size: 38px; }
  .num-box input, .search-input-wrap input[type="search"], .inline-num-row input[type="number"] { min-block-size: 36px; }
}

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

/* ===== app.js generated-control hooks (Task 7) ========================= */
.field-tools { display: inline-flex; align-items: center; gap: var(--sp-1); flex: none; }
.var-group-head { flex-wrap: wrap; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:disabled:hover { background: var(--surface); border-color: var(--line); }
