/* ============================================================================
   Nexivo Design Kit — tokens.css
   One source of truth for colour, space, type, radius, shadow, motion, z, safe-area.
   Dark is the default. Light = [data-theme=light] or OS preference.
   One accent per product: <html data-accent="violet|green|blue|gold|red">.
   Import order: fonts.css → tokens.css → kit.css → motion.css → your app css.
   Lane 1 upgrade (2026-10-19): Radix text/accent steps, shadcn borders, Primer/Open Props/Polaris
   shadows (ring + tinted layers + top highlight), iOS drawer easing, Arabic metrics. See docs/ENGINE-UPGRADE.md.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* ---- surfaces: step by LIGHTNESS (M3 tones 6/10/15/20/22); rings only on FLOATING things ---- */
  --bg:            #0E0F13;
  --surface:       #1A1C22;
  --surface-2:     #23262D;
  --surface-3:     #2C3039;
  --surface-4:     #353942;             /* menus / popovers floating over a sheet (M3 surface_container_highest) */
  --border:        rgba(255, 255, 255, 0.10);   /* shadcn v4 dark border 10 % */
  --border-strong: rgba(255, 255, 255, 0.16);   /* shadcn input 15 % / Radix step-6 17 % */
  --overlay:       rgba(6, 7, 10, 0.64);        /* solid backdrop; blur only on sheets, desktop only */
  --control:       var(--surface-2);   /* chips, inputs, search sitting on --bg */
  --seg-track:     var(--surface-2);
  --seg-pill:      var(--surface-3);
  --card-ring:     inset 0 0 0 1px rgba(255, 255, 255, 0.05);   /* cards on dark keep a hairline inset ring */

  /* ---- text: 3 steps max. --text-3 ONLY on --bg / --surface (Radix: 11/12 guaranteed on steps 1–2) ---- */
  --text:   #F2F3F5;
  --text-2: #B0B4BA;   /* Radix slate-11 (Lc 60); 6.4:1 even on surface-3 */
  --text-3: #8A8F99;   /* 5.3:1 on surface, 4.07:1 on surface-3 → never there */
  --text-on-dark: #F2F3F5;

  /* ---- status: *-soft = tint fill; --danger-fill = solid fill that carries WHITE text (4.9:1) ---- */
  --success: #32C275;
  --danger:  #F0515A;
  --warning: #F0A52D;
  --info:    #4A9DF5;
  --danger-fill: #D4323D;
  --danger-text: #FF8A8E;   /* danger AS TEXT on surface-3/4 (4.7:1); --danger itself is fine on bg/surface */
  --success-soft: rgba(50, 194, 117, 0.14);
  --danger-soft:  rgba(240, 81, 90, 0.14);
  --warning-soft: rgba(240, 165, 45, 0.14);
  --info-soft:    rgba(74, 157, 245, 0.14);

  /* ---- accent (default violet): step 9 = fill, step 11 = text, alpha 3/4 = tint / selected ---- */
  --accent:       #5F5DF0;   /* white on it = 4.9:1 */
  --accent-hover: #6E6CF6;
  --accent-press: #4F4DE3;
  --accent-fg:    #FFFFFF;
  --_accent-text-dark: #BAA7FF;                  /* Radix violet-11: the text step of the hue (9:1 on bg, 6.3:1 on surface-3) */
  --_accent-text-light: #4F4DE3;                 /* the LIGHT text step (5.5:1 on #F3F4F7); each preset mints its own, accent-press is too light for green/blue/gold/red */
  --accent-text:  var(--_accent-text-dark);      /* accent AS TEXT; light theme = accent-press */
  --accent-text-inv: var(--_accent-text-light);  /* accent text on an INVERSE (light) surface (.k-toast--inverse): the light text step, not accent-press (green 3.2:1, gold 2.5:1) */
  --accent-soft:  rgba(95, 93, 240, 0.14);       /* badge / banner tint */
  --accent-soft-2: rgba(95, 93, 240, 0.22);      /* SELECTED row / chip / table row (Radix violet-a3) ≠ badge tint */
  --accent-ring:  rgba(95, 93, 240, 0.45);

  /* ---- spacing: 4-px scale ------------------------------------------------ */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px; --s5: 20px;  --s6: 24px;
  --s7: 28px; --s8: 32px; --s9: 40px; --s10: 48px; --s11: 56px; --s12: 64px;
  --gutter: var(--s4);          /* screen side padding */
  --card-pad: var(--s3);        /* inside cards */
  --row-h: 56px;                /* list row */
  --fixture-h: 64px;            /* fixture row */
  --tap: 44px;                  /* minimum touch target (hit area, may exceed the visible box) */
  --topbar-h: 56px;
  --tabbar-h: 60px;

  /* ---- radius ------------------------------------------------------------- */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 24px; --r-full: 999px;

  /* ---- type --------------------------------------------------------------- */
  --font-latin:  "Inter", -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-arabic: "IBM Plex Sans Arabic", "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --font: var(--font-latin);

  --t-xs: 12px;  --lh-xs: 16px;
  --t-sm: 14px;  --lh-sm: 20px;
  --t-md: 16px;  --lh-md: 24px;
  --t-lg: 20px;  --lh-lg: 28px;
  --t-xl: 24px;  --lh-xl: 32px;
  --t-2xl: 32px; --lh-2xl: 40px;
  --t-3xl: 40px; --lh-3xl: 44px;   /* big scores / balances only */

  --w-regular: 400; --w-medium: 500; --w-semibold: 600; --w-bold: 700;
  --ls-tight: -0.01em;             /* Latin titles ≥ 20px; 0 under lang=ar (joined script is never tracked) */
  --ls-display: -0.02em;           /* Latin 32px+; 0 under lang=ar */

  /* ---- shadows: tinted to the bg hue (Open Props 228 40% 2%), 1 px translucent ring (Primer),
          inset top highlight (Polaris bevel). FLOATING things only; cards use --card-ring. ---- */
  --sh-bevel: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --sh-1: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 0 1px rgba(255, 255, 255, 0.05), 0 1px 2px hsl(228 40% 2% / 0.40);
  --sh-2: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 8px 16px -4px hsl(228 40% 2% / 0.55), 0 24px 48px -12px hsl(228 40% 2% / 0.45);
  --sh-3: 0 0 0 1px rgba(255, 255, 255, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 16px -4px hsl(228 40% 2% / 0.50), 0 24px 48px -12px hsl(228 40% 2% / 0.50), 0 48px 96px -24px hsl(228 40% 2% / 0.45);

  /* ---- motion ------------------------------------------------------------- */
  --ease:       cubic-bezier(0.2, 0, 0, 1);      /* ease-out, never bounce */
  --ease-in:    cubic-bezier(0.4, 0, 1, 1);
  --ease-out-strong: cubic-bezier(0.23, 1, 0.32, 1); /* .k-enter, popovers (Emil: built-in easings are too weak) */
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);  /* iOS drawer curve: sheets, toasts — no wobble */
  --ease-spring: cubic-bezier(0.34, 1.26, 0.64, 1); /* the ONLY overshoot: FAB (motion.css) */
  --dur-fast:   150ms;   /* colour, hover */
  --dur-press:  160ms;   /* press scale .97 (Emil 100–160 ms) */
  --dur:        200ms;   /* position: pill, ink, chips */
  --dur-slow:   320ms;   /* progress, count-up, bump, podium, flip */
  --dur-enter:  400ms;   /* things that appear: .k-enter, sheet, toast */
  --stagger:    40ms;    /* list enter, per item, max 8 */

  /* ---- z-index ------------------------------------------------------------ */
  --z-raised: 1; --z-sticky: 10; --z-tabbar: 20; --z-sheet: 30; --z-modal: 40; --z-toast: 50;

  /* ---- safe area ---------------------------------------------------------- */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-start:  env(safe-area-inset-left, 0px);
  --safe-end:    env(safe-area-inset-right, 0px);

  /* ---- icon: 1.5 beside regular text, 2 beside semibold (kit.css sets it in buttons/headings) ---- */
  --icon: 24px; --icon-sm: 20px; --icon-stroke: 1.5;
}

/* ---- Light theme (same block twice: OS preference, then explicit attribute) ---- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #F3F4F7; --surface: #FBFBFD; --surface-2: #F3F4F7; --surface-3: #E8EAF0; --surface-4: #FBFBFD;   /* no pure white (rule 7): surface = #FBFBFD */
    --border: rgba(18, 20, 28, 0.08); --border-strong: rgba(18, 20, 28, 0.16);
    --overlay: rgba(18, 20, 28, 0.40);
    --control: #FBFBFD; --seg-track: #E8EAF0; --seg-pill: #FBFBFD;
    --card-ring: inset 0 0 0 1px rgba(18, 20, 28, 0.05);
    --text: #15171C; --text-2: #5C616D; --text-3: #697080; --accent-text: var(--_accent-text-light); --accent-text-inv: var(--_accent-text-dark);
    --success: #15803D; --danger: #C62F39; --warning: #B45309; --info: #1F66C9; --danger-fill: #D0323C; --danger-text: #C62F39;   /* light status = text-safe on white (≥ 4.6:1) */
    --sh-bevel: inset 0 1px 0 rgba(255, 255, 255, 0.70);
    --sh-1: inset 0 1px 0 rgba(255, 255, 255, 0.70), 0 0 0 1px hsl(228 3% 15% / 0.06), 0 1px 2px hsl(228 3% 15% / 0.06);
    --sh-2: 0 0 0 1px hsl(228 3% 15% / 0.06), 0 8px 16px -4px hsl(228 3% 15% / 0.08), 0 24px 48px -12px hsl(228 3% 15% / 0.08);
    --sh-3: 0 0 0 1px hsl(228 3% 15% / 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.70), 0 8px 16px -4px hsl(228 3% 15% / 0.08), 0 24px 48px -12px hsl(228 3% 15% / 0.10), 0 48px 96px -24px hsl(228 3% 15% / 0.10);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F3F4F7; --surface: #FBFBFD; --surface-2: #F3F4F7; --surface-3: #E8EAF0; --surface-4: #FBFBFD;   /* no pure white (rule 7): surface = #FBFBFD */
  --border: rgba(18, 20, 28, 0.08); --border-strong: rgba(18, 20, 28, 0.16);
  --overlay: rgba(18, 20, 28, 0.40);
  --control: #FBFBFD; --seg-track: #E8EAF0; --seg-pill: #FBFBFD;
  --card-ring: inset 0 0 0 1px rgba(18, 20, 28, 0.05);
  --text: #15171C; --text-2: #5C616D; --text-3: #697080; --accent-text: var(--_accent-text-light); --accent-text-inv: var(--_accent-text-dark);
  --success: #15803D; --danger: #C62F39; --warning: #B45309; --info: #1F66C9; --danger-fill: #D0323C; --danger-text: #C62F39;   /* light status = text-safe on white (≥ 4.6:1) */
  --sh-bevel: inset 0 1px 0 rgba(255, 255, 255, 0.70);
  --sh-1: inset 0 1px 0 rgba(255, 255, 255, 0.70), 0 0 0 1px hsl(228 3% 15% / 0.06), 0 1px 2px hsl(228 3% 15% / 0.06);
  --sh-2: 0 0 0 1px hsl(228 3% 15% / 0.06), 0 8px 16px -4px hsl(228 3% 15% / 0.08), 0 24px 48px -12px hsl(228 3% 15% / 0.08);
  --sh-3: 0 0 0 1px hsl(228 3% 15% / 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.70), 0 8px 16px -4px hsl(228 3% 15% / 0.08), 0 24px 48px -12px hsl(228 3% 15% / 0.10), 0 48px 96px -24px hsl(228 3% 15% / 0.10);
}

/* ---- Accent presets (one per product) ------------------------------------- */
:root[data-accent="green"] {
  --accent: #2DB36A; --accent-hover: #3BC177; --accent-press: #249B5A; --_accent-text-dark: #5CD68E; --_accent-text-light: #1B7048; --accent-text: var(--_accent-text-dark);
  --accent-fg: #07200F; --accent-soft: rgba(45, 179, 106, 0.14);   /* ink on green (6.4:1); white was 2.7:1 */ --accent-soft-2: rgba(45, 179, 106, 0.22); --accent-ring: rgba(45, 179, 106, 0.45);
}
:root[data-accent="blue"] {
  --accent: #2A6FD9; --accent-hover: #3D8BFF; --accent-press: #1F5FC4; --_accent-text-dark: #7DB5FF; --_accent-text-light: #1D5FBF; --accent-text: var(--_accent-text-dark);
  --accent-fg: #FFFFFF; --accent-soft: rgba(42, 111, 217, 0.14); --accent-soft-2: rgba(42, 111, 217, 0.22); --accent-ring: rgba(42, 111, 217, 0.45);   /* fill 4.8:1 with white (was #3D8BFF 3.3:1) */
}
:root[data-accent="gold"] {
  --accent: #E3A726; --accent-hover: #ECB53A; --accent-press: #C8921C; --_accent-text-dark: #F0BE4C; --_accent-text-light: #8A5A00; --accent-text: var(--_accent-text-dark);
  --accent-fg: #1B1300; --accent-soft: rgba(227, 167, 38, 0.14); --accent-soft-2: rgba(227, 167, 38, 0.22); --accent-ring: rgba(227, 167, 38, 0.45);
}
:root[data-accent="red"] {
  --accent: #D23339; --accent-hover: #E5484D; --accent-press: #BE2A33; --_accent-text-dark: #FF7A7E; --_accent-text-light: #BE2A33; --accent-text: var(--_accent-text-dark);
  --accent-fg: #FFFFFF; --accent-soft: rgba(210, 51, 57, 0.14); --accent-soft-2: rgba(210, 51, 57, 0.22); --accent-ring: rgba(210, 51, 57, 0.45);   /* fill 4.9:1 with white (was #E5484D 3.9:1) */
}

/* ---- Base ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: var(--lh-md);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--text);
}
/* Arabic: Plex Arabic, NO tracking (joined script), 13 px caption floor, taller small line-height.
   Digits stay Inter tabular: Plex Arabic's unicode-range (fonts.css) excludes U+0030–0039. */
html[lang="ar"], html[lang^="ar-"] { --font: var(--font-arabic); --ls-tight: 0; --ls-display: 0; --t-xs: 13px; --lh-sm: 22px; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--w-regular) var(--t-sm) / var(--lh-sm) var(--font); }
h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg, video { display: block; max-inline-size: 100%; }
a { color: inherit; text-decoration: none; }
:focus { outline: none; }
/* focus ring = the TEXT step of the accent (Radix: ring is a step lighter than the solid), readable on surface-3 too */
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft-2); }

/* numbers always tabular */
.k-num, [data-num], table td:is(.num, [data-num]) { font-variant-numeric: tabular-nums lining-nums; font-feature-settings: "tnum" 1, "lnum" 1; }

/* theme switch: add .k-theme-switching to <html> for one frame while toggling data-theme (Rauno / Paco) */
.k-theme-switching, .k-theme-switching *, .k-theme-switching *::before, .k-theme-switching *::after { transition: none !important; }

@media (prefers-reduced-motion: reduce) {
  /* reduced motion = no MOVEMENT; opacity/colour fades stay (150–200 ms) so state changes remain visible (Emil STANDARDS, lane 2) */
  :root { --dur-enter: 0ms; --stagger: 0ms; --dur-press: 0ms; }
  *, *::before, *::after { animation-iteration-count: 1 !important; transition-property: opacity, color, background-color, border-color, box-shadow !important; }
}

/* presets come after the light block, so re-assert accent-as-text in light for every preset */
:root[data-theme="light"][data-accent] { --accent-text: var(--_accent-text-light); --accent-text-inv: var(--_accent-text-dark); }
