/* =====================================================================
   YourHR — Design Tokens (theme.css)
   Single source of truth for color, type, spacing, radius, shadow, motion.
   Light theme default · dark-theme-ready · white-label-ready.
   Consumed by app.css (components) and dashboard.js (chart palette).
   ===================================================================== */

/* ===== A) BRAND PRESETS (10) — <html data-brand="sky">, reset/default=indigo ===== */
:root,
[data-brand="default"] { --hr-primary:#4f46e5; --hr-primary-hover:#4338ca; --brand-500:#6366f1; --brand-700:#4338ca; --hr-secondary:#64748b; --hr-success:#059669; --hr-warning:#d97706; --hr-danger:#e11d48; --hr-info:#0891b2; }
[data-brand="sky"]      { --hr-primary:#2b9de3; --hr-primary-hover:#1b86c7; --brand-500:#44a9e6; --brand-700:#2484bf; --hr-secondary:#64748b; --hr-success:#0d9488; --hr-warning:#f59e0b; --hr-danger:#e11d48; --hr-info:#0ea5e9; }
[data-brand="slate"]    { --hr-primary:#3b5bdb; --hr-primary-hover:#2f49b0; --brand-500:#5c7cfa; --brand-700:#2f49b0; --hr-secondary:#475569; --hr-success:#16a34a; --hr-warning:#ca8a04; --hr-danger:#dc2626; --hr-info:#2563eb; }
[data-brand="emerald"]  { --hr-primary:#059669; --hr-primary-hover:#047857; --brand-500:#10b981; --brand-700:#047857; --hr-secondary:#64748b; --hr-success:#16a34a; --hr-warning:#d97706; --hr-danger:#dc2626; --hr-info:#0891b2; }
[data-brand="teal"]     { --hr-primary:#0d9488; --hr-primary-hover:#0f766e; --brand-500:#14b8a6; --brand-700:#0f766e; --hr-secondary:#64748b; --hr-success:#059669; --hr-warning:#ea8c00; --hr-danger:#e11d48; --hr-info:#0891b2; }
[data-brand="royal"]    { --hr-primary:#7c3aed; --hr-primary-hover:#6d28d9; --brand-500:#8b5cf6; --brand-700:#6d28d9; --hr-secondary:#6b7280; --hr-success:#059669; --hr-warning:#d97706; --hr-danger:#e11d48; --hr-info:#2563eb; }
[data-brand="rose"]     { --hr-primary:#e11d48; --hr-primary-hover:#be123c; --brand-500:#f43f5e; --brand-700:#be123c; --hr-secondary:#64748b; --hr-success:#059669; --hr-warning:#d97706; --hr-danger:#dc2626; --hr-info:#0891b2; }
[data-brand="amber"]    { --hr-primary:#d97706; --hr-primary-hover:#b45309; --brand-500:#f59e0b; --brand-700:#b45309; --hr-secondary:#64748b; --hr-success:#16a34a; --hr-warning:#ea8c00; --hr-danger:#dc2626; --hr-info:#0891b2; }
[data-brand="midnight"] { --hr-primary:#1e3a8a; --hr-primary-hover:#1e3a70; --brand-500:#2563eb; --brand-700:#172554; --hr-secondary:#475569; --hr-success:#059669; --hr-warning:#d97706; --hr-danger:#dc2626; --hr-info:#0891b2; }
[data-brand="coral"]    { --hr-primary:#f97316; --hr-primary-hover:#ea580c; --brand-500:#fb923c; --brand-700:#c2410c; --hr-secondary:#64748b; --hr-success:#16a34a; --hr-warning:#eab308; --hr-danger:#dc2626; --hr-info:#0ea5e9; }

:root {
  /* ---- Brand — derived from --hr-primary (Block A preset); white-label: override
         --hr-primary via [data-brand] OR the per-tenant inline <style> --brand override ---- */
  --brand:          var(--hr-primary);
  --brand-600:      var(--hr-primary);
  --brand-700:      var(--hr-primary-hover, #4338ca);
  /* --brand-500 set per-preset in Block A (default #6366f1) */
  --brand-400:      color-mix(in srgb, var(--hr-primary) 55%, #fff);
  --brand-soft:     color-mix(in srgb, var(--hr-primary) 10%, #fff);
  --brand-soft-2:   color-mix(in srgb, var(--hr-primary) 18%, #fff);
  --on-brand:       #ffffff;
  --brand-grad:     linear-gradient(135deg, var(--brand-500) 0%, var(--hr-primary) 55%, var(--brand-700) 100%);
  --brand-shadow:   color-mix(in srgb, var(--hr-primary) 32%, transparent);

  /* ---- Semantic accents (each paired with a soft tint for badges/tiles) ---- */
  --success:        #059669;  --success-soft: #ecfdf5;
  --warning:        #d97706;  --warning-soft: #fffbeb;
  --danger:         #e11d48;  --danger-soft:  #fff1f2;
  --info:           #0891b2;  --info-soft:    #ecfeff;
  --secondary:      #64748b;  --secondary-soft:#f1f5f9;

  /* ---- Semantic TEXT tokens (theme-adaptive foreground for badge-soft/tile/btn-soft/stat-trend/.text-*).
         Light values = WCAG-AA on light soft-tints (≥4.6:1, from F-19). Dark values overridden in dark block.
         One token = correct in BOTH themes, so no per-theme override needed at call sites. ---- */
  --success-text:   #047857;  /* 5.2:1 on --success-soft (light) */
  --warning-text:   #92400e;  /* เข้มขึ้นให้ ≥4.5:1 บน badge amber (เดิม #b45309 borderline ~4.1) — dark override ที่ :186 */
  --danger-text:    #be123c;  /* 5.7:1 on --danger-soft */
  --info-text:      #0e7490;  /* 5.2:1 on --info-soft */
  --secondary-text: #475569;  /* 6.9:1 on --secondary-soft */
  --brand-text:     var(--brand-700);            /* soft-primary btn + links (light) */
  --btn-on-bright:  #07111f;  /* dark label for solid warning/info/success fills (≥5:1 both modes) */

  /* ---- Neutral surfaces (cool slate) ---- */
  --bg:             #f5f7fb;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --surface-3:      #f1f5f9;
  --elevated:       #ffffff;
  --border:         #e7ebf1;
  --border-2:       #d7dde8;
  --text:           #0f172a;
  --text-2:         #475569;
  /* F-01: #5f6776 clears WCAG 1.4.3 AA ≥4.5:1 with safe margin on every surface muted text sits on —
     white 5.69:1, --surface-3 #f1f5f9 5.2:1, --bg #f5f7fb 5.31:1, --surface-2 #f8fafc 5.4:1.
     (was #677084 = 4.53:1 on --surface-3, too tight for sub-pixel rendering.)
     F-01 dark: dark --muted lifted to #828ca1 (worst case 4.62:1 on --surface-3) — see dark block below. */
  --muted:          #5f6776;

  /* ---- Sidebar (light default in :root; dark navy via [data-theme=dark]).
         --side-grad kept (navy) for any consumer; Block C in app.css drives .sidebar bg. ---- */
  --side-bg:        #ffffff;
  --side-bg-2:      #f2f5f9;
  --side-grad:      linear-gradient(180deg, #111c30 0%, #0c1320 100%);
  --side-text:      #2c333f;
  --side-muted:     #8a93a3;
  --side-section:   #8a93a3; /* sidebar section labels (light) */
  --side-hover:     color-mix(in srgb, var(--hr-primary) 7%, transparent);
  --side-active-bg: color-mix(in srgb, var(--hr-primary) 12%, transparent);
  --side-active-tx: var(--brand-700);
  --side-active-bar:var(--hr-primary);
  --side-w:         264px;
  --side-w-collapsed: 76px;

  /* ---- Topbar ---- */
  --top-h:          62px;

  /* ---- Typography ---- */
  --font:    "Noto Sans Thai","Noto Sans Myanmar","Noto Sans Khmer","Noto Sans Lao","Sarabun",system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
  --fs-xs:   .75rem;     /* 12 */
  --fs-sm:   .8125rem;   /* 13 */
  --fs-md:   .875rem;    /* 14 */
  --fs-base: .9375rem;   /* 15 */
  --fs-lg:   1.0625rem;  /* 17 */
  --fs-xl:   1.25rem;    /* 20 */
  --fs-2xl:  1.5rem;     /* 24 */
  --fs-3xl:  1.875rem;   /* 30 */
  --fs-num:  1.75rem;    /* dashboard numbers */
  --fw-normal:400; --fw-medium:500; --fw-semibold:600; --fw-bold:700; --fw-black:800;
  --lh-tight:1.2; --lh:1.5; --lh-loose:1.7;

  /* ---- Spacing (4px base) ---- */
  --sp-1:.25rem; --sp-2:.5rem; --sp-3:.75rem; --sp-4:1rem; --sp-5:1.25rem;
  --sp-6:1.5rem; --sp-8:2rem; --sp-10:2.5rem; --sp-12:3rem;

  /* ---- Radius ---- */
  --r-xs:6px; --r-sm:9px; --r-md:13px; --r-lg:16px; --r-xl:20px; --r-2xl:26px; --r-pill:999px;

  /* ---- Shadows (soft, layered) ---- */
  --sh-xs: 0 1px 2px rgba(15,23,42,.05);
  --sh-sm: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --sh-card: 0 1px 2px rgba(16,24,40,.04), 0 2px 6px rgba(16,24,40,.05);
  --sh-md: 0 6px 16px rgba(15,23,42,.07), 0 2px 6px rgba(15,23,42,.04);
  --sh-lg: 0 14px 32px rgba(15,23,42,.12), 0 4px 12px rgba(15,23,42,.06);
  --sh-dropdown: 0 10px 34px rgba(15,23,42,.16);
  /* F-12 focus indicator: --ring-outline is the load-bearing SOLID outline (WCAG 1.4.11 ≥3:1,
     survives overflow:hidden ancestors); --ring is a reinforcing soft halo. */
  /* TODO(dark-mode audit): F-12 — re-verify the soft-halo --ring alpha (.55) contrast in BOTH
     light & dark during the deferred dark-mode pass; do NOT tune now (light+dark sensitive). */
  --ring:         0 0 0 3px color-mix(in srgb, var(--hr-primary) 55%, transparent);
  --ring-outline: var(--hr-primary); /* brand-aware solid outline */
  --scroll-thumb: #cbd3e1; /* F-12/dark: tokenized scrollbar (dark override in dark block) */

  /* ---- Motion ---- */
  --ease: cubic-bezier(.4,0,.2,1);
  --t-fast:120ms; --t:180ms; --t-slow:280ms;

  /* ---- Z-index scale ---- */
  --z-side:1040; --z-top:1030; --z-bottomnav:1050; --z-dropdown:1060; --z-modal:1070; --z-toast:1090;

  /* ---- Chart palette (read by dashboard.js via getComputedStyle) ---- */
  --c-1:#4f46e5; --c-2:#0891b2; --c-3:#059669; --c-4:#d97706;
  --c-5:#e11d48; --c-6:#7c3aed; --c-7:#0ea5e9; --c-8:#94a3b8;
  --c-grid:#eef1f6; --c-axis:#9aa4b6; --c-track:#eef1f6;

  /* ---- Back-compat aliases (legacy --hr-* used by existing views).
         NOTE: --hr-primary / --hr-primary-hover are the BRAND SOURCE, set per-preset in
         Block A — do NOT re-alias them here (would create a circular var() reference). ---- */
  --hr-primary-dark: var(--brand-700);
  --hr-secondary: var(--secondary);
  --hr-success: var(--success);
  --hr-warning: var(--warning);
  --hr-danger: var(--danger);
  --hr-info: var(--info);
  --hr-bg: var(--bg);
  --hr-surface: var(--surface);
  --hr-text: var(--text);
  --hr-muted: var(--muted);
  --hr-border: var(--border);
  --hr-radius: var(--r-md);
  --hr-radius-sm: var(--r-sm);
  --hr-shadow: var(--sh-card);
  --hr-shadow-lg: var(--sh-lg);
  --hr-sidebar-w: var(--side-w);
  --hr-font: var(--font);
}

/* ---- Dark theme (toggle: <html data-theme="dark"> via theme.js) ---- */
[data-theme="dark"] {
  --bg:        #0b1120;
  --surface:   #121c30;
  --surface-2: #0e1729;
  --surface-3: #18233c;
  --elevated:  #16223a;
  --border:    #586691; /* dark: lifted from #233149 (1.44:1) → 3.3:1 for WCAG 1.4.11 boundary */
  --border-2:  #6678a8; /* dark: lifted from #2c3a54 → 3.9:1 (inputs/controls/dividers) */
  --text:      #e6ebf4;
  --text-2:    #9aa6bd;
  --muted:     #828ca1; /* F-01 dark: lifted from #6b7689 (3.4–4.1:1, failed AA) → ≥4.5:1 on all dark surfaces */
  /* sidebar (dark navy) — overrides the light :root sidebar tokens; Block C drives .sidebar bg */
  --side-bg:        #0e1626;
  --side-bg-2:      #0a111e;
  --side-text:      #c4cee0;
  --side-muted:     #6c7891;
  --side-section:   #828ea8;
  --side-hover:     rgba(255,255,255,.06);
  --side-active-bg: color-mix(in srgb, var(--hr-primary) 22%, transparent);
  --side-active-tx: #ffffff;
  --brand-soft:   color-mix(in srgb, var(--hr-primary) 22%, transparent);
  --brand-soft-2: color-mix(in srgb, var(--hr-primary) 30%, transparent);
  --success-soft: rgba(5,150,105,.16);
  --warning-soft: rgba(217,119,6,.16);
  --danger-soft:  rgba(225,29,72,.16);
  --info-soft:    rgba(8,145,178,.16);
  --secondary-soft: rgba(100,116,139,.18);
  /* dark semantic TEXT (verified: ≥4.5:1 on dark soft-tints + surface) */
  --success-text: #34d399; --warning-text: #fbbf24; --danger-text: #fb7185;
  --info-text: #38bdf8; --secondary-text: #94a3b8;
  --brand-text: color-mix(in srgb, var(--hr-primary) 60%, #fff); /* brand-aware link/soft-primary text on dark */
  --sh-card: 0 1px 2px rgba(0,0,0,.4);
  --sh-md: 0 6px 16px rgba(0,0,0,.45);
  --sh-lg: 0 14px 32px rgba(0,0,0,.55);
  --sh-dropdown: 0 10px 34px rgba(0,0,0,.6);
  /* F-12: lighter focus indicator on near-black surfaces (brand-aware, derived from --hr-primary) */
  --ring:         0 0 0 3px color-mix(in srgb, var(--brand-400) 65%, transparent);
  --ring-outline: var(--brand-400);
  --scroll-thumb: #33415a;
  --c-grid:#1e293b; --c-axis:#8b97ab; --c-track:#1e293b; /* axis lifted #64748b(3.96)→6.4:1 */
  /* map Bootstrap body/control vars เข้า dark token — แก้บั๊ก input/form-control ขาวล้วนใน dark
     (Bootstrap form-control ใช้ --bs-body-bg/-color; เดิมค้าง #fff/#212529 ในหน้า full-load: payslip unlock, login, invite) */
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-3);
  --bs-border-color: var(--border);
  --bs-secondary-color: var(--text-2);
  color-scheme: dark;
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.001ms !important; transition-duration:.001ms !important; }
}
