/* =========================================================
   ControlIO — Canonical Design Tokens
   Handle: wb-tokens · owned by wb-ui-kit · Step 3 Pass A

   THIS IS THE SINGLE SOURCE OF TRUTH for colour, spacing,
   typography, radii, elevation, motion, layering and layout.

   Rules:
   - Nothing else may declare a :root{} block of design tokens.
     Component CSS consumes var(--x); it does not define it.
   - Every consumer stylesheet must declare 'wb-tokens' in its
     wp_enqueue_style() $deps so load order is contractual
     rather than accidental. A missing token must be a visible
     bug, not a silent fallback.
   - Day-themes deliberately override the SEMANTIC layer below
     (--surface, --accent, --on-accent, --border, --shadow).
     Runtime re-skinning is a supported requirement, so those
     names must stay overridable and must not be inlined.

   Values moved verbatim from the theme's assets/css/layout/
   default.css so this introduces no visual change. Tokens
   marked NEW did not previously exist.
   ========================================================= */

:root{
  /* ---------------------------------------------------------
     1. PRIMITIVES — raw values. Not for direct use in
     components; reference the semantic layer instead.
     --------------------------------------------------------- */

  /* ----- Brand core ----- */
  --brand-burnt: #E17A30;   /* primary accent */
  --brand-tan:   #FBE4C2;   /* soft support */
  --brand-brown: #3D2B1F;   /* deep contrast */

  /* ----- Responsive contract (reference only) -----
     Documentation of the contract in docs/RESPONSIVE_CONTRACT.md.
     These CANNOT be used in @media conditions — custom properties
     are not valid there and there is no preprocessor. The contract
     is enforced by ops/ci/validate-breakpoints.sh instead. Kept
     because they are still useful in calc() and container queries. */
  --bp-xs-max: 479px;
  --bp-sm-min: 480px;
  --bp-sm-max: 767px;
  --bp-md-min: 768px;
  --bp-md-max: 1023px;
  --bp-lg-min: 1024px;
  --bp-lg-max: 1279px;
  --bp-xl-min: 1280px;
  --bp-xl-max: 1599px;
  --bp-xxl-min: 1600px;
  --bp-xxl-max: 1919px;
  --bp-ultra-min: 1920px;
  --bp-nav-max: 1200px;

  /* ----- Typography ----- */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", Arial, sans-serif;
  --font-display: var(--font-body);
  --font-ui: var(--font-body);
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 32px;
  --text-3xl: 40px;
  --leading-tight: 1.2;
  --leading-snug: 1.35;
  --leading-base: 1.5;
  --leading-loose: 1.7;

  /* ----- Spacing — 4px base, 8px rhythm ----- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* ----- Shape ----- */
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 18px;
  --radius-2xl: 20px;
  --radius-pill: 999px;
  --radius: var(--radius-lg);

  /* ----- Elevation ----- */
  --shadow-xs: 0 1px 2px rgba(14, 20, 28, .06);
  --shadow-sm: 0 10px 24px rgba(14, 20, 28, .06);
  --shadow-md: 0 14px 34px rgba(14, 20, 28, .08);
  --shadow-lg: 0 20px 48px rgba(14, 20, 28, .12);
  --shadow-xl: 0 28px 64px rgba(14, 20, 28, .16);
  --shadow: var(--shadow-md);

  /* NEW — semantic elevation roles (brief 3.45). Aliases over the
     scale above so hierarchy is expressed by intent, not by size. */
  --elevation-flat: none;
  --elevation-raised: var(--shadow-sm);
  --elevation-overlay: var(--shadow-lg);

  /* ---------------------------------------------------------
     2. MOTION — NEW (brief 3.42–3.44).
     The audit found 18 distinct transition durations and 32
     animation durations, all ad hoc. Components must use these.
     --------------------------------------------------------- */
  --duration-fast:   120ms;  /* state feedback: hover, focus, press */
  --duration-normal: 200ms;  /* reveal/conceal: dropdown, toast */
  --duration-slow:   320ms;  /* travel: drawer, sheet, modal */

  --ease-standard: cubic-bezier(.2, 0, 0, 1);   /* default */
  --ease-out:      cubic-bezier(0, 0, 0, 1);    /* entering */
  --ease-in:       cubic-bezier(.3, 0, 1, 1);   /* leaving */

  /* ---------------------------------------------------------
     3. INTERACTION SIZING — NEW (brief 3.13).
     44px is the minimum comfortable touch target.
     --------------------------------------------------------- */
  --touch-target-min: 44px;
  --control-height-sm: 36px;
  --control-height-md: 44px;
  --control-height-lg: 52px;

  /* ---------------------------------------------------------
     4. SEMANTIC LAYER — what components actually consume.
     Day-themes override these; keep them overridable.
     --------------------------------------------------------- */

  /* ----- Base UI ----- */
  --bg:    #FAF3EA;  /* page background */
  --text:  #2B2B2B;  /* primary text */
  --muted: #6B6B6B;  /* secondary text */

  /* ----- Accent system (derived from Desert Dingo) ----- */
  --accent:   var(--brand-burnt); /* #E17A30 */
  /* 60/40, not 70/30. --accent-2 is the LIGHT stop of every accent gradient that
     carries --on-accent (white) text — the search and filter CTAs, the header
     bar, plugin-compat's buttons — and the gradient's worst stop governs. At
     70/30 it computes #b0622b, which is 4.54:1 behind white: AA by 0.04, with
     no margin for a day-theme shifting --brand-burnt. 60/40 gives #9f5a29 at
     5.29:1. Where --accent-2 is instead mixed toward --text as a foreground,
     darkening only raises contrast, so both roles improve. */
  --accent-2: color-mix(in srgb, var(--brand-burnt) 60%, var(--brand-brown) 40%);
  --accent-3: color-mix(in srgb, var(--brand-burnt) 55%, var(--brand-brown) 45%); /* hover/active */
  --on-accent: #ffffff;

  /* Accessible accent, for anything involving TEXT.
   *
   * The brand hue is too light to carry text at WCAG AA:
   *   white on #E17A30 ............ 2.99:1  (needs 4.5)
   *   #E17A30 text on --bg ........ 2.71:1  (needs 4.5)
   * Both already failed before Step 3 — this is a pre-existing defect, not one
   * introduced by the primitives.
   *
   * Rather than change the brand colour, --accent stays exactly as it is for
   * decorative use (focus rings, borders, dividers, large non-text marks) and
   * this darker sibling is used wherever text is involved: primary button
   * fills, accent-coloured link and label text, badges.
   *
   * Derived with color-mix rather than hard-coded so that day-themes, which
   * override --accent, get a correctly darkened variant for free.
   * 74% is the minimum darkening at which BOTH uses reach 4.5:1
   * (#A65A24 → 5.11:1 behind white, 4.64:1 as text on --bg).
   */
  --accent-strong: color-mix(in srgb, var(--accent) 74%, #000 26%);

  /* ----- Surfaces & borders ----- */
  --surface:   #ffffff;
  --surface-2: #fafafa;
  --surface-3: color-mix(in srgb, var(--surface) 84%, var(--bg) 16%);
  --surface-muted: color-mix(in srgb, var(--surface) 92%, var(--bg) 8%);
  --border:    color-mix(in srgb, var(--text) 14%, var(--bg) 86%); /* subtle hairline */
  --border-strong: color-mix(in srgb, var(--text) 18%, var(--bg) 82%);
  --border-soft: color-mix(in srgb, var(--text) 8%, var(--bg) 92%);

  /* ----- Focus — NEW (brief 3.63) -----
     One visible focus treatment for every interactive element.
     Deliberately built on --accent so it re-skins with day-themes. */
  --focus-color: var(--accent);
  --focus-width: 3px;
  --focus-offset: 2px;
  --focus-ring: 0 0 0 var(--focus-width) color-mix(in srgb, var(--focus-color) 45%, transparent);

  /* ----- Status ----- */
  --status-success: #0a7f2e;   /* white-on 5.14:1 · as-text-on-bg 4.67:1 */
  /* Was #b36b00, which measured 4.18:1 behind white and 3.80:1 as text — both
     below WCAG AA. Darkened by the minimum needed to clear 4.5:1 on both, so the
     amber character is kept. */
  --status-warning: #a16000;   /* white-on 5.01:1 · as-text-on-bg 4.55:1 */
  --status-error: #b00020;     /* white-on 7.33:1 · as-text-on-bg 6.65:1 */
  --status-info: #5b5b00;      /* white-on 7.14:1 · as-text-on-bg 6.48:1 */

  /* ---------------------------------------------------------
     5. LAYOUT
     --------------------------------------------------------- */
  --container-narrow: min(100%, 48rem);
  --container-reading: min(100%, 72rem);
  --container-content: min(100%, 90rem);
  --container-wide: min(100%, 110rem);
  --container: clamp(18rem, 92vw, 108rem);
  --content-gutter: clamp(var(--space-3), 2vw, var(--space-5));
  --section-gap: clamp(var(--space-5), 3vw, var(--space-7));
  --drawer-max: 28rem;
  --drawer-max-wide: 30rem;
  --drawer-max-ultra: 32rem;
  --cols-desktop: 4;

  /* ---------------------------------------------------------
     6. LAYERING — one z-index contract (brief 3.62).
     The audit found 25 distinct raw z-index values, max 99999.
     Nothing may invent a value outside this scale.
     --------------------------------------------------------- */
  --z-base: 1;
  --z-sticky: 40;
  --z-header: 70;
  --z-dropdown: 75;        /* NEW — above the header it anchors to */
  --z-store-notice: 80;
  --z-overlay: 90;
  --z-drawer: 100;
  --z-modal: 200;
  --z-toast: 300;          /* NEW — confirmations must clear a modal */

  /* ---------------------------------------------------------
     7. COMPONENT TOKENS
     --------------------------------------------------------- */
  --surface-elevated: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface) 96%, var(--bg) 4%),
    color-mix(in srgb, var(--surface) 88%, var(--bg) 12%)
  );
  --surface-warm: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 8%, var(--surface) 92%),
    color-mix(in srgb, var(--brand-tan) 18%, var(--surface) 82%)
  );
  /* Panel surfaces shared by cart, checkout and account pages. Moved here from
     the theme's plugin-compat.css, which was the only loaded definer — surfaces.css
     declared a competing set but was never enqueued. Every value derives from the
     semantic tokens above, so day-themes re-skin these without touching them. */
  --wb-ui-surface-radius: var(--radius-xl, 18px);
  --wb-ui-surface-radius-sm: var(--radius-lg, 16px);
  --wb-ui-surface-padding: clamp(var(--space-4, 16px), 2vw, var(--space-5, 24px));
  --wb-ui-surface-shadow: var(--shadow-sm, 0 10px 24px rgba(14, 20, 28, .06));
  --wb-ui-surface-border: var(--border-strong, var(--border));
  --wb-ui-surface-bg: var(--surface-elevated, var(--surface));
  --wb-ui-surface-bg-soft: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface) 98%, var(--bg) 2%),
    color-mix(in srgb, var(--surface) 91%, var(--bg) 9%)
  );

  --card-bg: var(--surface);
  --card-border: var(--border);
  --card-shadow: var(--shadow);
  --card-media-bg: var(--surface-2);
  --card-body-bg: var(--card-bg);

  --badge-bg: var(--accent-strong);  /* carries text — see --accent-strong */
  --badge-text: var(--on-accent);

  --chip-bg: color-mix(in srgb, var(--text) 6%, transparent);
  --chip-in-bg: #f0fff5;
  --chip-out-bg: #fff5f5;

  --search-bg: var(--surface);
  --search-border: color-mix(in srgb, var(--text) 12%, transparent);
  --search-panel-bg: var(--surface);
  --search-shadow: 0 8px 24px rgba(0,0,0,.12);
  --search-thumb-bg: var(--surface-2);
  --search-stock-in-bg: var(--chip-in-bg);
  --search-stock-out-bg: var(--chip-out-bg);

  --toast-bg: #111111;
  --toast-text: #ffffff;
  --toast-muted: rgba(255,255,255,.7);
  --toast-action-bg: rgba(255,255,255,.14);
  --toast-action-bg-hover: rgba(255,255,255,.22);
  --toast-close-bg: rgba(255,255,255,.12);

  --filter-bg: var(--surface);
  --filter-border: color-mix(in srgb, var(--text) 10%, transparent);
  --filter-text: var(--text);

  --overlay-bg: rgba(0,0,0,.35);

  --backorder-border: var(--accent);
  --backorder-bg: color-mix(in oklab, var(--accent) 8%, var(--surface) 92%);
  --backorder-ack: #2e7d32;
  --backorder-ack-bg: color-mix(in oklab, var(--backorder-ack) 8%, var(--surface) 92%);
  --backorder-text: var(--on-accent);
}

/* ---------------------------------------------------------
   Dark mode overrides (applies when <html class="dark">)
   Only the semantic layer changes. Primitives do not.
   --------------------------------------------------------- */
html.dark{
  --bg:    #111111;
  --text:  #F2F2F2;
  --muted: #BDBDBD;

  /* Slightly deepen in dark for contrast */
  --accent:   color-mix(in srgb, var(--brand-burnt) 80%, #000 20%);
  --accent-2: color-mix(in srgb, var(--brand-brown) 60%, var(--brand-burnt) 40%);
  --on-accent: #ffffff;

  /* Surfaces & borders tuned for dark */
  --surface:   #151515;
  --surface-2: #1b1b1b;
  --surface-3: #202020;
  --surface-muted: color-mix(in srgb, var(--surface) 85%, var(--bg) 15%);
  --border:    color-mix(in srgb, var(--bg) 70%, #000 30%);
  --border-strong: color-mix(in srgb, var(--text) 18%, var(--bg) 82%);
  --border-soft: color-mix(in srgb, var(--text) 10%, var(--bg) 90%);
  --surface-elevated: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface) 96%, #fff 4%),
    color-mix(in srgb, var(--surface-2) 92%, #fff 8%)
  );
  --surface-warm: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 10%, var(--surface) 90%),
    color-mix(in srgb, var(--surface-2) 86%, var(--brand-brown) 14%)
  );

  --chip-bg: color-mix(in srgb, var(--text) 10%, transparent);
  --toast-bg: #0b0f16;
  --toast-text: #e9f5ff;
  --toast-muted: rgba(233,245,255,.7);
}

/* ---------------------------------------------------------
   Reduced motion (brief 3.44).
   Neutralise the duration tokens at the source, so every
   component that uses them honours the preference without
   needing its own media query.
   --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce){
  :root{
    --duration-fast:   1ms;
    --duration-normal: 1ms;
    --duration-slow:   1ms;
  }
}
