/* ==========================================================================
   Al Omran CRM — Design Tokens
   The single source of truth for colour, typography, spacing, geometry,
   elevation, materials, control sizing and motion.

   Loads FIRST, before every theme and component layer.

   ARCHITECTURE
   ------------
   Two tiers, and the distinction matters:

     1. PRIMITIVES  (--lapis-700, --gold-500, --neutral-400 …)
        Raw brand and neutral ramps. Never referenced by component CSS.

     2. SEMANTICS   (--surface-raised, --label-secondary, --accent …)
        Named by role. Component CSS references ONLY these.

   Because components speak semantics, a dark theme is later added by
   redefining the semantic block alone — no component file is touched.
   Dark mode is deliberately NOT implemented in this phase; the structure
   below is what keeps that a small change rather than a rewrite.

   RULES FOR CONTRIBUTORS
   ----------------------
   - Never write a raw hex in a component file. Add a semantic token here.
   - Never reference a primitive from a component file. Go through a semantic.
   - Font sizes below --fs-micro (11px) need an explicit, documented reason.
   - Elevation is a 5-step scale. If a shadow isn't on it, it's a mistake.
   ========================================================================== */

:root{

  /* ======================================================================
     TIER 1 — PRIMITIVES
     ====================================================================== */

  /* ---- Lapis (brand navy) -------------------------------------------
     Sampled from the Al Omran mark: faceted lapis lazuli with gold veining.
     900 is the mark's deepest field; 500 is the mid-tone used for links
     and secondary brand moments. Contrast on white noted per step. */
  --lapis-900:#071027;   /* 19.6:1  deepest field, inverse surfaces        */
  --lapis-800:#0A1330;   /* 18.3:1  brand primary — matches app_settings   */
  --lapis-700:#16295E;   /* 13.9:1  raised inverse surface                 */
  --lapis-600:#1F3A6B;   /* 10.7:1                                         */
  --lapis-500:#274C77;   /*  8.8:1  brand secondary                        */
  --lapis-400:#4F78A8;   /*  4.3:1  large text / borders only              */
  --lapis-300:#8FB0D4;   /*         decorative on navy                     */
  --lapis-200:#C4D6EA;   /*         borders on light                       */
  --lapis-100:#EEF3FA;   /*         brand wash                             */
  --lapis-050:#F5F8FC;   /*         faintest brand tint                    */

  /* ---- Gold (brand accent) ------------------------------------------
     The mark's gold is a LINE colour, never a mass. On light surfaces it
     fails contrast as text (#C9A24A = 2.4:1), so the ramp darkens for
     text use. 500 is the true brand gold — borders, rules, on-navy. */
  --gold-800:#765C12;    /*  6.3:1  gold text on light                     */
  --gold-700:#8A6D19;    /*  4.9:1  gold text on light, lighter option     */
  --gold-600:#A88433;    /*         hover / pressed on light               */
  --gold-500:#C9A24A;    /*  7.6:1 on lapis-800 — THE brand gold           */
  --gold-400:#D9B65C;    /*         on-navy hover                          */
  --gold-300:#E8CE84;    /* 11.8:1 on lapis-800 — gold text on navy        */
  --gold-200:#F0DCA2;    /*         specular highlight                     */
  --gold-100:#F6EBC2;    /*         gold border on light                   */
  --gold-050:#FBF7E9;    /*         gold wash                              */

  /* ---- Neutrals -------------------------------------------------------
     Cooled toward lapis rather than pure grey, so neutrals sit with the
     brand instead of fighting it. Contrast on white noted. */
  --neutral-900:#101828;  /* 17.4:1  primary label                         */
  --neutral-800:#1D2939;  /* 14.4:1                                        */
  --neutral-700:#344054;  /* 10.5:1  strong label                          */
  --neutral-600:#475467;  /*  7.7:1  secondary label                       */
  --neutral-500:#667085;  /*  5.0:1  tertiary label — AA floor for body    */
  --neutral-400:#8A93A8;  /*  3.1:1  decorative / large text only          */
  --neutral-350:#CBD3E1;  /*         emphasis separator                    */
  --neutral-300:#D8E1EB;  /*         strong separator — the value the      */
                          /*         codebase actually reaches for         */
  --neutral-200:#E1E7EF;  /*         default separator                     */
  --neutral-100:#EEF2F6;  /*         subtle separator                      */
  --neutral-050:#F8FAFC;  /*         sunken surface                        */
  --white:#FFFFFF;

  /* ---- Status ---------------------------------------------------------
     Each has a text-safe value, a wash, and a border. */
  --success-700:#087443;  --success-100:#ECFDF3;  --success-200:#A6E6C5;
  --warning-700:#9A6700;  --warning-100:#FFF7E8;  --warning-200:#F5DBA5;
  --danger-700:#B42318;   --danger-100:#FEF3F2;   --danger-200:#FECDCA;
  --info-700:#175CD3;     --info-100:#EFF8FF;     --info-200:#B2DDFF;
  --warning-500:#F79009;  /* dot / indicator fill — not text on light      */
  --teal-700:#0F766E;     /*  5.0:1  notes & knowledge-base accent         */
  --teal-100:#EEF6F5;

  /* ---- Brand service colours (never re-themed) ------------------------ */
  --whatsapp-600:#087443;
  --whatsapp-050:#F0FAF5;
  --whatsapp-200:#CDEBDD;


  /* ======================================================================
     TIER 2 — SEMANTICS   ← component CSS references only these
     ====================================================================== */

  /* ---- Surfaces -------------------------------------------------------
     Three conceptual planes, plus a sunken well and an inverse family.
     Borders separate; shadows are reserved for genuine elevation. */
  --surface-canvas:#F3F6FA;         /* the page itself                     */
  --surface-raised:var(--white);    /* cards, tables, panels               */
  --surface-overlay:var(--white);   /* modals, popovers, menus             */
  --surface-sunken:var(--neutral-050); /* inputs, wells, table headers     */
  --surface-inverse:var(--lapis-800);  /* sidebar, hero blocks             */
  --surface-inverse-raised:var(--lapis-700);
  --surface-accent-wash:var(--lapis-100);
  --surface-gold-wash:var(--gold-050);

  /* ---- Labels ---------------------------------------------------------
     Every step meets AA on --surface-raised except -quaternary, which is
     decorative only and must never carry meaning on its own. */
  --label-primary:var(--neutral-900);
  --label-secondary:var(--neutral-600);
  --label-tertiary:var(--neutral-500);
  --label-quaternary:var(--neutral-400);
  --label-inverse:var(--white);
  --label-inverse-secondary:#AEBBD0;
  --label-accent:var(--lapis-500);
  --label-gold:var(--gold-800);
  --label-on-gold:var(--lapis-900);

  /* ---- Separators & borders ------------------------------------------- */
  --separator-subtle:var(--neutral-100);
  --separator:var(--neutral-200);
  --separator-strong:var(--neutral-300);
  --separator-inverse:rgba(232,206,132,.16);
  --border-width:1px;

  /* ---- Fills (interactive backgrounds) -------------------------------- */
  --fill-subtle:var(--neutral-050);
  --fill-hover:var(--neutral-100);
  --fill-pressed:var(--neutral-200);
  --fill-inverse-hover:rgba(255,255,255,.07);
  --fill-inverse-pressed:rgba(255,255,255,.12);

  /* ---- Accent ---------------------------------------------------------
     Lapis is the primary action colour; gold is the ACCENT — active states,
     focus, rules and marks of distinction. Gold is never a button fill on
     a light surface: it fails contrast and cheapens the mark. */
  --accent:var(--lapis-800);
  --accent-hover:var(--lapis-700);
  --accent-pressed:var(--lapis-900);
  --accent-wash:var(--lapis-100);
  --accent-border:var(--lapis-200);
  --accent-label:var(--lapis-500);

  --gold:var(--gold-500);            /* rules, active indicators, on-navy  */
  --gold-hover:var(--gold-400);
  --gold-text:var(--gold-800);       /* the only gold safe as light text   */
  --gold-on-inverse:var(--gold-300);
  --gold-border:var(--gold-100);
  --gold-wash:var(--gold-050);

  /* ---- Status (semantic) ---------------------------------------------- */
  --status-success:var(--success-700);  --status-success-wash:var(--success-100);  --status-success-border:var(--success-200);
  --status-warning:var(--warning-700);  --status-warning-wash:var(--warning-100);  --status-warning-border:var(--warning-200);
  --status-danger:var(--danger-700);    --status-danger-wash:var(--danger-100);    --status-danger-border:var(--danger-200);
  --status-info:var(--info-700);        --status-info-wash:var(--info-100);        --status-info-border:var(--info-200);


  /* ======================================================================
     ELEVATION — 5 steps, no more
     Replaces 165 ad-hoc shadows. Depth is communicated by material and
     hairline first; shadow only for things that genuinely float.
     ====================================================================== */
  --elevation-0:none;
  --elevation-1:0 1px 2px rgba(10,19,48,.05);                              /* resting card   */
  --elevation-2:0 1px 3px rgba(10,19,48,.06),0 6px 16px rgba(10,19,48,.05);/* raised card    */
  --elevation-3:0 2px 6px rgba(10,19,48,.07),0 12px 28px rgba(10,19,48,.09);/* popover/menu  */
  --elevation-4:0 4px 12px rgba(10,19,48,.10),0 24px 56px rgba(10,19,48,.16);/* modal        */
  --elevation-inset:inset 0 1px 2px rgba(10,19,48,.06);

  /* Inverse elevation — shadows on navy need more opacity to register. */
  --elevation-inverse-2:0 2px 8px rgba(2,8,23,.28);
  --elevation-inverse-3:0 12px 32px rgba(2,8,23,.34);


  /* ======================================================================
     MATERIALS — translucent chrome (Phase B)
     Chrome floats above content; content scrolls beneath it.
     ====================================================================== */
  --material-blur:20px;
  --material-saturate:180%;
  --material-light:rgba(255,255,255,.72);
  --material-light-thick:rgba(255,255,255,.86);
  --material-inverse:rgba(10,19,48,.72);
  --material-rim:inset 0 1px 0 rgba(255,255,255,.5);
  --scrim:rgba(7,16,39,.52);


  /* ======================================================================
     GEOMETRY — radius
     Replaces 37 near-identical values (7,8,9,10,11,12,13,14,15px).
     ====================================================================== */
  --radius-xs:6px;      /* chips, tiny controls          */
  --radius-sm:8px;      /* buttons, inputs, icon buttons */
  --radius-md:12px;     /* cards, panels                 */
  --radius-lg:16px;     /* modals, large surfaces        */
  --radius-xl:20px;     /* hero blocks                   */
  --radius-pill:999px;  /* badges, capsules              */
  --radius-circle:50%;


  /* ======================================================================
     TYPOGRAPHY
     ====================================================================== */
  --font-sans:"Segoe UI Variable Text","Segoe UI","Noto Sans Arabic",Tahoma,Arial,sans-serif;
  --font-mono:"Cascadia Mono",Consolas,"Courier New",monospace;

  /* Eight intentional steps. --fs-micro is the floor for readable text. */
  --fs-micro:11px;        /* badges, timestamps, dense meta   */
  --fs-caption:12px;      /* secondary copy, labels, hints    */
  --fs-data:13px;         /* table cells, dense body, buttons */
  --fs-body:14px;         /* primary body copy                */
  --fs-subsection:15px;   /* card headings                    */
  --fs-section:16px;      /* section headings                 */
  --fs-title:20px;        /* page title                       */
  --fs-display:22px;      /* hero / feature title             */

  /* Optical tracking — tightens as size grows, mimicking a variable face. */
  --tracking-tight:-.022em;   /* display                      */
  --tracking-snug:-.015em;    /* titles                       */
  --tracking-normal:-.006em;  /* body                         */
  --tracking-wide:.06em;      /* uppercase micro-labels       */

  --lh-tight:1.25;
  --lh-snug:1.45;
  --lh-body:1.6;
  --lh-relaxed:1.75;

  /* Real weights only. Synthetic values (750, 850…) render unpredictably
     across the Latin and Arabic faces and are not used. */
  --fw-regular:400;
  --fw-medium:500;
  --fw-semibold:600;
  --fw-bold:700;


  /* ======================================================================
     SPACING — 4px grid
     ====================================================================== */
  --space-1:4px;
  --space-2:8px;
  --space-3:12px;
  --space-4:16px;
  --space-5:20px;
  --space-6:24px;
  --space-8:32px;
  --space-10:40px;
  --space-12:48px;


  /* ======================================================================
     ICONS & CONTROLS
     ====================================================================== */
  --icon-sm:16px;   /* inline with caption text, sub-navigation */
  --icon-md:18px;   /* default control icon                    */
  --icon-lg:20px;   /* primary navigation, section headers     */
  --icon-xl:24px;   /* empty states, feature marks             */

  --control-height-sm:32px;
  --control-height:38px;
  --control-height-lg:44px;
  --input-height:40px;
  --input-height-lg:44px;
  --icon-button-size:36px;
  --touch-target:44px;   /* WCAG 2.5.8 on coarse pointers */


  /* ======================================================================
     FOCUS — one visible ring everywhere
     Gold reads as "the system is listening", and carries 7.6:1 on navy
     plus a visible edge on light. Never removed without a replacement.
     ====================================================================== */
  --focus-ring-width:3px;
  --focus-ring-color:rgba(201,162,74,.55);
  --focus-ring-offset:2px;
  --focus-ring-shadow:0 0 0 3px rgba(39,76,119,.16);


  /* ======================================================================
     MOTION — fast / normal / slow
     Animate opacity and transform only. No bounce, no spin.
     ====================================================================== */
  --motion-fast:120ms;
  --motion-normal:180ms;
  --motion-slow:240ms;
  --ease-standard:cubic-bezier(.2,.8,.2,1);
  --ease-exit:cubic-bezier(.4,0,1,1);


  /* ======================================================================
     LAYOUT
     ====================================================================== */
  --sidebar-width:268px;
  --topbar-height:64px;
  --content-max:1720px;


  /* ======================================================================
     LEGACY ALIASES
     Names the V2.x layers still reference. They now resolve from the
     semantic tier, so the old cascade inherits the new system for free.
     Do not add new ones; migrate callers to semantics instead.
     ====================================================================== */
  --surface-page:var(--surface-canvas);
  --surface-panel:var(--surface-raised);
  --surface:var(--surface-raised);
  --surface-2:var(--surface-sunken);
  --bg:var(--surface-canvas);
  --text:var(--label-primary);
  --ink:var(--label-primary);
  --muted:var(--label-tertiary);
  --line:var(--separator);
  --line-strong:var(--separator-strong);

  --elevation-none:var(--elevation-0);
  --elevation-subtle:var(--elevation-1);
  --elevation-raised:var(--elevation-2);
  --elevation-overlay:var(--elevation-3);
  --shadow-sm:var(--elevation-1);
  --shadow:var(--elevation-3);

  --border-subtle:var(--separator-subtle);
  --border-default:var(--separator);
  --border-strong:var(--separator-strong);

  --success:var(--status-success);
  --warning:var(--status-warning);
  --danger:var(--status-danger);
  --info:var(--status-info);

  --gold-bright:var(--gold-300);
  --gold-soft:var(--gold-050);
  --radius:var(--radius-md);
}

/* Arabic sets slightly looser body leading; headings keep the tight steps
   so page titles do not drift apart between the two languages. */
[dir=rtl]{
  --lh-snug:1.6;
  --lh-body:1.75;
  --lh-relaxed:1.9;
}

/* Both languages share one stack so weight, metrics and rhythm match. */
html,body{font-family:var(--font-sans)}

/* The icon macro emits explicit width/height; these guards keep anything
   that slips off the scale from distorting its container. */
.ui-icon,.brand-svg{flex:0 0 auto}

/* One visible focus ring for every interactive control, including those
   the legacy layers style by hand. Outline (not box-shadow) so it is never
   clipped by an ancestor's overflow. */
:where(a,button,input,select,textarea,summary,[tabindex]):focus-visible{
  outline:var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset:var(--focus-ring-offset);
}

@media(prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.01ms!important;
    animation-iteration-count:1!important;
    transition-duration:.01ms!important;
    scroll-behavior:auto!important;
  }
}
