/**
 * 180 Degrees Unified Design System Tokens
 * Version: 2.0.0 (23 Nov 2026)
 * Riyadh Luxury Care & Pre-owned Luxury Platform
 * 
 * WCAG AA Contrast Compliant in Light and Dark themes
 * 4px Spacing Grid · Card Radius 12px · Button/Input Radius 10px
 * English: Montserrat · Arabic: Tajawal
 */

:root {
  /* =====================================================================
     Brand Primary & Accent Palette
     ===================================================================== */
  --brand-navy: #00263E;
  --brand-navy-rgb: 0, 38, 62;
  --brand-navy-hover: #001C2E;
  --brand-copper: #A26936;
  --brand-copper-rgb: 162, 105, 54;
  --brand-copper-hover: #8D5A2D;
  --brand-copper-subtle: #F6EDE5;
  --brand-light-blue: #A2C7E2;
  /* 23 Nov 2026: header / footer / hero surfaces, navy in both themes (brand-navy turns light blue in dark mode) */
  --chrome: #00263E;
  --chrome-deep: #001C2E;
  --chrome-hero: #00263E;
  --chrome-end: #0A3D62;
  --brand-light-blue-rgb: 162, 199, 226;
  --brand-cream: #FCF4DE;
  --brand-cream-rgb: 252, 244, 222;
  --brand-cream-border: #E8D9B5;

  /* =====================================================================
     Functional / Semantic Palette (Light)
     ===================================================================== */
  --color-error: #C0392B;
  --color-error-rgb: 192, 57, 43;
  --color-error-bg: #FDEDEB;
  --color-error-border: #F5B7B1;

  --color-success: #1B8A5A;
  --color-success-rgb: 27, 138, 90;
  --color-success-bg: #E8F7F0;
  --color-success-border: #A3E0C4;

  --color-warning: #C67D0A;
  --color-warning-rgb: 198, 125, 10;
  --color-warning-bg: #FEF7EB;
  --color-warning-border: #F7D8A1;

  --color-info: #1D70B8;
  --color-info-rgb: 29, 112, 184;
  --color-info-bg: #EBF4FC;
  --color-info-border: #A9D1F5;

  /* =====================================================================
     Surface & Backgrounds (Light)
     ===================================================================== */
  --color-bg-page: #FFFFFF;
  --color-bg-subtle: #F9FAFB;
  --color-bg-card: #FFFFFF;
  --color-bg-elevated: #FFFFFF;
  --color-bg-selected: var(--brand-cream);
  --color-bg-overlay: rgba(0, 38, 62, 0.45);

  /* =====================================================================
     Typography & Foreground (Light)
     ===================================================================== */
  --color-text-primary: #00263E;
  --color-text-secondary: #5D6D7A;
  --color-text-muted: #8494A1;
  --color-text-inverse: #FFFFFF;
  --color-text-copper: var(--brand-copper);
  --color-text-cream: #FCF4DE;

  /* =====================================================================
     Borders & Dividers (Light)
     ===================================================================== */
  --color-border: #E2E6E9;
  --color-border-subtle: #EEF1F3;
  --color-border-focus: var(--brand-navy);
  --color-border-selected: var(--brand-navy);
  --color-border-copper: var(--brand-copper);

  /* =====================================================================
     Stage & Status Tokens (Unified across all internal apps + portal)
     ===================================================================== */
  --stage-received-color: #1D70B8;
  --stage-received-bg: #EBF4FC;
  --stage-received-border: #A9D1F5;

  --stage-assessment-color: #C67D0A;
  --stage-assessment-bg: #FEF7EB;
  --stage-assessment-border: #F7D8A1;

  --stage-progress-color: #00263E;
  --stage-progress-bg: #E9EEF2;
  --stage-progress-border: #B2C4D1;

  --stage-qc-color: #8D5A2D;
  --stage-qc-bg: #F8EDE4;
  --stage-qc-border: #E0C1A6;

  --stage-dispatch-color: #553C9A;
  --stage-dispatch-bg: #F2EEFB;
  --stage-dispatch-border: #CAB8F2;

  --stage-ready-color: #795200;
  --stage-ready-bg: #FCF4DE;
  --stage-ready-border: #E7D5A3;

  --stage-collected-color: #1B8A5A;
  --stage-collected-bg: #E8F7F0;
  --stage-collected-border: #A3E0C4;

  --stage-cancelled-color: #C0392B;
  --stage-cancelled-bg: #FDEDEB;
  --stage-cancelled-border: #F5B7B1;

  /* =====================================================================
     Typography Scale (Montserrat EN / Tajawal AR)
     Two to three weights: Regular 400, Medium 500/600, Bold 700
     ===================================================================== */
  --font-en: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-ar: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --text-display: clamp(2rem, 4vw, 2.75rem);
  --text-display-lh: 1.15;
  --text-display-tracking: -0.02em;

  --text-h1: clamp(1.65rem, 3vw, 2.125rem);
  --text-h1-lh: 1.25;

  --text-h2: clamp(1.35rem, 2.5vw, 1.625rem);
  --text-h2-lh: 1.3;

  --text-h3: 1.25rem;
  --text-h3-lh: 1.4;

  --text-h4: 1.0625rem;
  --text-h4-lh: 1.45;

  --text-body: 1rem;
  --text-body-lh: 1.55;

  --text-small: 0.875rem;
  --text-small-lh: 1.5;

  --text-caption: 0.75rem;
  --text-caption-lh: 1.4;

  /* =====================================================================
     Spacing (Strict 4px Grid)
     ===================================================================== */
  --space-0: 0px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* =====================================================================
     Border Radii
     ===================================================================== */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-input: 10px;    /* Button & Input: 10px */
  --radius-button: 10px;
  --radius-card: 12px;      /* Cards: 12px */
  --radius-modal: 16px;
  --radius-sheet: 20px;
  --radius-full: 9999px;

  /* =====================================================================
     Shadows (Subtle, calibrated with Navy undertone)
     ===================================================================== */
  --shadow-sm: 0 1px 2px 0 rgba(0, 38, 62, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 38, 62, 0.08), 0 2px 4px -2px rgba(0, 38, 62, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 38, 62, 0.08), 0 4px 6px -4px rgba(0, 38, 62, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 38, 62, 0.1), 0 8px 10px -6px rgba(0, 38, 62, 0.05);
  --shadow-card-hover: 0 12px 24px -4px rgba(0, 38, 62, 0.12);

  /* =====================================================================
     Motion & Transitions
     ===================================================================== */
  --motion-duration-fast: 150ms;
  --motion-duration-normal: 250ms;
  --motion-duration-slow: 350ms;
  --motion-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --motion-ease-out: cubic-bezier(0, 0, 0.2, 1);

  /* =====================================================================
     Breakpoints & Layout Max Widths
     ===================================================================== */
  --bp-phone: 640px;
  --bp-tablet: 1024px;
  --bp-desktop: 1280px;
  --bp-wide: 1440px;
  --layout-max-width: 1280px;
  --layout-reader-width: 760px;

  /* =====================================================================
     Z-Index Hierarchy
     ===================================================================== */
  --z-base: 1;
  --z-sticky: 100;
  --z-header: 1000;
  --z-dropdown: 1100;
  --z-drawer: 1200;
  --z-modal-backdrop: 1450;
  --z-modal: 1500;
  --z-popover: 1510;
  --z-toast: 1600;
  --z-tooltip: 1700;
}

/* =========================================================================
   Dark Theme (Active via prefers-color-scheme or data-theme="dark")
   Deep Navy Background (#001826), Cards (#0B3350), Borders (#1E4766)
   Cream & White Text, Copper and Light Blue Accents
   ========================================================================= */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --chrome: #001826;
    --chrome-deep: #00111B;
    --chrome-hero: #001420;
    --chrome-end: #0B3350;
    --brand-navy: #A2C7E2;
    --brand-navy-rgb: 162, 199, 226;
    --brand-navy-hover: #BFDCF1;
    --brand-copper: #C88A52;
    --brand-copper-rgb: 200, 138, 82;
    --brand-copper-hover: #D79F6C;
    --brand-copper-subtle: #241A12;

    --brand-cream: #352912;
    --brand-cream-border: #624A1D;

    --color-error: #E05D50;
    --color-error-rgb: 224, 93, 80;
    --color-error-bg: #381512;
    --color-error-border: #6B231C;

    --color-success: #34D399;
    --color-success-rgb: 52, 211, 153;
    --color-success-bg: #0A3222;
    --color-success-border: #166544;

    --color-warning: #FBBF24;
    --color-warning-rgb: 251, 191, 36;
    --color-warning-bg: #3D2D08;
    --color-warning-border: #7A580E;

    --color-info: #60A5FA;
    --color-info-rgb: 96, 165, 250;
    --color-info-bg: #0C2847;
    --color-info-border: #1E4E7C;

    /* Dark Surfaces */
    --color-bg-page: #001826;
    --color-bg-subtle: #062235;
    --color-bg-card: #0B3350;
    --color-bg-elevated: #113F63;
    --color-bg-selected: #17384E;
    --color-bg-overlay: rgba(0, 12, 20, 0.75);

    /* Dark Typography */
    --color-text-primary: #FCF4DE;   /* Cream headers and key text */
    --color-text-secondary: #9BB3C4; /* Soft readable secondary */
    --color-text-muted: #6C8596;
    --color-text-inverse: #001826;
    --color-text-copper: #C88A52;
    --color-text-cream: #FCF4DE;

    /* Dark Borders */
    --color-border: #1E4766;
    --color-border-subtle: #143750;
    --color-border-focus: #A2C7E2;
    --color-border-selected: #C88A52;
    --color-border-copper: #C88A52;

    /* Dark Stage Tokens */
    --stage-received-color: #60A5FA;
    --stage-received-bg: #0C2847;
    --stage-received-border: #1E4E7C;

    --stage-assessment-color: #FBBF24;
    --stage-assessment-bg: #3D2D08;
    --stage-assessment-border: #7A580E;

    --stage-progress-color: #A2C7E2;
    --stage-progress-bg: #0F324E;
    --stage-progress-border: #23527A;

    --stage-qc-color: #D79F6C;
    --stage-qc-bg: #382414;
    --stage-qc-border: #6E4728;

    --stage-dispatch-color: #B794F4;
    --stage-dispatch-bg: #291D45;
    --stage-dispatch-border: #553B8C;

    --stage-ready-color: #FDE68A;
    --stage-ready-bg: #382C0E;
    --stage-ready-border: #6B5418;

    --stage-collected-color: #34D399;
    --stage-collected-bg: #0A3222;
    --stage-collected-border: #166544;

    --stage-cancelled-color: #E05D50;
    --stage-cancelled-bg: #381512;
    --stage-cancelled-border: #6B231C;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7);
    --shadow-card-hover: 0 12px 24px -4px rgba(0, 0, 0, 0.65);
  }
}

/* Explicit data-theme="dark" attribute selector */
[data-theme="dark"] {
  --chrome: #001826;
  --chrome-deep: #00111B;
  --chrome-hero: #001420;
  --chrome-end: #0B3350;
  --brand-navy: #A2C7E2;
  --brand-navy-rgb: 162, 199, 226;
  --brand-navy-hover: #BFDCF1;
  --brand-copper: #C88A52;
  --brand-copper-rgb: 200, 138, 82;
  --brand-copper-hover: #D79F6C;
  --brand-copper-subtle: #241A12;

  --brand-cream: #352912;
  --brand-cream-border: #624A1D;

  --color-error: #E05D50;
  --color-error-rgb: 224, 93, 80;
  --color-error-bg: #381512;
  --color-error-border: #6B231C;

  --color-success: #34D399;
  --color-success-rgb: 52, 211, 153;
  --color-success-bg: #0A3222;
  --color-success-border: #166544;

  --color-warning: #FBBF24;
  --color-warning-rgb: 251, 191, 36;
  --color-warning-bg: #3D2D08;
  --color-warning-border: #7A580E;

  --color-info: #60A5FA;
  --color-info-rgb: 96, 165, 250;
  --color-info-bg: #0C2847;
  --color-info-border: #1E4E7C;

  /* Dark Surfaces */
  --color-bg-page: #001826;
  --color-bg-subtle: #062235;
  --color-bg-card: #0B3350;
  --color-bg-elevated: #113F63;
  --color-bg-selected: #17384E;
  --color-bg-overlay: rgba(0, 12, 20, 0.75);

  /* Dark Typography */
  --color-text-primary: #FCF4DE;
  --color-text-secondary: #9BB3C4;
  --color-text-muted: #6C8596;
  --color-text-inverse: #001826;
  --color-text-copper: #C88A52;
  --color-text-cream: #FCF4DE;

  /* Dark Borders */
  --color-border: #1E4766;
  --color-border-subtle: #143750;
  --color-border-focus: #A2C7E2;
  --color-border-selected: #C88A52;
  --color-border-copper: #C88A52;

  /* Dark Stage Tokens */
  --stage-received-color: #60A5FA;
  --stage-received-bg: #0C2847;
  --stage-received-border: #1E4E7C;

  --stage-assessment-color: #FBBF24;
  --stage-assessment-bg: #3D2D08;
  --stage-assessment-border: #7A580E;

  --stage-progress-color: #A2C7E2;
  --stage-progress-bg: #0F324E;
  --stage-progress-border: #23527A;

  --stage-qc-color: #D79F6C;
  --stage-qc-bg: #382414;
  --stage-qc-border: #6E4728;

  --stage-dispatch-color: #B794F4;
  --stage-dispatch-bg: #291D45;
  --stage-dispatch-border: #553B8C;

  --stage-ready-color: #FDE68A;
  --stage-ready-bg: #382C0E;
  --stage-ready-border: #6B5418;

  --stage-collected-color: #34D399;
  --stage-collected-bg: #0A3222;
  --stage-collected-border: #166544;

  --stage-cancelled-color: #E05D50;
  --stage-cancelled-bg: #381512;
  --stage-cancelled-border: #6B231C;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7);
  --shadow-card-hover: 0 12px 24px -4px rgba(0, 0, 0, 0.65);
}

/* Explicit data-theme="light" resets to light mode regardless of prefers-color-scheme */
[data-theme="light"] {
  --brand-navy: #00263E;
  --brand-navy-rgb: 0, 38, 62;
  --brand-navy-hover: #001C2E;
  --brand-copper: #A26936;
  --brand-copper-rgb: 162, 105, 54;
  --brand-copper-hover: #8D5A2D;
  --brand-copper-subtle: #F6EDE5;
  --brand-light-blue: #A2C7E2;
  /* 23 Nov 2026: header / footer / hero surfaces, navy in both themes (brand-navy turns light blue in dark mode) */
  --chrome: #00263E;
  --chrome-deep: #001C2E;
  --chrome-hero: #00263E;
  --chrome-end: #0A3D62;
  --brand-light-blue-rgb: 162, 199, 226;
  --brand-cream: #FCF4DE;
  --brand-cream-border: #E8D9B5;

  --color-error: #C0392B;
  --color-error-bg: #FDEDEB;
  --color-error-border: #F5B7B1;

  --color-success: #1B8A5A;
  --color-success-bg: #E8F7F0;
  --color-success-border: #A3E0C4;

  --color-warning: #C67D0A;
  --color-warning-bg: #FEF7EB;
  --color-warning-border: #F7D8A1;

  --color-info: #1D70B8;
  --color-info-bg: #EBF4FC;
  --color-info-border: #A9D1F5;

  --color-bg-page: #FFFFFF;
  --color-bg-subtle: #F9FAFB;
  --color-bg-card: #FFFFFF;
  --color-bg-elevated: #FFFFFF;
  --color-bg-selected: var(--brand-cream);
  --color-bg-overlay: rgba(0, 38, 62, 0.45);

  --color-text-primary: #00263E;
  --color-text-secondary: #5D6D7A;
  --color-text-muted: #8494A1;
  --color-text-inverse: #FFFFFF;
  --color-text-copper: var(--brand-copper);
  --color-text-cream: #FCF4DE;

  --color-border: #E2E6E9;
  --color-border-subtle: #EEF1F3;
  --color-border-focus: var(--brand-navy);
  --color-border-selected: var(--brand-navy);
  --color-border-copper: var(--brand-copper);

  --stage-received-color: #1D70B8;
  --stage-received-bg: #EBF4FC;
  --stage-received-border: #A9D1F5;

  --stage-assessment-color: #C67D0A;
  --stage-assessment-bg: #FEF7EB;
  --stage-assessment-border: #F7D8A1;

  --stage-progress-color: #00263E;
  --stage-progress-bg: #E9EEF2;
  --stage-progress-border: #B2C4D1;

  --stage-qc-color: #8D5A2D;
  --stage-qc-bg: #F8EDE4;
  --stage-qc-border: #E0C1A6;

  --stage-dispatch-color: #553C9A;
  --stage-dispatch-bg: #F2EEFB;
  --stage-dispatch-border: #CAB8F2;

  --stage-ready-color: #795200;
  --stage-ready-bg: #FCF4DE;
  --stage-ready-border: #E7D5A3;

  --stage-collected-color: #1B8A5A;
  --stage-collected-bg: #E8F7F0;
  --stage-collected-border: #A3E0C4;

  --stage-cancelled-color: #C0392B;
  --stage-cancelled-bg: #FDEDEB;
  --stage-cancelled-border: #F5B7B1;
}

/* =========================================================================
   Base Resets & Direction-Aware Typography
   ========================================================================= */
html {
  font-family: var(--font-en);
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  line-height: var(--text-body-lh);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html[dir="rtl"], [dir="rtl"] {
  font-family: var(--font-ar);
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  transition: background-color var(--motion-duration-normal) var(--motion-ease),
              color var(--motion-duration-normal) var(--motion-ease);
}

/* Phone touch optimisations & prevent tap highlight */
* {
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

@media (pointer: coarse) {
  button, select, input[type="checkbox"], input[type="radio"] {
    min-height: 44px;
  }
}

@media (max-width: 640px) {
  input, select, textarea {
    font-size: 16px !important; /* Prevents iOS auto-zoom on field focus */
  }
}
