:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f8fafc; --border: #e3e8f0; --text: #0f172a; --muted: #64748b;
  --accent: #4f46e5; --accent-soft: #eef2ff; --on-accent: #ffffff;
  --ok: #059669; --ok-soft: #ecfdf5; --warn: #b45309; --warn-soft: #fffbeb;
  --bad: #dc2626; --bad-soft: #fef2f2; --info: #2563eb; --info-soft: #eff6ff; --sim: #7c3aed; --sim-soft: #f5f3ff;
  --s-private: #8b5cf6; --s-premium: #3b82f6; --s-basic: #14b8a6; --s-residual: #ec4899; --s-other: #94a3b8;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #111a2e; --surface-2: #0e1628; --border: #1f2b45; --text: #e5e9f2; --muted: #93a0b8;
    --accent: #818cf8; --accent-soft: #1e2350; --on-accent: #0b1020;
    --ok: #34d399; --ok-soft: #0d2b22; --warn: #fbbf24; --warn-soft: #2e2410;
    --bad: #f87171; --bad-soft: #321417; --info: #60a5fa; --info-soft: #11223f; --sim: #a78bfa; --sim-soft: #231b42;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
code, .mono { font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
h2 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h3 { margin: 0 0 8px; font-size: 16px; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
svg { width: 16px; height: 16px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 28px; height: 28px; padding: 5px; border-radius: 9px; color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), #06b6d4); }
.title { font-weight: 700; letter-spacing: -.01em; }
.subtitle { font-size: 12px; color: var(--muted); margin-top: -2px; }
.topbar-mid { display: flex; gap: 8px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }

/* layout */
main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; display: grid; gap: 20px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; }
@media (max-width: 1080px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 640px) { main, .topbar { padding-left: 16px; padding-right: 16px; } .topbar-mid { order: 3; flex-basis: 100%; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
details > summary.card-head { margin: 0; cursor: pointer; list-style: none; }
details[open] > summary.card-head { margin-bottom: 14px; }
details > summary::-webkit-details-marker { display: none; }
.section-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; font-weight: 400; }

/* pills & chips */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ro { color: var(--info); background: var(--info-soft); border-color: transparent; }
.pill.rw { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.pill.sim { color: var(--sim); background: var(--sim-soft); border-color: transparent; }
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
  white-space: nowrap; }
.tag.ok { color: var(--ok); background: var(--ok-soft); } .tag.warn { color: var(--warn); background: var(--warn-soft); }
.tag.bad { color: var(--bad); background: var(--bad-soft); } .tag.info { color: var(--info); background: var(--info-soft); }
.tag.sim { color: var(--sim); background: var(--sim-soft); } .tag.muted { color: var(--muted); background: var(--surface-2); }
.slice-pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; color: var(--sc); background: color-mix(in srgb, var(--sc) 14%, transparent); white-space: nowrap; }
.slice-pill::before, .sdot { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--sc); display: inline-block; }
.sdot.all { --sc: var(--muted); }
[data-slice="private"] { --sc: var(--s-private); } [data-slice="premium"] { --sc: var(--s-premium); }
[data-slice="basic"] { --sc: var(--s-basic); } [data-slice="residual"] { --sc: var(--s-residual); }
[data-slice=""], [data-slice="none"] { --sc: var(--s-other); }
.count { display: inline-flex; min-width: 22px; justify-content: center; padding: 0 7px; border-radius: 999px;
  background: var(--bad-soft); color: var(--bad); font-size: 12px; margin-left: 6px; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 550; font-size: 13px; padding: 7px 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.busy { opacity: .7; pointer-events: none; }
input, select { font: inherit; font-size: 13.5px; width: 100%; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
.field.grow { flex: 1 1 240px; } .field.narrow { flex: 0 0 110px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }
.subhead { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  margin: 18px 0 8px; display: flex; gap: 10px; align-items: baseline; }
.subhead .hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { font: inherit; font-size: 13px; font-weight: 550; padding: 5px 12px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.rates { display: grid; grid-template-columns: 150px 1fr; gap: 12px; }
.rates-inner { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.field.rate span { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 640px) { .rates { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: center; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.check input { width: auto; }
.actions-row { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.actions-row.end { justify-content: flex-end; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .bar { height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); }
.kpi.bad .bar i { background: var(--bad); } .kpi.warn .bar i { background: var(--warn); }

/* attention */
.attention { border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); padding: 12px 20px; }
.attention .card-head { margin: 0; }
.warn-ico { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--bad-soft);
  color: var(--bad); font-size: 12px; font-weight: 800; margin-right: 4px; }
.attn-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.attn-list li { display: flex; gap: 10px; align-items: baseline; font-size: 13px; padding: 7px 10px; border-radius: 9px; background: var(--surface-2); }
.attn-list li b { flex: 0 0 auto; }
.attn-list li span { color: var(--muted); overflow-wrap: anywhere; }

/* device cards */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.device { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; border-top: 3px solid var(--sc, var(--border)); }
.device-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 10px; }
.device-id { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.device-kind { font-size: 12px; color: var(--muted); font-weight: 500; }
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 6px 10px; padding: 4px 16px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.unknown { color: var(--bad); font-weight: 650; }
.device-err { margin: 0 16px 12px; padding: 8px 10px; border-radius: 9px; background: var(--bad-soft); color: var(--bad); font-size: 12.5px;
  overflow-wrap: anywhere; }
.device-progress { margin: 0 16px 12px; padding: 8px 10px; border-radius: 9px; background: var(--info-soft); color: var(--info); font-size: 12.5px;
  display: flex; gap: 8px; align-items: center; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.device-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--border);
  background: var(--surface-2); flex-wrap: wrap; }
.device-foot { flex-wrap: nowrap; }
.device-foot select { width: auto; max-width: 120px; padding: 4px 8px; font-size: 12.5px; }
.device-foot .spacer { flex: 1; }
.device-more { padding: 10px 16px 14px; border-top: 1px dashed var(--border); font-size: 12.5px; display: grid; gap: 6px; }
.device-more pre { margin: 4px 0 0; max-height: 220px; overflow: auto; padding: 10px; border-radius: 9px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 11.5px; }

/* chips (device selection) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 13px; font-weight: 550; color: var(--text);
  user-select: none; transition: border-color .15s, background .15s; }
.chip:hover { border-color: var(--sc, var(--accent)); }
.chip.on { border-color: var(--sc, var(--accent)); background: color-mix(in srgb, var(--sc, var(--accent)) 14%, var(--surface)); }
.chip .sdot { width: 8px; height: 8px; }
.chip .ri { font-size: 12px; }
.chip .ri.ok { color: var(--ok); } .chip .ri.bad { color: var(--bad); } .chip .ri.warn { color: var(--warn); }

/* slices panel */
.slice-list { display: grid; gap: 10px; }
.slice-row { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border-left: 3px solid var(--sc); }
.slice-row .name { font-weight: 650; display: flex; justify-content: space-between; align-items: center; }
.slice-row .meta { font-size: 12px; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td { padding: 7px 10px; }
.table td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 240px; color: var(--muted); }
.table tr.detail > td { background: var(--surface-2); }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 24px !important; }

/* dry-run */
#dryOut { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.cmd { display: block; max-width: 520px; overflow-x: auto; white-space: nowrap; padding: 4px 8px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); }
.notice { padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; }
.notice.bad { background: var(--bad-soft); color: var(--bad); } .notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* dialog & toasts */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px;
  width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
dialog p { color: var(--muted); margin: 0 0 6px; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); }
.toast { padding: 11px 14px; border-radius: 11px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13px; border-left: 4px solid var(--info); animation: toast-in .2s ease-out; overflow-wrap: anywhere; }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- tabs & run-tests layout (v4) ---- */
.tabs { display: flex; gap: 4px; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.tab { padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--muted); text-decoration: none !important; }
.tab:hover { color: var(--text); }
.tab.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.topbar .brand { flex: 0 0 auto; }
.topbar .tabs { margin-right: auto; }
.tabpane { display: grid; gap: 20px; }
.token-box { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); }
.token-box input { border: 0; background: transparent; padding: 6px 0; width: 130px; box-shadow: none !important; }
.section-head .spacer { flex: 1; }
.slice-list.horizontal { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.defaults { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }
.actions-row.tight { margin: 0; }
.test-rows td { padding: 8px 8px; }
.test-rows input, .test-rows select { padding: 5px 8px; font-size: 13px; }
.test-rows input[type=number] { width: 76px; }
.test-rows input.rate { width: 96px; }
.test-rows select { width: auto; }
.test-rows input[type=checkbox], #selAll { width: auto; }
.test-rows tr.off td:not(:first-child) { opacity: .5; }
.test-rows .dev { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-weight: 650; }
.status-cell { min-width: 230px; }
.progress { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-top: 5px; border: 1px solid var(--border); }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #06b6d4); transition: width .5s linear; }
.res { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12.5px; }
.res b { font-variant-numeric: tabular-nums; }
.dlg-body { color: var(--muted); font-size: 13.5px; }
.dlg-body table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 12.5px; }
.dlg-body td { padding: 4px 6px; border-bottom: 1px solid var(--border); color: var(--text); }
dialog { width: min(560px, calc(100vw - 32px)); }
@media (max-width: 900px) { .topbar .tabs { order: 3; flex-basis: 100%; justify-content: center; } }

/* ---- per-second (v7) ---- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text);
  padding-bottom: 6px; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: 0 0 auto; }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: left .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { left: 18px; }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }
.spark { display: block; width: 220px; height: 46px; }
.spark .ul { stroke: var(--accent); } .spark .dl { stroke: #06b6d4; }
.spark-legend { display: flex; gap: 10px; font-size: 11.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.spark-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

/* card slots are plain wrappers around each device card (v12) */
.card-slot { display: contents; }

/* ---- runs table: fixed columns so an opened run cannot push the buttons out of view (v18) ---- */
.runs-table { table-layout: fixed; width: 100%; min-width: 980px; }
.runs-table > thead > tr > th:nth-child(1) { width: 140px; }   /* run */
.runs-table > thead > tr > th:nth-child(2) { width: 150px; }   /* created */
.runs-table > thead > tr > th:nth-child(3) { width: 100px; }   /* status */
.runs-table > thead > tr > th:nth-child(5) { width: 150px; }   /* spec */
.runs-table > thead > tr > th:nth-child(6) { width: 140px; }   /* aggregate */
.runs-table > thead > tr > th:nth-child(7) { width: 300px; }   /* actions */
.runs-table > tbody > tr > td { overflow-wrap: anywhere; }
.runs-table td.run-actions { text-align: right; white-space: nowrap; }
.runs-table .run-toggle { min-width: 84px; justify-content: center; }
.runs-table > tbody > tr.detail > td { padding: 0 0 12px; overflow-wrap: normal; }
.runs-table > tbody > tr.detail td.mono { white-space: nowrap; }
.runs-table > tbody > tr.detail > td > .table-wrap { margin: 0; padding: 0 8px; overflow-x: auto; max-width: 100%; }
.runs-table > tbody > tr.detail > td > .notice { margin: 10px 8px; }

/* sign-in */
.who { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.who .hint { font-weight: 400; }
.card-head .spacer { flex: 1; }
#viewOnly { margin-bottom: 16px; }
