/* ==========================================================================
   OFinder "Atlas" design tokens, v1.0 (staging copy only)
   Pairs with OFinder-Atlas-design-system.md
   Everything here is a token or a tiny helper. No component layout lives here.
   Contrast ratios in comments were computed against the stated background
   and meet WCAG 2.2 AA (4.5:1 body, 3:1 large text / UI borders).
   ========================================================================== */

:root {
  /* ---------- 1. Colour primitives: light ("paper") ---------- */
  --paper-0:        #FFFDF8;   /* card surface                 */
  --paper-50:       #FAF7F1;   /* app background (warm paper)  */
  --paper-100:      #F6F2E9;   /* sunken / input background    */
  --paper-200:      #E5DECF;   /* hairline                     */
  --paper-300:      #8F8B7E;   /* divider, decorative only     */

  --ink-900:        #1A1C1B;   /* on paper-50  body text */
  --ink-700:        #4A4E48;   /* on paper-50  secondary */
  --ink-500:        #6D7069;   /* on paper-50  meta text */
  --ink-400:        #6D7069;   /* icons, non-text only  */

  --teal-700:       #123B33;   /* on white  primary text/fill */
  --teal-600:       #174A40;   /* with white text  hover     */
  --teal-500:       #174A40;   /* with white text  large only */
  --teal-100:       #ECF0EC;
  --teal-50:        #ECF0EC;

  --ember-600:      #8A6A2F;   /* on white  deadline / urgent text */
  --ember-500:      #8A6A2F;   /* graphic + large text only       */
  --ember-100:      #F5EEDA;

  --amber-700:      #7A5200;   /*  6.1:1 on amber-100 */
  --amber-100:      #FCEFD2;
  --green-700:      #1B6B3A;   /*  6.0:1 on teal-50   */
  --red-700:        #9E2A20;   /*  7.5:1 on white     */
  --focus:          #1B63D6;   /*  5.5:1 on white     */

  /* ---------- 2. Colour primitives: dark ("night glass") ---------- */
  /* The dark theme is built on the brand's own deep green (#123B33, the light theme's primary
     button), not on a near-black: the page sits a step below the brand green, cards sit on it, and
     raised surfaces climb from there. 10.8:1 text on the card surface, 6.5:1 for muted text. */
  --night-950:      #0C2620;   /* page background: deep green, never black */
  --night-900:      #123B33;   /* card surface: the brand green itself      */
  --night-850:      #17463C;   /* raised surface / sheet                    */
  --night-800:      #1D5145;   /* pressed, chips, wells                     */
  --night-700:      #245C4F;   /* hover on raised                           */

  --chalk-50:       #F2F0E6;   /* on night-900, 10.8:1      */
  --chalk-300:      #C6D6CD;   /* on night-900              */
  --chalk-500:      #A9C2B6;   /* on night-900, 6.5:1       */

  --lime-300:       #D8EC9F;   /* the dark-mode primary fill         */
  --lime-400:       #E6F5BC;   /* its hover                          */
  --lime-900:       #16211C;   /* text on a lime fill, 12.9:1        */
  --mint-300:       #A3BFAE;   /* legacy name, no longer the primary */
  --mint-400:       #B6CFBF;
  --mint-900:       #1F2A24;

  --ember-400:      #DCC08A;   /* brass links on night-900, 7.0:1 */
  --amber-300:      #F2C46B;   /* 10.6:1 on night-900 */
  --green-300:      #6BD79B;   /*  9.8:1 on night-900 */
  --red-300:        #FF8F82;   /*  7.8:1 on night-900 */
  --focus-dark:     #8CB6FF;   /*  8.5:1 on night-900 */

  /* ---------- 3. Semantic aliases: light ---------- */
  --color-bg:            var(--paper-50);
  --color-bg-sunken:     var(--paper-100);
  --color-surface:       var(--paper-0);
  --color-surface-2:     var(--paper-50);
  --color-surface-3:     var(--paper-100);
  --color-text:          var(--ink-900);
  --color-text-secondary:var(--ink-700);
  --color-text-meta:     var(--ink-500);
  --color-text-inverse:  var(--paper-0);
  --color-border:        var(--paper-200);
  --color-border-strong: #8F8B7E;            /* on white */
  --color-primary:       var(--teal-700);
  --color-primary-hover: var(--teal-600);
  --color-primary-tint:  var(--teal-50);
  --color-on-primary:    var(--paper-0);
  --color-accent:        var(--ember-600);
  --color-accent-tint:   var(--ember-100);
  --color-on-accent:     var(--paper-0);   /* text on a brass fill, dark only */
  --color-disc:          #EAE6DA;          /* avatar initial disc, no lime   */
  --color-disc-ink:      #123B33;
  --color-success:       var(--green-700);
  --color-warning:       var(--amber-700);
  --color-warning-tint:  var(--amber-100);
  --color-danger:        var(--red-700);
  --color-focus:         var(--focus);
  --color-scrim:         rgba(26, 28, 27, 0.48);
  --color-media-scrim:   linear-gradient(180deg, rgba(16,18,16,0) 42%, rgba(16,18,16,0.82) 100%);
  --color-skeleton:      linear-gradient(90deg, var(--paper-100) 0%, #FDFAF4 50%, var(--paper-100) 100%);

  /* ---------- 4. Semantic aliases: dark ---------- */
  /* applied by [data-theme="dark"] and by system preference unless the
     document pins a theme with data-theme="light" */
  --dark-color-bg:            var(--night-950);
  --dark-color-bg-sunken:     #091D18;
  --dark-color-surface:       var(--night-900);
  --dark-color-surface-2:     var(--night-850);
  --dark-color-surface-3:     var(--night-800);
  --dark-color-text:          var(--chalk-50);
  --dark-color-text-secondary:var(--chalk-300);
  --dark-color-text-meta:     var(--chalk-500);
  --dark-color-text-inverse:  var(--night-950);
  --dark-color-border:        #2E6456;
  --dark-color-border-strong: #5E9A88;       /* on night-900 */
  --dark-color-primary:       var(--lime-300);
  --dark-color-primary-hover: var(--lime-400);
  --dark-color-primary-tint:  var(--night-800);
  --dark-color-on-primary:    var(--lime-900);
  --dark-color-accent:        var(--ember-400);
  --dark-color-accent-tint:   #26382E;
  --dark-color-on-accent:     #16211C;
  --dark-color-disc:          var(--night-800);
  --dark-color-disc-ink:      var(--lime-300);
  --dark-color-success:       var(--green-300);
  --dark-color-warning:       var(--amber-300);
  --dark-color-warning-tint:  #33260C;
  --dark-color-danger:        var(--red-300);
  --dark-color-focus:         var(--focus-dark);
  --dark-color-scrim:         rgba(6, 7, 6, 0.66);
  --dark-color-skeleton:      linear-gradient(90deg, #17463C80 0%, #1D514580 50%, #17463C80 100%);

  /* ---------- 5. Type ---------- */
  /* Rubik sets Latin and Cyrillic; Cairo is the Arabic face. Both @font-face rules
     carry their own unicode-range, so the browser picks the script face itself. */
  --font-ui:      "Rubik", "Cairo", ui-sans-serif, system-ui, "Segoe UI", Tahoma, sans-serif;
  --font-display-latin: "Rubik", "Cairo", ui-sans-serif, system-ui, "Segoe UI", Tahoma, sans-serif;
  --font-display-ar:    "Rubik", "Cairo", ui-sans-serif, system-ui, "Segoe UI", Tahoma, sans-serif;
  /* No monospace in the product UI (owner, 2026-11-30): the code face read robotic next to Rubik,
     so the token now resolves to the UI face and every label, handle and link follows. */
  --font-mono:    "Rubik", "Cairo", ui-sans-serif, system-ui, "Segoe UI", Tahoma, sans-serif;

  --fs-display-1: clamp(2rem, 1.4rem + 2.6vw, 2.75rem);   /* 32 → 44 */
  --fs-display-2: clamp(1.75rem, 1.35rem + 1.6vw, 2.25rem); /* 28 → 36 */
  --fs-h1:        clamp(1.5rem, 1.3rem + 0.9vw, 1.875rem);  /* 24 → 30 */
  --fs-h2:        clamp(1.3125rem, 1.2rem + 0.5vw, 1.5rem); /* 21 → 24 */
  --fs-h3:        1.25rem;    /* 20 */
  --fs-body-lg:   1.0625rem;  /* 17, Arabic body minimum */
  --fs-body:      1rem;       /* 16 */
  --fs-body-sm:   0.9375rem;  /* 15 */
  --fs-label:     0.8125rem;  /* 13 */
  --fs-caption:   0.75rem;    /* 12 */
  --fs-code:      0.78125rem; /* 12.5 */

  --lh-tight:     1.2;
  --lh-heading:   1.35;   /* Latin/Cyrillic */
  --lh-heading-ar:1.45;
  --lh-body:      1.55;
  --lh-body-ar:   1.8;    /* Arabic needs the extra leading for harakat + descenders */
  --lh-ui:        1.25;

  --tracking-tight: -0.015em;  /* Latin display only */
  --tracking-normal: 0;
  --tracking-wide: 0.02em;     /* small caps labels, Latin only */

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

  /* ---------- 6. Space (4pt base, 2px for hairlines) ---------- */
  --space-0: 0;
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 6px;
  --space-4: 8px;
  --space-5: 12px;
  --space-6: 16px;
  --space-7: 20px;
  --space-8: 24px;
  --space-9: 32px;
  --space-10: 40px;
  --space-11: 48px;
  --space-12: 64px;
  --space-13: 80px;
  --space-14: 96px;

  /* ---------- 7. Radii ---------- */
  --radius-xs:  4px;
  --radius-sm:  8px;
  --radius-md:  12px;   /* buttons, inputs */
  --radius-lg:  16px;   /* media inside a card */
  --radius-xl:  20px;   /* card, mobile */
  --radius-2xl: 24px;   /* card, desktop */
  --radius-3xl: 28px;   /* bottom sheet, modal */
  --radius-pill: 999px;

  /* ---------- 8. Elevation ---------- */
  --shadow-1: 0 1px 2px rgba(15,21,23,.06), 0 1px 1px rgba(15,21,23,.04);
  --shadow-2: 0 2px 6px rgba(15,21,23,.07), 0 10px 24px -14px rgba(15,21,23,.16);
  --shadow-3: 0 12px 32px -12px rgba(15,21,23,.20), 0 2px 8px rgba(15,21,23,.06);
  --shadow-pop: 0 24px 56px -24px rgba(15,21,23,.32);
  --shadow-dark-1: 0 1px 0 rgba(255,255,255,.04) inset;
  --shadow-dark-pop: 0 24px 56px -20px rgba(0,0,0,.72);
  --ring-focus: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-focus);
  --ring-focus-dark: 0 0 0 2px var(--dark-color-surface), 0 0 0 4px var(--dark-color-focus);

  /* ---------- 9. Layout ---------- */
  --shell-max: 1240px;
  --feed-col: 640px;
  --rail-col: 320px;
  --nav-rail: 248px;
  --gutter-mobile: 16px;
  --gutter-tablet: 24px;
  --gutter-desktop: 32px;
  --tabbar-h: 56px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --touch-min: 44px;      /* our floor; WCAG 2.5.8 asks 24px */
  --control-h: 48px;

  /* ---------- 10. Motion ---------- */
  --dur-1: 100ms;   /* press, hover tint */
  --dur-2: 160ms;   /* default UI transition */
  --dur-3: 220ms;   /* popover, tab switch */
  --dur-4: 320ms;   /* sheet, card expand */
  --dur-5: 480ms;   /* poll bar fill, chart draw */
  --dur-6: 700ms;   /* one-off celebration only */

  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-out:      cubic-bezier(0.05, 0.7, 0.1, 1);
  --ease-in:       cubic-bezier(0.3, 0, 0.8, 0.15);
  --ease-spring:   cubic-bezier(0.34, 1.3, 0.64, 1); /* press-release only */
  --stagger-1: 40ms;

  /* ---------- 11. Z-index ---------- */
  --z-base: 0;
  --z-sticky: 10;
  --z-tabbar: 30;
  --z-sheet: 40;
  --z-modal: 50;
  --z-toast: 60;
  --z-staging-banner: 70;
}

/* ---------- 12. Dark theme binding ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  --color-bg:             var(--dark-color-bg);
  --color-bg-sunken:      var(--dark-color-bg-sunken);
  --color-surface:        var(--dark-color-surface);
  --color-surface-2:      var(--dark-color-surface-2);
  --color-surface-3:      var(--dark-color-surface-3);
  --color-text:           var(--dark-color-text);
  --color-text-secondary: var(--dark-color-text-secondary);
  --color-text-meta:      var(--dark-color-text-meta);
  --color-text-inverse:   var(--dark-color-text-inverse);
  --color-border:         var(--dark-color-border);
  --color-border-strong:  var(--dark-color-border-strong);
  --color-primary:        var(--dark-color-primary);
  --color-primary-hover:  var(--dark-color-primary-hover);
  --color-primary-tint:   var(--dark-color-primary-tint);
  --color-on-primary:     var(--dark-color-on-primary);
  --color-accent:         var(--dark-color-accent);
  --color-accent-tint:    var(--dark-color-accent-tint);
  --color-on-accent:      var(--dark-color-on-accent);
  --color-disc:           var(--dark-color-disc);
  --color-disc-ink:       var(--dark-color-disc-ink);
  --color-success:        var(--dark-color-success);
  --color-warning:        var(--dark-color-warning);
  --color-warning-tint:   var(--dark-color-warning-tint);
  --color-danger:         var(--dark-color-danger);
  --color-focus:          var(--dark-color-focus);
  --color-scrim:          var(--dark-color-scrim);
  --color-skeleton:       var(--dark-color-skeleton);
  --shadow-1: var(--shadow-dark-1);
  --shadow-2: var(--shadow-dark-1);
  --shadow-3: var(--shadow-dark-pop);
  --ring-focus: var(--ring-focus-dark);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --color-bg:             var(--dark-color-bg);
    --color-bg-sunken:      var(--dark-color-bg-sunken);
    --color-surface:        var(--dark-color-surface);
    --color-surface-2:      var(--dark-color-surface-2);
    --color-surface-3:      var(--dark-color-surface-3);
    --color-text:           var(--dark-color-text);
    --color-text-secondary: var(--dark-color-text-secondary);
    --color-text-meta:      var(--dark-color-text-meta);
    --color-text-inverse:   var(--dark-color-text-inverse);
    --color-border:         var(--dark-color-border);
    --color-border-strong:  var(--dark-color-border-strong);
    --color-primary:        var(--dark-color-primary);
    --color-primary-hover:  var(--dark-color-primary-hover);
    --color-primary-tint:   var(--dark-color-primary-tint);
    --color-on-primary:     var(--dark-color-on-primary);
    --color-accent:         var(--dark-color-accent);
    --color-accent-tint:    var(--dark-color-accent-tint);
    --color-on-accent:      var(--dark-color-on-accent);
    --color-disc:           var(--dark-color-disc);
    --color-disc-ink:       var(--dark-color-disc-ink);
    --color-success:        var(--dark-color-success);
    --color-warning:        var(--dark-color-warning);
    --color-warning-tint:   var(--dark-color-warning-tint);
    --color-danger:         var(--dark-color-danger);
    --color-focus:          var(--dark-color-focus);
    --color-scrim:          var(--dark-color-scrim);
    --color-skeleton:       var(--dark-color-skeleton);
    --shadow-1: var(--shadow-dark-1);
    --shadow-2: var(--shadow-dark-1);
    --shadow-3: var(--shadow-dark-pop);
    --ring-focus: var(--ring-focus-dark);
  }
}

/* ---------- 13. Script-aware typography helpers ---------- */
html { font-family: var(--font-ui); }
[lang="ar"] {
  font-family: var(--font-ui);
  line-height: var(--lh-body-ar);
  letter-spacing: 0 !important;   /* letter-spacing breaks Arabic joins */
}
[lang="ar"] :is(h1, h2, h3, .display) { line-height: var(--lh-heading-ar); }
.display            { font-family: var(--font-display-latin); letter-spacing: var(--tracking-tight); }
[lang="ar"] .display{ font-family: var(--font-display-ar); letter-spacing: 0; }
.u-mono             { font-family: var(--font-mono); }
.u-tabular          { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.u-balance          { text-wrap: balance; }
.u-pretty           { text-wrap: pretty; }

/* ---------- 14. Direction-safe helpers ---------- */
.u-start-rule { border-inline-start: 3px solid var(--color-accent); padding-inline-start: var(--space-5); }
.u-mirror     { transform: scaleX(1); }
[dir="rtl"] .u-mirror { transform: scaleX(-1); }

/* ---------- 15. Focus + motion safety ---------- */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
  border-radius: var(--radius-sm);
}
@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;
  }
  .motion-only { display: none !important; }
}
