/*
 * wger design tokens
 *
 * Single source of truth for colour, spacing, radius, shadow and type.
 * Consumed by:
 *   - Bootstrap 5.3 (scss/main.scss maps its CSS variables onto these)
 *   - MUI (react-components theme.ts mirrors the same values and switches
 *     colour scheme on the same [data-bs-theme] attribute)
 *
 * Theme selection: <html data-bs-theme="light|dark">, set before first paint by
 * the inline script in template.html (localStorage "wger-theme", falling back to
 * prefers-color-scheme). Keep values here and in react/src/theme/tokens.ts in sync.
 *
 * Contrast: every text/background pair below is ≥ 4.5:1 (WCAG 2.1 AA, normal text);
 * --wg-color-text-muted is ≥ 4.5:1 on both --wg-color-bg and --wg-color-surface.
 */

:root {
  /* Typography: system UI stack, no web font download */
  --wg-font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans",
    "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --wg-font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --wg-font-size-xs: 0.75rem;    /* 12 */
  --wg-font-size-sm: 0.875rem;   /* 14 */
  --wg-font-size-md: 1rem;       /* 16, body */
  --wg-font-size-lg: 1.125rem;   /* 18 */
  --wg-font-size-xl: 1.25rem;    /* 20, h4 */
  --wg-font-size-2xl: 1.5rem;    /* 24, h3 */
  --wg-font-size-3xl: clamp(1.5rem, 1.2rem + 1.2vw, 1.875rem);   /* 24 to 30, h2 */
  --wg-font-size-4xl: clamp(1.75rem, 1.3rem + 1.8vw, 2.25rem);   /* 28 to 36, h1 */

  --wg-font-weight-regular: 400;
  --wg-font-weight-medium: 500;
  --wg-font-weight-semibold: 600;
  --wg-font-weight-bold: 700;
  --wg-line-height-tight: 1.25;
  --wg-line-height-body: 1.55;

  /* Spacing: 4 px base */
  --wg-space-1: 0.25rem;  /* 4 */
  --wg-space-2: 0.5rem;   /* 8 */
  --wg-space-3: 0.75rem;  /* 12 */
  --wg-space-4: 1rem;     /* 16 */
  --wg-space-5: 1.5rem;   /* 24 */
  --wg-space-6: 2rem;     /* 32 */
  --wg-space-7: 3rem;     /* 48 */
  --wg-space-8: 4rem;     /* 64 */

  /* Radius */
  --wg-radius-sm: 6px;
  --wg-radius-md: 10px;
  --wg-radius-lg: 16px;
  --wg-radius-pill: 999px;

  /* Sizing */
  --wg-touch-target: 44px;
  --wg-container-max: 1200px;
  --wg-navbar-height: 60px;

  /* Motion */
  --wg-duration-fast: 120ms;
  --wg-duration-base: 200ms;
  --wg-ease: cubic-bezier(0.2, 0, 0, 1);
  --wg-focus-ring-width: 3px;
}

/* ---------------------------------------------------------------- light */
:root,
[data-bs-theme="light"] {
  color-scheme: light;

  --wg-color-primary: #2a4c7d;          /* brand navy, 8.7:1 on white */
  --wg-color-primary-hover: #223f69;
  --wg-color-primary-subtle: #e8eef7;
  --wg-color-on-primary: #ffffff;

  --wg-color-accent: #c8303e;           /* brand red, darkened for 5.1:1 on white */
  --wg-color-accent-hover: #a82733;
  --wg-color-accent-subtle: #fdecee;
  --wg-color-on-accent: #ffffff;

  --wg-color-success: #2e7d32;
  --wg-color-success-subtle: #e8f5e9;
  --wg-color-warning: #8a5a00;          /* text-safe amber */
  --wg-color-warning-subtle: #fff4dc;
  --wg-color-danger: #c62828;
  --wg-color-danger-subtle: #fdecea;
  --wg-color-info: #0b6aa2;
  --wg-color-info-subtle: #e6f3fa;
  --wg-color-on-success: #ffffff;       /* 5.1:1 */
  --wg-color-on-warning: #ffffff;       /* 5.9:1 */
  --wg-color-on-danger: #ffffff;        /* 5.6:1 */
  --wg-color-on-info: #ffffff;          /* 5.8:1 */

  --wg-color-bg: #f5f7fa;               /* page */
  --wg-color-surface: #ffffff;          /* cards, navbar, modals */
  --wg-color-surface-2: #eef2f6;        /* table stripes, inputs-on-surface, hovers */
  --wg-color-border: #d9e0e8;
  --wg-color-border-strong: #b7c2cf;
  --wg-color-border-control: #7d8a98;   /* form control outlines, ≥3:1 on bg and surface (WCAG 1.4.11) */

  --wg-color-text: #17212b;
  --wg-color-text-muted: #55636f;       /* 5.7:1 on bg, 6.2:1 on surface */
  --wg-color-text-subtle: #6b7884;      /* 4.2:1: large text and icons only (3:1 rule) */

  --wg-color-focus: #3b82f6;

  /* Chart series: ordered, distinguishable, AA against surface */
  --wg-chart-1: #2a4c7d;
  --wg-chart-2: #c8303e;
  --wg-chart-3: #2e7d32;
  --wg-chart-4: #b26a00;
  --wg-chart-5: #6a4bb5;
  --wg-chart-6: #0b6aa2;
  --wg-chart-grid: #e3e8ee;

  --wg-shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);
  --wg-shadow-md: 0 4px 12px rgb(16 24 40 / 0.08), 0 2px 4px rgb(16 24 40 / 0.05);
  --wg-shadow-lg: 0 12px 32px rgb(16 24 40 / 0.14);
}

/* ----------------------------------------------------------------- dark */
[data-bs-theme="dark"] {
  color-scheme: dark;

  --wg-color-primary: #8fb3ea;          /* 8.6:1 on surface */
  --wg-color-primary-hover: #a9c5f0;
  --wg-color-primary-subtle: #1c2a3d;
  --wg-color-on-primary: #0d1520;

  --wg-color-accent: #ff7a85;
  --wg-color-accent-hover: #ff97a0;
  --wg-color-accent-subtle: #3a1d22;
  --wg-color-on-accent: #1a0b0d;

  --wg-color-success: #74c47a;
  --wg-color-success-subtle: #17301a;
  --wg-color-warning: #f2b84b;
  --wg-color-warning-subtle: #33270f;
  --wg-color-danger: #ff8a80;
  --wg-color-danger-subtle: #3a1a18;
  --wg-color-info: #6cc4f0;
  --wg-color-info-subtle: #10293a;
  --wg-color-on-success: #0d1520;       /* 8.7:1 */
  --wg-color-on-warning: #0d1520;       /* 10.3:1 */
  --wg-color-on-danger: #0d1520;        /* 8.0:1 */
  --wg-color-on-info: #0d1520;          /* 9.4:1 */

  --wg-color-bg: #0e141b;
  --wg-color-surface: #161e27;
  --wg-color-surface-2: #1e2833;
  --wg-color-border: #2b3744;
  --wg-color-border-strong: #3d4b5a;
  --wg-color-border-control: #6b7a8a;   /* ≥3:1 on bg, surface and surface-2 */

  --wg-color-text: #e6edf3;
  --wg-color-text-muted: #a3b1bf;       /* 7.6:1 on surface */
  --wg-color-text-subtle: #8796a5;

  --wg-color-focus: #7aa7ff;

  --wg-chart-1: #8fb3ea;
  --wg-chart-2: #ff7a85;
  --wg-chart-3: #74c47a;
  --wg-chart-4: #f2b84b;
  --wg-chart-5: #b9a2f2;
  --wg-chart-6: #6cc4f0;
  --wg-chart-grid: #2b3744;

  --wg-shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --wg-shadow-md: 0 4px 12px rgb(0 0 0 / 0.45);
  --wg-shadow-lg: 0 12px 32px rgb(0 0 0 / 0.55);
}

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