:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f242c;
  --border: #30363d;
  --border-soft: #242b34;
  --text: #e6edf3;
  --muted: #8b949e;
  --blue: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a {
  color: var(--blue);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 34px;
  padding: 0 12px;
  color: #fff;
  background: #1f6feb;
  border: 1px solid #388bfd;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  background: #388bfd;
}

input,
select {
  min-height: 34px;
  padding: 0 10px;
  color: var(--text);
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 12px 24px;
  background: rgba(22, 27, 34, 0.98);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(63, 185, 80, 0.14);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
}

.nav-links a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
  border-radius: 6px;
  white-space: nowrap;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
  background: #21262d;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.page-shell {
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: 18px 24px 32px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-heading h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.page-heading p {
  margin: 4px 0 0;
  color: var(--muted);
}

.filters,
.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi-grid.three {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.metric-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.metric-card {
  min-height: 112px;
  padding: 14px;
}

.metric-card h2,
.panel-title h2 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.metric-value {
  margin-top: 8px;
  font-size: 26px;
  line-height: 1.1;
  font-weight: 800;
}

.metric-card p {
  margin: 8px 0 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.page-shell > .panel {
  margin-bottom: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 12px;
}

.panel-title span,
.panel-title a {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
  gap: 14px;
  margin-bottom: 14px;
}

.two-column.equal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.two-column.wide-left {
  grid-template-columns: minmax(0, 1.35fr) minmax(420px, .65fr);
}

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

.mini-metric {
  min-height: 74px;
  padding: 11px;
  background: #0d1117;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
}

.mini-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.mini-metric strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.mini-metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.routing-list,
.routing-grid {
  display: grid;
  gap: 10px;
}

.routing-list {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.routing-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.regime-guide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.regime-guide-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 9px;
  color: var(--muted);
  background: #0d1117;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  font-size: 12px;
}

.regime-guide-item.active {
  color: var(--text);
  border-color: rgba(88, 166, 255, .45);
  background: rgba(88, 166, 255, .08);
}

.routing-item {
  min-height: 150px;
  padding: 11px;
  background: #0d1117;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
}

.routing-item.compact {
  min-height: 112px;
}

.routing-item.active {
  border-color: rgba(63, 185, 80, .42);
  background: rgba(63, 185, 80, .06);
}

.routing-item.watching {
  border-color: rgba(210, 153, 34, .44);
}

.routing-item.blocked {
  border-color: rgba(248, 81, 73, .48);
  background: rgba(248, 81, 73, .05);
}

.routing-head {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.status-dot {
  margin-top: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.active {
  background: var(--green);
}

.status-dot.watching {
  background: var(--yellow);
}

.status-dot.blocked {
  background: var(--red);
}

.routing-name {
  min-width: 0;
  font-weight: 700;
}

.routing-bias {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.routing-regimes {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.regime-chip {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  color: var(--muted);
  background: #21262d;
  border: 1px solid transparent;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.regime-chip.active {
  color: var(--text);
  border-color: currentColor;
}

.regime-chip.green { color: var(--green); background: rgba(63, 185, 80, .12); }
.regime-chip.red { color: var(--red); background: rgba(248, 81, 73, .12); }
.regime-chip.yellow { color: var(--yellow); background: rgba(210, 153, 34, .13); }
.regime-chip.blue { color: var(--blue); background: rgba(88, 166, 255, .12); }
.regime-chip.purple { color: var(--purple); background: rgba(188, 140, 255, .12); }

.routing-when,
.routing-setup {
  margin: 9px 0 0;
  line-height: 1.35;
}

.routing-when {
  color: var(--text);
  font-size: 13px;
}

.routing-setup {
  color: var(--muted);
  font-size: 12px;
}

.routing-note {
  min-height: 24px;
  margin-top: 10px;
  padding: 6px 8px;
  color: var(--muted);
  background: #161b22;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  font-size: 12px;
}

.routing-status {
  min-height: 20px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #21262d;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
}

.klf-compact,
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}

.klf-symbol-card,
.level-set-card {
  min-width: 0;
  padding: 11px;
  background: #0d1117;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
}

.klf-symbol-head,
.level-set-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.klf-symbol-head strong,
.level-set-head strong {
  display: block;
  font-size: 15px;
}

.klf-symbol-head span,
.level-set-head span,
.level-set-head .muted {
  color: var(--muted);
  font-size: 12px;
}

.klf-core-row,
.level-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.klf-core-row {
  margin-top: 9px;
}

.klf-core-row span {
  color: var(--muted);
  font-size: 12px;
}

.level-chip-row {
  margin-top: 10px;
}

.level-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 8px;
  color: var(--muted);
  background: #21262d;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.level-chip.green {
  color: var(--green);
  background: rgba(63, 185, 80, .10);
}

.level-chip.red {
  color: var(--red);
  background: rgba(248, 81, 73, .10);
}

.level-chip small {
  color: var(--purple);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.chart-box {
  position: relative;
  min-height: 160px;
}

.chart-box.tall {
  min-height: 320px;
}

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

.compact-table {
  margin-top: 12px;
}

.compact-table table {
  min-width: 580px;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

th {
  padding: 9px 10px;
  color: var(--muted);
  background: #21262d;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: 0;
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #21262d;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.green,
.pill.green {
  color: var(--green);
  background: rgba(63, 185, 80, .12);
}

.badge.red,
.pill.red {
  color: var(--red);
  background: rgba(248, 81, 73, .12);
}

.badge.yellow,
.pill.yellow {
  color: var(--yellow);
  background: rgba(210, 153, 34, .13);
}

.badge.blue,
.pill.blue {
  color: var(--blue);
  background: rgba(88, 166, 255, .12);
}

.badge.purple,
.pill.purple {
  color: var(--purple);
  background: rgba(188, 140, 255, .12);
}

.green { color: var(--green); }
.red { color: var(--red); }
.yellow { color: var(--yellow); }
.blue { color: var(--blue); }
.purple { color: var(--purple); }
.muted { color: var(--muted); }

.empty-state {
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

.error-banner {
  padding: 12px 24px;
  color: var(--red);
  background: rgba(248, 81, 73, .12);
  border-bottom: 1px solid var(--red);
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(340px, 100%);
  padding: 32px 26px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.login-card h1 {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 18px;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.login-card input,
.login-card button {
  width: 100%;
}

.login-card button {
  margin-top: 12px;
}

.login-error {
  margin-top: 12px;
  color: var(--red);
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-meta {
    justify-content: space-between;
  }

  .kpi-grid,
  .kpi-grid.three {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .two-column,
  .two-column.equal,
  .two-column.wide-left {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .page-shell {
    padding: 14px 12px 24px;
  }

  .topbar {
    padding: 12px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filters,
  .actions {
    justify-content: flex-start;
  }

  .filters input,
  .filters select,
  .filters button {
    width: 100%;
  }

  .kpi-grid,
  .kpi-grid.three {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: auto;
  }

  .broker-cards { grid-template-columns: 1fr; }
}

/* ── Broker Status ─────────────────────────────────────────────────────────── */
.broker-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 4px 0;
}

.broker-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.broker-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.broker-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.broker-badge {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green  { background: #22c55e; }
.dot-yellow { background: #eab308; }
.dot-red    { background: #ef4444; }
.dot-grey   { background: #6b7280; }

.broker-mode {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.broker-nlv {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 2px;
}

.broker-sub {
  font-size: 0.78rem;
}

.broker-error {
  font-size: 0.72rem;
  color: #ef4444;
  margin-top: 2px;
}

/* ── PMCC ──────────────────────────────────────────────────────────────────── */
.pmcc-summary-panel { margin-bottom: 0; }

.pmcc-summary-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.pmcc-summary-row:last-child { border-bottom: none; }
.pmcc-summary-row strong { min-width: 3.5rem; }

.pmcc-group-card { margin-bottom: 1rem; }

.pmcc-leap-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0;
  font-size: 0.88rem;
}
.pmcc-leap-row > div { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.pmcc-leap-prices { gap: 1.5rem; }

.pmcc-metrics-row {
  display: flex;
  gap: 2rem;
  padding: 0.4rem 0;
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 0.3rem 0 0.5rem;
}

.pmcc-shorts { display: flex; flex-direction: column; gap: 0.3rem; }

.pmcc-leg-row {
  display: flex;
  gap: 1.2rem;
  align-items: center;
  font-size: 0.82rem;
  padding: 0.3rem 0.4rem;
  background: #161b22;
  border-radius: 4px;
}
