/* ==========================================================================
   Urso SW Design · Tokens 1.0.0
   Richtung „Ruhige Werkstatt“: präzise, werkzeughaft, still.
   Einzige Quelle für Werte. Komponenten nutzen nur die semantischen
   Tokens (--color-*, --space-*, --radius-*, --shadow-*, --motion-*).
   Spiegelbild: tokens.json (plattformneutral). Beide synchron halten.
   ========================================================================== */

/* Schriften: in Projekten selbst hosten (z. B. @fontsource/hanken-grotesk,
   @fontsource/jetbrains-mono). Fallback-Stacks sind metrisch nah. */

:root {
  color-scheme: light dark;

  /* ---------- Primitive: Neutral „Stein“ (leicht warm) ---------- */
  --stone-0: #ffffff;
  --stone-50: #fafaf8;
  --stone-100: #f3f2ef;
  --stone-200: #e6e4df;
  --stone-300: #d3d0c9;
  --stone-400: #a8a49b;
  --stone-500: #8c887e;
  --stone-600: #6b675e;
  --stone-700: #57534b;
  --stone-800: #3a3731;
  --stone-850: #25231f;
  --stone-900: #171614;
  /* Dark-Flächen */
  --stone-d-surface: #1f1e1b;
  --stone-d-raised: #282622;
  --stone-d-border: #34312c;
  --stone-d-border-strong: #6e6a61;
  --stone-d-muted: #a39f96;
  --stone-d-text: #edebe6;

  /* ---------- Primitive: Akzent „Petrol/Tanne“ ---------- */
  --petrol-50: #e6f2ef;
  --petrol-100: #d5eae5;
  --petrol-200: #a9d3ca;
  --petrol-300: #75b6a9;
  --petrol-400: #5fb3a5;
  --petrol-500: #2f7f72;
  --petrol-600: #1f6f64;
  --petrol-700: #195a52;
  --petrol-800: #154842;
  --petrol-900: #0e1e1b;

  /* ---------- Primitive: Status ---------- */
  --red-50: #fcedeb;
  --red-600: #b42318;
  --red-700: #9a1c13;
  --red-300: #f07a6e;
  --amber-50: #fbf1e3;
  --amber-700: #8a4b08;
  --amber-300: #e0a54a;
  --green-50: #e9f3ea;
  --green-700: #2b6b34;
  --green-300: #6fbf7a;

  /* ---------- Semantik: Farbe (Light) ---------- */
  --color-bg: var(--stone-50);
  --color-surface: var(--stone-0);
  --color-surface-subtle: var(--stone-100);
  --color-surface-sunken: var(--stone-100);
  --color-overlay-backdrop: rgb(23 22 20 / 0.4);

  --color-border: var(--stone-200);
  --color-border-strong: var(--stone-300);
  --color-border-control: var(--stone-500); /* ≥ 3:1 für Formularrahmen */

  --color-text: var(--stone-900);
  --color-text-secondary: var(--stone-700);
  --color-text-muted: var(--stone-600); /* ≥ 4.5:1 auf bg und subtle */
  --color-text-disabled: var(--stone-400); /* nur für deaktivierte Elemente */
  --color-text-inverse: var(--stone-0);

  --color-accent: var(--petrol-600);
  --color-accent-hover: var(--petrol-700);
  --color-accent-active: var(--petrol-800);
  --color-accent-subtle: var(--petrol-50);
  --color-accent-subtle-text: var(--petrol-700);
  --color-on-accent: var(--stone-0);

  --color-focus-ring: var(--petrol-600);

  --color-danger: var(--red-600);
  --color-danger-hover: var(--red-700);
  --color-danger-subtle: var(--red-50);
  --color-danger-subtle-text: var(--red-700);
  --color-on-danger: var(--stone-0);
  --color-warning: var(--amber-700);
  --color-warning-subtle: var(--amber-50);
  --color-success: var(--green-700);
  --color-success-subtle: var(--green-50);

  --color-hover-overlay: rgb(23 22 20 / 0.05);
  --color-press-overlay: rgb(23 22 20 / 0.09);
  --color-skeleton: var(--stone-200);

  /* ---------- Typografie ---------- */
  --font-sans: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  /* Feste rem-Skala, Verhältnis ≈ 1.2 (Produkt-UI, nicht fluid) */
  --text-xs: 0.75rem;    /* 12 · Meta, Badges */
  --text-sm: 0.875rem;   /* 14 · Labels, Tabellen, sekundär */
  --text-base: 1rem;     /* 16 · Fließtext, Inputs */
  --text-lg: 1.125rem;   /* 18 · Lead, Card-Titel */
  --text-xl: 1.375rem;   /* 22 · H3 */
  --text-2xl: 1.75rem;   /* 28 · H2 */
  --text-3xl: 2.25rem;   /* 36 · H1 */
  --text-4xl: 3rem;      /* 48 · Display, sparsam */

  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.01em;

  --measure: 68ch;

  /* ---------- Spacing (4-px-Basis, 8-px-Rhythmus) ---------- */
  --space-0: 0;
  --space-px: 1px;
  --space-0-5: 0.125rem; /* 2 */
  --space-1: 0.25rem;    /* 4 */
  --space-2: 0.5rem;     /* 8 */
  --space-3: 0.75rem;    /* 12 */
  --space-4: 1rem;       /* 16 */
  --space-5: 1.25rem;    /* 20 */
  --space-6: 1.5rem;     /* 24 */
  --space-8: 2rem;       /* 32 */
  --space-10: 2.5rem;    /* 40 */
  --space-12: 3rem;      /* 48 */
  --space-16: 4rem;      /* 64 */
  --space-20: 5rem;      /* 80 */
  --space-24: 6rem;      /* 96 */

  /* ---------- Größen ---------- */
  --size-touch: 2.75rem;        /* 44 · Mindest-Touch-Target */
  --size-control-sm: 2rem;      /* 32 · nur mit 44-px-Trefferfläche */
  --size-control-md: 2.5rem;    /* 40 · Desktop-Standard */
  --size-control-lg: 2.75rem;   /* 44 · Touch-Standard */
  --size-icon-sm: 1rem;         /* 16 */
  --size-icon-md: 1.25rem;      /* 20 */
  --size-icon-lg: 1.5rem;       /* 24 */
  --icon-stroke: 1.75;
  --container-sm: 40rem;        /* 640 */
  --container-md: 48rem;        /* 768 */
  --container-lg: 64rem;        /* 1024 */
  --container-xl: 80rem;        /* 1280 */
  --sidebar-width: 16rem;       /* 256 */
  --size-topbar: 3.5rem;        /* 56 */
  --size-checkbox: 1.125rem;    /* 18 */
  --size-switch-w: 2.25rem;     /* 36 */
  --size-switch-h: 1.25rem;     /* 20 */
  --size-menu-min: 12rem;       /* 192 */

  /* Breakpoints (nur Referenz; in Media Queries Literale nutzen) */
  --bp-sm: 640px;
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;

  /* ---------- Radien ---------- */
  --radius-none: 0;
  --radius-sm: 4px;    /* Badges, Checkbox */
  --radius-md: 6px;    /* Controls: Button, Input, Select */
  --radius-lg: 10px;   /* Flächen: Card, Modal, Menü */
  --radius-full: 9999px;

  /* ---------- Linien & Schatten ---------- */
  --border-width: 1px;
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  /* Flächen bekommen keine Schatten, sondern eine 1-px-Linie. */
  --shadow-none: none;
  --shadow-overlay: 0 1px 2px rgb(23 22 20 / 0.06), 0 8px 24px -4px rgb(23 22 20 / 0.14);

  /* ---------- Z-Index ---------- */
  --z-base: 0;
  --z-sticky: 10;
  --z-dropdown: 30;
  --z-overlay: 40;
  --z-modal: 50;
  --z-toast: 60;

  /* ---------- Motion ---------- */
  --motion-duration-fast: 150ms;   /* Press, Hover, Toggle */
  --motion-duration-base: 200ms;   /* Menüs, Popover, Tabs */
  --motion-duration-slow: 300ms;   /* Modal, Drawer, Toast */
  --motion-duration-page: 450ms;   /* Seitenübergang (Obergrenze) */
  --motion-stagger: 30ms;          /* Listen-Versatz, max. 40ms */
  --motion-stagger-max: 40ms;
  --motion-stagger-count: 8;       /* max. gestaffelte Elemente */
  --motion-duration-pulse: 1200ms; /* nur Skeleton */
  --motion-duration-spin: 800ms;   /* nur Lade-Spinner, eine Umdrehung */

  --motion-ease-out: cubic-bezier(0.23, 1, 0.32, 1);      /* Ein-/Ausblenden */
  --motion-ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);  /* Bewegung auf dem Screen */
  --motion-ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);   /* Drawer, Sheets */
  --motion-ease-hover: ease;                             /* Farbe, Hover */

  --motion-distance-sm: 4px;
  --motion-distance-md: 8px;
  --motion-scale-press: 0.97;
  --motion-scale-enter: 0.96;
}

/* ---------- Dark: System-Präferenz ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: var(--stone-900);
    --color-surface: var(--stone-d-surface);
    --color-surface-subtle: var(--stone-d-raised);
    --color-surface-sunken: #131210;
    --color-overlay-backdrop: rgb(0 0 0 / 0.6);
    --color-border: var(--stone-d-border);
    --color-border-strong: #46423b;
    --color-border-control: var(--stone-d-border-strong);
    --color-text: var(--stone-d-text);
    --color-text-secondary: #c9c5bd;
    --color-text-muted: var(--stone-d-muted);
    --color-text-disabled: #5e5a52;
    --color-text-inverse: var(--stone-900);
    --color-accent: var(--petrol-400);
    --color-accent-hover: #74c2b5;
    --color-accent-active: #8ccfc3;
    --color-accent-subtle: #17312d;
    --color-accent-subtle-text: #8ccfc3;
    --color-on-accent: var(--petrol-900);
    --color-focus-ring: var(--petrol-400);
    --color-danger: var(--red-300);
    --color-danger-hover: #f49186;
    --color-danger-subtle: #3a1814;
    --color-danger-subtle-text: #f6a59c;
    --color-on-danger: #1a0b09;
    --color-warning: var(--amber-300);
    --color-warning-subtle: #33260f;
    --color-success: var(--green-300);
    --color-success-subtle: #172b1a;
    --color-hover-overlay: rgb(255 255 255 / 0.05);
    --color-press-overlay: rgb(255 255 255 / 0.09);
    --color-skeleton: var(--stone-d-raised);
    --shadow-overlay: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -4px rgb(0 0 0 / 0.5);
  }
}

/* ---------- Dark: explizit gewählt ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: var(--stone-900);
  --color-surface: var(--stone-d-surface);
  --color-surface-subtle: var(--stone-d-raised);
  --color-surface-sunken: #131210;
  --color-overlay-backdrop: rgb(0 0 0 / 0.6);
  --color-border: var(--stone-d-border);
  --color-border-strong: #46423b;
  --color-border-control: var(--stone-d-border-strong);
  --color-text: var(--stone-d-text);
  --color-text-secondary: #c9c5bd;
  --color-text-muted: var(--stone-d-muted);
  --color-text-disabled: #5e5a52;
  --color-text-inverse: var(--stone-900);
  --color-accent: var(--petrol-400);
  --color-accent-hover: #74c2b5;
  --color-accent-active: #8ccfc3;
  --color-accent-subtle: #17312d;
  --color-accent-subtle-text: #8ccfc3;
  --color-on-accent: var(--petrol-900);
  --color-focus-ring: var(--petrol-400);
  --color-danger: var(--red-300);
  --color-danger-hover: #f49186;
  --color-danger-subtle: #3a1814;
  --color-danger-subtle-text: #f6a59c;
  --color-on-danger: #1a0b09;
  --color-warning: var(--amber-300);
  --color-warning-subtle: #33260f;
  --color-success: var(--green-300);
  --color-success-subtle: #172b1a;
  --color-hover-overlay: rgb(255 255 255 / 0.05);
  --color-press-overlay: rgb(255 255 255 / 0.09);
  --color-skeleton: var(--stone-d-raised);
  --shadow-overlay: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -4px rgb(0 0 0 / 0.5);
}

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

/* ---------- Reduced Motion: vollständig ---------- */
/* Bewegung entfällt. Erlaubt bleibt nur ein kurzer Opacity-Wechsel,
   damit Zustände nicht flackern. Distanzen und Skalierung werden neutral. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-duration-fast: 0ms;
    --motion-duration-base: 0ms;
    --motion-duration-slow: 0ms;
    --motion-duration-page: 0ms;
    --motion-stagger: 0ms;
    --motion-stagger-max: 0ms;
    --motion-distance-sm: 0px;
    --motion-distance-md: 0px;
    --motion-scale-press: 1;
    --motion-scale-enter: 1;
  }
}

/* ---------- Basis (opt-in über class="urso" auf <html> oder <body>) ---------- */
:where(.urso) {
  font-family: var(--font-sans);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

:where(.urso) :where(.tabular, td, th) {
  font-variant-numeric: tabular-nums;
}

:where(.urso) :focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus-ring);
  outline-offset: var(--focus-ring-offset);
}
