:root {
  --bg-canvas: #070b14;
  --bg-surface: #0d1424;
  --bg-elevated: #131d33;
  --bg-inset: #050810;
  --border-subtle: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(16, 185, 129, 0.48);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --mint: #34d399;
  --emerald: #10b981;
  --indigo: #818cf8;
  --amber: #fbbf24;
  --rose: #fb7185;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, Menlo, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.accent-mint { color: var(--mint); }
.accent-indigo { color: var(--indigo); }
.accent-amber { color: var(--amber); }
.accent-rose { color: var(--rose); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--emerald);
  color: #031510;
  padding: 8px 14px;
  font-weight: 700;
  z-index: 100;
}

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

/* ================= HEADER & TABS ================= */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(7, 11, 20, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

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

.brand-text {
  min-width: 0;
}

.brand-logo {
  border-radius: 9px;
  flex-shrink: 0;
}

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

.brand-name {
  margin: 0;
  font-size: 1.26rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.67rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.tag-value {
  background: rgba(16, 185, 129, 0.16);
  color: var(--mint);
  border: 1px solid rgba(52, 211, 153, 0.45);
}

.tag-spec {
  background: rgba(99, 102, 241, 0.16);
  color: #c7d2fe;
  border: 1px solid rgba(129, 140, 248, 0.35);
}

.brand-tagline {
  margin: 2px 0 0;
  font-size: 0.81rem;
  color: var(--text-muted);
}

.header-ctas {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 0.79rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 120ms ease, filter 120ms ease, border-color 140ms ease;
  text-align: center;
  max-width: 100%;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.73rem;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #4f46e5);
  color: #f8fafc;
}

.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-outline {
  background: rgba(15, 23, 42, 0.88);
  color: var(--text-main);
  border-color: rgba(148, 163, 184, 0.35);
}

.btn-outline:hover {
  border-color: var(--mint);
}

.btn-ghost {
  background: rgba(19, 29, 51, 0.8);
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.24);
}

.btn-ghost:hover {
  border-color: var(--indigo);
  color: #f8fafc;
}

.module-tabs {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 20px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mod-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 0;
}

.mod-tab.is-active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.tab-code {
  color: var(--mint);
  font-weight: 700;
}

.header-live-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--mint);
  box-shadow: 0 0 10px var(--emerald);
}

/* ================= MAIN WORKBENCH ================= */
.workbench {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px 20px 36px;
  min-width: 0;
}

.panel-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  min-width: 0;
}

.panel-header-row h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.panel-sub {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 780px;
}

.preset-pills,
.chip-grid {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 0;
}

.preset-chip {
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--bg-surface);
  color: #cbd5e1;
  border: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  max-width: 100%;
}

.preset-chip.is-active {
  background: rgba(16, 185, 129, 0.18);
  color: #ecfdf5;
  border-color: var(--mint);
}

.split-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  min-width: 0;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

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

.badge-pill,
.state-badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.67rem;
  font-weight: 700;
  background: rgba(99, 102, 241, 0.16);
  color: #c7d2fe;
  border: 1px solid rgba(129, 140, 248, 0.35);
}

.state-badge.is-active {
  background: rgba(16, 185, 129, 0.18);
  color: var(--mint);
  border-color: rgba(52, 211, 153, 0.45);
}

.state-badge.is-warn {
  background: rgba(251, 191, 36, 0.18);
  color: var(--amber);
  border-color: rgba(251, 191, 36, 0.45);
}

.state-badge.is-danger {
  background: rgba(251, 113, 133, 0.18);
  color: var(--rose);
  border-color: rgba(251, 113, 133, 0.45);
}

.field-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-group label {
  font-size: 0.74rem;
  font-weight: 600;
  color: #cbd5e1;
}

.field-group input,
.field-group select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-inset);
  color: var(--text-main);
  border: 1px solid rgba(148, 163, 184, 0.25);
  font-size: 0.82rem;
}

.kpi-strip-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.kpi-box {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.kpi-k {
  font-size: 0.62rem;
  color: var(--text-muted);
}

.kpi-v {
  font-size: 0.96rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
}

.verdict-box {
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  font-size: 0.76rem;
  color: #e2e8f0;
  word-break: break-word;
}

.bar-stack-box {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.stacked-track {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: #0f172a;
}

.seg {
  height: 100%;
  transition: width 180ms ease;
}

.seg-naive { background: #6366f1; }
.seg-smart { background: #10b981; }
.seg-lost { background: #334155; }

.legend-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.68rem;
  color: #cbd5e1;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 4px;
}

.dot-naive { background: #6366f1; }
.dot-smart { background: #10b981; }
.dot-lost { background: #475569; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.ledger-wrap,
.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 295px;
  overflow-y: auto;
  min-width: 0;
}

.ledger-row,
.sched-row {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ledger-row.is-applied {
  border-color: rgba(52, 211, 153, 0.45);
}

.ledger-row.is-blocked {
  border-color: rgba(251, 191, 36, 0.5);
}

.ledger-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 700;
}

.code-tabs,
.toolbar-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.code-tab {
  padding: 4px 9px;
  border-radius: 7px;
  background: var(--bg-inset);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  font-size: 0.71rem;
  font-weight: 700;
  cursor: pointer;
}

.code-tab.is-active {
  background: rgba(16, 185, 129, 0.16);
  color: var(--mint);
  border-color: var(--mint);
}

.code-preview {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  color: #cbd5e1;
  font-size: 0.73rem;
  line-height: 1.45;
  overflow-x: auto;
  max-width: 100%;
  max-height: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

.mini-pre {
  max-height: 120px;
}

/* ================= CONVERSION BANNER & TOAST ================= */
.vault-cta-strip {
  margin-top: 20px;
  padding: 18px 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.14), rgba(79, 70, 229, 0.16));
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  min-width: 0;
}

.vault-cta-copy {
  max-width: 760px;
  min-width: 0;
}

.vault-cta-copy h3 {
  margin: 6px 0 4px;
  font-size: 1.05rem;
}

.vault-cta-copy p {
  margin: 0;
  font-size: 0.84rem;
  color: #cbd5e1;
}

.vault-cta-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.toast-pill {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 60;
  padding: 9px 14px;
  border-radius: 8px;
  background: rgba(5, 12, 24, 0.96);
  border: 1px solid var(--mint);
  color: var(--mint);
  font-size: 0.75rem;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
}

/* ================= RESPONSIVE ZERO-OVERFLOW (390x844 MOBILE) ================= */
@media (max-width: 960px) {
  .split-2 {
    grid-template-columns: minmax(0, 1fr);
  }
  .header-live-status {
    display: none;
  }
}

@media (max-width: 620px) {
  .header-inner {
    padding: 10px 12px;
  }
  .module-tabs {
    padding: 0 12px 10px;
  }
  .workbench {
    padding: 12px;
  }
  .field-row-2,
  .kpi-strip-3,
  .action-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .btn,
  .mod-tab {
    font-size: 0.73rem;
  }
}
