/* ============================================================
   GLOBAL.CSS — Design Tokens, Reset, Base Elements, Utilities
   ============================================================ */

/* --- Design Tokens (Light Mode) --- */
:root {
  /* Color Palette */
  --color-bg:           #f3f4f6;
  --color-bg-alt:       #f9fafb;
  --color-bg-elevated:  #ffffff;
  --color-surface:      #fafbfc;
  --color-card:         #ffffff;
  --color-border:       #e5e7eb;
  --color-border-focus: #a5b4fc;
  --color-text:         #111827;
  --color-text-soft:    #6b7280;
  --color-text-muted:   #9ca3af;
  --color-accent:       #5046e5;
  --color-accent-hover: #4338ca;
  --color-accent-light: #eef2ff;
  --color-success:      #10b981;
  --color-error:        #ef4444;
  --color-warning:      #f59e0b;
  --color-info:         #5046e5;

  /* Spacing Scale (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;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Poppins', var(--font-sans);
  --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;

  /* Borders & Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg:  0 4px 6px rgba(0,0,0,0.04), 0 10px 30px rgba(0,0,0,0.08);
  --shadow-xl:  0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);

  /* Transitions */
  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;

  /* Font Mono */
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;

  /* Z-index Scale */
  --z-base:     1;
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-modal:    300;
  --z-toast:    400;
  --z-tooltip:  500;
}

/* --- Dark Mode Token Overrides --- */
[data-theme="dark"] {
  --color-bg:           #0f1117;
  --color-bg-alt:       #1a1d27;
  --color-bg-elevated:  #1e2130;
  --color-surface:      #252836;
  --color-card:         #1e2130;
  --color-border:       #2d3141;
  --color-border-focus: #7c73f5;
  --color-text:         #e5e7eb;
  --color-text-soft:    #9ca3af;
  --color-text-muted:   #6b7280;
  --color-accent:       #7c73f5;
  --color-accent-hover: #9b94f7;
  --color-accent-light: #1e1b4b;
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:  0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --shadow-lg:  0 4px 6px rgba(0,0,0,0.3), 0 10px 30px rgba(0,0,0,0.2);
  --color-success: #34d399;
  --color-error:   #f87171;
  --color-warning: #fbbf24;
  --color-info:    #7c73f5;
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

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

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

button {
  font-family: inherit;
  cursor: pointer;
}

/* --- Focus Visible (global keyboard focus ring) --- */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* --- Smooth theme transitions --- */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition: background-color 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              fill 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              stroke 0.45s cubic-bezier(0.4, 0, 0.2, 1) !important;
}
/* Subtle veil overlay during theme switch */
html.theme-transitioning::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 99999;
  pointer-events: none;
  background: #888;
  animation: theme-veil 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes theme-veil {
  0%   { opacity: 0; }
  25%  { opacity: 0.045; }
  100% { opacity: 0; }
}

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

/* --- Utility Classes --- */
.u-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.u-text-center { text-align: center; }
.u-text-left   { text-align: left; }
.u-text-right  { text-align: right; }
.u-mt-4 { margin-top: var(--space-4); }
.u-mt-6 { margin-top: var(--space-6); }
.u-mb-4 { margin-bottom: var(--space-4); }
.u-mb-6 { margin-bottom: var(--space-6); }
.u-hidden { display: none !important; }

/* --- Container --- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}
