/* ═══════════════════════════════════════════════════════════════
   AEGIS v12 — Live Paper Trading Dashboard
   Dark institutional theme · Data-dense · Responsive
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --bg: #0a0a0f;
  --bg-card: #13131a;
  --bg-card-hover: #181822;
  --border: rgba(255,255,255,0.06);
  --border-accent: rgba(20,184,166,0.2);
  --text: #e8e8ed;
  --text-muted: #8b8b96;
  --text-faint: #52525e;
  --accent: #14b8a6;
  --accent-dim: rgba(20,184,166,0.15);
  --accent-glow: rgba(20,184,166,0.08);

  /* Regime Colors */
  --regime-calm: #22c55e;
  --regime-monitoring: #3b82f6;
  --regime-elevated: #f59e0b;
  --regime-stress: #f97316;
  --regime-crisis: #ef4444;

  /* Semantic */
  --positive: #22c55e;
  --negative: #ef4444;
  --neutral: #8b8b96;

  /* Type */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Radius */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Transitions */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  font-variant-numeric: tabular-nums lining-nums;
}

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  border-top: 2px solid var(--accent);
}

.header__inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.header__logo {
  color: var(--text);
  flex-shrink: 0;
}

.header__title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
}

.header__title-dim {
  color: var(--text-muted);
  font-weight: 400;
}

.header__subtitle {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  line-height: 1.4;
}

/* Regime Badge */
.regime-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.regime-badge__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.regime-badge[data-regime="CALM"] {
  background: rgba(34,197,94,0.1);
  border-color: rgba(34,197,94,0.3);
  color: var(--regime-calm);
}
.regime-badge[data-regime="CALM"] .regime-badge__dot { background: var(--regime-calm); }

.regime-badge[data-regime="MONITORING"] {
  background: rgba(59,130,246,0.1);
  border-color: rgba(59,130,246,0.3);
  color: var(--regime-monitoring);
}
.regime-badge[data-regime="MONITORING"] .regime-badge__dot { background: var(--regime-monitoring); }

.regime-badge[data-regime="ELEVATED"] {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.3);
  color: var(--regime-elevated);
}
.regime-badge[data-regime="ELEVATED"] .regime-badge__dot { background: var(--regime-elevated); }

.regime-badge[data-regime="STRESS"] {
  background: rgba(249,115,22,0.1);
  border-color: rgba(249,115,22,0.3);
  color: var(--regime-stress);
}
.regime-badge[data-regime="STRESS"] .regime-badge__dot { background: var(--regime-stress); }

.regime-badge[data-regime="CRISIS"] {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: var(--regime-crisis);
}
.regime-badge[data-regime="CRISIS"] .regime-badge__dot { background: var(--regime-crisis); }

/* ── Main ── */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-6) var(--sp-12);
}

/* ── Sections ── */
.section {
  margin-bottom: var(--sp-6);
  animation: fadeUp 0.6s var(--ease) both;
}

.section:nth-child(1) { animation-delay: 0.05s; }
.section:nth-child(2) { animation-delay: 0.1s; }
.section:nth-child(3) { animation-delay: 0.15s; }
.section:nth-child(4) { animation-delay: 0.2s; }
.section:nth-child(5) { animation-delay: 0.25s; }
.section:nth-child(6) { animation-delay: 0.3s; }
.section:nth-child(7) { animation-delay: 0.35s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--sp-3);
}

.section__count {
  color: var(--text-faint);
  font-weight: 400;
}

/* ── KPI Strip ── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: var(--sp-3);
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}

.kpi-card:hover {
  border-color: var(--border-accent);
  background: var(--bg-card-hover);
}

.kpi-card__label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.kpi-card__value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}

.kpi-card__value--positive { color: var(--positive); }
.kpi-card__value--negative { color: var(--negative); }
.kpi-card__value--accent   { color: var(--accent); }

.kpi-card__sub {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.kpi-card__sub--positive { color: var(--positive); }
.kpi-card__sub--negative { color: var(--negative); }

/* Hedge bar */
.hedge-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  margin-top: var(--sp-1);
  overflow: hidden;
}

.hedge-bar__fill {
  height: 100%;
  border-radius: 2px;
  transition: width 1s var(--ease);
}

/* ── Signal Grid ── */
.signal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3);
}

.signal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  transition: border-color 0.3s var(--ease), background 0.3s var(--ease);
}

.signal-card:hover {
  border-color: var(--border-accent);
  background: var(--bg-card-hover);
}

.signal-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-2);
}

.signal-card__label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.signal-card__badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.signal-card__value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: var(--sp-2);
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Progress bar */
.progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 1s var(--ease);
}

/* ── Market Grid ── */
.market-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--sp-2);
}

.market-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  transition: border-color 0.3s var(--ease);
}

.market-card:hover {
  border-color: var(--border-accent);
}

.market-card__ticker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.market-card__price {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.market-card__change {
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-mono);
}

.market-card__change--positive { color: var(--positive); }
.market-card__change--negative { color: var(--negative); }
.market-card__change--neutral  { color: var(--neutral); }

/* ── Execution Grid ── */
.execution-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3);
}

.execution-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.execution-card__label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
}

.execution-card__value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.execution-card__sub {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  margin-top: 2px;
}

/* ── Charts ── */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  position: relative;
}

.chart-container canvas {
  width: 100% !important;
  max-height: 360px;
}

.chart-container--small canvas {
  max-height: 240px;
}

.chart-legend {
  display: flex;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
  flex-wrap: wrap;
}

.chart-legend__item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: 12px;
  color: var(--text-muted);
}

.chart-legend__swatch {
  width: 12px;
  height: 3px;
  border-radius: 1px;
  display: inline-block;
}

/* ── Journal Table ── */
.table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  -webkit-overflow-scrolling: touch;
}

.journal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.journal-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.journal-table th {
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.journal-table td {
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.journal-table tbody tr {
  transition: background 0.15s var(--ease);
}

.journal-table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

.journal-table tbody tr:last-child td {
  border-bottom: none;
}

.direction-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  font-family: var(--font-body);
}

.direction-badge--increase {
  background: rgba(249,115,22,0.12);
  color: #fb923c;
  border: 1px solid rgba(249,115,22,0.25);
}

.direction-badge--decrease {
  background: rgba(34,197,94,0.12);
  color: #4ade80;
  border: 1px solid rgba(34,197,94,0.25);
}

/* ── Footer ── */
.footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-6);
  text-align: center;
}

.footer__inner {
  max-width: 1440px;
  margin: 0 auto;
}

.footer__model {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: var(--sp-1);
}

.footer__attribution {
  font-size: 11px;
}

.footer__attribution a {
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.2s;
}

.footer__attribution a:hover {
  color: var(--accent);
}

/* ── Loading state ── */
.loading-placeholder {
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
  height: 20px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header__inner {
    padding: var(--sp-3) var(--sp-4);
  }

  .header__title {
    font-size: 15px;
  }

  .header__title-dim {
    display: none;
  }

  .main {
    padding: var(--sp-3) var(--sp-4) var(--sp-8);
  }

  .kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .signal-grid {
    grid-template-columns: 1fr 1fr;
  }

  .market-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .execution-grid {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-card__value {
    font-size: 18px;
  }

  .signal-card__value {
    font-size: 20px;
  }

  .chart-container {
    padding: var(--sp-3);
  }

  .chart-container canvas {
    max-height: 260px;
  }

  .chart-container--small canvas {
    max-height: 200px;
  }
}

@media (max-width: 480px) {
  .kpi-strip {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
  }

  .signal-grid {
    grid-template-columns: 1fr;
  }

  .market-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .execution-grid {
    grid-template-columns: 1fr;
  }

  .kpi-card {
    padding: var(--sp-3);
  }

  .kpi-card__value {
    font-size: 16px;
  }
}

/* ── Utility: regime-colored values ── */
.regime-calm { color: var(--regime-calm) !important; }
.regime-monitoring { color: var(--regime-monitoring) !important; }
.regime-elevated { color: var(--regime-elevated) !important; }
.regime-stress { color: var(--regime-stress) !important; }
.regime-crisis { color: var(--regime-crisis) !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
