/* ============================================
   THEME TOKENS & UNIVERSAL UTILITIES
   Shared across pages (index, company-card, etc.)
   ============================================ */

/* CSS Variables - Dark (default) */
:root {
  /* Core Colors - Dark Theme */
  --color-bg-primary: #010409;
  --color-bg-secondary: #0D1117;
  --color-bg-tertiary: #161B22;
  --color-bg-quaternary: #1C2128;

  --color-text-primary: #E6EDF3;
  --color-text-secondary: #C9D1D9;
  --color-text-muted: #9CA3AF;
  --color-text-subtle: #7C8590;
  --color-text-inverse: #0D1117;

  --color-border-primary: #30363D;
  --color-border-secondary: #21262D;
  --color-border-subtle: #161B22;

  /* Score Colors */
  --color-score-purple: #a855f7;
  --color-score-blue: #3b82f6;
  --color-score-green: #22c55e;
  --color-score-yellow: #eab308;
  --color-score-orange: #f97316;
  --color-score-red: #ef4444;

  /* Score Glows */
  --glow-purple: rgba(168, 85, 247, 0.3);
  --glow-blue: rgba(59, 130, 246, 0.3);
  --glow-green: rgba(34, 197, 94, 0.3);
  --glow-yellow: rgba(234, 179, 8, 0.3);
  --glow-orange: rgba(249, 115, 22, 0.3);
  --glow-red: rgba(239, 68, 68, 0.3);

  /* Charts */
  --chart-line-color: #a855f7;
  --chart-grid-color: #30363D;
  --chart-text-color: #9CA3AF;
  --chart-positive: #22c55e;
  --chart-negative: #ef4444;

  /* Interaction */
  --hover-opacity: 0.8;
  --focus-ring-color: rgba(59, 130, 246, 0.5);
  --focus-ring-width: 3px;

  /* Shadows */
  --shadow-color: 0, 0, 0;
  --shadow-opacity-sm: 0.5;
  --shadow-opacity-md: 0.5;
  --shadow-opacity-lg: 0.5;
  --shadow-opacity-xl: 0.5;
  --shadow-glass: 0 14px 40px rgba(var(--shadow-color), 0.22);

  /* Layout */
  --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;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Roboto Mono', monospace;
  --text-xs: 0.75rem; --text-sm: 0.875rem; --text-base: 1rem; --text-lg: 1.125rem;
  --text-xl: 1.25rem; --text-2xl: 1.5rem; --text-3xl: 1.875rem; --text-4xl: 2.25rem;
  --weight-normal: 400; --weight-medium: 500; --weight-semibold: 600; --weight-bold: 700;
  --leading-tight: 1.2; --leading-normal: 1.5; --leading-relaxed: 1.75;

  /* Radii */
  --radius-sm: 0.25rem; --radius-md: 0.375rem; --radius-lg: 0.5rem; --radius-xl: 0.75rem; --radius-2xl: 1rem; --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-Index */
  --z-below: -1; --z-base: 0; --z-dropdown: 100; --z-sticky: 200; --z-overlay: 300; --z-modal: 400; --z-popover: 500; --z-tooltip: 600;

  /* Breakpoints */
  --breakpoint-mobile: 375px; --breakpoint-tablet: 768px; --breakpoint-desktop: 1024px; --breakpoint-wide: 1920px;

  /* Touch */
  --touch-target-min: 44px; --touch-target-comfortable: 48px; --touch-target-large: 56px;
}

/* Light Theme Overrides */
body.light-theme {
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f8f9fa;
  --color-bg-tertiary: #e9ecef;
  --color-bg-quaternary: #dee2e6;

  --color-text-primary: #0b0d0e;
  --color-text-secondary: #2e3338;
  --color-text-muted: #495057;
  --color-text-subtle: #6c757d;
  --color-text-inverse: #ffffff;

  --color-border-primary: #dee2e6;
  --color-border-secondary: #ced4da;
  --color-border-subtle: #e9ecef;

  --color-score-purple: #9333ea;
  --color-score-blue: #2563eb;
  --color-score-green: #16a34a;
  --color-score-yellow: #ca8a04;
  --color-score-orange: #ea580c;
  --color-score-red: #dc2626;

  --glow-purple: rgba(147, 51, 234, 0.2);
  --glow-blue: rgba(37, 99, 235, 0.2);
  --glow-green: rgba(22, 163, 74, 0.2);
  --glow-yellow: rgba(202, 138, 4, 0.2);
  --glow-orange: rgba(234, 88, 12, 0.2);
  --glow-red: rgba(220, 38, 38, 0.2);

  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-bg-hover: rgba(255, 255, 255, 0.92);
  --glass-bg-active: rgba(255, 255, 255, 0.95);
  --glass-border: rgba(0, 0, 0, 0.1);
  --glass-border-hover: rgba(0, 0, 0, 0.15);
  --glass-gradient-start: rgba(255, 255, 255, 0.95);
  --glass-gradient-end: rgba(248, 249, 250, 0.7);
  --glass-inset-shadow: inset 0 0 20px rgba(255, 255, 255, 0.9);
  --glass-blur: blur(20px);
  --glass-saturate: saturate(120%);

  --shadow-color: 0, 0, 0;
  --shadow-opacity-sm: 0.05;
  --shadow-opacity-md: 0.08;
  --shadow-opacity-lg: 0.1;
  --shadow-opacity-xl: 0.15;

  --chart-line-color: #9333ea;
  --chart-grid-color: #e5e7eb;
  --chart-text-color: #6b7280;
  --chart-positive: #16a34a;
  --chart-negative: #dc2626;

  --focus-ring-color: rgba(37, 99, 235, 0.5);

  /* Light theme shadow tuning */
  --shadow-glass: 0 12px 24px rgba(0, 0, 0, 0.08);
}

/* Universal text helpers */
.dynamic-value { color: var(--color-text-primary) !important; font-weight: 500; }
.muted-label { color: var(--color-text-muted) !important; }
.muted-heading { color: var(--color-text-secondary) !important; }
.subtle-text { color: var(--color-text-subtle) !important; }
.secondary-text { color: var(--color-text-secondary) !important; }
h1, h2, h3, h4, h5, h6 { color: var(--color-text-primary); }

/* Light theme utility remaps for readability */
.light-theme .text-gray-100,
.light-theme .text-gray-200,
.light-theme .text-gray-300 { color: var(--color-text-primary) !important; }
.light-theme .text-gray-400,
.light-theme .text-gray-500,
.light-theme .text-gray-600 { color: var(--color-text-secondary) !important; }
.light-theme .text-green-400,
.light-theme .text-green-500 { color: #059669 !important; }
.light-theme .text-blue-400,
.light-theme .text-blue-500 { color: #2563eb !important; }
.light-theme .text-red-400,
.light-theme .text-red-500 { color: #dc2626 !important; }
.light-theme .text-purple-400,
.light-theme .text-purple-500 { color: #7c3aed !important; }

/* Universal tooltip styles */
.ui-tooltip {
  position: fixed;
  z-index: 2147483647;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--glass-gradient-start, rgba(255,255,255,0.08)) 0%, var(--glass-gradient-end, rgba(255,255,255,0.02)) 100%);
  backdrop-filter: var(--glass-blur, blur(20px)) var(--glass-saturate, saturate(180%));
  -webkit-backdrop-filter: var(--glass-blur, blur(20px)) var(--glass-saturate, saturate(180%));
  border: 1px solid var(--glass-border, rgba(255,255,255,0.1));
  box-shadow: 0 4px 12px rgba(0,0,0,0.4), 0 16px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  color: var(--color-text-primary, #E6EDF3);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-line;
  pointer-events: none;
  transition: opacity var(--transition-fast, 150ms ease);
  max-width: min(320px, calc(100vw - 16px));
}

/* Disable legacy pseudo-tooltips globally to prevent conflicts */
[data-tooltip]::after { content: none !important; }

/* Mobile: make tooltip targets discoverable */
@media (max-width: 768px) {
  .analysis-content [data-tooltip],
  .score-breakdown-label[data-tooltip],
  .tier-name[data-tooltip],
  .rank-badge[data-tooltip] {
    text-decoration: underline dotted var(--color-text-secondary);
    text-underline-offset: 2px;
  }
}

/* --------------------------------------------
   Section Surface (glass panel for sections)
   -------------------------------------------- */
.section-surface {
  position: relative;
  background: linear-gradient(140deg, var(--glass-gradient-start) 0%, var(--glass-gradient-end) 100%);
  backdrop-filter: var(--glass-blur) var(--glass-saturate);
  -webkit-backdrop-filter: var(--glass-blur) var(--glass-saturate);
  border: 1px solid color-mix(in oklab, var(--glass-border) 70%, transparent);
  border-radius: var(--radius-xl);
  padding: clamp(var(--space-4), 2.5vw, var(--space-6));
  margin-bottom: var(--space-12);
  box-shadow: var(--shadow-glass);
  overflow: hidden;
  transition: background-color var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base), color var(--transition-base);
}

.section-surface::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    60% 60% at 15% 0%,
    color-mix(in oklab, var(--color-text-primary) 3%, transparent) 0%,
    transparent 60%
  );
  pointer-events: none;
}

.section-surface::after {
  content: '';
  position: absolute;
  inset: -28% -32% -28% -32%;
  background:
    radial-gradient(75% 75% at 18% 28%, color-mix(in oklab, var(--color-score-purple) 4%, transparent) 0%, transparent 90%),
    radial-gradient(70% 70% at 82% 22%, color-mix(in oklab, var(--color-score-blue) 3.5%, transparent) 0%, transparent 90%),
    radial-gradient(85% 60% at 50% 92%, color-mix(in oklab, var(--color-score-purple) 2.5%, transparent) 0%, transparent 92%);
  filter: blur(32px);
  transform: translate3d(0,0,0);
  animation: surfaceMeshDrift 38s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes surfaceMeshDrift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(1%, -1%, 0) scale(1.005); }
}

@media (max-width: 767px) {
  .section-surface {
    /* lighter blur on mobile for perf */
    backdrop-filter: blur(10px) saturate(140%);
    -webkit-backdrop-filter: blur(10px) saturate(140%);
    padding: var(--space-4);
    margin-bottom: var(--space-8);
  }
}

@media (prefers-reduced-motion: reduce) {
  .section-surface::after { animation: none; }
}

/* Dark theme refinement: slightly stronger ambience so panels read on deep backgrounds */
body:not(.light-theme) .section-surface {
  border-color: color-mix(in oklab, var(--glass-border) 85%, transparent);
}

body:not(.light-theme) .section-surface::before {
  background: radial-gradient(
    60% 60% at 15% 0%,
    color-mix(in oklab, var(--color-text-primary) 6%, transparent) 0%,
    transparent 60%
  );
}

body:not(.light-theme) .section-surface::after {
  background:
    radial-gradient(75% 75% at 18% 28%, color-mix(in oklab, var(--color-score-purple) 8%, transparent) 0%, transparent 90%),
    radial-gradient(70% 70% at 82% 22%, color-mix(in oklab, var(--color-score-blue) 7%, transparent) 0%, transparent 90%),
    radial-gradient(85% 60% at 50% 92%, color-mix(in oklab, var(--color-score-purple) 5%, transparent) 0%, transparent 92%);
  filter: blur(28px);
}
