/*
 * Mosaedak V9.0 design tokens — "Intelligence, without complexity".
 * Layer 1 of 5: tokens → base → components → layout → features.
 * Every colour used by components is a semantic token defined here.
 * Contrast (WCAG 2.2): text ≥ 4.5:1 and UI boundaries ≥ 3:1 on their intended surface in every theme.
 */

/* ---------- Typography assets (self-hosted, SIL OFL 1.1 — see assets/fonts/OFL-1.1.txt) ---------- */
/* Arabic glyphs come from Noto Sans Arabic; Latin text falls through to the platform UI font. */
@font-face {
  font-family: "Mosaedak Arabic";
  src: url("../assets/fonts/noto-sans-arabic-regular.woff") format("woff");
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+25CC;
}
@font-face {
  font-family: "Mosaedak Arabic";
  src: url("../assets/fonts/noto-sans-arabic-medium.woff") format("woff");
  font-weight: 500 600; font-style: normal; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+25CC;
}
@font-face {
  font-family: "Mosaedak Arabic";
  src: url("../assets/fonts/noto-sans-arabic-bold.woff") format("woff");
  font-weight: 700 800; font-style: normal; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+25CC;
}

:root {
  /* ---- Type families ---- */
  --font-sans: "Mosaedak Arabic", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Code", Menlo, Consolas, "Mosaedak Arabic", "Liberation Mono", monospace; /* Arabic inside code keeps correct shaping */

  /* ---- Type scale (UI is compact; reading text is roomier) ---- */
  --fs-2xs: 0.6875rem;  /* 11px — only for kbd hints / counters */
  --fs-xs: 0.75rem;     /* 12px */
  --fs-sm: 0.8125rem;   /* 13px */
  --fs-base: 0.875rem;  /* 14px — UI controls */
  --fs-md: 0.9375rem;   /* 15px */
  --fs-reading: 1rem;   /* 16px — message body; adjusted by the text-size preference */
  --fs-lg: 1.125rem;    /* 18px */
  --fs-xl: 1.375rem;    /* 22px */
  --fs-2xl: 1.75rem;    /* 28px */
  --fs-3xl: 2.125rem;   /* 34px — home greeting on wide screens */

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

  --lh-tight: 1.25;
  --lh-snug: 1.45;
  --lh-ui: 1.5;
  --lh-reading: 1.85; /* Arabic needs generous leading for diacritics and ascenders */

  /* ---- Spacing (4px grid) ---- */
  --sp-0: 0;
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* ---- Radii ---- */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* ---- Motion ---- */
  --dur-instant: 90ms;
  --dur-fast: 130ms;   /* small feedback */
  --dur-base: 190ms;   /* standard transitions */
  --dur-panel: 260ms;  /* sheets, sidebar, artifact panel */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.25, 1);
  --ease-spring: cubic-bezier(0.3, 1.25, 0.5, 1);

  /* ---- Layout ---- */
  --sidebar-w: 272px;
  --rail-w: 64px;
  --topbar-h: 56px;
  --reading-w: 46rem;     /* ~70 Arabic characters per line at 16px */
  --composer-w: 48rem;
  --artifact-w: min(44vw, 640px);
  --tap: 44px;            /* minimum touch target */
  --control-h: 36px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-start: env(safe-area-inset-right, 0px); /* RTL inline-start */
  --safe-end: env(safe-area-inset-left, 0px);

  /* ---- Layers ---- */
  --z-sticky: 10;
  --z-sidebar: 30;
  --z-scrim: 40;
  --z-panel: 45;
  --z-popover: 60;
  --z-dialog: 70;
  --z-toast: 80;

  /* ---- Brand constants (theme-independent) ---- */
  --brand-emerald: #299b72;
  --brand-ivory: #fbf9f2;
  --brand-bronze: #b5782c;
}

/* ======================================================================
   Graphite — dark theme (default for legacy "dark" preference)
   ====================================================================== */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #151a18;
  --bg-sunken: #111513;
  --surface-1: #1b211f;   /* sidebar */
  --surface-2: #222927;   /* composer, cards */
  --surface-3: #2a322f;   /* menus, elevated */
  --surface-hover: rgb(226 240 233 / 0.06);
  --surface-active: rgb(226 240 233 / 0.10);
  --surface-selected: rgb(77 196 148 / 0.13);
  --overlay: rgb(5 8 7 / 0.62);

  --border-subtle: rgb(226 240 233 / 0.07);
  --border: rgb(226 240 233 / 0.11);
  --border-strong: rgb(226 240 233 / 0.20);
  --border-control: #5b6862; /* 3.2:1 on surface-2 for form boundaries */

  --text: #f1f4ef;        /* 15.6:1 on bg */
  --text-2: #aab7b0;      /* 8.4:1 */
  --text-3: #86948d;      /* 5.5:1 */
  --text-disabled: #5f6b66;
  --text-on-accent: #04140d;

  --accent: #3dbe8b;              /* primary action fill (7.6:1 with text-on-accent) */
  --accent-hover: #4fcb98;
  --accent-pressed: #33a87a;
  --accent-text: #5ccb9e;         /* links, active labels on bg (8.7:1) */
  --accent-soft: rgb(61 190 139 / 0.14);
  --accent-softer: rgb(61 190 139 / 0.08);
  --accent-border: rgb(92 203 158 / 0.42);
  --focus-ring: #7ddcb4;

  --danger: #f08a7e;
  --danger-soft: rgb(240 138 126 / 0.12);
  --warning: #e6b964;
  --warning-soft: rgb(230 185 100 / 0.12);
  --success: var(--accent-text);
  --info: #8fb8e8;

  --code-bg: #101412;
  --code-border: rgb(226 240 233 / 0.08);
  --code-text: #dfe7e2;
  --syn-keyword: #f3a3c4;
  --syn-string: #a5dba0;
  --syn-number: #f2c27d;
  --syn-comment: #7d8b84;
  --syn-fn: #8ccbf5;

  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.28);
  --shadow-2: 0 6px 18px -6px rgb(0 0 0 / 0.45), 0 1px 0 rgb(255 255 255 / 0.03) inset;
  --shadow-3: 0 18px 48px -12px rgb(0 0 0 / 0.6), 0 0 0 1px var(--border);
  --composer-shadow: 0 10px 30px -14px rgb(0 0 0 / 0.65), 0 0 0 1px var(--border);

  --ambient: none;
  --brand-mark: #4fcb98;
  --energy-1: #2f8f69;
  --energy-2: #4fcb98;
  --selection: rgb(61 190 139 / 0.32);
}

/* ======================================================================
   Ivory — light theme
   ====================================================================== */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f5f4ed;
  --bg-sunken: #eeede5;
  --surface-1: #efeee6;
  --surface-2: #ffffff;
  --surface-3: #ffffff;
  --surface-hover: rgb(32 40 36 / 0.05);
  --surface-active: rgb(32 40 36 / 0.09);
  --surface-selected: rgb(31 127 93 / 0.10);
  --overlay: rgb(26 32 29 / 0.38);

  --border-subtle: rgb(32 40 36 / 0.07);
  --border: rgb(32 40 36 / 0.12);
  --border-strong: rgb(32 40 36 / 0.22);
  --border-control: #8a958f; /* 3.1:1 on white */

  --text: #1f2723;        /* 14.4:1 on bg */
  --text-2: #56645c;      /* 5.6:1 */
  --text-3: #5f6c65;      /* 5.0:1 on bg, 4.7:1 on sidebar */
  --text-disabled: #a3aca7;
  --text-on-accent: #ffffff;

  --accent: #1f7f5d;              /* white text 4.9:1 */
  --accent-hover: #1a7253;
  --accent-pressed: #166447;
  --accent-text: #1b7353;         /* 5.3:1 on bg */
  --accent-soft: rgb(31 127 93 / 0.11);
  --accent-softer: rgb(31 127 93 / 0.06);
  --accent-border: rgb(31 127 93 / 0.38);
  --focus-ring: #1f7f5d;

  --danger: #b4392c;
  --danger-soft: rgb(180 57 44 / 0.09);
  --warning: #8a5a00;
  --warning-soft: rgb(196 140 30 / 0.12);
  --success: var(--accent-text);
  --info: #2c5f9e;

  --code-bg: #f3f3ee;
  --code-border: rgb(32 40 36 / 0.09);
  --code-text: #23302a;
  --syn-keyword: #a3236b;
  --syn-string: #2f7a2a;
  --syn-number: #9a5b00;
  --syn-comment: #6b7670;
  --syn-fn: #1f5f9e;

  --shadow-1: 0 1px 2px rgb(32 40 36 / 0.08);
  --shadow-2: 0 8px 20px -10px rgb(32 40 36 / 0.22), 0 1px 2px rgb(32 40 36 / 0.06);
  --shadow-3: 0 22px 50px -18px rgb(32 40 36 / 0.32), 0 0 0 1px var(--border);
  --composer-shadow: 0 12px 30px -18px rgb(32 40 36 / 0.35), 0 0 0 1px var(--border);

  --brand-mark: #1f7f5d;
  --energy-1: #6bbd9b;
  --energy-2: #1f7f5d;
  --selection: rgb(31 127 93 / 0.20);
}

/* ======================================================================
   Aurora — optional accent treatment (works over Graphite or Ivory).
   It never changes layout or legibility tokens; only ambient light and energy accents.
   ====================================================================== */
:root[data-aurora="on"] {
  --brand-mark: #5fd0b0;
  --energy-1: #2ea58a;
  --energy-2: #7c9cf0;
  --ambient:
    radial-gradient(60rem 26rem at 85% -12%, rgb(61 190 139 / 0.16), transparent 70%),
    radial-gradient(44rem 22rem at 10% -8%, rgb(124 156 240 / 0.12), transparent 70%);
}
:root[data-aurora="on"][data-theme="light"] {
  --brand-mark: #1d7a63;
  --energy-1: #2a9a7c;
  --energy-2: #5674d0;
  --ambient:
    radial-gradient(60rem 26rem at 85% -12%, rgb(31 127 93 / 0.12), transparent 70%),
    radial-gradient(44rem 22rem at 10% -8%, rgb(86 116 208 / 0.10), transparent 70%);
}

/* High-contrast preference: stronger text and boundaries without changing the identity. */
:root[data-contrast="high"] {
  --text-2: var(--text);
  --text-3: var(--text-2);
  --border: var(--border-strong);
  --border-subtle: var(--border);
}

/* Text-size preference (affects reading text and the UI root proportionally). */
:root[data-font-size="small"] { --fs-reading: 0.9375rem; }
:root[data-font-size="large"] { --fs-reading: 1.125rem; }
:root[data-chat-width="wide"] { --reading-w: 58rem; --composer-w: 60rem; }
