/*
 * Reserve Flow Analytics — Unified Design System
 * Version 1.0 | 2026-03-13
 *
 * Shared across: dts_dashboard, futures_lab dashboards
 * Fonts: Inter (body), Outfit (headlines), JetBrains Mono (data)
 * Brand accent: cyan #06b6d4
 */

/* ─── Fonts ─── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Outfit:wght@500;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ─── Design Tokens ─── */
:root {
  /* Backgrounds */
  --bg-base: #060608;
  --bg-surface: #0f0f13;
  --bg-surface-hover: #16161a;
  --bg-elevated: #1e1e24;

  /* Borders */
  --border: #24242c;
  --border-hover: #343440;
  --border-subtle: rgba(255, 255, 255, 0.04);

  /* Text */
  --text-primary: #FAFAFA;
  --text-secondary: #94A3B8;
  --text-dim: #555;

  /* Brand accent */
  --accent: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.4);
  --accent-bg: rgba(6, 182, 212, 0.1);
  --accent-border: rgba(6, 182, 212, 0.25);

  /* Semantic: data-driven only */
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.15);
  --green-bright: #34d399;
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.15);
  --red-bright: #f87171;
  --yellow: #f59e0b;
  --yellow-bg: rgba(245, 158, 11, 0.15);
  --yellow-bright: #fbbf24;
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.15);
  --blue-bright: #60a5fa;

  /* Spacing scale (4px base) */
  --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;
  --sp-16: 64px;
  --sp-20: 80px;

  /* Border radius */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 9999px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: all 0.3s var(--ease);
  --transition-fast: all 0.15s var(--ease);

  /* Typography scale */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 32px;
  --text-4xl: 40px;
  --text-5xl: 56px;
}


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


/* ─── Base ─── */
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
}


/* ─── Layout ─── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--sp-6);
}

.container--narrow {
  max-width: 900px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
}

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


/* ─── Typography ─── */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  line-height: 1.2;
}

h1 {
  font-size: var(--text-5xl);
  font-weight: 800;
  letter-spacing: -1.5px;
  background: linear-gradient(135deg, #fff 30%, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: var(--text-3xl);
  font-weight: 700;
}

h3 {
  font-size: var(--text-xl);
  font-weight: 600;
}

h4 {
  font-size: var(--text-lg);
  font-weight: 600;
}

.mono {
  font-family: var(--font-mono);
}

.label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
}


/* ─── Header ─── */
.rfa-header {
  position: relative;
  padding: var(--sp-20) 0 var(--sp-16);
  margin-bottom: var(--sp-16);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(circle at 10% 80%, rgba(6, 182, 212, 0.08), transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(59, 130, 246, 0.06), transparent 40%);
}

.rfa-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.5;
}

.rfa-header--compact {
  padding: var(--sp-10) 0 var(--sp-8);
  margin-bottom: var(--sp-8);
  text-align: center;
}

.rfa-header--compact h1 {
  font-size: var(--text-3xl);
  letter-spacing: -1px;
}

.rfa-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-xl);
  font-weight: 400;
  max-width: 600px;
}

.rfa-header--compact .rfa-subtitle {
  font-size: var(--text-base);
  font-family: var(--font-mono);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  margin-top: var(--sp-8);
}

.header-meta span {
  color: var(--text-secondary);
  background: var(--bg-surface);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.header-meta strong {
  color: var(--text-primary);
  font-weight: 600;
}


/* ─── Section ─── */
.section {
  margin-bottom: var(--sp-16);
}

.section-title {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--sp-8);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.section-title::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
  flex-shrink: 0;
}


/* ─── Cards ─── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-5) var(--sp-6);
  transition: var(--transition);
}

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

.card--interactive:hover {
  background: var(--bg-surface-hover);
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.card-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.card-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  margin: var(--sp-1) 0 var(--sp-1);
}

.card-change {
  font-size: var(--text-sm);
  font-weight: 600;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3);
}


/* ─── Status top-bar on cards ─── */
.card--status {
  position: relative;
  overflow: hidden;
}

.card--status::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  transition: var(--transition);
}

.card--status.green::before { background: var(--green); }
.card--status.red::before { background: var(--red); }
.card--status.yellow::before { background: var(--yellow); }
.card--status.blue::before { background: var(--blue); }


/* ─── Badges ─── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge--green { background: var(--green-bg); color: var(--green-bright); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge--red { background: var(--red-bg); color: var(--red-bright); border: 1px solid rgba(239, 68, 68, 0.2); }
.badge--yellow { background: var(--yellow-bg); color: var(--yellow-bright); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge--blue { background: var(--blue-bg); color: var(--blue-bright); border: 1px solid rgba(59, 130, 246, 0.2); }
.badge--accent { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-border); }
.badge--neutral { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }


/* ─── Tables ─── */
.rfa-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.rfa-table th {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rfa-table th:not(:first-child) {
  text-align: right;
}

.rfa-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.rfa-table td:not(:first-child) {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
}

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

.rfa-table--bordered {
  border-collapse: separate;
  border-spacing: 0;
}

.rfa-table--bordered th {
  background: var(--bg-base);
  color: var(--text-primary);
  font-weight: 600;
  padding: var(--sp-4);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
}

.rfa-table--bordered th:first-child { border-left: 1px solid var(--border); border-top-left-radius: var(--radius-sm); }
.rfa-table--bordered th:last-child { border-right: 1px solid var(--border); border-top-right-radius: var(--radius-sm); }
.rfa-table--bordered td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.rfa-table--bordered tr td:first-child { border-left: 1px solid var(--border); }
.rfa-table--bordered tr td:last-child { border-right: 1px solid var(--border); }
.rfa-table--bordered tr:last-child td:first-child { border-bottom-left-radius: var(--radius-sm); }
.rfa-table--bordered tr:last-child td:last-child { border-bottom-right-radius: var(--radius-sm); }
.rfa-table--bordered tr:hover td { background: var(--bg-elevated); }


/* ─── Buttons & Toggles ─── */
.btn {
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-body);
  transition: var(--transition-fast);
}

.btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn.active {
  background: var(--accent-bg);
  color: var(--text-primary);
  border-color: var(--accent-border);
}

.btn--primary {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--accent-border);
  color: var(--text-primary);
}

.btn--primary:hover {
  background: rgba(6, 182, 212, 0.35);
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}


/* ─── Callout ─── */
.callout {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: var(--sp-6) var(--sp-8);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  transition: var(--transition);
}

.callout:hover {
  transform: translateX(4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.callout--green { border-left-color: var(--green); background: linear-gradient(90deg, rgba(16, 185, 129, 0.04), transparent); }
.callout--red { border-left-color: var(--red); background: linear-gradient(90deg, rgba(239, 68, 68, 0.04), transparent); }
.callout--yellow { border-left-color: var(--yellow); background: linear-gradient(90deg, rgba(245, 158, 11, 0.04), transparent); }

.callout h4 {
  margin-bottom: 10px;
  font-size: var(--text-lg);
  font-family: var(--font-heading);
  font-weight: 600;
}

.callout--green h4 { color: var(--green-bright); }
.callout--red h4 { color: var(--red-bright); }
.callout--yellow h4 { color: var(--yellow-bright); }
.callout p { color: var(--text-secondary); line-height: 1.6; }


/* ─── Insight / Note box ─── */
.insight {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.insight strong {
  color: var(--text-primary);
}

.note {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-base);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}


/* ─── Collapsible sections ─── */
details { margin-bottom: var(--sp-6); }

details summary {
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-secondary);
  padding: var(--sp-4) var(--sp-6);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: var(--transition);
  list-style: none;
}

details summary::-webkit-details-marker { display: none; }
details summary::before { content: "+ "; color: var(--accent); font-family: var(--font-mono); }
details[open] summary::before { content: "- "; }
details[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; color: var(--text-primary); background: var(--bg-surface-hover); }
details summary:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

details .detail-content {
  padding: var(--sp-6);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}


/* ─── Chart containers ─── */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 380px;
}

.chart-wrap--sm { height: 240px; }
.chart-wrap--lg { height: 480px; }


/* ─── Legend ─── */
.legend {
  display: flex;
  gap: var(--sp-5);
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.legend span {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}


/* ─── Color utilities ─── */
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-blue { color: var(--blue); }
.text-accent { color: var(--accent); }
.text-muted { color: var(--text-secondary); }
.text-dim { color: var(--text-dim); }
.text-primary { color: var(--text-primary); }

.bg-green { background: var(--green-bg); }
.bg-red { background: var(--red-bg); }
.bg-yellow { background: var(--yellow-bg); }
.bg-blue { background: var(--blue-bg); }


/* ─── Gauge bar ─── */
.gauge-bar-wrap {
  position: relative;
  height: 18px;
  border-radius: 9px;
  overflow: hidden;
  background: linear-gradient(to right, var(--red), rgba(239, 68, 68, 0.5), var(--text-secondary), rgba(16, 185, 129, 0.5), var(--green));
}

.gauge-marker {
  position: absolute;
  top: -4px;
  width: 3px;
  height: 26px;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
  transition: left 0.6s var(--ease);
}


/* ─── Loading ─── */
.loading {
  text-align: center;
  padding: var(--sp-16);
  color: var(--text-secondary);
  font-size: var(--text-md);
}


/* ─── Footer ─── */
.rfa-footer {
  font-size: var(--text-xs);
  color: var(--text-dim);
  text-align: center;
  padding-top: var(--sp-4);
  margin-top: var(--sp-2);
}


/* ─── Animations ─── */
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px var(--accent-glow); }
  50% { box-shadow: 0 0 12px var(--accent-glow); }
}

@keyframes highlight {
  0% { box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.6); }
  100% { box-shadow: none; }
}

.animate-pulse { animation: pulse 2s infinite; }
.animate-highlight { animation: highlight 1.5s ease; }


/* ─── Scrollbar (Webkit) ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }


/* ─── Light Mode ─── */
[data-theme="light"] {
  --bg-base: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f3f5;
  --bg-elevated: #e9ecef;

  --border: #dee2e6;
  --border-hover: #ced4da;
  --border-subtle: rgba(0, 0, 0, 0.06);

  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-dim: #9ca3af;

  --accent: #0891b2;
  --accent-glow: rgba(8, 145, 178, 0.3);
  --accent-bg: rgba(8, 145, 178, 0.08);
  --accent-border: rgba(8, 145, 178, 0.2);

  --green: #059669;
  --green-bg: rgba(5, 150, 105, 0.1);
  --green-bright: #10b981;
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.08);
  --red-bright: #ef4444;
  --yellow: #d97706;
  --yellow-bg: rgba(217, 119, 6, 0.1);
  --yellow-bright: #f59e0b;
  --blue: #2563eb;
  --blue-bg: rgba(37, 99, 235, 0.08);
  --blue-bright: #3b82f6;
}

/* Light mode adjustments for elements that need explicit overrides */
[data-theme="light"] h1 {
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

[data-theme="light"] .card {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .card--interactive:hover {
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .rfa-header {
  background:
    radial-gradient(circle at 10% 80%, rgba(8, 145, 178, 0.06), transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(37, 99, 235, 0.04), transparent 40%);
}

[data-theme="light"] .header-meta span {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .rfa-table tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .rfa-table--bordered tr:hover td {
  background: var(--bg-surface-hover);
}

[data-theme="light"] .callout:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .gauge-bar-wrap {
  background: linear-gradient(to right, var(--red), rgba(220, 38, 38, 0.3), var(--text-secondary), rgba(5, 150, 105, 0.3), var(--green));
}

[data-theme="light"] .gauge-marker {
  background: var(--text-primary);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] ::-webkit-scrollbar-track { background: var(--bg-base); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: var(--border); }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }


/* ─── Theme Toggle ─── */
.theme-toggle {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  z-index: 1000;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  cursor: pointer;
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.theme-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}


/* ─── Responsive ─── */
@media (max-width: 768px) {
  :root {
    --text-5xl: 36px;
    --text-4xl: 28px;
    --text-3xl: 24px;
  }

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

  .rfa-header { padding: var(--sp-10) 0 var(--sp-8); margin-bottom: var(--sp-10); }

  .section { margin-bottom: var(--sp-10); }
}
