:root {
  --bg-page: #f1f5f9;
  --bg-header: #0b1120;
  --bg-subbar: #111a2e;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-code: #0f172a;
  --ink-primary: #0f172a;
  --ink-secondary: #334155;
  --ink-muted: #64748b;
  --border: #cbd5e1;
  --border-dark: #334155;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-tint: #e0f2fe;
  --pass: #059669;
  --pass-bg: #ecfdf5;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --fail: #e11d48;
  --fail-bg: #fff1f2;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SFMono-Regular", Menlo, monospace;
  --radius: 6px;
}

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

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  line-height: 1.48;
  overflow-x: hidden;
}

code,
pre,
.num,
.mono-meta,
.mono-val,
.tab-idx,
.pill {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #ffffff;
  padding: 8px 14px;
  z-index: 100;
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

/* STUDIO HEADER */
.studio-header {
  background: var(--bg-header);
  color: #f8fafc;
  border-bottom: 1px solid #1e293b;
}

.studio-top {
  max-width: 1420px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  border-radius: var(--radius);
  border: 1px solid var(--border-dark);
  flex-shrink: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: #94a3b8;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
}

.pill-price {
  background: #fef3c7;
  color: #92400e;
}

.pill-spec {
  background: #0f2942;
  color: #38bdf8;
  border: 1px solid #0369a1;
}

.studio-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.vp-switch {
  display: inline-flex;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f172a;
}

.vp-btn {
  background: transparent;
  color: #cbd5e1;
  border: 0;
  border-right: 1px solid var(--border-dark);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.vp-btn:last-child {
  border-right: 0;
}

.vp-btn.is-active {
  background: var(--accent);
  color: #ffffff;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.studio-header .btn-outline {
  background: #111c33;
  color: #e2e8f0;
  border-color: var(--border-dark);
}

.studio-header .btn-outline:hover {
  background: #1e293b;
}

.btn-outline {
  background: var(--bg-card);
  color: var(--ink-primary);
  border-color: var(--border);
}

.btn-outline:hover {
  background: var(--bg-subtle);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.76rem;
}

.btn-lg {
  padding: 10px 18px;
  font-size: 0.9rem;
}

.btn-lock {
  background: #ffffff;
  color: var(--ink-primary);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.btn-lock.is-locked {
  background: #0f172a;
  color: #38bdf8;
  border-color: #0284c7;
}

/* VIEW SWITCHER BAR */
.switcher-bar {
  max-width: 1420px;
  margin: 0 auto;
  padding: 10px 20px;
  background: var(--bg-subbar);
  border-top: 1px solid #1e293b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.view-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: var(--radius);
  border: 1px solid #334155;
  background: #0f172a;
  color: #cbd5e1;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.view-tab:hover {
  border-color: #38bdf8;
  color: #ffffff;
}

.view-tab.is-active {
  background: #ffffff;
  color: #0f172a;
  border-color: #ffffff;
}

.tab-idx {
  font-size: 0.72rem;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(2, 132, 199, 0.2);
  color: #38bdf8;
}

.view-tab.is-active .tab-idx {
  background: var(--accent);
  color: #ffffff;
}

.switcher-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #94a3b8;
  font-family: var(--font-mono);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

/* PREVIEW STAGE */
.preview-stage {
  max-width: 1420px;
  margin: 0 auto;
  padding: 20px;
}

.preview-shell {
  margin: 0 auto;
  width: 100%;
  transition: max-width 0.2s ease;
}

.preview-shell.is-desktop {
  max-width: 100%;
}

.preview-shell.is-tablet {
  max-width: 820px;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #e2e8f0;
}

.preview-shell.is-mobile {
  max-width: 390px;
  border: 2px solid #0f172a;
  border-radius: 14px;
  padding: 12px;
  background: #e2e8f0;
}

.tpl-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tpl-head {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.tpl-head h2 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 750;
}

.tpl-sub {
  margin: 3px 0 0;
  font-size: 0.86rem;
  color: var(--ink-muted);
}

.tpl-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ctrl-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink-primary);
  font-size: 0.82rem;
  font-weight: 600;
}

.chip-group {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}

.chip-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--ink-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn.is-active {
  background: var(--ink-primary);
  color: #ffffff;
  border-color: var(--ink-primary);
}

/* KPI CARDS */
.kpi-row-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.preview-shell.is-mobile .kpi-row-4,
.preview-shell.is-mobile .waterfall-split,
.preview-shell.is-mobile .gate-layout,
.preview-shell.is-mobile .diff-split {
  grid-template-columns: 1fr;
}

.kpi-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.kpi-lbl {
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--ink-muted);
}

.kpi-val {
  font-size: 1.4rem;
  font-weight: 750;
  font-family: var(--font-mono);
}

.kpi-note {
  font-size: 0.75rem;
  color: var(--ink-secondary);
}

/* PANEL BOX & TABLES */
.panel-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  min-width: 0;
}

.panel-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--bg-page);
  flex-wrap: wrap;
}

.panel-box-head h3 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
}

.mono-meta {
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th,
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--bg-page);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  background: var(--bg-subtle);
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.data-table th.num,
.data-table td.num {
  text-align: right;
}

.data-table tbody tr {
  cursor: pointer;
}

.data-table tbody tr:hover {
  background: var(--accent-tint);
}

.data-table tbody tr.is-selected {
  background: #e0f2fe;
}

.badge-st {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.st-pass { background: var(--pass-bg); color: var(--pass); }
.st-warn { background: var(--warn-bg); color: var(--warn); }
.st-fail { background: var(--fail-bg); color: var(--fail); }

.failure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.failure-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--fail);
  border-radius: 4px;
  padding: 10px;
}

.failure-item strong {
  display: block;
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

.failure-item span {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--ink-secondary);
}

/* VIEW 2: WATERFALL */
.waterfall-split {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr);
  gap: 16px;
}

.waterfall-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wf-row {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 9px 10px;
  cursor: pointer;
  background: #ffffff;
  text-align: left;
  width: 100%;
}

.wf-row:hover {
  border-color: var(--accent);
}

.wf-row.is-selected {
  border-color: var(--accent);
  background: #f0f9ff;
}

.wf-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.wf-name {
  font-weight: 700;
  color: var(--ink-primary);
}

.wf-stats {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.wf-track {
  position: relative;
  height: 12px;
  background: var(--bg-page);
  border-radius: 999px;
  overflow: hidden;
}

.wf-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
}

.wf-bar.kind-llm { background: #0284c7; }
.wf-bar.kind-tool { background: #059669; }
.wf-bar.kind-retry { background: #d97706; }
.wf-bar.kind-error { background: #e11d48; }

.span-kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.span-kv {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 9px;
}

.span-kv span {
  display: block;
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.span-kv strong {
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.code-box {
  margin: 0;
  padding: 12px;
  background: var(--bg-code);
  color: #e2e8f0;
  border-radius: var(--radius);
  font-size: 0.76rem;
  line-height: 1.48;
  overflow-x: auto;
  max-height: 280px;
}

/* VIEW 3: DIFF JUDGE */
.diff-lines {
  background: var(--bg-code);
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  overflow-x: auto;
}

.diff-line {
  padding: 2px 6px;
  white-space: pre-wrap;
}

.diff-add {
  background: rgba(16, 185, 129, 0.2);
  color: #a7f3d0;
}

.diff-del {
  background: rgba(244, 63, 94, 0.2);
  color: #fecdd3;
}

.judge-cases {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.judge-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.judge-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.diff-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.diff-pane {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  font-size: 0.82rem;
}

.diff-pane h4 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

.judge-override-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* VIEW 4: RELEASE GATE */
.gate-banner {
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid;
}

.gate-banner.is-pass {
  background: var(--pass-bg);
  border-color: #6ee7b7;
  color: #065f46;
}

.gate-banner.is-block {
  background: var(--fail-bg);
  border-color: #fda4af;
  color: #9f1239;
}

.gate-banner h3 {
  margin: 0 0 3px;
  font-size: 1.05rem;
}

.gate-banner p {
  margin: 0;
  font-size: 0.84rem;
}

.gate-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 1.35fr);
  gap: 16px;
}

.gate-sliders {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.mono-val {
  color: var(--accent);
  font-weight: 700;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.gate-checks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.gate-check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.82rem;
}

/* COMMERCIAL BANNER */
.bundle-banner {
  margin-top: 18px;
  background: var(--bg-header);
  color: #f8fafc;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.bundle-banner h2 {
  margin: 8px 0 6px;
  font-size: 1.12rem;
}

.bundle-banner p {
  margin: 0;
  font-size: 0.86rem;
  color: #cbd5e1;
  max-width: 680px;
}

.bundle-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.bundle-banner .btn-outline {
  background: #111c33;
  color: #f8fafc;
  border-color: var(--border-dark);
}

/* FOOTER & MODAL */
.studio-footer {
  margin-top: 24px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.footer-inner {
  max-width: 1420px;
  margin: 0 auto;
  padding: 15px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.footer-nav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.footer-nav a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 17, 32, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 80;
}

.modal-card {
  width: 100%;
  max-width: 620px;
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.modal-head h2 {
  margin: 6px 0 0;
  font-size: 1.15rem;
}

.modal-close {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-list {
  padding-left: 18px;
  margin: 14px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.86rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--bg-header);
  color: #ffffff;
  border: 1px solid var(--border-dark);
  padding: 10px 15px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  font-weight: 600;
  z-index: 95;
}

@media (max-width: 960px) {
  .kpi-row-4,
  .waterfall-split,
  .gate-layout,
  .diff-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .studio-top,
  .switcher-bar,
  .preview-stage {
    padding-left: 12px;
    padding-right: 12px;
  }

  .studio-actions .btn,
  .bundle-actions .btn,
  .btn {
    white-space: normal;
    text-align: center;
    max-width: 100%;
  }

  .vp-switch {
    display: none;
  }
}
