/* Daftar design tokens: the one place for colour roles, spacing, radius, type, sizes, motion and layers.
   Colours build on the brand palette in app.css (:root and its two dark blocks), so light and dark mode
   switch together. RULE: components read these tokens; no raw hex or px for spacing/radius/font-size.
   RULE: never use var(--x) for a name that is not defined (an undefined var silently drops the rule). */

/* The new Saudi riyal sign (U+20C1, SAMA's official drawing): most fonts do not have it yet. This one-glyph font
   is used for that character only and is embedded in PDFs saved from the browser. Built by scripts/build-riyal-font.py. */
@font-face { font-family: 'Daftar Saudi Riyal'; src: url('/vendor/fonts/saudi-riyal/saudi-riyal.woff') format('woff');
  font-display: block; unicode-range: U+20C1; }

:root {
  /* ---------- Colour roles (light and dark come from app.css) ---------- */
  --color-bg: var(--bg);
  --color-surface: var(--panel);
  --color-surface-2: var(--panel-2);
  --color-surface-hover: var(--navbar-hover);
  --color-surface-inset: var(--panel-2);
  --color-text: var(--text);
  --color-text-muted: var(--muted);
  --color-text-disabled: color-mix(in srgb, var(--muted) 70%, var(--panel));
  --color-text-on-primary: #ffffff;
  --color-shade: #000000; /* mixed into fills to darken them (dark-mode buttons) */
  --color-border: var(--border);
  --color-border-strong: var(--border-strong);
  --color-primary: var(--primary);
  --color-primary-hover: var(--primary-2);
  --color-primary-subtle: var(--primary-soft);
  --color-primary-text: var(--primary-text);
  --color-success: var(--success);  --color-success-subtle: var(--success-soft);
  --color-warning: var(--warning);  --color-warning-subtle: var(--warning-soft);
  --color-danger: var(--danger);    --color-danger-subtle: var(--danger-soft);
  --color-info: var(--info);        --color-info-subtle: var(--info-soft);
  /* Text that sits on a tone's own soft background: mixed towards the text colour so it passes contrast
     in both themes (plain --warning on --warning-soft is too light). */
  --color-success-strong: color-mix(in srgb, var(--success) 70%, var(--text));
  --color-warning-strong: color-mix(in srgb, var(--warning) 65%, var(--text));
  --color-danger-strong: color-mix(in srgb, var(--danger) 75%, var(--text));
  --color-info-strong: color-mix(in srgb, var(--info) 75%, var(--text));
  --color-focus: var(--primary);
  --focus-ring: 0 0 0 2px var(--panel), 0 0 0 4px var(--primary); /* solid ring with a gap: 3:1+ in both themes */
  --color-backdrop: rgba(15, 23, 42, .45);
  --card: var(--panel); /* used by inventory.css and barcode.css but never defined before: broke dark mode */

  /* ---------- Typography ---------- */
  /* "Daftar Saudi Riyal" holds only the Saudi riyal sign U+20C1 (see @font-face below), so it comes first */
  --font-sans: "Daftar Saudi Riyal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", Arial, sans-serif;
  --font-mono: "Daftar Saudi Riyal", "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-2xs: 11px;   /* section labels, tiny badges */
  --text-nav: 13.5px; /* side menu rows (EMI) */
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* ---------- Spacing (4px base) ---------- */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-12: 48px;

  /* ---------- Radius ---------- */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 14px;  /* flyouts and dropdown panels */
  --radius-2xl: 16px; /* bottom sheets */
  --radius-pill: 999px;

  /* ---------- Controls ---------- */
  --control-height-sm: 32px;
  --control-height-md: 36px;
  --control-height-lg: 44px;
  --control-padding-x: 10px;

  /* ---------- Side menu (EMI business portal proportions, narrowed for wide accounting tables) ---------- */
  --sidenav-width: 264px;
  --sidenav-width-collapsed: 72px;
  --sidenav-drawer-width: min(288px, 86vw);
  --sidenav-item-height: 42px;
  --sidenav-child-height: 38px;
  --sidenav-item-radius: 11px;
  --sidenav-child-radius: 9px;
  --sidenav-icon-box: 20px;
  --sidenav-icon-size: 18px;
  --sidenav-indicator-width: 3px;
  --sidenav-indicator-height: 18px;
  --sidenav-toggle-size: 32px;
  --sidenav-flyout-width: 232px;
  --sidenav-children-indent: 32px;
  --sidenav-guide-inset: 21px;
  --color-hover-wash: color-mix(in srgb, var(--color-text) 6%, transparent);
  --color-hover-wash-strong: color-mix(in srgb, var(--color-text) 8%, transparent);
  --color-text-faint: color-mix(in srgb, var(--color-text-muted) 72%, var(--color-surface));
  --color-tooltip-bg: var(--color-text);
  --color-tooltip-text: var(--color-surface);

  /* ---------- Form fields (EMI floating-field shell: label above, filled 44px box, brand focus) ---------- */
  --field-height: var(--control-height-lg);
  --field-height-compact: var(--control-height-md);
  --field-height-cell: var(--control-height-sm);
  --field-radius: 9px;
  --field-radius-cell: 7px;
  --field-pad-start: 14px;
  --field-pad-end: 10px;
  --field-label-gap: 4px;
  --field-message-gap: 6px;
  --field-textarea-min: 112px;
  --field-select-pad-end: 36px;
  --field-suffix-width: 52px;
  --field-bg: color-mix(in srgb, var(--color-surface-2) 40%, var(--color-surface));
  --field-bg-hover: color-mix(in srgb, var(--color-surface-2) 75%, var(--color-surface));
  --field-bg-focus: var(--color-surface);
  --field-bg-disabled: var(--color-surface-2);
  --field-bg-readonly: color-mix(in srgb, var(--color-surface-2) 60%, var(--color-surface));
  --field-bg-error: color-mix(in srgb, var(--color-danger-subtle) 55%, var(--color-surface));
  --field-bg-on: color-mix(in srgb, var(--color-primary-subtle) 70%, var(--color-surface));
  --field-border: var(--color-border);
  --field-border-hover: var(--color-border-strong);
  --field-border-focus: var(--color-primary);
  --field-border-error: var(--color-danger);
  --field-border-on: color-mix(in srgb, var(--color-primary) 45%, transparent);
  --field-label: var(--color-text-muted);
  --field-placeholder: color-mix(in srgb, var(--color-text-muted) 62%, var(--color-surface));
  --field-chevron: var(--color-primary-text);
  --field-halo: 0 0 0 3px color-mix(in srgb, var(--color-primary) 16%, transparent);
  --field-halo-error: 0 0 0 3px color-mix(in srgb, var(--color-danger) 16%, transparent);
  --field-option-active: color-mix(in srgb, var(--color-primary) 10%, transparent);
  --check-size: 18px;
  --check-radius: 5px;
  --switch-width: 42px;
  --switch-height: 24px;
  --switch-knob: 18px;
  --switch-gap: 3px;
  --color-switch-off: color-mix(in srgb, var(--color-text-muted) 70%, var(--color-surface));
  --color-knob: var(--color-text-on-primary);
  --touch-target: 44px; /* coarse pointers (fingers): the smallest thing you can tap */
  --table-fade: 28px;   /* the soft edge that says a table scrolls sideways */

  /* ---------- Elevation: only things that float get a shadow ---------- */
  --shadow-dropdown: 0 10px 28px -10px rgba(15, 23, 42, .28);
  --shadow-dialog: 0 24px 60px -18px rgba(15, 23, 42, .40);
  --shadow-popover: 0 16px 36px rgba(15, 23, 42, .12);
  --shadow-raised: 0 10px 24px -14px rgba(15, 23, 42, .35);
  --shadow-tooltip: 0 10px 30px -12px rgba(15, 23, 42, .35), 0 4px 12px -4px rgba(15, 23, 42, .18);
  --shadow-knob: 0 2px 4px rgba(0, 0, 0, .2);
  --backdrop-blur: 3px;

  /* ---------- Motion ---------- */
  --motion-fast: 120ms;
  --motion-base: 200ms;
  --ease: cubic-bezier(.2, .6, .2, 1);
  --ease-standard: cubic-bezier(.4, 0, .2, 1);
  --motion-switch: 250ms;

  /* ---------- Chart series (cost center charts): teal first, then hues far apart; 8 = "others" ---------- */
  --chart-1: #0f766e; --chart-2: #2b6cb0; --chart-3: #b7791f; --chart-4: #c2523f;
  --chart-5: #6d5bd0; --chart-6: #b0457f; --chart-7: #5f7f1a; --chart-8: #8a9a97;
  --chart-na: color-mix(in srgb, var(--muted) 45%, var(--panel)); /* "not assigned": quiet on purpose */

  /* ---------- Layers (never invent a z-index) ---------- */
  --z-sticky: 10;
  --z-control-panel: 11;
  --z-navbar: 12;
  --z-sidenav: 35;
  --z-flyout: 50;
  --z-backdrop: 55;
  --z-drawer: 60;
  --z-dropdown: 450; /* above dialogs: a dropdown inside a dialog must open on top of it */
  --z-dialog: 400;
  --z-toast: 500;
  --z-skip: 600; /* the skip link sits above everything while it has focus */
}
/* Floating things need deeper shadows on dark surfaces. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --shadow-popover: 0 18px 42px rgba(2, 6, 23, .45);
    --shadow-raised: 0 12px 28px -14px rgba(0, 0, 0, .8);
    --shadow-tooltip: 0 10px 30px -12px rgba(0, 0, 0, .6), 0 4px 12px -4px rgba(0, 0, 0, .4);
    --chart-1: #2dd4bf; --chart-2: #6aa8e8; --chart-3: #e0a744; --chart-4: #f08a72;
    --chart-5: #a394f0; --chart-6: #e27fb5; --chart-7: #a3c95a; --chart-8: #6b7f7c;
  }
}
:root[data-theme="dark"] {
  --shadow-popover: 0 18px 42px rgba(2, 6, 23, .45);
  --shadow-raised: 0 12px 28px -14px rgba(0, 0, 0, .8);
  --shadow-tooltip: 0 10px 30px -12px rgba(0, 0, 0, .6), 0 4px 12px -4px rgba(0, 0, 0, .4);
  --chart-1: #2dd4bf; --chart-2: #6aa8e8; --chart-3: #e0a744; --chart-4: #f08a72;
  --chart-5: #a394f0; --chart-6: #e27fb5; --chart-7: #a3c95a; --chart-8: #6b7f7c;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; scroll-behavior: auto !important; }
}
