/* Layout concept: an instrument band (dark KPI strip) above a two-column workbench:
   parameters as a term-sheet ledger on the left, analysis on the right. */

* { box-sizing: border-box; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app { container: app / inline-size; max-width: 1360px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* header */
.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between; }
.top h1 { margin: 0; font-size: 28px; line-height: 1.1; font-weight: 600; letter-spacing: -.02em; text-wrap: balance; }
.top p { margin: 6px 0 0; color: var(--ink2); max-width: 60ch; }
.badge { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 5px 12px; font-size: 12px; color: var(--ink2); }
.badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.presets { display: flex; flex-wrap: nowrap; gap: 8px; align-items: center; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.presets > * { flex: none; }
.presets .lbl, .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 500; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 11px; text-align: left; line-height: 1.2; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip b { font-weight: 600; font-size: 13px; }
.chip span { font-size: 11px; color: var(--ink2); font-family: var(--mono); }
.chip:hover { background: var(--hover); }
.chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip em { font-style: normal; font-size: 10.5px; color: var(--accent-ink); text-transform: uppercase; letter-spacing: .06em; }

/* KPI band */
.band { background: var(--band-bg); color: var(--band-fg); border-radius: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); z-index: 5; }
.band .k { padding: 14px 16px; min-width: 0; border-top: 1px solid var(--band-line); display: flex; flex-direction: column; gap: 3px; }
.band .k:nth-child(-n+2) { border-top: 0; }
.band .k:nth-child(even) { border-left: 1px solid var(--band-line); }
.band .kl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--band-muted); font-weight: 500; }
.band .kv { font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; white-space: nowrap; }
.band .kv small { display: block; font-size: 12px; font-weight: 500; color: var(--band-muted); letter-spacing: 0; margin-top: 2px; }
.band .ks { font-size: 12px; color: var(--band-muted); }
.band .k:last-child { grid-column: 1 / -1; }
.band .kd { font-size: 12px; font-family: var(--mono); min-height: 16px; white-space: nowrap; }
.band .kd i { font-style: normal; margin-right: 4px; }
.band .kd .bad { color: #ff9a6e; font-weight: 500; } .band .kd .good { color: #3fbf5f; font-weight: 500; } .band .kd .eq { color: var(--band-muted); }
.band .hero .kv { font-size: 40px; color: var(--band-accent); }
.band .hero { grid-column: 1 / -1; border-left: 0 !important; }
.band .hero .spark { position: absolute; right: 16px; top: 30px; opacity: .95; }
.band .hero { position: relative; }
.band .hero .ks { max-width: 70%; }

/* toolbar */
.bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.bar .sp { flex: 1; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 500; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.pri:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.note { font-size: 12px; color: var(--ink2); }

/* workbench */
.bench { display: flex; flex-direction: column; gap: 16px; }
.ctrls { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.results { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.grp { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.grp > button { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: baseline; gap: 10px; padding: 12px 14px; cursor: pointer; }
.grp > button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
.grp > button .gt { font-weight: 600; font-size: 14px; flex: none; }
.grp > button .gs { flex: 1; min-width: 0; text-align: right; font-family: var(--mono); font-size: 11.5px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp > button .ch { flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.grp.open > button .ch { transform: rotate(-135deg) translateY(-2px); }
.grp .gb { display: none; padding: 2px 14px 14px; flex-direction: column; gap: 14px; }
.grp.open .gb { display: flex; }

.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ctl-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.ctl-top label, .ctl-top .cl { font-size: 12.5px; color: var(--ink); display: flex; align-items: center; gap: 6px; min-width: 0; }
.help { all: unset; box-sizing: border-box; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--axis); color: var(--muted); font: 600 10px/14px var(--font); text-align: center; cursor: pointer; flex: none; }
.help:hover, .help[aria-expanded="true"] { color: var(--accent-ink); border-color: var(--accent); }
.help:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { margin: 0; font-size: 12px; color: var(--ink2); line-height: 1.4; background: var(--panel); border-radius: 8px; padding: 8px 10px; }
.val { display: flex; align-items: center; gap: 4px; flex: none; }
.val input { width: 74px; text-align: right; border: 1px solid transparent; background: var(--panel); border-radius: 6px; padding: 3px 6px; font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.val input:hover { border-color: var(--axis); }
.val input:disabled { opacity: .5; }
.val .u { font-size: 11px; color: var(--muted); min-width: 20px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0; cursor: pointer; --pct: 50%; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--pct), var(--grid) var(--pct)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--pct), var(--grid) var(--pct)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
input[type=range]:disabled { opacity: .4; cursor: default; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 4px; font-size: 12px; font-weight: 500; color: var(--ink2); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--hover); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.seg button:focus-visible { outline-offset: -2px; }
select, input[type=date] { width: 100%; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 7px 9px; font-size: 13px; }
.sw { all: unset; box-sizing: border-box; width: 34px; height: 20px; border-radius: 10px; background: var(--axis); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.sw[aria-checked="true"] { background: var(--accent); }
.sw[aria-checked="true"]::after { transform: translateX(14px); }
.sw:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.swrow { display: flex; align-items: center; gap: 10px; }
.swrow .cl { flex: 1; font-size: 12.5px; }
.sub { display: flex; flex-direction: column; gap: 10px; padding-left: 12px; border-left: 2px solid var(--grid); }
.kv2 { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink2); }
.kv2 b { font-family: var(--mono); font-weight: 500; color: var(--ink); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 9px 14px; font-size: 13.5px; font-weight: 500; color: var(--ink2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.panel { display: flex; flex-direction: column; gap: 14px; }
.panel[hidden] { display: none; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px 16px; box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.card-h { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: flex-start; justify-content: space-between; }
.card-h h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.005em; }
.card-h p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink2); max-width: 70ch; }
.mini-seg { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; flex: none; }
.mini-seg button { border: 0; background: transparent; padding: 3px 10px; font-size: 11.5px; color: var(--ink2); font-weight: 500; }
.mini-seg button + button { border-left: 1px solid var(--border); }
.mini-seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.plot { position: relative; min-width: 0; }
.plot svg { display: block; width: 100%; overflow: visible; }
.plot svg text { font-family: var(--font); font-size: 11px; fill: var(--ink2); }
.plot svg .mono { font-family: var(--mono); }
.plot svg .strong { fill: var(--ink); font-weight: 600; }
.plot svg .ttl { fill: var(--ink2); font-size: 11px; font-weight: 500; letter-spacing: .02em; }
.plot svg .tick { fill: var(--muted); }
.plot svg .crit { fill: var(--crit-text); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend i.ln { height: 0; width: 16px; border-top: 2px solid; border-radius: 0; }
.legend i.ds { height: 0; width: 16px; border-top: 2px dashed; border-radius: 0; }
.tip { position: absolute; z-index: 6; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.22); padding: 8px 10px; font-size: 12px; min-width: 150px; max-width: 250px; }
.tip .t0 { font-weight: 600; margin-bottom: 4px; display: block; }
.tip .r { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 1px 0; color: var(--ink2); }
.tip .r b { color: var(--ink); font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.tip .r i { display: inline-block; width: 12px; height: 0; border-top: 3px solid; margin-right: 6px; vertical-align: middle; }
.tip .r.tot { border-top: 1px solid var(--grid); margin-top: 3px; padding-top: 4px; }

/* tables */
.tw { overflow: auto; max-width: 100%; border: 1px solid var(--border); border-radius: 8px; }
.tw.tall { max-height: 560px; }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 6px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.t th { position: sticky; top: 0; background: var(--panel); font-family: var(--font); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); font-weight: 500; z-index: 1; border-bottom: 1px solid var(--axis); }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t tbody tr:hover td { background: var(--hover); }
table.t tfoot td { font-weight: 600; background: var(--panel); position: sticky; bottom: 0; border-top: 1px solid var(--axis); }
table.t td.l, table.t th.l { text-align: left; }
.flag { display: inline-block; min-width: 16px; padding: 0 3px; text-align: center; border-radius: 4px; font-size: 10px; font-weight: 600; margin-left: 2px; background: var(--grid); color: var(--ink2); }
.flag.f { background: color-mix(in srgb, var(--s7) 22%, transparent); color: var(--ink); }
.flag.c { background: color-mix(in srgb, var(--s2) 25%, transparent); color: var(--ink); }
.flag.p { background: color-mix(in srgb, var(--s5) 30%, transparent); color: var(--ink); }
.bad { color: var(--crit-text); font-weight: 600; }
.ok { color: var(--good-text); }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 9px; font-size: 11.5px; font-weight: 500; border: 1px solid var(--border); background: var(--surface); }
.pill.bad { border-color: var(--crit); color: var(--crit-text); }
.pill.ok { border-color: var(--good); color: var(--good-text); }

/* composition bar */
.comp { display: flex; height: 26px; gap: 2px; }
.comp > div { min-width: 3px; border-radius: 0; }
.comp > div:first-child { border-radius: 4px 0 0 4px; } .comp > div:last-child { border-radius: 0 4px 4px 0; }
.checks { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.checks div { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; }
.checks b { font-family: var(--mono); font-weight: 500; font-size: 11.5px; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* term sheet */
.ts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px 32px; }
.ts h3 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 500; }
.ts dl { margin: 0; display: grid; grid-template-columns: minmax(96px, 150px) minmax(0, 1fr); gap: 7px 14px; }
.ts dt { color: var(--ink2); font-size: 12.5px; }
.ts dd { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; }
.method { font-size: 12.5px; color: var(--ink2); }
.method summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.method ul { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.foot { font-size: 12px; color: var(--muted); }

@container app (min-width: 640px) {
  .band { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .band .k:nth-child(-n+2) { border-top: 0; }
  .band .k:nth-child(even) { border-left: 0; }
  .band .k { border-top: 1px solid var(--band-line); border-left: 1px solid var(--band-line); }
  .band .k:nth-child(-n+4) { border-top: 0; }
  .band .hero { grid-column: 1 / -1; border-left: 0; }
  .band .k:nth-child(2), .band .k:nth-child(5) { border-left: 0; }
  .band .k:last-child { grid-column: auto; }
  .band .kv small { display: inline; margin: 0 0 0 3px; }
  .grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container app (min-width: 900px) {
  .presets { flex-wrap: wrap; overflow: visible; }
  .band { grid-template-columns: 1.7fr repeat(5, minmax(0, 1fr)); position: sticky; top: 0; box-shadow: 0 8px 20px -10px rgba(0,0,0,.35); }
  .band .k { border-top: 0 !important; border-left: 1px solid var(--band-line) !important; padding: 14px 14px; }
  .band .hero { grid-column: auto; border-left: 0 !important; padding-left: 18px; }
  .band .kv { font-size: 22px; }
  .band .hero .kv { font-size: 34px; }
  .band .hero .ks { max-width: 100%; }
  .band .hero .spark { top: 26px; right: 14px; }
}
@container app (min-width: 1020px) {
  .bench { flex-direction: row; align-items: flex-start; }
  .ctrls { width: 372px; flex: none; position: sticky; top: calc(var(--band-h, 130px) + 12px); max-height: calc(100vh - var(--band-h, 130px) - 28px); overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
  .results { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (forced-colors: active) { .seg button[aria-checked="true"], .mini-seg button[aria-pressed="true"] { outline: 2px solid Highlight; } }

.ctl.ind { padding-left: 12px; border-left: 2px solid var(--grid); }
.ctl[hidden], .grp .gb [hidden] { display: none !important; }
.slot { outline: none; cursor: default; }
.slot:hover .mk, .slot:focus .mk { filter: brightness(1.14); }
.slot:focus-visible .mk { stroke: var(--ink); stroke-width: 1.5; }
.plot svg rect[tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.legend i.hollow { width: 9px; height: 9px; border-radius: 50%; border: 2px solid; background: var(--surface); }
.pill { margin: 0; }
.tw table.t td.bad { color: var(--crit-text); font-weight: 600; }
.tw table.t td.ok { color: var(--good-text); }
.band .hero .kv small { font-size: 16px; }

[hidden] { display: none !important; }
.plot svg .halo { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.band { padding: 0; }
.band .k { padding: 12px 14px; }
