:root {
  --bg: #08090d;
  --panel: #10131a;
  --line: #232836;
  --text: #e8ebf3;
  --muted: #8b92a6;
  --green: #3ddc97;
  --red: #ff5c7a;
  --gold: #f5c15c;
  --cyan: #6cd4ff;
  --spot: #ff4d6d;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px 20px 24px;
  gap: 12px;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.brand .kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.brand h1 {
  margin: 4px 0 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.brand h1 span { color: var(--cyan); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.search {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.search input {
  background: transparent;
  color: var(--text);
  border: 0;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  width: 10.5rem;
  letter-spacing: 0.04em;
}
.search input::placeholder { color: var(--muted); letter-spacing: 0; }
.search button {
  background: #1a2230;
  color: var(--text);
  border: 0;
  border-left: 1px solid var(--line);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.members { font-size: 12px; color: var(--muted); }
.seg {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.seg button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.seg button.on {
  background: #1a2230;
  color: var(--text);
}
.meta { text-align: right; color: var(--muted); font-size: 13px; line-height: 1.45; }
.meta .spot { color: var(--text); font-size: 22px; font-weight: 600; letter-spacing: -0.03em; }
.meta .spot em { font-style: normal; color: var(--muted); font-size: 13px; margin-left: 8px; }
.kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 10px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 12px;
  min-height: 78px;
}
.kpi .lbl { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.kpi .val { margin-top: 6px; font-size: 20px; font-weight: 600; letter-spacing: -0.03em; }
.kpi .sub { margin-top: 2px; font-size: 11px; color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; }
.kpi.pos .val { color: var(--green); }
.kpi.neg .val { color: var(--red); }
.kpi.gold .val { color: var(--gold); }
.stage {
  min-height: 520px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: visible;
  position: relative;
}
.hover {
  position: absolute;
  z-index: 5;
  min-width: 220px;
  max-width: 320px;
  padding: 8px 10px;
  background: #161b26;
  border: 1px solid #3a4254;
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.stage.slim { min-height: 200px; }
canvas { display: block; width: 100%; height: 100%; }
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}
.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}
.swatch.pos { background: var(--green); }
.swatch.neg { background: var(--red); }
.swatch.spot { background: var(--spot); }
.swatch.flip { background: transparent; border: 1.5px dashed var(--gold); height: 0; width: 16px; }
.note { color: var(--muted); font-size: 12px; line-height: 1.5; }

.status-banner {
  background: #1a2230;
  border: 1px solid #3a4a66;
  color: #d7e2f5;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
}
.status-banner[data-kind="stale"],
.status-banner[data-kind="fixture"] {
  border-color: #6a5a2a;
  background: #1b1720;
  color: #f0d2b0;
}
.status-banner[data-kind="feed"] {
  border-color: #6a3a3a;
  background: #201616;
  color: #f0c0c0;
}

.serve-hint {
  background: #1b1720;
  border: 1px solid #3a2a22;
  color: #f0d2b0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.serve-hint code {
  display: inline-block;
  margin: 2px 4px;
  color: #fff4e0;
}
.app.loading .seg button.on {
  box-shadow: inset 0 0 0 1px var(--cyan);
}
.tables { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.table-wrap {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
table.book { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
table.book th, table.book td { text-align: right; padding: 6px 10px; }
table.book th {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
table.book td { border-bottom: 1px solid #1a1e29; }
table.book th:nth-child(1), table.book td:nth-child(1) { text-align: left; }

/* Sticky Strike / Expiry table headers on scroll */
.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  box-shadow: 0 1px 0 var(--line);
}
.book-overlay-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  box-shadow: 0 1px 0 var(--line);
}

.pos-t { color: var(--green); }
.neg-t { color: var(--red); }
.atm { background: rgba(108, 212, 255, 0.06); }
.err { color: var(--red); padding: 24px; }
@media (max-width: 980px) {
  .kpis, .tables { grid-template-columns: 1fr; }
  .stage { min-height: 420px; }
  .meta { text-align: left; }
}


/* Ticket A — Book / Market / Residual panel (additive) */
.book-overlay {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.book-overlay[hidden] { display: none !important; }
.book-overlay-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.book-overlay-head h2 {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.book-overlay-note {
  margin: 0;
  max-width: 34rem;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: right;
}
.book-overlay-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}
.book-ingest {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
}
.book-ingest summary { cursor: pointer; color: var(--text); }
.book-ingest textarea {
  width: 100%;
  margin-top: 8px;
  background: #0c0f16;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}
.book-ingest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.book-ingest-actions button {
  background: #1a2230;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.book-ingest-status { font-size: 12px; color: var(--muted); }
.book-ingest-status.ok { color: var(--green); }
.book-ingest-status.error { color: var(--red); }
.book-ingest-hint { font-size: 12px; color: var(--muted); margin: 8px 0 6px; }
.book-overlay-table-wrap { max-height: 240px; overflow: auto; }

.provenance-banner {
  background: #141a24;
  border: 1px solid #2a3548;
  color: #a8b4c8;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.45;
  margin-top: -4px;
}
.provenance-banner[hidden] { display: none !important; }
.provenance-banner[data-kind="live"] { border-color: #2a5a48; color: #b8e0cc; }
.provenance-banner[data-kind="delayed"] { border-color: #3a4a66; color: #c5d2e8; }
.provenance-banner[data-kind="fixture"] { border-color: #6a5a2a; color: #e0d0a8; }
.provenance-banner[data-kind="stale"] { border-color: #6a5a2a; color: #f0d2b0; }
.refresh-study {
  margin-top: 6px;
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line, #3a4154);
  background: #1a2230;
  color: #d7e2f5;
  cursor: pointer;
}
.refresh-study:hover { border-color: var(--cyan, #5ec8ff); }
.app.public-mode .book-overlay { display: none !important; }
.status-banner[data-kind="uw"] {
  border-color: #6a3a3a;
  background: #201616;
  color: #f0c0c0;
}

.book-window {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted, #8a93a6);
  padding: 0 2px;
}
.book-window select {
  font: inherit;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg, #e8ecf4);
  background: var(--panel, #1a2030);
  border: 1px solid var(--border, #2c3548);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 4.5rem;
}


.empty-state {
  margin: 0.75rem 1.25rem 0;
  padding: 0.85rem 1rem;
  border: 1px dashed rgba(148, 163, 184, 0.45);
  border-radius: 10px;
  color: #94a3b8;
  background: rgba(15, 23, 42, 0.35);
  text-align: center;
  font-size: 0.95rem;
}
.empty-state[hidden] { display: none; }
.status-banner[data-kind="empty"] {
  border-color: rgba(148, 163, 184, 0.35);
  color: #94a3b8;
}

/* Ticket M — per-expiry include toggles */
table.book th.expiry-on, table.book td.expiry-on {
  text-align: center;
  width: 2.4em;
}
.expiry-toggle {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #3ddc97;
}
.progressive-banner {
  font-size: 12px;
  color: var(--muted);
}


/* Ticket N — gray-stay OFF + bulk All on/off */
.expiry-bulk {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  flex-wrap: wrap;
}
.expiry-bulk-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.expiry-bulk-btn {
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #2a3142;
  background: #171b26;
  color: #e8ebf3;
  cursor: pointer;
}
.expiry-bulk-btn:hover {
  border-color: #3ddc97;
  color: #3ddc97;
}
.expiry-row-off td:not(.expiry-on) {
  opacity: 0.38;
  color: #6b7280;
  text-decoration: line-through;
  text-decoration-color: #4a5163;
}
.expiry-row-off td.expiry-on {
  opacity: 0.7;
}
