/* =============================================================================
   Design Tokens — single source of truth for light + dark palettes.
   Light defaults live in :root; dark overrides live in [data-theme="dark"].
   Keep both blocks side by side when editing colors so they never drift apart.
   ============================================================================= */

:root {
  /* ── Colour scheme ──
     Tells the browser which palette to render its OWN chrome in: scrollbars
     on every scrollable element, form controls, textarea resize grips, the
     canvas behind the page. Without it the browser assumes light and paints
     white scrollbars over the dark theme on any surface our CSS has not
     explicitly claimed - which is most of them. Set it here rather than in a
     component file: it has to be on the element the theme attribute lives on
     so it cascades to everything, vendor widgets included. ── */
  color-scheme: light;

  /* ── Brand Colors ──
     --color-primary-rgb is the same color as --color-primary, spelled out as
     an "r, g, b" triplet so it can sit inside rgba(var(--color-primary-rgb), a)
     for a tinted background/shadow - a bare hex can't go inside rgba(). Every
     such tint in the codebase should be built this way, not a hardcoded
     rgba(R,G,B,a) triplet, so a palette switch (Wachi.UI.applyPalette) can
     retint it just by setting these two custom properties. ── */
  --color-primary:        #102a43;
  --color-primary-rgb:    16, 42, 67;
  --color-primary-hover:  #0b1f2c;
  --color-accent:         #102a43;
  --color-on-accent:      #ffffff;
  --color-secondary:      #3b82f6;
  --color-link:           #102a43;

  /* Bootstrap ships these as its own stock blue at :root; point them at our
     brand color instead (Bootstrap 5's compiled CSS already reads .btn-primary/
     badges/pagination-active etc. from var(--bs-primary), so this is enough -
     no SCSS recompile needed). Dark mode does the same in its own block below,
     which is how that theme's primary has been able to differ from Bootstrap's
     default at all. */
  --bs-primary:            var(--color-primary);
  --bs-primary-rgb:        var(--color-primary-rgb);

  /* ── Neutral Palette ── */
  --color-bg-app:         #f6f7f9;
  --color-bg-white:       #ffffff;
  --color-bg-surface:     #f8f9fb;
  --color-bg-header:      #f7f9fc;

  --color-text-primary:   #111111;
  --color-text-secondary: #333333;
  --color-text-muted:     #667085;
  --color-text-light:     #5b6472;
  --color-text-white:     #ffffff;
  --color-text-sky:       #87ceeb;
  --color-text-blue:      #4da6ff;

  --color-border:         #e4e8ee;
  --color-border-light:   #eef1f5;
  --color-border-medium:  #d0d0d0;
  --color-border-input:   #cfd6e0;

  /* ── Dark Surfaces (Topbar / Sidebar) ── */
  --color-dark-bg:        #102a43;
  --color-dark-surface:   #2d2d30;
  --color-dark-hover:     #3a3a3e;
  --color-dark-active:    #3e3e42;
  --color-dark-border:    #3a3a3d;
  --color-dark-text:      #cccccc;
  --color-dark-text-dim:  #a0a0a0;
  --color-dark-text-muted:#888888;

  /* ── Status / Badge ── */
  --color-status-active-bg:   #dff6dd;
  --color-status-active-fg:   #1e7e1e;
  --color-status-inactive-bg: #fde7e7;
  --color-status-inactive-fg: #c42b1c;
  --color-status-pending-bg:  #fff4ce;
  --color-status-pending-fg:  #ffc107;

  /* ── Soft status pills (badge with a shape mark) - tinted fill, dark ink ── */
  --pill-secondary-bg: #eef0f3;  --pill-secondary-fg: #475467;
  --pill-warning-bg:   #fff1cc;  --pill-warning-fg:   #855400;
  --pill-primary-bg:   rgba(var(--color-primary-rgb), .10);  --pill-primary-fg: var(--color-primary);
  --pill-success-bg:   #e1f4e8;  --pill-success-fg:   #146c43;
  --pill-danger-bg:    #fde7e7;  --pill-danger-fg:    #b42318;
  --pill-info-bg:      #e0f2fe;  --pill-info-fg:      #026aa2;

  /* Behind the workspace card (UI_UX_RULES §10.6). */
  --color-bg-frame:    #e9edf2;

  /* ── Selection ── */
  /* Tints of the brand colour rather than a fixed blue, so they follow the
     palette the user picked (UI_UX_RULES §10). */
  --color-row-selected:   rgba(var(--color-primary-rgb), .10);
  --color-row-hover:      rgba(var(--color-primary-rgb), .04);

  /* ── Scrollbars ── */
  --scrollbar-thumb:       #c3cad5;
  --scrollbar-thumb-hover: #98a2b3;
  --scrollbar-track:       #f3f5f8;

  /* ── Emphasis text on tinted warning backgrounds (darker than
        --color-status-pending-fg so it stays readable on light bg) ── */
  --color-warning-strong: #b38600;

  /* ── Typography (เพิ่มการรองรับฟอนต์ไทย Sarabun สมบูรณ์แบบ) ── */
  --font-family:          'Inter', 'Sarabun', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --font-mono:            Consolas, 'Courier New', monospace;
  --font-size-base:       12px;
  --font-size-xs:         10px;
  --font-size-sm:         10.5px;
  --font-size-md:         11px;
  --font-size-lg:         11.5px;
  --font-size-title:      14px;
  --line-height:          1.35;

  /* ── Spacing ── */
  --space-1:  2px;
  --space-2:  3px;
  --space-3:  4px;
  --space-4:  5px;
  --space-5:  6px;
  --space-6:  8px;
  --space-8:  10px;
  --space-10: 12px;
  --space-12: 14px;
  --space-16: 16px;

  /* ── Component Sizes ── */
  --topbar-height:            32px;
  --sidebar-width:            200px;
  --sidebar-collapsed-width:  56px;
  --icon-size:                14px;
  --icon-size-sm:             12px;
  --icon-size-lg:             16px;
  --icon-size-xl:             20px;
  --row-height:               26px;
  --header-height:            28px;
  --page-bar-height:          30px;
  --title-row-height:         32px;
  --cmd-bar-height:           28px;
  --tab-bar-height:           26px;
  --status-bar-height:        22px;
  --btn-height:               22px;

  /* ── Radius ── */
  --radius-sm:   6px;
  --radius-md:   10px;
  /* For large surfaces - module tiles, empty states, panels. 6px on a 200px
     box reads as a 2014 card; the small radii above stay right for buttons
     and inputs, which is why this is a separate token rather than a bump. */
  --radius-lg:   12px;
  --radius-full: 50%;

  /* ── Elevation & UI Motion ── */
  --elevation-1:      0 1px 2px rgba(var(--color-primary-rgb), .06), 0 1px 3px rgba(var(--color-primary-rgb), .04);
  --elevation-2:      0 4px 12px rgba(var(--color-primary-rgb), .08);
  --elevation-3:      0 16px 36px rgba(var(--color-primary-rgb), .12);
  --elevation-topbar: 0 1px 0 rgba(var(--color-primary-rgb), .08);
  /* Focus halo on inputs and buttons - one tint, in the brand colour. */
  --focus-ring:       0 0 0 3px rgba(var(--color-primary-rgb), .14);
  --surface-sheen:    linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0));
  --transition-ui:    180ms cubic-bezier(.2,.9,.3,1);

  /* ── Theme Mapping Variables ── */
  --card-bg:         var(--color-bg-white);
  --border-color:    var(--color-border);
  --topbar-bg:       var(--color-dark-bg);
  --topbar-text:     var(--color-text-white);
  --sidebar-bg:      var(--color-bg-white);
  --sidebar-text:    var(--color-text-primary);
  --surface-bg:      var(--color-bg-surface);
  --content-bg:      var(--color-bg-app);
  --pagebar-bg:      var(--color-bg-white);
  --pagebar-border:  var(--color-border);
}

[data-theme="dark"] {
  /* Browser-drawn chrome follows the theme - see the note in :root. */
  color-scheme: dark;

  /* Custom Design Tokens */
  --color-primary:        #6366f1;
  --color-primary-rgb:    99, 102, 241;
  --color-primary-hover:  #8b5cf6;
  --color-accent:         #6366f1;
  --color-on-accent:      #ffffff;
  --color-secondary:      #3b82f6;
  --color-link:           #6366f1;
  --color-bg-app:         #07101f;
  --color-bg-white:       #0a1425;
  --color-bg-surface:     rgba(13,24,42,.82);
  --color-bg-header:      #111a20;
  --color-text-primary:   #eef3fb;
  --color-text-secondary: #8997ad;
  --color-text-muted:     #74839a;
  --color-text-light:     #eef3fb;
  --color-text-white:     #ffffff;
  --color-text-black:     #000000;
  --color-text-sky:       #72c2ff;
  --color-border:         rgba(255,255,255,.07);
  --color-border-light:   rgba(255,255,255,.05);
  --color-border-medium:  rgba(255,255,255,.08);
  --color-border-input:   rgba(255,255,255,.12);
  --color-dark-bg:        #07101f;
  --color-dark-surface:   rgba(13,24,42,.82);
  --color-dark-hover:     #0a1425;
  --color-dark-active:    #050a13;
  --color-dark-border:    rgba(255,255,255,.09);
  --color-dark-text:      #eef3fb;
  --color-dark-text-dim:  #8997ad;
  --color-dark-text-muted:#74839a;
  --color-status-active-bg:   #1a3d1a;
  --color-status-active-fg:   #4caf50;
  --color-status-inactive-bg: #3d1a1a;
  --color-status-inactive-fg: #f44336;
  --color-status-pending-bg:  #3d3a1a;
  --color-status-pending-fg:  #ffc107;
  --color-row-selected:   rgba(var(--color-primary-rgb),.12);
  --pill-secondary-bg: rgba(255,255,255,.08);  --pill-secondary-fg: #c1c9d6;
  --pill-warning-bg:   rgba(255,193,7,.15);    --pill-warning-fg:   #ffd666;
  --pill-primary-bg:   rgba(var(--color-primary-rgb), .22);
  --pill-primary-fg:   color-mix(in srgb, var(--color-primary) 45%, #ffffff);
  --pill-success-bg:   rgba(76,175,80,.16);    --pill-success-fg:   #7bd88f;
  --pill-danger-bg:    rgba(244,67,54,.16);    --pill-danger-fg:    #ff8a80;
  --pill-info-bg:      rgba(13,202,240,.14);   --pill-info-fg:      #67d4f5;
  --color-bg-frame:    #040912;
  --color-row-hover:      #0a1425;
  /* Solid values, not white-alpha: these are the colours dark mode has
     actually been shipping. theme-dark.css used to hardcode them with
     !important, which quietly beat the rgba() tokens that used to sit
     here - so the tokens were dead and the hex was the real palette.
     Folded back in here so there is one source again. */
  --scrollbar-thumb:       #26314f;
  --scrollbar-thumb-hover: #34456b;
  --scrollbar-track:       #050a13;
  --color-warning-strong: #ffc107;
  --elevation-1: 0 1px 4px rgba(0,0,0,0.3);
  --elevation-2: 0 6px 20px rgba(0,0,0,0.4);
  --elevation-3: 0 18px 40px rgba(0,0,0,0.5);
  --elevation-topbar: 0 2px 8px rgba(0,0,0,0.3);
  --topbar-bg:       #07101f;
  --topbar-text:     var(--color-dark-text);
  --sidebar-bg:      #0a1425;
  --sidebar-text:    var(--color-text-primary);
  --surface-bg:      rgba(13,24,42,.82);
  --content-bg:      #07101f;
  --pagebar-bg:      #0a1425;
  --pagebar-border:  rgba(255,255,255,.08);
  
  /* Bootstrap Variable Overrides (for components using --bs-* variables) */
  --bs-body-bg:           #07101f;
  --bs-body-color:        #eef3fb;
  --bs-secondary-color:   #8997ad;
  --bs-tertiary-bg:       rgba(13,24,42,.82);
  --bs-border-color:      rgba(255,255,255,.08);
  --bs-primary:           var(--color-primary);
  --bs-primary-rgb:       var(--color-primary-rgb);
}
