/* =====================================================================
   Design tokens. Components use only these variables, never raw hex.

   Brief
   - Style: clean commerce, soft surfaces, one primary, calm motion
   - Color: 1 primary (per skin) + 1 accent (amber) + slate neutrals
   - Type: Prompt (headings) / IBM Plex Sans Thai (body), 16px base, lh 1.6
   - Space: 4px base scale   - Radius: 10px controls, 16px cards
   - Motion: 150-250ms, transform/opacity only, off for reduced-motion

   Skins: <html data-skin="indigo|ocean|emerald|sunset|rose|mono|ember">  (+ "console" for the back office)
   Mode:  <html data-mode="light|dark">  (set before paint by inline script)
   Contrast: text on primary >= 4.5:1 in every skin and mode.
   ===================================================================== */

:root {
  /* Type */
  --font-heading: "Prompt", "IBM Plex Sans Thai", system-ui, sans-serif;
  --font-body: "IBM Plex Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-xs: 0.8125rem;   /* 13px: badges, meta only */
  --fs-sm: 0.875rem;    /* 14px */
  --fs-md: 1rem;        /* 16px body */
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: clamp(1.5rem, 1.2rem + 1.5vw, 2.25rem);
  --fs-3xl: clamp(1.875rem, 1.4rem + 2.4vw, 3rem);
  --lh-body: 1.6;
  --lh-tight: 1.25;

  /* Space (4px scale) */
  --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;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;
  --tap: 44px;               /* minimum touch target */
  --container: 72rem;

  /* Motion */
  --dur-fast: 150ms;
  --dur-base: 220ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* Accent (shared by all skins) */
  --color-accent: #f59e0b;
  --color-on-accent: #1c1917;

  /* ---------- Light neutrals ---------- */
  --color-bg: #f6f7fb;
  --color-surface: #ffffff;
  --color-surface-2: #eef0f6;
  --color-text: #0f172a;
  --color-text-muted: #475569;      /* 7.5:1 on surface */
  --color-border: #d8dce6;
  --color-border-strong: #94a3b8;

  --color-success: #047857;  --color-success-soft: #d1fae5;
  --color-warning: #92400e;  --color-warning-soft: #fef3c7;
  --color-danger:  #b91c1c;  --color-danger-soft:  #fee2e2;
  --color-info:    #1d4ed8;  --color-info-soft:    #dbeafe;

  --shadow-sm: 0 1px 2px rgb(15 23 42 / 0.06);
  --shadow-md: 0 4px 16px rgb(15 23 42 / 0.08);

  /* ---------- Default skin: indigo ---------- */
  --color-primary: #4338ca;          /* 7.0:1 with white */
  --color-primary-hover: #3730a3;
  --color-on-primary: #ffffff;
  --color-primary-soft: #e0e7ff;
  --color-on-primary-soft: #312e81;

  --focus-ring: 0 0 0 3px var(--color-surface), 0 0 0 5px var(--color-primary);

  /* Glass surfaces + glow (v2 look). Glass needs a solid fallback: see @supports in store.css/console.css. */
  --radius-xl: 24px;
  --color-hot: #dc2626; --color-on-hot: #ffffff;  /* "ขายดี" badge, 4.8:1 in both modes */
  --glass: color-mix(in srgb, var(--color-surface) 78%, transparent);
  --glass-border: color-mix(in srgb, var(--color-text) 10%, transparent);
  --glow: color-mix(in srgb, var(--color-primary) 35%, transparent);
  --hero-from: var(--color-primary-soft);
  --hero-to: var(--color-surface);

  color-scheme: light;
}

/* ---------- Skins (light) ---------- */
[data-skin="ocean"]   { --color-primary:#1d4ed8; --color-primary-hover:#1e40af; --color-primary-soft:#dbeafe; --color-on-primary-soft:#1e3a8a; }
[data-skin="emerald"] { --color-primary:#047857; --color-primary-hover:#065f46; --color-primary-soft:#d1fae5; --color-on-primary-soft:#064e3b; }
[data-skin="sunset"]  { --color-primary:#c2410c; --color-primary-hover:#9a3412; --color-primary-soft:#ffedd5; --color-on-primary-soft:#7c2d12; }
[data-skin="rose"]    { --color-primary:#be123c; --color-primary-hover:#9f1239; --color-primary-soft:#ffe4e6; --color-on-primary-soft:#881337; }
[data-skin="mono"]    { --color-primary:#18181b; --color-primary-hover:#3f3f46; --color-primary-soft:#e4e4e7; --color-on-primary-soft:#18181b; }

/* ---------- Dark mode tokens ---------- */
/* The inline script in <head> sets data-mode before first paint:
   saved choice first, otherwise the OS setting. */
[data-mode="dark"] {
  --color-bg: #0b1120;
  --color-surface: #111a2e;
  --color-surface-2: #1a2540;
  --color-text: #e5e9f2;
  --color-text-muted: #a3b0c5;      /* 7.4:1 on surface */
  --color-border: #2a3654;
  --color-border-strong: #4b5b7c;

  --color-success: #6ee7b7;  --color-success-soft: #0f3a2d;
  --color-warning: #fcd34d;  --color-warning-soft: #3a2c0b;
  --color-danger:  #fca5a5;  --color-danger-soft:  #3f1717;
  --color-info:    #93c5fd;  --color-info-soft:    #142a52;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 6px 20px rgb(0 0 0 / 0.45);

  /* Light primary + dark text in dark mode keeps >= 8:1 */
  --color-primary: #a5b4fc;
  --color-primary-hover: #c7d2fe;
  --color-on-primary: #0b1120;
  --color-primary-soft: #232a5c;
  --color-on-primary-soft: #dfe5ff;

  color-scheme: dark;
}
[data-mode="dark"][data-skin="ocean"]   { --color-primary:#93c5fd; --color-primary-hover:#bfdbfe; --color-primary-soft:#142a52; --color-on-primary-soft:#dbeafe; }
[data-mode="dark"][data-skin="emerald"] { --color-primary:#6ee7b7; --color-primary-hover:#a7f3d0; --color-primary-soft:#0f3a2d; --color-on-primary-soft:#d1fae5; }
[data-mode="dark"][data-skin="sunset"]  { --color-primary:#fdba74; --color-primary-hover:#fed7aa; --color-primary-soft:#3b2210; --color-on-primary-soft:#ffedd5; }
[data-mode="dark"][data-skin="rose"]    { --color-primary:#fda4af; --color-primary-hover:#fecdd3; --color-primary-soft:#3d1520; --color-on-primary-soft:#ffe4e6; }
[data-mode="dark"][data-skin="mono"]    { --color-primary:#e4e4e7; --color-primary-hover:#ffffff; --color-primary-soft:#27272a; --color-on-primary-soft:#f4f4f5; }

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; }
}

/* ---------- Ember: warm dark storefront (black + orange glass) ----------
   Light: orange-700 on cream, white text on primary 5.2:1.
   Dark (default for this skin): orange-400 on near-black with near-black text on primary 8.9:1. */
[data-skin="ember"] {
  --color-bg: #fbf7f3; --color-surface: #ffffff; --color-surface-2: #f4ebe3;
  --color-text: #1c1410; --color-text-muted: #5b4a3e; --color-border: #eadccf; --color-border-strong: #b49c89;
  --color-primary: #c2410c; --color-primary-hover: #9a3412; --color-on-primary: #ffffff;
  --color-primary-soft: #ffedd5; --color-on-primary-soft: #7c2d12;
  --color-accent: #ea580c; --color-on-accent: #ffffff;
  --hero-from: #fff1e6; --hero-to: #ffffff;
}
[data-mode="dark"][data-skin="ember"] {
  --color-bg: #0c0907; --color-surface: #1a1410; --color-surface-2: #261d17;
  --color-text: #f7efe8; --color-text-muted: #c8b6a8;      /* 8.6:1 on surface */
  --color-border: #3a2c22; --color-border-strong: #6b5444;
  --color-primary: #fb923c; --color-primary-hover: #fdba74; --color-on-primary: #1c0a00;
  --color-primary-soft: #3b2210; --color-on-primary-soft: #ffedd5;
  --color-accent: #fb923c; --color-on-accent: #1c0a00;
  --glow: rgb(251 146 60 / 0.28);
  --hero-from: #2a1709; --hero-to: #120d0a;
  --shadow-md: 0 10px 30px rgb(0 0 0 / 0.55);
}

/* ---------- Console: back office (CRM look: white cards, royal blue, soft blue shadows) ----------
   Light: navy text on white, blue-600 primary with white text 6.4:1.
   Dark: periwinkle primary with navy text 8:1. Chart colors keep >= 3:1 against the card surface. */
[data-skin="console"] {
  --color-bg: #f1f3fb; --color-surface: #ffffff; --color-surface-2: #f5f7fe;
  --color-text: #12163a; --color-text-muted: #5a6080; --color-border: #e5e8f4; --color-border-strong: #a7aecb;
  --color-primary: #3b4ef0; --color-primary-hover: #2f3fd6; --color-on-primary: #ffffff;
  --color-primary-soft: #eaedff; --color-on-primary-soft: #2633b5;
  --color-success: #0f7a55; --color-success-soft: #e3f6ee;
  --color-warning: #9a5a00; --color-warning-soft: #fff3df;
  --color-danger:  #c52b3d; --color-danger-soft:  #fde8eb;
  --color-info:    #2633b5; --color-info-soft:    #eaedff;
  --color-violet: #6d3fd6; --color-violet-soft: #f1ebff;
  --hero-from: #4c5ef7; --hero-to: #3240e6; --on-hero: #ffffff; --on-hero-muted: #dfe3ff; --hero-accent: #ffffff; --hero-down: #ffd0d6;
  --chart-1: #3b4ef0; --chart-2: #6f86f7; --chart-3: #e07a10; --chart-4: #27a376; --chart-5: #8a90a6; --chart-6: #8b5cf6;
  --chart-track: #eceffa;
  --tone-blue: #3b4ef0; --tone-blue-2: #5b6cf8; --tone-green: #0f7a55; --tone-green-2: #22a374;
  --tone-amber: #b45309; --tone-amber-2: #d97706; --tone-violet: #6d3fd6; --tone-violet-2: #8b5cf6;  /* white icons >= 3:1 */
  --card-shadow: 0 1px 2px rgb(18 22 58 / 0.04), 0 14px 34px -14px rgb(59 78 240 / 0.18);
  --card-shadow-hover: 0 2px 4px rgb(18 22 58 / 0.05), 0 22px 44px -16px rgb(59 78 240 / 0.28);
  --glow: rgb(59 78 240 / 0.14);
}
[data-mode="dark"][data-skin="console"] {
  --color-bg: #0a0d1f; --color-surface: #131834; --color-surface-2: #1a2045;
  --color-text: #eef0ff; --color-text-muted: #a8aed2; --color-border: #252c57; --color-border-strong: #4a538a;
  --color-primary: #8f9cff; --color-primary-hover: #b3bcff; --color-on-primary: #0a0d1f;
  --color-primary-soft: #232a66; --color-on-primary-soft: #e3e7ff;
  --color-success: #6ee7b7; --color-success-soft: #0f3a2d;
  --color-warning: #fcd34d; --color-warning-soft: #3a2c0b;
  --color-danger:  #fca5a5; --color-danger-soft:  #3f1717;
  --color-info:    #b3bcff; --color-info-soft:    #232a66;
  --color-violet: #c4b5fd; --color-violet-soft: #2a1f55;
  --hero-from: #4c5ef7; --hero-to: #2a37c4; --on-hero: #ffffff; --on-hero-muted: #dfe3ff; --hero-accent: #ffffff; --hero-down: #ffd0d6;
  --chart-1: #8f9cff; --chart-2: #5b6ef5; --chart-3: #fbbf24; --chart-4: #34d399; --chart-5: #94a3b8; --chart-6: #c4b5fd;
  --chart-track: #222a55;
  --card-shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 16px 36px -16px rgb(0 0 0 / 0.7);
  --card-shadow-hover: 0 2px 4px rgb(0 0 0 / 0.45), 0 24px 44px -16px rgb(0 0 0 / 0.75);
  --glow: rgb(143 156 255 / 0.12);
}
