/* ============================================================
   DropshipSA v2 — Design System (P0 foundation)
   Source of truth: design.md sections 4 (tokens) and 5 (type).

   This file is the ONLY place that holds raw hex, spacing, and
   font values. Every component consumes tokens, never raw values.
   Loading this file changes nothing on its own — it is the
   foundation the redesign is built on (design.md 15.2 Phase 0).

   Order inside this file:
     1. Self-hosted @font-face (no Google Fonts at runtime)
     2. Light token set (:root default + [data-theme="light"])
     3. Dark token set (prefers-color-scheme + [data-theme="dark"])
     4. Type scale tokens (section 5.2)
     5. Base font wiring + reduced-motion guard
   ============================================================ */

/* ------------------------------------------------------------
   1. Fonts — self-hosted (design.md 2.4, 5.1)
   Files live in ./fonts/. No CDN / Google Fonts at runtime.
   Weights 400/500/600/700 per section 5.1.
   ------------------------------------------------------------ */

/* IBM Plex Sans Arabic — kept as the fallback face behind Tajawal (issue #416) */
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-arabic-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-arabic-500.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-arabic-600.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-arabic-700.woff2') format('woff2');
}

/* Tajawal — primary Arabic + UI face (replaces IBM Plex Sans Arabic, issue #416).
   Tajawal ships 400/500/700 only. There is no 600, so the 600 used by headings
   falls back to the nearest weight. */
@font-face {
  font-family: 'Tajawal';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/tajawal-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Tajawal';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/tajawal-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Tajawal';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/tajawal-700.woff2') format('woff2');
}

/* IBM Plex Sans — secondary Latin face (pairs with the Arabic member) */
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-500.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-600.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-700.woff2') format('woff2');
}

/* Amiri — for later store themes (design.md 5.1 / 13) */
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/amiri-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Amiri';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/amiri-700.woff2') format('woff2');
}

/* Reem Kufi — for later store themes (design.md 5.1 / 13) */
@font-face {
  font-family: 'Reem Kufi';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/reem-kufi-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Reem Kufi';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/reem-kufi-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Reem Kufi';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/reem-kufi-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Reem Kufi';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/reem-kufi-700.woff2') format('woff2');
}

/* ------------------------------------------------------------
   2. Light token set — default (design.md 4.2 - 4.7)
   ------------------------------------------------------------ */
:root {
  /* Brand (Vermilion) ramp — 4.2 */
  --brand-50:  #FFF4EF;
  --brand-100: #FED7CB;
  --brand-200: #FDBBA6;
  --brand-300: #FB9576;
  --brand-400: #FA6238;
  --brand-500: #FD3F0F;
  --brand-600: #E5350C;
  --brand-700: #C23934;
  --brand-800: #9B2A28;
  --brand-900: #7A211F;

  /* Neutral (warm stone / cream) ramp — 4.2 */
  --n-0:   #FFFFFF;
  --n-50:  #FFFBF7;
  --n-100: #F7F5F0;
  --n-200: #ECE9E2;
  --n-300: #DED9CF;
  --n-400: #A8A29E;
  --n-500: #78716C;
  --n-600: #57534E;
  --n-700: #44403C;
  --n-800: #303030;
  --n-900: #1C1A19;

  /* Semantic status colors — 4.2 */
  --success:    #15803D;
  --success-bg: #DCFCE7;
  --warning:    #B45309;
  --warning-bg: #FEF3C7;
  --danger:     #B91C1C;
  --danger-bg:  #FEE2E2;
  --info:       #1D4FD8;
  --info-bg:    #DBEAFE;

  /* Semantic role tokens — what components reference — 4.2 */
  --bg:            var(--n-50);
  --surface:       var(--n-0);
  --surface-2:     var(--n-100);
  --text:          var(--n-800);
  /* Muted and subtle were one step lighter (n-500 / n-400). On the cream
     background n-400 was only 2.4:1, so hints and placeholders were hard to
     read. Both are darkened one step so they pass WCAG AA (issue #386). */
  --text-muted:    var(--n-600);
  --text-subtle:   var(--n-500);
  --border:        var(--n-200);
  --border-strong: var(--n-300);
  --accent:        var(--brand-500);
  --accent-hover:  var(--brand-700);
  --accent-weak:   var(--brand-100);
  /* Accent-coloured TEXT (issue #1590). --accent is a fill colour: on the cream
     ground it measures 3.46:1, so a link painted with it fails WCAG AA (4.5:1).
     This is the darker shade to write accent words with — brand-700 measures
     5.19:1 on the cream page and 5.35:1 on the white card. Use --accent to fill
     a shape, --accent-ink to write on one. */
  --accent-ink:    var(--brand-700);
  --focus-ring:    color-mix(in srgb, var(--accent) 40%, transparent);

  /* Spacing scale — 4px base — 4.3 */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Radius — 4.4 */
  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   14px;
  --r-xl:   20px;
  --r-pill: 999px;

  /* Elevation / shadow — 4.5 */
  --shadow-xs: 0 1px 2px rgba(2,6,23,.05);
  --shadow-sm: 0 1px 3px rgba(2,6,23,.08), 0 1px 2px rgba(2,6,23,.04);
  --shadow-md: 0 4px 12px -2px rgba(2,6,23,.10);
  --shadow-lg: 0 12px 28px -8px rgba(2,6,23,.16);

  /* Motion — 4.6 */
  --ease:     cubic-bezier(.2,.7,.2,1);
  --dur-fast: 120ms;
  --dur:      200ms;
  --dur-slow: 320ms;

  /* Z-index scale — 4.7 */
  --z-base:     0;
  --z-sticky:   100;
  --z-header:   200;
  --z-dropdown: 300;
  --z-overlay:  400;
  --z-modal:    500;
  --z-toast:    600;

  /* Type scale tokens — section 5.2 (rem, 16px base) */
  --font-sans-ar: 'Tajawal', 'IBM Plex Sans Arabic', Arial, sans-serif;
  --font-sans:    'Tajawal', 'IBM Plex Sans', Arial, sans-serif;
  --font-display: var(--font-sans-ar);

  /* Sizes are two steps bigger than the original spec (issues #386, #416):
     Arabic script needs more size than Latin to stay clear. Body is 17px,
     small is 15px, label is 14px. Headings, line-heights and weights do not
     change. */
  --fs-display: 2.5rem;    --lh-display: 1.15;  --fw-display: 700;
  --fs-h1:      2rem;      --lh-h1:      1.2;   --fw-h1:      700;
  --fs-h2:      1.5rem;    --lh-h2:      1.25;  --fw-h2:      650;
  --fs-h3:      1.25rem;   --lh-h3:      1.3;   --fw-h3:      650;
  --fs-body-lg: 1.1875rem; --lh-body-lg: 1.6;   --fw-body-lg: 400;
  --fs-body:    1.0625rem; --lh-body:    1.6;   --fw-body:    400;
  --fs-small:   0.9375rem; --lh-small:   1.5;   --fw-small:   400;
  --fs-label:   0.875rem;  --lh-label:   1.4;   --fw-label:   600;
}

/* Explicit light override — 4.1 (same values as default :root).
   Also answers the app-wide hook `data-theme-style="light"` that the wrappers
   set on <body> and the footer toggle flips, so switching back to light is
   clean everywhere (issue #600). */
[data-theme-style="light"],
:root[data-theme="light"] {
  --bg:            var(--n-50);
  --surface:       var(--n-0);
  --surface-2:     var(--n-100);
  --text:          var(--n-800);
  --text-muted:    var(--n-600);
  --text-subtle:   var(--n-500);
  --border:        var(--n-200);
  --border-strong: var(--n-300);
  --accent:        var(--brand-500);
  --accent-hover:  var(--brand-700);
  --accent-weak:   var(--brand-100);
  --accent-ink:    var(--brand-700);
  --focus-ring:    color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ------------------------------------------------------------
   3. Dark token set — warm dark (design.md 4.2 dark role tokens)
   The dark role tokens are shared by the "Luxury" store theme.
   IMPORTANT: the design is LIGHT-first. Dark is applied ONLY when explicitly
   requested via data-theme="dark" (the Luxury storefront theme). We do NOT
   follow the OS `prefers-color-scheme`, so the merchant dashboard and every
   default surface stay light (cream), matching the prototype.

   ONE hook for the whole app (issue #600): the merchant panel, settings and
   product pages set `data-theme-style="dark"` on <body> (from
   \Altum\ThemeStyle) and the footer toggle flips that same attribute at
   runtime. Wiring the dark tokens to that hook flips every page that consumes
   design tokens in one place — no page-by-page work. The Luxury storefront
   theme keeps using :root[data-theme="dark"].
   ------------------------------------------------------------ */
[data-theme-style="dark"],
:root[data-theme="dark"] {
  --bg:            #1A1714;
  --surface:       #241F1B;
  --surface-2:     #2B2521;
  --text:          #F3ECE4;
  --text-muted:    #A8A29E;
  --text-subtle:   #7A706A;
  --border:        #322B26;
  --border-strong: #4A4038;
  --accent:        #FA6238;
  --accent-hover:  #FD3F0F;
  --accent-weak:   rgba(253,63,15,.14);
  /* On the warm dark ground the accent is already readable as text: #FA6238
     measures 5.84:1 on --bg and 5.34:1 on --surface. So dark needs no darker
     shade — the ink IS the accent here (issue #1590). */
  --accent-ink:    var(--accent);
  --focus-ring:    color-mix(in srgb, var(--accent) 40%, transparent);

  --shadow-xs: 0 1px 2px rgba(0,0,0,.45);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px -2px rgba(0,0,0,.55);
  --shadow-lg: 0 12px 28px -8px rgba(0,0,0,.6);
}

/* ------------------------------------------------------------
   4. Icon sprite helpers (design.md 6)
   One symbol, referenced by <use>. Directional icons flip in RTL.
   ------------------------------------------------------------ */
.icon {
  width: 1.25em;
  height: 1.25em;
  display: inline-block;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* Flip chevrons / arrows / back icons in RTL — 6 */
[dir="rtl"] .icon-flip-rtl {
  transform: scaleX(-1);
}

/* ------------------------------------------------------------
   5. Base wiring (safe, opt-in)
   Only sets tokenised font + tabular numerals on a helper class
   and body font var, so this foundation file does not restyle
   existing pages (design.md 15.2 Phase 0 — "no visible change").
   ------------------------------------------------------------ */
.ds-root {
  font-family: var(--font-sans-ar);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
   6. Reduced motion — honor user preference (design.md 4.6 / 14)
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
