:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263348;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.15);
  --blue: #38bdf8;
  --blue-bg: rgba(56, 189, 248, 0.14);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 14px 16px 64px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 4px 0 0; }
.small { font-size: 12.5px; }

/* Header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.brand-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
}
.brand-sub {
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.sync-pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}
.sync-pill.live { color: var(--green); border-color: rgba(16, 185, 129, 0.4); }

.verifier-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.verifier-pill .status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
}
.verifier-pill.pass { border-color: rgba(16, 185, 129, 0.5); background: var(--green-bg); color: #6ee7b7; }
.verifier-pill.pass .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.verifier-pill.fail { border-color: rgba(239, 68, 68, 0.7); background: var(--red-bg); color: #fca5a5; }
.verifier-pill.fail .status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* Critical Banner */
.critical-banner {
  background: linear-gradient(90deg, #991b1b, #dc2626);
  border: 1px solid #f87171;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.critical-title {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.4px;
}
.critical-detail { margin: 6px 0 0; font-size: 13.5px; color: #fee2e2; }

/* Signal Banner */
.signal-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.signal-banner.action { border-left-color: var(--red); background: linear-gradient(90deg, rgba(239,68,68,0.12), var(--surface) 45%); }
.signal-banner.pending { border-left-color: var(--amber); background: linear-gradient(90deg, rgba(245,158,11,0.12), var(--surface) 45%); }
.signal-banner-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 14.5px;
  font-weight: 500;
}
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.badge.green { background: var(--green-bg); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.4); }
.badge.amber { background: var(--amber-bg); color: #fcd34d; border: 1px solid rgba(245,158,11,0.4); }
.badge.red { background: var(--red-bg); color: #fca5a5; border: 1px solid rgba(239,68,68,0.45); }
.badge.blue { background: var(--blue-bg); color: #7dd3fc; border: 1px solid rgba(56,189,248,0.4); }

.signal-banner-kpis {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
.mini-kpi { display: flex; flex-direction: column; }
.mini-kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.mini-kpi strong { font-size: 15px; margin-top: 2px; }

/* Navigation Tabs */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  position: sticky;
  top: 8px;
  z-index: 20;
  backdrop-filter: blur(8px);
}
.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 9px 15px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tab.active { background: #2563eb; color: #fff; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Sections & Cards */
.section-block { margin-bottom: 24px; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}
.section-header h2 { margin: 0; font-size: 17px; font-weight: 700; }

.cards-stack { display: flex; flex-direction: column; gap: 14px; }
.affected-card {
  background: var(--surface);
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: var(--radius);
  padding: 16px;
}
.affected-card.urgent { border-color: rgba(239, 68, 68, 0.6); }
.affected-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.affected-head h3 { margin: 0; font-size: 16px; }
.affected-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: #10b981; border-color: #10b981; color: #052e16; }
.btn.secondary { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Portfolio Grid */
.portfolios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}
.portfolio-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.portfolio-card.needs-action { border-color: rgba(245, 158, 11, 0.55); }
.portfolio-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.portfolio-card-title { font-weight: 700; font-size: 15px; margin: 0; }
.tier-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}
.tier-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Allocation Bar */
.alloc-bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}
.alloc-seg { height: 100%; }

.alloc-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
  font-size: 13px;
}
.alloc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: rgba(255,255,255,0.025);
  border-radius: 6px;
}
.alloc-item .sym { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.alloc-item .swatch { width: 8px; height: 8px; border-radius: 2px; }

.portfolio-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}
.data-table td {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.delta-pos { color: #34d399; font-weight: 700; }
.delta-neg { color: #f87171; font-weight: 700; }
.delta-zero { color: var(--muted); }

/* Charts */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.range-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}
.range-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.range-btn.active { background: #2563eb; color: #fff; }
.toggle-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.chart-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.chart-card-head h2 { margin: 0; font-size: 16px; }
.chart-kpis {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.kpi-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}
.kpi-chip span { color: var(--muted); display: block; font-size: 10.5px; text-transform: uppercase; }
.kpi-chip strong { font-size: 13.5px; }

.plotly-box { width: 100%; }
.plotly-box.tall { height: 440px; }
.plotly-box.medium { height: 340px; }
.plotly-box.short { height: 210px; }
.plotly-box.mini { height: 220px; }

.controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.tv-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.tv-wrap.light { background: #ffffff; border-color: #cbd5e1; }
.tv-wrap.dark { background: #131722; border-color: #2a2e39; }
.tv-canvas { width: 100%; }
.tv-canvas.tall { height: 480px; }
.tv-canvas.mini { height: 230px; }
.tv-legend {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 6;
  pointer-events: none;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  padding: 4px 8px;
  border-radius: 6px;
}
.tv-wrap.light .tv-legend { background: rgba(255, 255, 255, 0.86); color: #131722; }
.tv-wrap.dark .tv-legend { background: rgba(19, 23, 34, 0.82); color: #d1d4dc; }
.tv-legend .tv-sym { font-weight: 700; margin-right: 8px; }
.tv-legend .tv-up { color: #089981; font-weight: 600; }
.tv-legend .tv-dn { color: #f23645; font-weight: 600; }
.tv-legend .tv-sma20 { color: #2962ff; font-weight: 600; margin-left: 10px; }
.tv-legend .tv-sma150 { font-weight: 600; margin-left: 10px; }
.tv-wrap.dark .tv-legend .tv-sma150 { color: #f59e0b; }
.tv-wrap.light .tv-legend .tv-sma150 { color: #131722; }
.tv-sig-badge {
  display: inline-block;
  margin-left: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
}
.tv-sig-badge.buy100 { background: #00a86b; }
.tv-sig-badge.buy50 { background: #0284c7; }
.tv-sig-badge.sell50 { background: #ea580c; }
.tv-sig-badge.sell0 { background: #e11d48; }

.sig-legend-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.sig-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.sig-pill.buy100 { background: rgba(0, 168, 107, 0.16); color: #34d399; border: 1px solid rgba(0, 168, 107, 0.45); }
.sig-pill.buy50 { background: rgba(2, 132, 199, 0.18); color: #38bdf8; border: 1px solid rgba(2, 132, 199, 0.5); }
.sig-pill.sell50 { background: rgba(234, 88, 12, 0.18); color: #fb923c; border: 1px solid rgba(234, 88, 12, 0.5); }
.sig-pill.sell0 { background: rgba(225, 29, 72, 0.18); color: #fb7185; border: 1px solid rgba(225, 29, 72, 0.5); }

/* Testfol.io Analytics & Correlation Toolbars */
.analytics-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.wrap-group { flex-wrap: wrap; }
.range-btn.regime { color: #cbd5e1; border-left: 1px solid rgba(148,163,184,0.18); }
.range-btn.regime.active { background: #7c3aed; color: #fff; }
.date-pickers {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.date-pickers input[type="date"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 12.5px;
  margin-left: 4px;
  color-scheme: dark;
}
.metric-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.metric-selector-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.metric-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.metric-chip {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}
.metric-chip.active {
  background: rgba(37, 99, 235, 0.25);
  color: #93c5fd;
  border-color: #3b82f6;
}

.component-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}
.comp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.comp-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.comp-ticker { font-weight: 800; font-size: 16px; }
.comp-price { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.comp-metrics {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Dollar Calculator */
.calc-panel {
  margin-top: 12px;
  padding: 14px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.calc-mode-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.calc-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.calc-field label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}
.calc-field input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.calc-orders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
}
.order-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.order-box.sell { border-left: 3px solid var(--red); }
.order-box.buy { border-left: 3px solid var(--green); }
.order-box h4 { margin: 0 0 8px; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.order-line {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(255,255,255,0.06);
}
.order-line:last-child { border-bottom: none; }

/* Audit */
.history-strip {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.hist-pip {
  width: 12px;
  height: 22px;
  border-radius: 3px;
  background: var(--green);
}
.hist-pip.fail { background: var(--red); }
.hist-pip.warn { background: var(--amber); }
.audit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(4px);
}
.modal-dialog {
  position: relative;
  z-index: 101;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.modal-header h3 { margin: 0; font-size: 17px; }
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
}

@media (max-width: 640px) {
  .app-shell { padding: 10px 10px 48px; }
  .brand-title { font-size: 16px; }
  .plotly-box.tall { height: 340px; }
  .component-grid { grid-template-columns: 1fr; }
  .portfolios-grid { grid-template-columns: 1fr; }
}
