/* ==========================================================================
   ZENNTAC — Design tokens
   --------------------------------------------------------------------------
   Single source of truth for visual values. Components must reference these
   custom properties instead of hard-coding colours, sizes or timings.
   Full documentation: docs/DESIGN-SYSTEM.md

   STATUS: PROVISIONAL (Phase 1).
   The scales, token names and structure are intended to be stable. The
   colour values and font families are neutral placeholders until the brand
   identity (logo, colours, typefaces) is confirmed. Changing a value here
   must not require changing any component.

   Two tiers:
   - Primitives (--zt-*): raw values. Never used directly in components.
   - Semantic / role tokens (--color-*, --type-*, --space-*…): what
     components use. Themes and surface contexts remap these.

   Rules:
   - Use logical properties in components (margin-inline, padding-block…);
     tokens never encode a physical direction.
   - Contrast ratios noted below were measured against WCAG 2.2 formulas.
     Re-check contrast whenever a colour value changes.
   - Custom properties cannot be used inside @media conditions; breakpoints
     are listed as reference values and must be used literally.
   ========================================================================== */

:root {
  /* ------------------------------------------------------------------------
     1. Colour — primitives (do not use directly in components)
     ------------------------------------------------------------------------ */
  --zt-ink-950: #0e1116;
  --zt-ink-900: #171b22;
  --zt-ink-800: #252a33;
  --zt-ink-600: #4a5160;
  --zt-ink-500: #5f6673;
  --zt-ink-400: #7d8390;
  --zt-ink-300: #9aa0ab;
  --zt-ink-200: #d9dbdf;
  --zt-ink-100: #eceef0;
  --zt-paper-50: #f6f6f3;
  --zt-white: #ffffff;

  --zt-accent-700: #115e59;
  --zt-accent-600: #0f766e;
  --zt-accent-300: #5eead4;
  --zt-accent-200: #99f6e4;
  --zt-accent-100: #e6f4f1;
  --zt-accent-950: #0b2b2a;

  --zt-success-700: #1e6b3a;
  --zt-warning-700: #8a5a00;
  --zt-error-700: #b42318;

  --zt-amber-100: #fff4d6;
  --zt-amber-800: #5c4300;

  /* Shadow tint as an RGB triplet, so shadows can vary alpha only */
  --zt-shadow-rgb: 14 17 22;

  /* ------------------------------------------------------------------------
     2. Colour — semantic roles (use these in components)
     Ratios: on --color-background / on --color-surface-muted.
     ------------------------------------------------------------------------ */
  --color-background: var(--zt-white);
  --color-surface: var(--zt-white);            /* cards, panels, inputs */
  --color-surface-muted: var(--zt-paper-50);   /* alternating sections */

  --color-text-primary: var(--zt-ink-950);     /* 18.9:1 / 17.5:1 */
  --color-text-secondary: var(--zt-ink-600);   /*  8.0:1 /  7.4:1 */
  --color-text-muted: var(--zt-ink-500);       /*  5.8:1 /  5.3:1 — still AA body text */

  --color-border: var(--zt-ink-200);           /* decorative dividers only */
  --color-border-strong: var(--zt-ink-400);    /* UI boundaries (inputs): 3.8:1 / 3.5:1 */

  --color-accent: var(--zt-accent-600);        /* text & UI: 5.5:1 / 5.1:1 (hand-computed, unverified) */
  --color-accent-hover: var(--zt-accent-700);
  --color-accent-soft: var(--zt-accent-100);   /* tint backgrounds; accent text on it 4.8:1 (hand-computed, unverified) */
  --color-on-accent: var(--zt-white);          /* on accent 5.5:1, on hover 7.6:1 (hand-computed, unverified) */

  --color-success: var(--zt-success-700);      /* 6.5:1 / 6.0:1 */
  --color-warning: var(--zt-warning-700);      /* 5.9:1 / 5.5:1 */
  --color-error: var(--zt-error-700);          /* 6.6:1 / 6.1:1 */

  --color-focus: var(--zt-accent-600);         /* ≥3:1 against both light surfaces */

  --color-link: var(--color-accent);
  --color-link-hover: var(--color-accent-hover);
  --color-selection: var(--zt-accent-100);

  /* Marker for clearly identifiable demo/placeholder content (8.5:1) */
  --color-demo-bg: var(--zt-amber-100);
  --color-demo-text: var(--zt-amber-800);

  /* ------------------------------------------------------------------------
     3. Typography — families
     System stacks only: no web-font requests until typefaces are chosen.
     ------------------------------------------------------------------------ */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-display: var(--font-sans);
  --font-arabic: system-ui, "Segoe UI", "SF Arabic", "Geeza Pro",
    "Noto Sans Arabic", Tahoma, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

  --font-body: var(--font-sans);
  --font-heading: var(--font-display);

  /* ------------------------------------------------------------------------
     4. Typography — primitive scales
     Fluid sizes interpolate between a 360px and a 1440px viewport.
     Every value mixes rem with vw so text still scales with browser zoom.
     ------------------------------------------------------------------------ */
  --text-xs: clamp(0.75rem, 0.7292rem + 0.0926vw, 0.8125rem);  /* 12 → 13px */
  --text-sm: clamp(0.875rem, 0.8542rem + 0.0926vw, 0.9375rem); /* 14 → 15px */
  --text-base: clamp(1rem, 0.9583rem + 0.1852vw, 1.125rem);    /* 16 → 18px */
  --text-lg: clamp(1.125rem, 1.0625rem + 0.2778vw, 1.3125rem); /* 18 → 21px */
  --text-xl: clamp(1.25rem, 1.1667rem + 0.3704vw, 1.5rem);     /* 20 → 24px */
  --text-2xl: clamp(1.5rem, 1.3333rem + 0.7407vw, 2rem);       /* 24 → 32px */
  --text-3xl: clamp(1.875rem, 1.5833rem + 1.2963vw, 2.75rem);  /* 30 → 44px */
  --text-4xl: clamp(2.25rem, 1.75rem + 2.2222vw, 3.75rem);     /* 36 → 60px */
  --text-5xl: clamp(2.75rem, 2rem + 3.3333vw, 5rem);           /* 44 → 80px */

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

  --leading-tight: 1.1;    /* display, h1 */
  --leading-snug: 1.25;    /* h2–h4, eyebrow, button */
  --leading-normal: 1.6;   /* body */
  --leading-relaxed: 1.75; /* long-form reading */

  --tracking-tighter: -0.03em;
  --tracking-tight: -0.02em;
  --tracking-snug: -0.01em;
  --tracking-normal: 0;
  --tracking-wide: 0.08em;

  --measure: 68ch;        /* comfortable line length for body copy */

  /* ------------------------------------------------------------------------
     5. Typography — roles (use these in components)
     Each role: family, size, weight, leading (line-height), tracking.
     Visual role is independent of HTML heading level: an <h2> may use the
     h1 role when the design needs it, keeping the outline correct for SEO.
     ------------------------------------------------------------------------ */
  --type-display-family: var(--font-heading);
  --type-display-size: var(--text-5xl);
  --type-display-weight: var(--font-weight-semibold);
  --type-display-leading: var(--leading-tight);
  --type-display-tracking: var(--tracking-tighter);

  --type-h1-family: var(--font-heading);
  --type-h1-size: var(--text-4xl);
  --type-h1-weight: var(--font-weight-semibold);
  --type-h1-leading: var(--leading-tight);
  --type-h1-tracking: var(--tracking-tight);

  --type-h2-family: var(--font-heading);
  --type-h2-size: var(--text-3xl);
  --type-h2-weight: var(--font-weight-semibold);
  --type-h2-leading: var(--leading-snug);
  --type-h2-tracking: var(--tracking-tight);

  --type-h3-family: var(--font-heading);
  --type-h3-size: var(--text-2xl);
  --type-h3-weight: var(--font-weight-semibold);
  --type-h3-leading: var(--leading-snug);
  --type-h3-tracking: var(--tracking-snug);

  --type-h4-family: var(--font-heading);
  --type-h4-size: var(--text-xl);
  --type-h4-weight: var(--font-weight-semibold);
  --type-h4-leading: var(--leading-snug);
  --type-h4-tracking: var(--tracking-snug);

  --type-body-large-family: var(--font-body);
  --type-body-large-size: var(--text-lg);
  --type-body-large-weight: var(--font-weight-regular);
  --type-body-large-leading: var(--leading-normal);
  --type-body-large-tracking: var(--tracking-normal);

  --type-body-family: var(--font-body);
  --type-body-size: var(--text-base);
  --type-body-weight: var(--font-weight-regular);
  --type-body-leading: var(--leading-normal);
  --type-body-tracking: var(--tracking-normal);

  --type-body-small-family: var(--font-body);
  --type-body-small-size: var(--text-sm);
  --type-body-small-weight: var(--font-weight-regular);
  --type-body-small-leading: var(--leading-normal);
  --type-body-small-tracking: var(--tracking-normal);

  --type-caption-family: var(--font-body);
  --type-caption-size: var(--text-xs);
  --type-caption-weight: var(--font-weight-regular);
  --type-caption-leading: var(--leading-normal);
  --type-caption-tracking: var(--tracking-normal);

  --type-eyebrow-family: var(--font-body);
  --type-eyebrow-size: var(--text-xs);
  --type-eyebrow-weight: var(--font-weight-semibold);
  --type-eyebrow-leading: var(--leading-snug);
  --type-eyebrow-tracking: var(--tracking-wide);
  --type-eyebrow-transform: uppercase;

  --type-button-family: var(--font-body);
  --type-button-size: var(--text-sm);
  --type-button-weight: var(--font-weight-semibold);
  --type-button-leading: var(--leading-snug);
  --type-button-tracking: var(--tracking-normal);

  /* ------------------------------------------------------------------------
     6. Spacing (4px base, rem-based)
     4 → 8 → 12 → 16, then each step grows by ~1.5×. Small steps for
     component internals, large steps for layout.
     ------------------------------------------------------------------------ */
  --space-0: 0;
  --space-1: 0.25rem;  /*   4px */
  --space-2: 0.5rem;   /*   8px */
  --space-3: 0.75rem;  /*  12px */
  --space-4: 1rem;     /*  16px */
  --space-5: 1.5rem;   /*  24px */
  --space-6: 2rem;     /*  32px */
  --space-7: 3rem;     /*  48px */
  --space-8: 4rem;     /*  64px */
  --space-9: 6rem;     /*  96px */
  --space-10: 8rem;    /* 128px */

  /* Fluid layout spacing (360px → 1440px viewport) */
  --space-section: clamp(4rem, 2.6667rem + 5.9259vw, 8rem);      /* 64 → 128px */
  --space-section-sm: clamp(3rem, 2.3333rem + 2.963vw, 5rem);    /* 48 →  80px */
  --space-gutter: clamp(1rem, 0.6667rem + 1.4815vw, 2rem);       /* 16 →  32px */

  /* ------------------------------------------------------------------------
     7. Containers
     ------------------------------------------------------------------------ */
  --container-narrow: 46rem;  /*  736px — articles, forms */
  --container-default: 76rem; /* 1216px — standard sections */
  --container-wide: 90rem;    /* 1440px — wide editorial compositions */
  --container-gutter: var(--space-gutter); /* minimum space at each inline edge */

  /* ------------------------------------------------------------------------
     8. Breakpoints — reference only; use literal values in @media.
     Mobile is the base (no query). Layouts add complexity with min-width:
       md  48em  (768px)   tablet
       lg  64em  (1024px)  desktop
       xl  80em  (1280px)  large desktop
     Prefer intrinsic layouts (fluid tokens, auto-fit grids) before adding
     a breakpoint.
     ------------------------------------------------------------------------ */

  /* ------------------------------------------------------------------------
     9. Radius (restrained)
     ------------------------------------------------------------------------ */
  --radius-none: 0;
  --radius-sm: 0.25rem;  /*  4px — tags, small controls */
  --radius-md: 0.5rem;   /*  8px — buttons, inputs */
  --radius-lg: 1rem;     /* 16px — cards, panels, media */
  --radius-pill: 999px;

  /* ------------------------------------------------------------------------
     10. Borders and focus
     ------------------------------------------------------------------------ */
  --border-width: 1px;
  --border-width-strong: 2px;

  --focus-ring-width: 3px;
  --focus-ring-offset: 2px;
  --focus-ring: var(--focus-ring-width) solid var(--color-focus);

  /* ------------------------------------------------------------------------
     11. Shadows — restrained; two layers (contact + ambient) read as
     natural depth. Prefer borders; use shadows to signal elevation.
     ------------------------------------------------------------------------ */
  --shadow-none: none;
  --shadow-sm: 0 1px 2px rgb(var(--zt-shadow-rgb) / 0.06);
  --shadow-md: 0 1px 2px rgb(var(--zt-shadow-rgb) / 0.04),
    0 4px 12px rgb(var(--zt-shadow-rgb) / 0.06);
  --shadow-lg: 0 2px 4px rgb(var(--zt-shadow-rgb) / 0.04),
    0 16px 40px rgb(var(--zt-shadow-rgb) / 0.1);

  /* ------------------------------------------------------------------------
     12. Motion
     ------------------------------------------------------------------------ */
  --duration-instant: 0ms;
  --duration-fast: 150ms;  /* hover, colour changes */
  --duration-base: 250ms;  /* small movements, reveals */
  --duration-slow: 400ms;  /* larger panels (e.g. mobile menu) */

  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);  /* entering */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);   /* leaving */

  /* Ready-made transition list for interactive colour changes */
  --transition-hover: color var(--duration-fast) var(--ease-standard),
    background-color var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard),
    text-decoration-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);

  /* ------------------------------------------------------------------------
     13. Layering
     ------------------------------------------------------------------------ */
  --z-base: 0;
  --z-raised: 10;
  --z-sticky: 100;
  --z-overlay: 200;
  --z-modal: 300;
  --z-toast: 400;

  /* ------------------------------------------------------------------------
     14. Component tokens (initial set; components are built after Phase 1)
     ------------------------------------------------------------------------ */
  --button-padding-block: var(--space-3);
  --button-padding-inline: var(--space-5);
  --button-radius: var(--radius-md);

  --card-padding: var(--space-6);
  --card-radius: var(--radius-lg);
  --card-border: var(--border-width) solid var(--color-border);

  --input-padding-block: var(--space-3);
  --input-padding-inline: var(--space-4);
  --input-radius: var(--radius-md);
  --input-border: var(--border-width) solid var(--color-border-strong);

  --header-height: 4.5rem;
  --tap-target-min: 2.75rem; /* 44px — comfortable touch target */
}

/* --------------------------------------------------------------------------
   Arabic: dedicated font stack, roomier line-height, no letter-spacing
   (tracking breaks Arabic letter joining) and no uppercase (Arabic has no
   case). Direction itself comes from <html lang="ar" dir="rtl">, not CSS.
   Role tokens resolve on :root, so overriding primitives here is enough.
   -------------------------------------------------------------------------- */
:root:lang(ar) {
  --font-body: var(--font-arabic);
  --font-heading: var(--font-arabic);

  --leading-tight: 1.35;
  --leading-snug: 1.5;
  --leading-normal: 1.85;
  --leading-relaxed: 1.95;

  --tracking-tighter: 0;
  --tracking-tight: 0;
  --tracking-snug: 0;
  --tracking-wide: 0;

  /* Arabic glyphs read smaller than Latin at the same size; the smallest
     step (12–13px) becomes hard to read, so small roles move up one step. */
  --type-eyebrow-size: var(--text-sm);
  --type-eyebrow-transform: none;
  --type-caption-size: var(--text-sm);
}

/* --------------------------------------------------------------------------
   Reduced motion: collapse durations so transitions become effectively
   instant. 0.01ms (not 0) keeps transitionend/animationend events firing
   for any script that waits on them.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0.01ms;
    --duration-base: 0.01ms;
    --duration-slow: 0.01ms;
  }
}
