/**
 * Commerce Learning Hub - Base Styles
 * 
 * Contains: CSS reset, custom properties (design tokens), typography
 * This file is loaded first — all other CSS files depend on these variables.
 */

/* ============================================
   CSS RESET (Modern, minimal)
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
  line-height: 1.2;
}

p {
  overflow-wrap: break-word;
}

/* ============================================
   DESIGN TOKENS (CSS Custom Properties)
   ============================================ */
:root {
  /* ---- Colors: Brand ---- */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-primary-dark: #1e40af;
  
  --color-secondary: #7c3aed;
  --color-secondary-hover: #6d28d9;
  --color-secondary-light: #ede9fe;
  
  --color-accent: #06b6d4;
  --color-accent-hover: #0891b2;
  
  /* ---- Colors: Semantic ---- */
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-info: #3b82f6;
  
  /* ---- Colors: Neutral (Light Mode) ---- */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-text: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #94a3b8;
  --color-text-inverse: #ffffff;
  
  /* ---- Typography ---- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --font-serif: 'Merriweather', Georgia, serif;
  
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */
  --text-4xl: 2.25rem;   /* 36px */
  --text-5xl: 3rem;      /* 48px */
  
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.75;
  
  /* ---- Spacing ---- */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */
  
  /* ---- Border Radius ---- */
  --radius-sm: 0.25rem;  /* 4px */
  --radius-md: 0.5rem;   /* 8px */
  --radius-lg: 0.75rem;  /* 12px */
  --radius-xl: 1rem;     /* 16px */
  --radius-2xl: 1.5rem;  /* 24px */
  --radius-full: 9999px;
  
  /* ---- Shadows ---- */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
  
  /* ---- Transitions ---- */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
  
  /* ---- Layout ---- */
  --header-height: 4rem;         /* 64px */
  --sidebar-width: 16rem;        /* 256px */
  --sidebar-width-collapsed: 4rem; /* 64px */
  --container-max: 80rem;        /* 1280px */
  --container-padding: 1.5rem;
  
  /* ---- Z-index scale ---- */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-header: 300;
  --z-sidebar: 400;
  --z-modal: 500;
  --z-toast: 600;
  --z-tooltip: 700;
  
  /* ---- Glassmorphism ---- */
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --glass-blur: 12px;
}

/* ============================================
   DARK THEME
   ============================================ */
[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-elevated: #334155;
  --color-border: #334155;
  --color-border-strong: #475569;
  --color-text: #f1f5f9;
  --color-text-secondary: #cbd5e1;
  --color-text-muted: #64748b;
  --color-text-inverse: #0f172a;
  
  --color-primary-light: #1e3a8a;
  --color-secondary-light: #4c1d95;
  
  --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(71, 85, 105, 0.3);
}

/* ============================================
   HIGH CONTRAST THEME (Accessibility)
   ============================================ */
[data-theme="high-contrast"] {
  --color-bg: #000000;
  --color-surface: #0a0a0a;
  --color-surface-elevated: #1a1a1a;
  --color-border: #ffffff;
  --color-border-strong: #ffffff;
  --color-text: #ffffff;
  --color-text-secondary: #ffffff;
  --color-text-muted: #cccccc;
  --color-text-inverse: #000000;
  
  --color-primary: #ffff00;
  --color-primary-hover: #ffff66;
  --color-primary-light: #333300;
  --color-primary-dark: #cccc00;
  
  --color-secondary: #00ffff;
  --color-secondary-hover: #66ffff;
  --color-secondary-light: #003333;
  
  --color-accent: #ff00ff;
  
  --color-success: #00ff00;
  --color-warning: #ffff00;
  --color-error: #ff3333;
  --color-info: #00ffff;
  
  --shadow-glass: none;
  --glass-bg: #000000;
  --glass-border: #ffffff;
  --glass-blur: 0px;
}

[data-theme="high-contrast"] a {
  text-decoration: underline;
}

[data-theme="high-contrast"] :focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

[data-theme="high-contrast"] .btn--primary {
  background: var(--color-primary);
  color: #000000;
  font-weight: var(--font-bold);
}

[data-theme="high-contrast"] .card,
[data-theme="high-contrast"] .module-card {
  border-width: 2px;
}

/* ============================================
   BASE TYPOGRAPHY
   ============================================ */
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-semibold);
  line-height: var(--leading-tight);
  color: var(--color-text);
}

h1 { font-size: var(--text-4xl); margin-bottom: var(--space-6); }
h2 { font-size: var(--text-3xl); margin-bottom: var(--space-5); }
h3 { font-size: var(--text-2xl); margin-bottom: var(--space-4); }
h4 { font-size: var(--text-xl); margin-bottom: var(--space-3); }
h5 { font-size: var(--text-lg); margin-bottom: var(--space-3); }
h6 { font-size: var(--text-base); margin-bottom: var(--space-2); }

p {
  margin-bottom: var(--space-4);
  color: var(--color-text-secondary);
}

a {
  color: var(--color-primary);
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

code {
  background: var(--color-surface-elevated);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

pre {
  background: var(--color-surface-elevated);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

pre code {
  background: none;
  padding: 0;
}

/* ============================================
   FOCUS STYLES (Accessibility)
   ============================================ */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================
   REDUCED MOTION (Accessibility)
   ============================================ */
@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;
  }
}

/* ============================================
   SELECTION
   ============================================ */
::selection {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

/* ============================================
   SCROLLBAR (Webkit)
   ============================================ */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ============================================
   ANCHOR SCROLL OFFSET
   Prevents sticky header from covering sections
   when user clicks #about, #modules, etc.
   ============================================ */
#modules,
#categories,
#about,
#bookmarks,
#history,
#calculators,
#analysis,
#investment,
#research,
#all-modules {
  scroll-margin-top: calc(var(--header-height) + 24px);
}

/* Smooth scroll for anchor links */
html {
  scroll-behavior: smooth;
}
