/* ==========================================================================
   Regional Vision Center (RVC) — Design Tokens v2.0
   Three layers: primitives -> semantic -> component. Use semantic tokens in UI.
   All text/background pairs listed in brand-guidelines-v2.md meet WCAG 2.2 AA.
   Bilingual: logical properties only (inline-start/end), never left/right.
   ========================================================================== */

:root {
  /* ---------- 1. Primitives ---------- */
  --blue-50:  #e8eff6;
  --blue-100: #d3e0ec;
  --blue-300: #9fb7cf;
  --blue-400: #7fb0e0;
  --blue-600: #406890;   /* logo swoosh */
  --blue-700: #2f5578;
  --blue-800: #1f3d5c;
  --blue-900: #14283d;

  --green-50:  #eaf6ee;
  --green-300: #8fd3a8;
  --green-500: #089040;  /* logo "ISION" — logo/graphics only, 4.14:1 on white */
  --green-600: #0b7a37;  /* UI green, 5.45:1 on white */
  --green-700: #06692f;

  --teal-600: #007995;   /* links / info, 5.04:1 on white */
  --teal-500: #00a3c8;   /* legacy cyan — decorative only, 2.97:1 */

  --gray-0:   #ffffff;
  --gray-50:  #f5f8fb;
  --gray-200: #dbe3ea;
  --gray-500: #6b7785;   /* large text / icons only on white */
  --gray-700: #4a5663;
  --gray-900: #1a1a1a;

  --red-600:   #b42318;
  --amber-700: #c2410c;

  /* ---------- 2. Semantic (light) ---------- */
  --color-bg:            var(--gray-0);
  --color-surface:       var(--gray-50);
  --color-surface-brand: var(--blue-50);
  --color-border:        var(--gray-200);

  --color-text:          var(--gray-900);
  --color-text-muted:    var(--gray-700);
  --color-text-on-brand: var(--gray-0);
  --color-heading:       var(--blue-800);

  --color-primary:       var(--blue-600);
  --color-primary-hover: var(--blue-700);
  --color-primary-press: var(--blue-800);
  --color-accent:        var(--green-600);
  --color-accent-hover:  var(--green-700);
  --color-link:          var(--teal-600);

  --color-focus:         var(--blue-800);
  --color-success:       var(--green-600);
  --color-warning:       var(--amber-700);
  --color-danger:        var(--red-600);

  --color-footer-bg:     var(--blue-900);
  --color-footer-text:   var(--gray-50);

  /* ---------- Typography ---------- */
  --font-latin:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-arabic: "IBM Plex Sans Arabic", "Cairo", "Segoe UI", Tahoma, sans-serif;
  --font-sans:   var(--font-latin);

  /* Fluid scale: 360px -> 1280px viewport, ratio ~1.2-1.25 */
  --text-xs:   clamp(0.75rem, 0.73rem + 0.1vw, 0.8125rem);
  --text-sm:   clamp(0.875rem, 0.85rem + 0.12vw, 0.9375rem);
  --text-base: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --text-lg:   clamp(1.125rem, 1.08rem + 0.25vw, 1.3125rem);
  --text-xl:   clamp(1.375rem, 1.26rem + 0.55vw, 1.75rem);
  --text-2xl:  clamp(1.75rem, 1.5rem + 1.1vw, 2.5rem);
  --text-3xl:  clamp(2.125rem, 1.7rem + 2vw, 3.5rem);

  --leading-tight: 1.2;
  --leading-body:  1.6;
  --leading-arabic: 1.85;   /* Arabic needs more line height */
  --measure: 68ch;          /* max line length for body copy */

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

  /* ---------- Spacing (4px base, 8pt rhythm) ---------- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;
  --section-y: clamp(3rem, 2rem + 5vw, 6rem);

  /* ---------- Layout ---------- */
  --container-max: 1200px;
  --container-pad: clamp(1rem, 4vw, 2rem);
  --grid-gap: clamp(1rem, 2vw, 1.5rem);
  --bp-sm: 640px;   /* reference values; use in @media / @container */
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;

  /* ---------- Shape, elevation, motion ---------- */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgb(20 40 61 / 0.08);
  --shadow-md: 0 4px 16px rgb(20 40 61 / 0.10);
  --shadow-lg: 0 12px 32px rgb(20 40 61 / 0.14);

  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;

  --tap-target: 44px;       /* min interactive size (WCAG 2.2 target size) */
  --focus-ring: 3px solid var(--color-focus);
  --focus-offset: 2px;
}

/* ---------- Dark mode ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg:            var(--blue-900);
  --color-surface:       #1a3350;
  --color-surface-brand: #1a3350;
  --color-border:        #2c4a69;
  --color-text:          var(--gray-50);
  --color-text-muted:    #b9c7d6;
  --color-heading:       var(--gray-0);
  --color-primary:       var(--blue-400);
  --color-primary-hover: #a3c8ec;
  --color-accent:        var(--green-300);
  --color-link:          #7fd0e6;
  --color-focus:         var(--gray-0);
  --color-footer-bg:     #0c1b2b;
  --color-text-on-brand: var(--blue-900); /* dark text on light green button */
}

/* ---------- Arabic / RTL ---------- */
:lang(ar) {
  --font-sans: var(--font-arabic);
  --leading-body: var(--leading-arabic);
  letter-spacing: 0;          /* never letter-space Arabic */
}

/* ---------- Base ---------- */
html { color-scheme: light; scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 {
  color: var(--color-heading);
  line-height: var(--leading-tight);
  font-weight: var(--weight-bold);
  text-wrap: balance;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
p, li { max-inline-size: var(--measure); text-wrap: pretty; }
a { color: var(--color-link); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.container {
  inline-size: min(100% - 2 * var(--container-pad), var(--container-max));
  margin-inline: auto;
}
.section { padding-block: var(--section-y); }

/* ---------- Components (starter) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-block-size: var(--tap-target); padding-inline: var(--space-5);
  border: 2px solid transparent; border-radius: var(--radius-pill);
  font: inherit; font-weight: var(--weight-semibold); text-decoration: none; cursor: pointer;
  transition: background var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.btn--primary   { background: var(--color-accent);  color: var(--color-text-on-brand); }
.btn--primary:hover { background: var(--color-accent-hover); }
.btn--secondary { background: transparent; color: var(--color-primary); border-color: var(--color-primary); }
.btn--secondary:hover { background: var(--color-surface-brand); }

.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-5); box-shadow: var(--shadow-sm);
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
