/* ============================================
   TOPOPS AI — Design System Tokens
   ============================================ */

:root {
  /* ── Brand Core ── */
  --brand-orange: #FF6633;
  --brand-orange-light: #FF8855;
  --brand-orange-dark: #E55A2B;
  --brand-feldgrau: #4C5B5C;
  --brand-moonstone: #53B3CB;
  --brand-lime: #BCD631;
  --brand-violet: #170B47;
  /* RGB triplets for alpha compositing */
  --accent-rgb: 255, 102, 51;
  --moonstone-rgb: 83, 179, 203;

  /* ── Backgrounds (deepest to lightest) ── */
  --bg-void: #050810;
  --bg-primary: #0A0F1E;
  --bg-secondary: #0F172A;
  --bg-card: #1E293B;
  --bg-card-hover: #253248;
  --bg-tertiary: #334155;
  --bg-elevated: #334155;
  --bg-input: #0F172A;

  /* ── Text ── */
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #7C8CA0;
  --text-inverse: #0F172A;

  /* ── Borders ── */
  --border-default: #1E293B;
  --border-subtle: #141C2E;
  --border-hover: #334155;
  --border-glow: rgba(var(--accent-rgb), 0.2);

  /* ── Financial Signals ── */
  --positive: #10B981;
  --positive-light: #34D399;
  --positive-bg: rgba(16, 185, 129, 0.1);
  --positive-border: rgba(16, 185, 129, 0.3);
  --negative: #EF4444;
  --negative-light: #F87171;
  --negative-bg: rgba(239, 68, 68, 0.1);
  --negative-border: rgba(239, 68, 68, 0.3);
  --warning: #F59E0B;
  --warning-light: #FBBF24;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --warning-border: rgba(245, 158, 11, 0.3);

  /* ── Chart Series ── */
  --chart-1: #FF6633;
  --chart-2: #53B3CB;
  --chart-3: #BCD631;
  --chart-4: #F59E0B;
  --chart-5: #8B5CF6;
  --chart-6: #EC4899;

  /* ── Shadows ── */
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-card-hover: 0 10px 25px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.3);
  --shadow-elevated: 0 20px 40px rgba(0, 0, 0, 0.5);

  /* ── Glow Effects ── */
  --glow-orange: 0 0 60px rgba(255, 102, 51, 0.15), 0 0 120px rgba(255, 102, 51, 0.05);
  --glow-orange-intense: 0 0 40px rgba(255, 102, 51, 0.3), 0 0 80px rgba(255, 102, 51, 0.1);
  --glow-moonstone: 0 0 60px rgba(83, 179, 203, 0.1);
  --glow-lime: 0 0 60px rgba(188, 214, 49, 0.1);

  /* ── Spacing ── */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* ── Border Radius ── */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  /* ── Transitions ── */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* ── Typography ── */
  --font-display: 'Jost', 'Verdana', sans-serif;
  --font-body: 'Jost', 'Verdana', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ============================================
   Light Mode Overrides
   When data-theme="light" is set by theme-engine.js,
   these provide CSS-only fallbacks for components
   that don't read JS variables directly.
   ============================================ */

[data-theme="light"] {
  --bg-void: #FFFFFF;
  --bg-primary: #F8FAFC;
  --bg-secondary: #F1F5F9;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F8FAFC;
  --bg-tertiary: #E2E8F0;
  --bg-elevated: #E2E8F0;
  --bg-input: #F1F5F9;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #F1F5F9;

  --border-default: #E2E8F0;
  --border-subtle: #F1F5F9;
  --border-hover: #CBD5E1;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card-hover: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.06);
  --shadow-elevated: 0 20px 40px rgba(0, 0, 0, 0.12);
}

/* Light mode scrollbar */
[data-theme="light"] ::-webkit-scrollbar-track {
  background: #F1F5F9;
}
[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #CBD5E1;
}

/* ============================================
   Light Mode — Dashboard Overrides
   Fix hardcoded dark classes (text-white, border-white, etc.)
   that Tailwind CDN can't theme-switch automatically.
   ============================================ */

/* Nav: fix text-white and white-alpha borders */
[data-theme="light"] #main-nav {
  background: rgba(255, 255, 255, 0.92) !important;
  border-bottom-color: var(--border-default) !important;
  backdrop-filter: blur(12px) saturate(180%);
}
[data-theme="light"] #main-nav a,
[data-theme="light"] #main-nav button,
[data-theme="light"] #main-nav p,
[data-theme="light"] #main-nav span {
  color: var(--text-secondary);
}
[data-theme="light"] #main-nav a[aria-current="page"],
[data-theme="light"] #userMenuName,
[data-theme="light"] #userDropdownName {
  color: var(--text-primary) !important;
}
[data-theme="light"] #main-nav a:hover {
  color: var(--text-primary) !important;
}
[data-theme="light"] #main-nav .bg-brand-orange,
[data-theme="light"] #main-nav .bg-brand-orange a {
  color: #fff !important;
}

/* Notification & user menu dropdowns */
[data-theme="light"] #notifPanel,
[data-theme="light"] #userMenuDropdown {
  background: #fff;
  border-color: var(--border-default);
}
[data-theme="light"] #notifPanel .border-b,
[data-theme="light"] #userMenuDropdown .border-b {
  border-color: var(--border-default) !important;
}

/* Dashboard toolbar area — fix dark band */
[data-theme="light"] .dashboard-toolbar,
[data-theme="light"] .dash-toolbar {
  background: var(--bg-secondary) !important;
  border-color: var(--border-default) !important;
}

/* Dashboard tabs */
[data-theme="light"] .dashboard-tab {
  color: var(--text-secondary);
}
[data-theme="light"] .dashboard-tab.active {
  color: var(--text-primary);
}

/* Fix all white-alpha borders in light mode */
[data-theme="light"] [class*="border-white"] {
  border-color: var(--border-default) !important;
}

/* Fix text-white in content areas (not on colored button backgrounds) */
[data-theme="light"] .dash-card .text-white,
[data-theme="light"] .tab-content .text-white,
[data-theme="light"] [data-section-body] .text-white,
[data-theme="light"] .portal-card .text-white,
[data-theme="light"] .portal-card-static .text-white,
[data-theme="light"] main .text-white,
[data-theme="light"] #main-content .text-white {
  color: var(--text-primary) !important;
}
/* Preserve white text on colored backgrounds */
[data-theme="light"] .bg-brand-orange .text-white,
[data-theme="light"] .bg-brand-orange.text-white,
[data-theme="light"] .bg-positive .text-white,
[data-theme="light"] .bg-negative .text-white,
[data-theme="light"] [class*="bg-brand-orange"] {
  color: #fff !important;
}

/* Portal cards */
[data-theme="light"] .portal-card,
[data-theme="light"] .portal-card-static {
  box-shadow: var(--shadow-card);
}
[data-theme="light"] .portal-card:hover {
  box-shadow: var(--shadow-card-hover);
}

/* Fix hover backgrounds (white/[0.04] invisible on light) */
[data-theme="light"] [class*="hover\:bg-white"] {
  --tw-bg-opacity: 0.06;
}
[data-theme="light"] [class*="hover\:bg-white"]:hover {
  background-color: rgba(0, 0, 0, 0.04) !important;
}

/* Health factor cards */
[data-theme="light"] .health-factor-card {
  background: var(--bg-card) !important;
  border-color: var(--border-default) !important;
  box-shadow: var(--shadow-card);
}
[data-theme="light"] .health-factor-card--overall {
  border-color: var(--brand-orange, #FF6633) !important;
}

/* Dash cards */
[data-theme="light"] .dash-card {
  background: var(--bg-card) !important;
  border-color: var(--border-default) !important;
  box-shadow: var(--shadow-card);
}

/* Filter pills and toggles */
[data-theme="light"] .period-pill,
[data-theme="light"] .basis-pill,
[data-theme="light"] .view-pill {
  color: var(--text-secondary);
}
[data-theme="light"] .period-pill.active,
[data-theme="light"] .basis-pill.active,
[data-theme="light"] .view-pill.active {
  color: var(--text-primary);
}

/* Month selector pills */
[data-theme="light"] .month-pill {
  color: var(--text-secondary);
  background: var(--bg-secondary);
}
[data-theme="light"] .month-pill.active,
[data-theme="light"] .month-pill.in-range {
  background: var(--brand-orange);
  color: #fff;
}

/* Modals */
[data-theme="light"] .modal-overlay {
  background: rgba(0, 0, 0, 0.3) !important;
}
[data-theme="light"] .modal-content,
[data-theme="light"] .modal-panel {
  background: #fff !important;
  border-color: var(--border-default) !important;
}

/* Tables */
[data-theme="light"] .data-table th {
  background: var(--bg-secondary) !important;
  color: var(--text-secondary);
}
[data-theme="light"] .data-table td {
  border-color: var(--border-default) !important;
}

/* Sticky columns */
[data-theme="light"] .sticky {
  background: inherit;
}
[data-theme="light"] td.sticky,
[data-theme="light"] th.sticky {
  background: var(--bg-card) !important;
}

/* Tooltips */
[data-theme="light"] [data-tooltip]:hover::after {
  background: var(--text-primary);
  color: var(--bg-card);
}

/* ============================================
   Base Resets
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ============================================
   Custom Scrollbar
   ============================================ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ============================================
   Focus-Visible States (Accessibility)
   ============================================ */

a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid rgba(255, 102, 51, 0.5);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  border-color: rgba(255, 102, 51, 0.4) !important;
  box-shadow: 0 0 0 3px rgba(255, 102, 51, 0.1) !important;
  outline: none;
}

/* ============================================
   Noise Texture Overlay
   ============================================ */

.noise::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
  opacity: 0.4;
}

/* ============================================
   Glassmorphism
   ============================================ */

.glass {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.glass-card {
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-xl);
}

/* ============================================
   Gradient Borders
   ============================================ */

.gradient-border {
  position: relative;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
}

.gradient-border::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 102, 51, 0.3), rgba(83, 179, 203, 0.1), rgba(255, 102, 51, 0.1));
  z-index: -1;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  padding: 1px;
}

/* ============================================
   Glow Card (featured tier, etc.)
   ============================================ */

.glow-card {
  position: relative;
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.glow-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 60px rgba(255, 102, 51, 0.06);
  pointer-events: none;
}

/* ============================================
   Scroll Reveal Animations
   ============================================ */

.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-delay-1 { transition-delay: 0.1s; }
.reveal-delay-2 { transition-delay: 0.2s; }
.reveal-delay-3 { transition-delay: 0.3s; }
.reveal-delay-4 { transition-delay: 0.4s; }
.reveal-delay-5 { transition-delay: 0.5s; }
.reveal-delay-6 { transition-delay: 0.6s; }

/* Stagger children */
.stagger-in > * {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.stagger-in.is-visible > * {
  opacity: 1;
  transform: translateY(0);
}

.stagger-in.is-visible > *:nth-child(1) { transition-delay: 0.05s; }
.stagger-in.is-visible > *:nth-child(2) { transition-delay: 0.13s; }
.stagger-in.is-visible > *:nth-child(3) { transition-delay: 0.21s; }
.stagger-in.is-visible > *:nth-child(4) { transition-delay: 0.29s; }
.stagger-in.is-visible > *:nth-child(5) { transition-delay: 0.37s; }
.stagger-in.is-visible > *:nth-child(6) { transition-delay: 0.45s; }
.stagger-in.is-visible > *:nth-child(7) { transition-delay: 0.53s; }
.stagger-in.is-visible > *:nth-child(8) { transition-delay: 0.61s; }

/* ============================================
   Float Animations
   ============================================ */

@keyframes float-slow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@keyframes float-medium {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes float-fast {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.float-slow { animation: float-slow 6s ease-in-out infinite; }
.float-medium { animation: float-medium 4.5s ease-in-out infinite; }
.float-fast { animation: float-fast 3s ease-in-out infinite; }

/* ============================================
   Pulse Glow
   ============================================ */

@keyframes pulse-glow {
  0%, 100% { box-shadow: var(--glow-orange); }
  50% { box-shadow: var(--glow-orange-intense); }
}

.pulse-glow {
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow-ring {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

/* ============================================
   Counter Animation
   ============================================ */

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

/* ============================================
   Nav States
   ============================================ */

.nav-transparent {
  background: transparent;
  border-bottom: 1px solid transparent;
}

.nav-scrolled {
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-default);
}

/* ============================================
   Button Hover Glow
   ============================================ */

.btn-glow {
  transition: all var(--transition-base);
}

.btn-glow:hover {
  box-shadow: 0 0 20px rgba(255, 102, 51, 0.3), 0 0 40px rgba(255, 102, 51, 0.1);
  transform: translateY(-1px);
}

/* ============================================
   Cursor Glow (hero sections)
   ============================================ */

.cursor-glow {
  position: fixed;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 102, 51, 0.06) 0%, transparent 70%);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cursor-glow-active .cursor-glow {
  opacity: 1;
}

/* ============================================
   Marquee Animation
   ============================================ */

@keyframes marquee {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.marquee-track {
  display: flex;
  animation: marquee 30s linear infinite;
}

.marquee-track:hover {
  animation-play-state: paused;
}

/* ============================================
   Monospace Financial
   ============================================ */

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

/* ============================================
   Variance Pills (from dashboard)
   ============================================ */

.variance-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
}

.variance-pill.positive {
  background: var(--positive-bg);
  color: var(--positive-light);
  border: 1px solid var(--positive-border);
}

.variance-pill.negative {
  background: var(--negative-bg);
  color: var(--negative-light);
  border: 1px solid var(--negative-border);
}

/* ============================================
   Reduced Motion
   ============================================ */

@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;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }

  .stagger-in > * {
    opacity: 1;
    transform: none;
  }

  .marquee-track {
    animation: none;
  }

  .cursor-glow {
    display: none;
  }

  .custom-cursor {
    display: none !important;
  }

  .has-custom-cursor, .has-custom-cursor * {
    cursor: auto !important;
  }
}

/* ============================================
   Custom Cursor
   ============================================ */

.custom-cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  background: #FF6633;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease, background 0.3s ease, opacity 0.3s ease;
  mix-blend-mode: difference;
  opacity: 0;
}
.custom-cursor.visible { opacity: 1; }
.custom-cursor.hover {
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1.5px solid rgba(255, 102, 51, 0.6);
  mix-blend-mode: normal;
}
.custom-cursor.clicking {
  transform: translate(-50%, -50%) scale(0.75);
}
.has-custom-cursor, .has-custom-cursor * {
  cursor: none !important;
}

@media (hover: none) {
  .custom-cursor { display: none !important; }
  .has-custom-cursor, .has-custom-cursor * { cursor: auto !important; }
}

/* ============================================
   Footer Heading Accent Bars
   ============================================ */

footer h4 {
  position: relative;
  padding-bottom: 0.5rem;
}

footer h4::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 24px;
  height: 2px;
  background: var(--brand-orange);
  border-radius: 1px;
}

/* ============================================
   Impersonation Banner (shared across all pages)
   ============================================ */

.impersonation-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.15), rgba(255, 102, 51, 0.12));
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  font-family: 'Jost', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--warning, #F59E0B);
  backdrop-filter: blur(8px);
}

.impersonation-banner .banner-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.impersonation-banner .banner-return {
  padding: 4px 12px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--warning, #F59E0B);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.impersonation-banner .banner-return:hover {
  background: rgba(245, 158, 11, 0.3);
}

body.is-impersonating { padding-top: 40px !important; }
body.is-impersonating > header:first-of-type,
body.is-impersonating > nav:first-of-type { top: 40px; }

/* ============================================
   Mobile Nav — Active Page Indicator
   ============================================ */

#mobile-menu a[aria-current="page"] {
  color: var(--brand-orange, #FF6633);
  position: relative;
  padding-left: 12px;
}

#mobile-menu a[aria-current="page"]::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--brand-orange, #FF6633);
  border-radius: 0 2px 2px 0;
}
