/* ============================================================
   K.W. Products — Design Tokens
   Single source of truth for color, spacing, type, motion.
   Loaded BEFORE all other stylesheets.
   ============================================================ */

:root {
  /* ---------- Color — Primary (Green) ---------- */
  --color-primary-50:  #f0faf0;
  --color-primary-100: #dcf2dd;
  --color-primary-200: #bbe5be;
  --color-primary-300: #8bce92;
  --color-primary-400: #5caf66;
  --color-primary-500: #3d944a;
  --color-primary-600: #2d6a3e;   /* brand */
  --color-primary-700: #245233;
  --color-primary-800: #1e4228;
  --color-primary-900: #163020;

  --color-accent-400:  #aed581;
  --color-accent-500:  #8bc34a;
  --color-accent-600:  #6fa03b;

  /* ---------- Color — Neutrals ---------- */
  --color-gray-50:  #f8fafc;
  --color-gray-100: #f1f5f9;
  --color-gray-200: #e2e8f0;
  --color-gray-300: #cbd5e1;
  --color-gray-400: #94a3b8;
  --color-gray-500: #64748b;
  --color-gray-600: #475569;
  --color-gray-700: #334155;
  --color-gray-800: #1e293b;
  --color-gray-900: #0f172a;

  /* ---------- Color — Semantic ---------- */
  --color-success:       #15803d;
  --color-success-soft:  #dcfce7;
  --color-success-text:  #14532d;
  --color-danger:        #dc2626;
  --color-danger-soft:   #fee2e2;
  --color-danger-text:   #7f1d1d;
  --color-warning:       #d97706;
  --color-warning-soft:  #fef3c7;
  --color-warning-text:  #78350f;
  --color-info:          #0369a1;
  --color-info-soft:     #dbeafe;
  --color-info-text:     #0c4a6e;

  /* ---------- Surface / UI chrome ---------- */
  --color-bg:            #f6f8f6;
  --color-surface:       #ffffff;
  --color-surface-2:     #f8fafc;
  --color-surface-3:     #f1f5f9;
  --color-border:        #e5e7eb;
  --color-border-strong: #cbd5e1;

  --color-text:          #0f172a;
  --color-text-muted:    #475569;
  --color-text-soft:     #64748b;
  --color-text-invert:   #ffffff;

  /* Runtime-tintable (admin settings overrides via inline style) */
  --color-primary: var(--color-primary-600);
  --color-primary-hover: var(--color-primary-700);
  --color-accent:  var(--color-accent-500);

  /* ---------- Spacing (4px grid) ---------- */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-14: 56px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* ---------- Radii ---------- */
  --radius-xs:   4px;
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-full: 9999px;

  /* ---------- Shadows ---------- */
  --shadow-xs: 0 1px 2px rgba(15,23,42,0.06);
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-lg: 0 12px 24px rgba(15,23,42,0.10), 0 4px 8px rgba(15,23,42,0.06);
  --shadow-xl: 0 24px 48px rgba(15,23,42,0.14), 0 8px 16px rgba(15,23,42,0.08);
  --shadow-focus: 0 0 0 3px rgba(45,106,62,0.25);

  /* ---------- Typography ---------- */
  --font-sans: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans Thai', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

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

  /* Fluid type scale — scales between mobile and desktop */
  --fs-xs:   clamp(0.72rem, 0.70rem + 0.10vw, 0.78rem);
  --fs-sm:   clamp(0.82rem, 0.78rem + 0.20vw, 0.90rem);
  --fs-base: clamp(0.94rem, 0.90rem + 0.25vw, 1.00rem);
  --fs-lg:   clamp(1.05rem, 1.00rem + 0.35vw, 1.15rem);
  --fs-xl:   clamp(1.18rem, 1.08rem + 0.50vw, 1.35rem);
  --fs-2xl:  clamp(1.40rem, 1.22rem + 0.85vw, 1.75rem);
  --fs-3xl:  clamp(1.75rem, 1.45rem + 1.40vw, 2.35rem);
  --fs-4xl:  clamp(2.10rem, 1.60rem + 2.40vw, 3.10rem);

  --lh-tight:   1.2;
  --lh-snug:    1.35;
  --lh-normal:  1.5;
  --lh-relaxed: 1.65;

  --ls-tight:  -0.02em;
  --ls-snug:   -0.01em;
  --ls-normal: 0;

  /* ---------- Z-index scale ---------- */
  --z-base:      0;
  --z-dropdown:  100;
  --z-header:    1000;
  --z-overlay:   1100;
  --z-backdrop:  1200;
  --z-modal:     1300;
  --z-popover:   1400;
  --z-toast:     1500;

  /* ---------- Motion ---------- */
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
  --ease-inout: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-in:    cubic-bezier(0.7, 0, 0.84, 0);
  --dur-fast:   120ms;
  --dur-base:   200ms;
  --dur-slow:   320ms;

  /* ---------- Touch target ---------- */
  --touch-min: 44px;

  /* ---------- Layout ---------- */
  --container-max: 1280px;
  --container-pad: clamp(16px, 3vw, 32px);

  /* ---------- Legacy aliases (backward compat — do not remove) ---------- */
  --primary:       var(--color-primary-600);
  --primary-dark:  var(--color-primary-700);
  --primary-light: var(--color-primary-400);
  --accent:        var(--color-accent-500);
  --text-dark:     var(--color-text);
  --radius:        var(--radius-md);
  --shadow-md-legacy: var(--shadow-md);
}

/* ---------- Admin dark mode ---------- */
[data-theme="dark"],
body.dark-mode {
  --color-bg:            #0b1220;
  --color-surface:       #111a2e;
  --color-surface-2:     #162238;
  --color-surface-3:     #1d2c47;
  --color-border:        #27365a;
  --color-border-strong: #374868;

  --color-text:          #e6edf7;
  --color-text-muted:    #a5b0c2;
  --color-text-soft:     #8594ab;

  --color-success-soft:  #103b23;
  --color-success-text:  #a8e5bd;
  --color-danger-soft:   #3b1313;
  --color-danger-text:   #fca5a5;
  --color-warning-soft:  #3b2a10;
  --color-warning-text:  #fde68a;
  --color-info-soft:     #0f2a40;
  --color-info-text:     #bfdbfe;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.35);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.25);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.55), 0 4px 8px rgba(0,0,0,0.35);
  --shadow-xl: 0 24px 48px rgba(0,0,0,0.6);
}

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