/* ==========================================================================
   Evolonic design tokens (owned by the ui app, see ui/README.md)
   --------------------------------------------------------------------------
   - Light theme: :root and [data-theme="light"]
   - Dark theme:  [data-theme="dark"]  AND  @media (prefers-color-scheme: dark)
                  for <html> without data-theme or with data-theme="system".
     The two dark blocks MUST stay identical (ui/tests/test_contrast.py checks it).
   - Exactly one accent hue ("Evolonic blue"). To rebrand, change only the
     --color-accent* values (light + both dark blocks) and run
     `.venv/bin/pytest ui/tests/test_contrast.py` – it asserts WCAG AA.
   - Status colors (success / warning / danger) are for meaning only.
   - Only opaque #rrggbb values for colors that carry text (the contrast test
     parses them); rgba() only for overlays, hovers and shadows.
   ========================================================================== */

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

  /* Accent – Evolonic blue (single accent hue) */
  --color-accent: #2257e0;          /* solid: primary buttons, active markers, checkboxes */
  --color-accent-hover: #1c4bc4;
  --color-accent-active: #183fa6;
  --color-accent-text: #1d4fcf;     /* accent used as text: links, active nav label */
  --color-accent-subtle: #edf2fe;   /* tinted background: selected nav item, info badge */
  --color-on-accent: #ffffff;       /* text on solid accent */

  /* Neutrals */
  --color-canvas: #fafbfc;          /* page background behind cards and surfaces */
  --color-bg: #ffffff;              /* content area */
  --color-bg-subtle: #f7f8fa;       /* sidebar, table headers */
  --color-bg-muted: #f0f2f5;        /* board columns, code, skeletons */
  --color-surface: #ffffff;         /* cards, inputs */
  --color-surface-raised: #ffffff;  /* dropdowns, modals, drawers, toasts */
  --color-border: #ebedf1;          /* separators (decorative) */
  --color-border-strong: #d5dae1;   /* card hover, dividers that matter */
  --color-border-input: #838c9b;    /* form control outlines (>= 3:1 vs surface) */
  --color-text: #0f1729;
  --color-text-muted: #586174;
  --color-text-disabled: #9aa2af;   /* disabled only (exempt from WCAG contrast) */
  --color-hover: rgba(16, 24, 40, 0.05);
  --color-pressed: rgba(16, 24, 40, 0.09);
  --color-overlay: rgba(16, 24, 40, 0.45);
  --color-focus: #2257e0;
  --color-focus-ring: rgba(34, 87, 224, 0.28);
  --color-shimmer: rgba(255, 255, 255, 0.65);
  --color-skeleton: #e8ebef;

  /* Status – meaning only */
  --color-success: #1e8a46;         /* solid: dots, progress fill */
  --color-success-text: #166c35;
  --color-success-subtle: #e7f5ec;
  --color-warning: #b26a00;
  --color-warning-text: #8a5300;
  --color-warning-subtle: #fdf3dc;
  --color-danger: #c8321f;
  --color-danger-hover: #ab2716;
  --color-danger-text: #b42318;
  --color-danger-subtle: #fdeceb;
  --color-on-danger: #ffffff;
  --color-info: #2257e0;            /* info = accent by design */
  --color-info-text: #1d4fcf;
  --color-info-subtle: #edf2fe;

  /* Avatars (initials fallback) */
  --color-avatar-bg: #dde6fb;
  --color-avatar-text: #183fa6;

  /* Shadows – soft, layered (only floating layers and interactive cards) */
  --shadow-xs: 0 1px 2px rgba(15, 23, 41, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 41, 0.04), 0 2px 6px rgba(15, 23, 41, 0.05);
  --shadow-md: 0 2px 4px rgba(15, 23, 41, 0.04), 0 8px 24px -6px rgba(15, 23, 41, 0.1);
  --shadow-lg: 0 4px 8px rgba(15, 23, 41, 0.04), 0 24px 56px -12px rgba(15, 23, 41, 0.18);
}

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

  --color-accent: #3567e6;
  --color-accent-hover: #2c5ad4;
  --color-accent-active: #2550c0;
  --color-accent-text: #8aadff;
  --color-accent-subtle: #172242;
  --color-on-accent: #ffffff;

  --color-canvas: #0a0e15;
  --color-bg: #0c1018;
  --color-bg-subtle: #111621;
  --color-bg-muted: #171d2a;
  --color-surface: #121826;
  --color-surface-raised: #182033;
  --color-border: #222a3a;
  --color-border-strong: #2e3850;
  --color-border-input: #6b7484;
  --color-text: #e7eaf0;
  --color-text-muted: #9ba4b5;
  --color-text-disabled: #5f6876;
  --color-hover: rgba(230, 233, 239, 0.06);
  --color-pressed: rgba(230, 233, 239, 0.1);
  --color-overlay: rgba(3, 5, 8, 0.66);
  --color-focus: #8aadff;
  --color-focus-ring: rgba(138, 173, 255, 0.3);
  --color-shimmer: rgba(255, 255, 255, 0.05);
  --color-skeleton: #262c35;

  --color-success: #2fa463;
  --color-success-text: #5fd394;
  --color-success-subtle: #10281b;
  --color-warning: #c98a1c;
  --color-warning-text: #f0b85a;
  --color-warning-subtle: #2b2210;
  --color-danger: #cc3d33;
  --color-danger-hover: #b3322a;
  --color-danger-text: #ff8a80;
  --color-danger-subtle: #321615;
  --color-on-danger: #ffffff;
  --color-info: #3567e6;
  --color-info-text: #8aadff;
  --color-info-subtle: #172242;

  --color-avatar-bg: #1f2d52;
  --color-avatar-text: #b9cdff;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.32);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32), 0 2px 6px rgba(0, 0, 0, 0.36);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.32), 0 8px 24px -6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.34), 0 24px 56px -12px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  :root[data-theme="system"] {
    color-scheme: dark;

    --color-accent: #3567e6;
    --color-accent-hover: #2c5ad4;
    --color-accent-active: #2550c0;
    --color-accent-text: #8aadff;
    --color-accent-subtle: #172242;
    --color-on-accent: #ffffff;

    --color-canvas: #0a0e15;
    --color-bg: #0c1018;
    --color-bg-subtle: #111621;
    --color-bg-muted: #171d2a;
    --color-surface: #121826;
    --color-surface-raised: #182033;
    --color-border: #222a3a;
    --color-border-strong: #2e3850;
    --color-border-input: #6b7484;
    --color-text: #e7eaf0;
    --color-text-muted: #9ba4b5;
    --color-text-disabled: #5f6876;
    --color-hover: rgba(230, 233, 239, 0.06);
    --color-pressed: rgba(230, 233, 239, 0.1);
    --color-overlay: rgba(3, 5, 8, 0.66);
    --color-focus: #8aadff;
    --color-focus-ring: rgba(138, 173, 255, 0.3);
    --color-shimmer: rgba(255, 255, 255, 0.05);
    --color-skeleton: #262c35;

    --color-success: #2fa463;
    --color-success-text: #5fd394;
    --color-success-subtle: #10281b;
    --color-warning: #c98a1c;
    --color-warning-text: #f0b85a;
    --color-warning-subtle: #2b2210;
    --color-danger: #cc3d33;
    --color-danger-hover: #b3322a;
    --color-danger-text: #ff8a80;
    --color-danger-subtle: #321615;
    --color-on-danger: #ffffff;
    --color-info: #3567e6;
    --color-info-text: #8aadff;
    --color-info-subtle: #172242;

    --color-avatar-bg: #1f2d52;
    --color-avatar-text: #b9cdff;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.32);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32), 0 2px 6px rgba(0, 0, 0, 0.36);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.32), 0 8px 24px -6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.34), 0 24px 56px -12px rgba(0, 0, 0, 0.7);
  }
}

/* --------------------------------------------------------------------------
   Theme-independent tokens
   -------------------------------------------------------------------------- */
:root {
  /* Spacing – 4px steps */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* Radii (V4: softer) */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --radius-full: 9999px;

  /* Typography – Inter, 12 / 14 / 16 / 20 / 24 / 32 px */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;   /* 12px – meta, badges, small buttons */
  --text-sm: 0.875rem;  /* 14px – UI default */
  --text-md: 1rem;      /* 16px – reading text, h3 */
  --text-lg: 1.25rem;   /* 20px – h2, section titles */
  --text-xl: 1.5rem;    /* 24px – page titles (h1) */
  --text-2xl: 2rem;     /* 32px – display */
  --text-3xl: 2.5rem;   /* 40px – hero numbers */
  --text-body-reading: 0.9375rem; /* 15px – .prose */
  --leading-tight: 1.25;
  --leading-snug: 1.4;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;
  /* Fixed line heights of the type roles (V4 Phase 3: no hard px in component CSS) */
  --line-xs: 16px;   /* meta, help, badges (12 px text) */
  --line-sm: 22px;   /* UI default, h3, card titles */
  --line-md: 28px;   /* h2 */
  --line-lg: 32px;   /* h1, display names */
  --line-xl: 40px;   /* .display, stat values */
  --line-2xl: 48px;  /* large stat values */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --tracking-tight: -0.011em;
  --tracking-display: -0.022em;

  /* Controls */
  --control-h-sm: 28px;
  --control-h-md: 36px;
  --control-h-lg: 40px;  /* form fields (.field) */
  --icon-sm: 14px;
  --icon-md: 16px;
  --icon-lg: 20px;

  /* Focus */
  --focus-width: 2px;
  --focus-offset: 2px;

  /* Motion (V4, PLAN_V4 3.8). Every animation has one purpose: feedback, orientation or completion.
     The --duration-* tokens stay as aliases for existing styles. */
  --motion-instant: 100ms;
  --motion-quick: 160ms;
  --motion-calm: 280ms;
  --motion-celebrate: 900ms;
  --ease-out-soft: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-width: 248px;
  --sidebar-width-collapsed: 60px;
  --topbar-height: 56px;
  --content-padding: var(--space-4); /* responsive, see ui.css (16/24/32/40 px) */
  --section-gap: 40px;
  --card-padding: 20px;
  --row-height: 44px;
  --content-reading: 720px;
  --content-narrow: 760px;
  --content-medium: 1120px;
  --drawer-width: 560px;

  /* Layers */
  --z-sticky: 20;
  --z-sidebar: 30;
  --z-topbar: 40;
  --z-dropdown: 50;
  --z-overlay: 60;
  --z-toast: 80;
  --z-tooltip: 90;
}

/* Reduced motion: the system setting (unless the profile says "full") or the profile setting "reduced". */
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) {
    --duration-fast: 0ms;
    --duration-base: 0ms;
    --duration-slow: 0ms;
    --motion-instant: 0ms;
    --motion-quick: 120ms;
    --motion-calm: 120ms;
    --motion-celebrate: 120ms;
  }
}
:root[data-motion="reduced"] {
  --duration-fast: 0ms;
  --duration-base: 0ms;
  --duration-slow: 0ms;
  --motion-instant: 0ms;
  --motion-quick: 120ms;
  --motion-calm: 120ms;
  --motion-celebrate: 120ms;
}
