/*
 * Financial Insights — custom design system (v2).
 * Replaces Tabler entirely. Dark-only, data-dense fintech dashboard aesthetic:
 * deep elevation scale (never pure black), indigo-violet brand accent,
 * green/red financial semantics, JetBrains Mono for numbers, IBM Plex Sans
 * for UI text. See MULTI_STRATEGY_GUIDE.md-adjacent pages for content this
 * skin wraps — this file only ever changes *how* things look.
 */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ============================== TOKENS ================================= */

:root {
  /* Elevation scale (dark-only; never pure black — OLED smear + feels cheap) */
  --bg-canvas: #0a0b0f;
  --bg-surface: #101218;
  --bg-elevated: #15171f;
  --bg-elevated-2: #1b1e28;
  --bg-elevated-3: #232733;

  --border-hairline: rgba(255, 255, 255, 0.08);
  --border-hairline-strong: rgba(255, 255, 255, 0.16);

  --text-primary: #F2F3F7;
  --text-secondary: #9AA1B2;
  --text-tertiary: #818798; /* 4.98:1 on --bg-elevated, 5.48:1 on --bg-canvas - WCAG AA for small text (was 3.67:1, large-text-only) */
  --on-accent: #FFFFFF;

  /* Brand accent — indigo/violet, continuing the app's existing mark */
  --accent: #6D5EF7;
  --accent-hover: #8073FA;
  --accent-active: #5A4CE0;
  --accent-soft: rgba(109, 94, 247, 0.14);
  --accent-glow: rgba(109, 94, 247, 0.35);

  /* Financial semantics — never rely on color alone; pair with icon/sign */
  --profit: #22C55E;
  --profit-soft: rgba(34, 197, 94, 0.14);
  --loss: #EF4444;
  --loss-soft: rgba(239, 68, 68, 0.14);
  --warning: #F59E0B;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --info: #38BDF8;
  --info-soft: rgba(56, 189, 248, 0.14);
  --neutral-soft: rgba(154, 161, 178, 0.14);

  /* Typography */
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 1rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.875rem;
  --text-3xl: 2.25rem;

  /* Spacing (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;

  /* Shadows — subtle; dark theme leans on layering + hairlines, not shadow */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 0 1px var(--accent-glow), 0 8px 24px rgba(109, 94, 247, 0.22);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 320ms;

  --sidebar-width: 260px;
  --topbar-height: 60px;

  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================== RESET =================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img, svg { display: block; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

::selection { background: var(--accent-soft); color: var(--text-primary); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated-3); border-radius: var(--radius-full); border: 2px solid var(--bg-canvas); }
::-webkit-scrollbar-thumb:hover { background: var(--border-hairline-strong); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }

.text-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-profit { color: var(--profit); }
.text-loss { color: var(--loss); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }

/* ============================== LAYOUT SHELL ============================ */

.app-shell { display: flex; min-height: 100dvh; }

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(109, 94, 247, 0.12), transparent 60%),
    var(--bg-surface);
  border-right: 1px solid var(--border-hairline);
  z-index: 40;
  transition: transform var(--duration-base) var(--ease-out);
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
}

.app-brand-name {
  font-weight: 700;
  font-size: var(--text-sm);
  line-height: 1.2;
  color: var(--text-primary);
}

.app-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
  display: flex;
  flex-direction: column;
}

.nav-section-title {
  display: block;
  color: var(--text-tertiary);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: var(--space-5) var(--space-4) var(--space-2);
}

.nav-list { list-style: none; margin: 0; padding: 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0.125rem var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  min-height: 40px;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.nav-link svg { flex-shrink: 0; opacity: 0.8; }

.nav-link:hover, .nav-link:focus-visible {
  background: var(--bg-elevated-2);
  color: var(--text-primary);
}

.nav-link.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-active));
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow-glow);
}

.nav-link.active svg { opacity: 1; }

.sidebar-widget {
  margin: var(--space-3) var(--space-3) 0;
  padding: var(--space-3);
  border-top: 1px solid var(--border-hairline);
}

.sidebar-account {
  border-top: 1px solid var(--border-hairline);
  padding: var(--space-3);
  position: relative;
}

.sidebar-account-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  min-height: 44px;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.sidebar-account-toggle:hover { background: var(--bg-elevated-2); }
.sidebar-account-toggle .chevron { margin-left: auto; opacity: 0.6; }

.app-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--accent-active));
  color: var(--on-accent);
  font-size: var(--text-sm);
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 39;
}

.topbar-mobile {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
  background: rgba(16, 18, 24, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .topbar-mobile { display: flex; }
  .sidebar-backdrop.is-open { display: block; }
}

/* ============================== PAGE ===================================== */

.page-body { flex: 1; padding: var(--space-6) 0 var(--space-16); }

.container-xl { max-width: 1320px; margin: 0 auto; padding: 0 var(--space-6); }

@media (max-width: 575.98px) {
  .container-xl { padding: 0 var(--space-4); }
  .page-body { padding: var(--space-4) 0 var(--space-12); }
}

.page-header { margin-bottom: var(--space-6); }
.page-pretitle {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--space-1);
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ============================== GRID ===================================== */

.grid { display: grid; gap: var(--space-4); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-12 { grid-template-columns: repeat(12, 1fr); }

@media (max-width: 991.98px) {
  .grid-cols-3, .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 575.98px) {
  .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr; }
}

.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
@media (max-width: 991.98px) {
  .span-4, .span-6, .span-8 { grid-column: span 12; }
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.w-full { width: 100%; }

/* ============================== CARD ===================================== */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-hairline);
}

.card-title { font-size: var(--text-md); font-weight: 600; letter-spacing: -0.01em; }
.card-body { padding: var(--space-5); }
.card-body-compact { padding: var(--space-3) var(--space-4); }

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stat-label {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ============================== BUTTONS ================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-xs); }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-glow); }

.btn-outline { background: transparent; border-color: var(--border-hairline-strong); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-elevated-2); border-color: var(--text-tertiary); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-elevated-2); color: var(--text-primary); }

.btn-danger { background: var(--loss); color: #fff; }
.btn-danger:hover { background: #f45f5f; }

.btn-outline-danger { background: transparent; border-color: rgba(239, 68, 68, 0.4); color: var(--loss); }
.btn-outline-danger:hover { background: var(--loss-soft); }

.btn-warning { background: var(--warning); color: #1a1200; }
.btn-outline-warning { background: transparent; border-color: rgba(245, 158, 11, 0.4); color: var(--warning); }
.btn-outline-warning:hover { background: var(--warning-soft); }

/* ============================== BADGES =================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
}

.badge-neutral { background: var(--neutral-soft); color: var(--text-secondary); }
.badge-accent { background: var(--accent-soft); color: #b3a8ff; }
.badge-profit { background: var(--profit-soft); color: var(--profit); }
.badge-loss { background: var(--loss-soft); color: var(--loss); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }

.badge-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.stat-value.with-dot {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* ============================== TABLES =================================== */

.table-wrap { overflow-x: auto; }

.table { font-size: var(--text-sm); }

.table th {
  text-align: left;
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-hairline);
  vertical-align: middle;
}

.table tbody tr { transition: background-color var(--duration-fast) var(--ease-out); }
.table tbody tr:hover { background: var(--bg-elevated-2); }
.table tbody tr:last-child td { border-bottom: none; }

.table .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.text-end { text-align: right; }

.empty-state {
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--text-tertiary);
}

/* ============================== FORMS ===================================== */

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-control, .form-select {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-hairline-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}

textarea.form-control { min-height: 88px; padding: var(--space-3); }

.form-control::placeholder { color: var(--text-tertiary); }

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-hint { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-2); }

.form-check { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; }
.form-check input[type="checkbox"], .form-check input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); }

.form-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.form-switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; width: 100%; height: 100%; }
.form-switch .track {
  position: absolute;
  inset: 0;
  background: var(--bg-elevated-3);
  border: 1px solid var(--border-hairline-strong);
  border-radius: var(--radius-full);
  transition: background-color var(--duration-base) var(--ease-out);
}
.form-switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform var(--duration-base) var(--ease-out);
}
.form-switch input:checked ~ .track { background: var(--accent); border-color: var(--accent); }
.form-switch input:checked ~ .thumb { transform: translateX(18px); background: #fff; }
.form-switch input:focus-visible ~ .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================== ALERTS =================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline);
  font-size: var(--text-sm);
  position: relative;
}

.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-body { flex: 1; }
.alert-title { font-weight: 600; margin-bottom: var(--space-1); }

.alert-success { background: var(--profit-soft); border-color: rgba(34, 197, 94, 0.3); color: var(--profit); }
.alert-info { background: var(--info-soft); border-color: rgba(56, 189, 248, 0.3); color: var(--info); }
.alert-warning { background: var(--warning-soft); border-color: rgba(245, 158, 11, 0.3); color: var(--warning); }
.alert-danger { background: var(--loss-soft); border-color: rgba(239, 68, 68, 0.3); color: var(--loss); }

.alert-dismiss {
  background: none;
  border: none;
  color: currentColor;
  opacity: 0.6;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.alert-dismiss:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }

/* ============================== DROPDOWN ================================= */

.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  min-width: 200px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-hairline-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: 50;
  display: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.dropdown-menu.dropup { bottom: calc(100% + 8px); left: 0; }
.dropdown-menu.dropdown-below { top: calc(100% + 8px); right: 0; }

.dropdown-menu.is-open { display: block; opacity: 1; transform: translateY(0); }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  min-height: 40px;
}
.dropdown-item:hover { background: var(--bg-elevated-3); color: var(--text-primary); }
.dropdown-divider { height: 1px; background: var(--border-hairline); margin: var(--space-2) 0; }

/* ============================== TABS ====================================== */

.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border-hairline); margin-bottom: var(--space-4); }

.tab-link {
  padding: var(--space-3) var(--space-4);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}
.tab-link:hover { color: var(--text-primary); }
.tab-link.active { color: var(--accent); border-bottom-color: var(--accent); }

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

/* ============================== MODAL ===================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 9, 0.7);
  backdrop-filter: blur(4px);
  z-index: 90;
  display: none;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out);
}
.modal-backdrop.is-open { display: block; opacity: 1; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 91;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal.is-open { display: flex; }

.modal-dialog {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-hairline-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: scale(0.96) translateY(8px);
  opacity: 0;
  transition: transform var(--duration-base) var(--ease-out), opacity var(--duration-base) var(--ease-out);
}
.modal.is-open .modal-dialog { transform: scale(1) translateY(0); opacity: 1; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-hairline);
}
.modal-title { font-size: var(--text-md); font-weight: 600; }
.modal-body { padding: var(--space-5); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-hairline);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--bg-elevated-3); color: var(--text-primary); }

/* ============================== MISC ====================================== */

.divider { height: 1px; background: var(--border-hairline); border: none; margin: var(--space-5) 0; }

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated-2) 25%, var(--bg-elevated-3) 37%, var(--bg-elevated-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--bg-elevated-2); }
  .spinner { animation-duration: 1.4s; }
}

/* ============================== DATATABLES.NET COMPAT ==================
 * analyse_lightyear.html / stock_analysis.html load DataTables.net from a
 * CDN for a few tables - it ships its own light-themed chrome (search box,
 * length select, pagination, sort arrows) that we don't control the markup
 * of. Dark-theme it here instead of forking the library. */

.dataTables_wrapper { color: var(--text-secondary); font-size: var(--text-sm); }

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-hairline-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.25rem 0.5rem;
}

.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label {
  color: var(--text-tertiary);
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  color: var(--text-secondary) !important;
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.625rem;
  border: 1px solid transparent !important;
  background: transparent !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--accent-soft) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-hairline-strong) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--bg-elevated-2) !important;
  color: var(--text-primary) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  color: var(--text-tertiary) !important;
  opacity: 0.5;
}

table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
  color: var(--text-tertiary);
}

/* ============================== SPARKLINES ================================ */

.sparkline-wrap { line-height: 0; }

/* ============================== FLASH-ON-UPDATE ===========================
 * Reinforces that a number came from a live poll, not a static render - a
 * cell/value briefly tints then fades back to normal. Never used for the
 * FIRST render (only on values that genuinely changed between polls). */

@keyframes flash-up { 0% { background: var(--profit-soft); } 100% { background: transparent; } }
@keyframes flash-down { 0% { background: var(--loss-soft); } 100% { background: transparent; } }
@keyframes flash-neutral { 0% { background: var(--accent-soft); } 100% { background: transparent; } }

.flash-up { animation: flash-up 1.1s var(--ease-out); }
.flash-down { animation: flash-down 1.1s var(--ease-out); }
.flash-neutral { animation: flash-neutral 1.1s var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  .flash-up, .flash-down, .flash-neutral { animation: none; }
}

.dt-buttons .btn, .dataTables_wrapper .dt-button {
  background: var(--bg-elevated-2) !important;
  border: 1px solid var(--border-hairline-strong) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
}

/* ============================== ENTRANCE MOTION ==========================
 * A dashboard that never moves reads as a static template. KPI rows fade
 * + rise in, staggered, on first paint - subtle, once, never re-triggered
 * by polling (the JS-driven live updates below don't replay this). */

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.grid > .stat-card, .grid > .card {
  animation: fade-in-up var(--duration-slow) var(--ease-out) backwards;
}
.grid > *:nth-child(1) { animation-delay: 0ms; }
.grid > *:nth-child(2) { animation-delay: 40ms; }
.grid > *:nth-child(3) { animation-delay: 80ms; }
.grid > *:nth-child(4) { animation-delay: 120ms; }
.grid > *:nth-child(5) { animation-delay: 160ms; }
.grid > *:nth-child(n+6) { animation-delay: 200ms; }

@media (prefers-reduced-motion: reduce) {
  .grid > .stat-card, .grid > .card { animation: none; }
}

/* ============================== HOVER DEPTH =============================
 * Flat backgrounds + hairlines read as "list", not "product" - interactive
 * surfaces get a touch of lift so the hierarchy is felt, not just seen. */

.stat-card, .card-interactive {
  transition: transform var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}
.stat-card:hover, .card-interactive:hover {
  transform: translateY(-2px);
  border-color: var(--border-hairline-strong);
  box-shadow: var(--shadow-md);
}

/* ============================== LIVE INDICATOR ============================
 * A trading bot is either working right now or it isn't - a static badge
 * undersells that. `.dot-live` pulses gently while something is actually
 * active (start/stop it via JS by toggling the class, not on a dead state). */

.dot-live {
  position: relative;
}
.dot-live::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0;
  animation: live-pulse 2s var(--ease-out) infinite;
}
@keyframes live-pulse {
  0% { opacity: 0.55; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.8); }
}
@media (prefers-reduced-motion: reduce) {
  .dot-live::after { animation: none; display: none; }
}

.nav-link.active {
  animation: nav-glow-pulse 3s ease-in-out infinite;
}
@keyframes nav-glow-pulse {
  0%, 100% { box-shadow: var(--shadow-glow); }
  50% { box-shadow: 0 0 0 1px var(--accent-glow), 0 10px 30px rgba(109, 94, 247, 0.32); }
}
@media (prefers-reduced-motion: reduce) {
  .nav-link.active { animation: none; }
}

/* ============================== HERO STAT ================================
 * For the one number on a page that matters more than the rest (total
 * portfolio value, today's bot P&L) - a stat-card is too quiet for that. */

.stat-hero {
  background:
    radial-gradient(140% 100% at 100% 0%, var(--accent-soft), transparent 60%),
    var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stat-hero .stat-label { color: var(--text-secondary); }

.stat-hero .stat-value {
  font-size: var(--text-3xl);
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-hero .stat-value.text-profit {
  background: linear-gradient(135deg, #4ade80, var(--profit));
  -webkit-background-clip: text;
  background-clip: text;
}
.stat-hero .stat-value.text-loss {
  background: linear-gradient(135deg, #fb7185, var(--loss));
  -webkit-background-clip: text;
  background-clip: text;
}

/* Standalone version of the hero gradient-text treatment, for prominent
   numbers that live outside a .stat-hero card (e.g. a page-header total). */
.text-gradient {
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-hero .stat-delta {
  font-size: var(--text-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  width: fit-content;
}

/* ============================== EMPTY STATE (v2) ========================= */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.empty-state-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
}

/* ============================== SECTION (borderless) ======================
 * Not every grouping needs a bordered box - overusing `.card` flattens the
 * hierarchy into one long list of identical boxes. `.section` is the plain
 * alternative: a heading + content, no chrome, for lower-emphasis groupings. */

.section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}
