/**
 * TINY SEED DESIGN SYSTEM v2.0
 * ============================
 * Unified design tokens, components, and utilities for Tiny Seed OS.
 * v2.0: Added warm earth palette, enhanced dark/light themes, premium
 *       components (tables, nav, toasts, empty states, typography system),
 *       and micro-interaction library from world-class design research.
 *
 * Usage:
 *   <link rel="stylesheet" href="tiny-seed-design-system.css">
 *   — OR inside an inline <style> block: @import url('tiny-seed-design-system.css');
 *
 * Modes:
 *   <html data-theme="light">  — customer-facing (CSA, Chef, Customer portals)
 *   <html data-theme="dark">   — admin dashboards (Accounting, Financial, Employee)
 *   Falls back to dark mode if no attribute is set.
 *
 * This file is ADDITIVE — it does NOT override existing :root unless you
 * opt in by adding data-theme to <html>. Existing files keep working as-is.
 */

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER 1: PRIMITIVE TOKENS (raw values, not used directly in components)
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Brand Green (OKLCH) ── */
  --ts-green-50:  oklch(0.97 0.04 155);
  --ts-green-100: oklch(0.93 0.08 155);
  --ts-green-200: oklch(0.87 0.14 155);
  --ts-green-300: oklch(0.80 0.18 155);
  --ts-green-400: oklch(0.74 0.20 155);
  --ts-green-500: oklch(0.68 0.19 155);   /* #22c55e equivalent — THE brand green */
  --ts-green-600: oklch(0.60 0.17 155);   /* #16a34a equivalent */
  --ts-green-700: oklch(0.52 0.15 155);
  --ts-green-800: oklch(0.43 0.12 155);
  --ts-green-900: oklch(0.34 0.09 155);

  /* ── Neutral (slate) ── */
  --ts-slate-50:  #f8fafc;
  --ts-slate-100: #f1f5f9;
  --ts-slate-200: #e2e8f0;
  --ts-slate-300: #cbd5e1;
  --ts-slate-400: #94a3b8;
  --ts-slate-500: #64748b;
  --ts-slate-600: #475569;
  --ts-slate-700: #334155;
  --ts-slate-800: #1e293b;
  --ts-slate-900: #0f172a;

  /* ── Warm Neutral (stone — for light-mode customer pages) ── */
  --ts-stone-50:  #fafaf9;
  --ts-stone-100: #f5f5f4;
  --ts-stone-200: #e7e5e4;
  --ts-stone-300: #d6d3d1;
  --ts-stone-400: #a8a29e;
  --ts-stone-500: #78716c;
  --ts-stone-600: #57534e;
  --ts-stone-700: #44403c;
  --ts-stone-800: #292524;
  --ts-stone-900: #1c1917;

  /* === WARM EARTH TOKENS === */

  /* ── Warm Earth (agriculture earth tones) ── */
  --ts-earth-50:  #fafaf8;
  --ts-earth-100: #f5f4f0;
  --ts-earth-200: #e8e6df;
  --ts-earth-300: #d4d1c7;
  --ts-earth-400: #a8a396;
  --ts-earth-500: #7c7768;
  --ts-earth-600: #5c5749;
  --ts-earth-700: #433f34;
  --ts-earth-800: #2a2720;
  --ts-earth-900: #1a1816;

  /* ── Harvest Gold ── */
  --ts-gold-50:  #fefbf0;
  --ts-gold-100: #fdf4d6;
  --ts-gold-200: #fbe8a8;
  --ts-gold-300: #f8d56e;
  --ts-gold-400: #f0bc3a;
  --ts-gold-500: #d4a574;   /* Brand gold accent */
  --ts-gold-600: #b8863a;
  --ts-gold-700: #8f6720;
  --ts-gold-800: #6b4d18;
  --ts-gold-900: #4a3510;

  /* ── Soil Brown (tertiary) ── */
  --ts-soil-400: #a67c52;
  --ts-soil-500: #8b6340;
  --ts-soil-600: #704e30;

  /* ── Sky Blue (water/irrigation) ── */
  --ts-sky-400: #60a5fa;
  --ts-sky-500: #3b82f6;
  --ts-sky-600: #2563eb;

  /* ── Accent palette ── */
  --ts-amber-400: #fbbf24;
  --ts-amber-500: #f59e0b;
  --ts-red-400:   #f87171;
  --ts-red-500:   #ef4444;
  --ts-blue-400:  #60a5fa;
  --ts-blue-500:  #3b82f6;
  --ts-purple-400:#a78bfa;
  --ts-purple-500:#8b5cf6;
  --ts-teal-400:  #2dd4bf;
  --ts-teal-500:  #14b8a6;

  /* ── Typography ── */
  --ts-font-sans: 'Inter', 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ts-font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

  /* Fluid type scale: min 320px → max 1280px */
  --ts-text-xs:   clamp(0.6875rem, 0.65rem + 0.1vw,  0.75rem);   /* 11-12px */
  --ts-text-sm:   clamp(0.8125rem, 0.78rem + 0.15vw, 0.875rem);   /* 13-14px */
  --ts-text-base: clamp(0.9375rem, 0.9rem  + 0.15vw, 1rem);       /* 15-16px */
  --ts-text-lg:   clamp(1.0625rem, 1rem    + 0.2vw,  1.125rem);   /* 17-18px */
  --ts-text-xl:   clamp(1.1875rem, 1.1rem  + 0.3vw,  1.25rem);    /* 19-20px */
  --ts-text-2xl:  clamp(1.375rem,  1.25rem + 0.4vw,  1.5rem);     /* 22-24px */
  --ts-text-3xl:  clamp(1.75rem,   1.5rem  + 0.6vw,  1.875rem);   /* 28-30px */
  --ts-text-4xl:  clamp(2.125rem,  1.8rem  + 1vw,    2.5rem);     /* 34-40px */

  /* ── Spacing scale (4px base) ── */
  --ts-space-1:  0.25rem;   /* 4px */
  --ts-space-2:  0.5rem;    /* 8px */
  --ts-space-3:  0.75rem;   /* 12px */
  --ts-space-4:  1rem;      /* 16px */
  --ts-space-5:  1.25rem;   /* 20px */
  --ts-space-6:  1.5rem;    /* 24px */
  --ts-space-8:  2rem;      /* 32px */
  --ts-space-10: 2.5rem;    /* 40px */
  --ts-space-12: 3rem;      /* 48px */
  --ts-space-16: 4rem;      /* 64px */

  /* ── Radius ── */
  --ts-radius-sm:   6px;
  --ts-radius-md:   10px;
  --ts-radius-lg:   16px;
  --ts-radius-xl:   24px;
  --ts-radius-full: 9999px;

  /* ── Shadows ── */
  --ts-shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --ts-shadow-sm:  0 2px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --ts-shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --ts-shadow-lg:  0 10px 25px rgba(0,0,0,0.10), 0 4px 10px rgba(0,0,0,0.05);
  --ts-shadow-xl:  0 20px 40px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.06);

  /* ── Transitions ── */
  --ts-ease-out:  cubic-bezier(0.16, 1, 0.3, 1);
  --ts-ease-in:   cubic-bezier(0.7, 0, 0.84, 0);
  --ts-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ts-dur-fast:   120ms;
  --ts-dur-normal: 200ms;
  --ts-dur-slow:   350ms;

  /* === EXTENDED PRIMITIVE TOKENS (from world-class research) === */

  /* ── Display font ── */
  --ts-font-display: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* ── Extended type scale ── */
  --ts-text-2xs:  0.694rem;   /* 11.1px */
  --ts-text-5xl:  3rem;       /* 48px */

  /* ── Line heights ── */
  --ts-leading-none:    1;
  --ts-leading-tight:   1.15;
  --ts-leading-snug:    1.3;
  --ts-leading-normal:  1.5;
  --ts-leading-relaxed: 1.625;
  --ts-leading-loose:   1.8;

  /* ── Letter spacing ── */
  --ts-tracking-tighter: -0.03em;
  --ts-tracking-tight:   -0.015em;
  --ts-tracking-normal:  0;
  --ts-tracking-wide:    0.025em;
  --ts-tracking-wider:   0.05em;
  --ts-tracking-widest:  0.1em;

  /* ── Extended spacing ── */
  --ts-space-0:   0;
  --ts-space-px:  1px;
  --ts-space-0\.5: 0.125rem;  /* 2px */
  --ts-space-1\.5: 0.375rem;  /* 6px */
  --ts-space-20: 5rem;        /* 80px */
  --ts-space-24: 6rem;        /* 96px */

  /* ── Extended radius ── */
  --ts-radius-none: 0;
  --ts-radius-2xl:  28px;

  /* ── Extended shadows ── */
  --ts-shadow-2xl:   0 25px 50px -12px rgba(0,0,0,0.15);
  --ts-shadow-inner: inset 0 2px 4px rgba(0,0,0,0.04);

  /* ── Glow shadows (accent elements) ── */
  --ts-glow-green: 0 0 20px oklch(0.68 0.19 155 / 0.25);
  --ts-glow-gold:  0 0 20px rgba(212, 165, 116, 0.25);
  --ts-glow-blue:  0 0 20px rgba(59, 130, 246, 0.25);

  /* ── Extended motion ── */
  --ts-ease-default: cubic-bezier(0.2, 0, 0, 1);    /* Productive motion */
  --ts-ease-bounce:  cubic-bezier(0.34, 1.8, 0.64, 1);
  --ts-dur-instant:  0ms;
  --ts-dur-moderate: 300ms;
  --ts-dur-slower:   600ms;

  /* ── Z-index scale ── */
  --ts-z-base:     0;
  --ts-z-raised:   1;
  --ts-z-dropdown: 10;
  --ts-z-sticky:   20;
  --ts-z-overlay:  30;
  --ts-z-modal:    40;
  --ts-z-toast:    50;
  --ts-z-tooltip:  60;

  /* === CHART / DATA VISUALIZATION COLORS === */
  --ts-chart-primary-100: oklch(0.68 0.19 155 / 1.0);
  --ts-chart-primary-60:  oklch(0.68 0.19 155 / 0.6);
  --ts-chart-primary-30:  oklch(0.68 0.19 155 / 0.3);
  --ts-chart-primary-10:  oklch(0.68 0.19 155 / 0.1);
  --ts-chart-1: oklch(0.68 0.19 155);   /* Green - primary */
  --ts-chart-2: #d4a574;                 /* Gold - accent */
  --ts-chart-3: #3b82f6;                 /* Blue */
  --ts-chart-4: #a78bfa;                 /* Purple */
  --ts-chart-5: #f59e0b;                 /* Amber */
  --ts-chart-6: #14b8a6;                 /* Teal */
}


/* ═══════════════════════════════════════════════════════════════════════════
   LAYER 2: SEMANTIC TOKENS (theme-aware, use these in components)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── WARM DARK THEME (default for admin dashboards) ──
   Inspired by Linear's restraint + agriculture warmth.
   Uses warm charcoal (#141211 base) instead of cool slate. */
[data-theme="dark"],
:root:not([data-theme]) {
  /* Backgrounds: warm charcoal with subtle brown undertone */
  --ts-bg-base:       #141211;   /* Deepest background */
  --ts-bg-subtle:     #1a1816;   /* Slightly raised */
  --ts-bg-surface:    #201e1b;   /* Card surfaces */
  --ts-bg-elevated:   #282520;   /* Elevated elements (dropdowns, popovers) */
  --ts-bg-overlay:    #302d27;   /* Highest elevation */
  --ts-bg-hover:      rgba(255, 255, 255, 0.04);
  --ts-bg-active:     rgba(255, 255, 255, 0.07);
  --ts-bg-selected:   oklch(0.68 0.19 155 / 0.08);
  --ts-bg-backdrop:   rgba(0, 0, 0, 0.7);

  /* Text */
  --ts-text:          #ece8e1;   /* Primary text - warm off-white */
  --ts-text-secondary: #a09888;  /* Secondary - warm gray */
  --ts-text-muted:    #6b6258;   /* Muted - warm dark gray */
  --ts-text-disabled: #4a4440;   /* Disabled */
  --ts-text-inverse:  #141211;   /* For use on light backgrounds */
  --ts-text-on-primary: #0a1208; /* Text on green backgrounds */

  /* Borders */
  --ts-border:        rgba(255, 255, 255, 0.06);   /* Subtle */
  --ts-border-strong: rgba(255, 255, 255, 0.10);   /* Emphasized */
  --ts-border-focus:  oklch(0.68 0.19 155 / 0.5);  /* Focus ring */
  --ts-border-hover:  rgba(255, 255, 255, 0.15);   /* Hover */

  /* Brand colors */
  --ts-primary:       var(--ts-green-500);
  --ts-primary-hover: var(--ts-green-400);
  --ts-primary-muted: oklch(0.68 0.19 155 / 0.12);
  --ts-primary-subtle:oklch(0.68 0.19 155 / 0.06);

  --ts-accent:        var(--ts-gold-500);
  --ts-accent-hover:  var(--ts-gold-400);
  --ts-accent-muted:  rgba(212, 165, 116, 0.12);

  /* Semantic colors */
  --ts-success:       #22c55e;
  --ts-success-muted: rgba(34, 197, 94, 0.12);
  --ts-warning:       #f59e0b;
  --ts-warning-muted: rgba(245, 158, 11, 0.12);
  --ts-danger:        #ef4444;
  --ts-danger-muted:  rgba(239, 68, 68, 0.12);
  --ts-info:          #3b82f6;
  --ts-info-muted:    rgba(59, 130, 246, 0.12);

  /* Shadows (darker for dark theme) */
  --ts-shadow-card:     0 2px 8px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.2);
  --ts-shadow-dropdown: 0 8px 30px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.3);
  --ts-shadow-modal:    0 24px 48px rgba(0,0,0,0.5), 0 12px 24px rgba(0,0,0,0.3);

  /* Glass / Frosted */
  --ts-glass-bg:      rgba(32, 30, 27, 0.75);
  --ts-glass-border:  rgba(255, 255, 255, 0.06);
  --ts-glass-blur:    16px;

  /* Gradients */
  --ts-gradient-primary: linear-gradient(135deg, var(--ts-green-500) 0%, var(--ts-green-600) 100%);
  --ts-gradient-accent:  linear-gradient(135deg, var(--ts-gold-400) 0%, var(--ts-gold-600) 100%);
  --ts-gradient-surface: linear-gradient(180deg, var(--ts-bg-surface) 0%, var(--ts-bg-subtle) 100%);
  --ts-gradient-glow:    radial-gradient(ellipse at top, oklch(0.68 0.19 155 / 0.08) 0%, transparent 70%);
}

/* ── WARM LIGHT THEME (customer-facing portals) ──
   Organic, crafted, approachable. Uses warm off-white (#fafaf8). */
[data-theme="light"] {
  /* Backgrounds */
  --ts-bg-base:       #fafaf8;   /* Warm off-white */
  --ts-bg-subtle:     #f5f4f0;   /* Barely visible contrast */
  --ts-bg-surface:    #ffffff;   /* White cards */
  --ts-bg-elevated:   #ffffff;   /* Elevated elements */
  --ts-bg-overlay:    #f0efe9;   /* Highest visual layer */
  --ts-bg-hover:      rgba(0, 0, 0, 0.03);
  --ts-bg-active:     rgba(0, 0, 0, 0.05);
  --ts-bg-selected:   oklch(0.68 0.19 155 / 0.06);
  --ts-bg-backdrop:   rgba(0, 0, 0, 0.5);

  /* Text */
  --ts-text:          #1a1816;   /* Warm near-black */
  --ts-text-secondary: #5c5749;  /* Warm dark gray */
  --ts-text-muted:    #a8a396;   /* Muted */
  --ts-text-disabled: #d4d1c7;   /* Disabled */
  --ts-text-inverse:  #fafaf8;
  --ts-text-on-primary: #ffffff;

  /* Borders */
  --ts-border:        rgba(0, 0, 0, 0.06);
  --ts-border-strong: rgba(0, 0, 0, 0.10);
  --ts-border-focus:  oklch(0.60 0.17 155 / 0.5);
  --ts-border-hover:  rgba(0, 0, 0, 0.15);

  /* Brand colors */
  --ts-primary:       var(--ts-green-600);   /* Slightly darker for light bg */
  --ts-primary-hover: var(--ts-green-700);
  --ts-primary-muted: oklch(0.60 0.17 155 / 0.08);
  --ts-primary-subtle:oklch(0.60 0.17 155 / 0.04);

  --ts-accent:        var(--ts-gold-600);
  --ts-accent-hover:  var(--ts-gold-700);
  --ts-accent-muted:  rgba(184, 134, 58, 0.08);

  /* Semantic */
  --ts-success:       #16a34a;
  --ts-success-muted: rgba(22, 163, 74, 0.08);
  --ts-warning:       #d97706;
  --ts-warning-muted: rgba(217, 119, 6, 0.08);
  --ts-danger:        #dc2626;
  --ts-danger-muted:  rgba(220, 38, 38, 0.08);
  --ts-info:          #2563eb;
  --ts-info-muted:    rgba(37, 99, 235, 0.08);

  /* Shadows (lighter for light theme) */
  --ts-shadow-card:     0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --ts-shadow-dropdown: 0 8px 24px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
  --ts-shadow-modal:    0 24px 48px rgba(0,0,0,0.12), 0 12px 24px rgba(0,0,0,0.06);

  /* Glass */
  --ts-glass-bg:      rgba(255, 255, 255, 0.7);
  --ts-glass-border:  rgba(0, 0, 0, 0.06);
  --ts-glass-blur:    16px;

  /* Gradients */
  --ts-gradient-primary: linear-gradient(135deg, var(--ts-green-500) 0%, var(--ts-green-600) 100%);
  --ts-gradient-accent:  linear-gradient(135deg, var(--ts-gold-500) 0%, var(--ts-gold-600) 100%);
  --ts-gradient-surface: linear-gradient(180deg, #ffffff 0%, var(--ts-bg-subtle) 100%);
  --ts-gradient-glow:    radial-gradient(ellipse at top, oklch(0.60 0.17 155 / 0.05) 0%, transparent 70%);
}


/* ═══════════════════════════════════════════════════════════════════════════
   BACKWARD-COMPATIBLE ALIASES
   Map legacy --primary, --bg-dark, etc. to the new system so existing
   code keeps working when this file is imported.
   ═══════════════════════════════════════════════════════════════════════════ */

[data-theme] {
  --primary:        var(--ts-primary);
  --primary-dark:   var(--ts-green-600);
  --secondary:      var(--ts-blue-500);
  --warning:        var(--ts-amber-500);
  --danger:         var(--ts-danger);
  --info:           var(--ts-info);
  --bg-dark:        var(--ts-bg-base);
  --bg-card:        var(--ts-bg-surface);
  --bg-hover:       var(--ts-bg-hover);
  --text:           var(--ts-text);
  --text-muted:     var(--ts-text-muted);
  --text-primary:   var(--ts-text);
  --text-secondary: var(--ts-text-secondary);
  --border:         var(--ts-border);
  --shadow:         var(--ts-shadow-md);
  --shadow-lg:      var(--ts-shadow-lg);
}


/* ═══════════════════════════════════════════════════════════════════════════
   LAYER 3: BASE RESET (opt-in via .ts-reset on <body>)
   Only applies when explicitly added — won't break existing pages.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-reset {
  margin: 0;
  font-family: var(--ts-font-sans);
  font-size: var(--ts-text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  background: var(--ts-bg-base);
  color: var(--ts-text);
}

.ts-reset *, .ts-reset *::before, .ts-reset *::after {
  box-sizing: border-box;
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: BUTTONS
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ts-space-2);
  padding: var(--ts-space-3) var(--ts-space-5);
  font-family: var(--ts-font-sans);
  font-size: var(--ts-text-sm);
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--ts-radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--ts-dur-fast) var(--ts-ease-out),
    border-color var(--ts-dur-fast) var(--ts-ease-out),
    box-shadow var(--ts-dur-fast) var(--ts-ease-out),
    transform var(--ts-dur-fast) var(--ts-ease-out);
  -webkit-user-select: none;
  user-select: none;
}

.ts-btn:active {
  transform: scale(0.97);
}

.ts-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Primary */
.ts-btn-primary {
  background: var(--ts-primary);
  color: #0a1628;
  box-shadow: 0 2px 8px oklch(0.68 0.19 155 / 0.30);
}
.ts-btn-primary:hover:not(:disabled) {
  background: var(--ts-primary-hover);
  box-shadow: 0 4px 14px oklch(0.68 0.19 155 / 0.40);
  transform: translateY(-1px);
}

/* Secondary / outline */
.ts-btn-secondary {
  background: transparent;
  color: var(--ts-text);
  border-color: var(--ts-border-strong);
}
.ts-btn-secondary:hover:not(:disabled) {
  background: var(--ts-bg-hover);
  border-color: var(--ts-primary);
}

/* Ghost */
.ts-btn-ghost {
  background: transparent;
  color: var(--ts-text-secondary);
}
.ts-btn-ghost:hover:not(:disabled) {
  background: var(--ts-bg-hover);
  color: var(--ts-text);
}

/* Danger */
.ts-btn-danger {
  background: var(--ts-danger);
  color: white;
}
.ts-btn-danger:hover:not(:disabled) {
  background: var(--ts-red-400);
  transform: translateY(-1px);
}

/* Sizes */
.ts-btn-sm {
  padding: var(--ts-space-2) var(--ts-space-3);
  font-size: var(--ts-text-xs);
  border-radius: var(--ts-radius-sm);
}
.ts-btn-lg {
  padding: var(--ts-space-4) var(--ts-space-6);
  font-size: var(--ts-text-base);
  min-height: 48px;
  border-radius: var(--ts-radius-lg);
}
.ts-btn-xl {
  padding: var(--ts-space-5) var(--ts-space-8);
  font-size: var(--ts-text-lg);
  min-height: 56px;
  border-radius: var(--ts-radius-lg);
}

/* Icon-only */
.ts-btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--ts-radius-md);
}

/* === EXTENDED BUTTON PATTERNS === */

/* Loading state */
.ts-btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.ts-btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ts-spin 600ms linear infinite;
}
.ts-btn-primary.ts-btn-loading::after {
  border-color: var(--ts-text-on-primary, #0a1208);
  border-right-color: transparent;
}

/* Button with subtle gradient (premium feel) */
.ts-btn-primary-gradient {
  background: linear-gradient(
    180deg,
    oklch(0.72 0.20 155) 0%,
    oklch(0.64 0.18 155) 100%
  );
  color: var(--ts-text-on-primary, #0a1208);
  border: 1px solid oklch(0.60 0.17 155 / 0.3);
  box-shadow:
    0 1px 2px rgba(0,0,0,0.1),
    inset 0 1px 0 oklch(0.80 0.18 155 / 0.3);
}
.ts-btn-primary-gradient:hover:not(:disabled) {
  background: linear-gradient(
    180deg,
    oklch(0.76 0.20 155) 0%,
    oklch(0.68 0.19 155) 100%
  );
  box-shadow:
    0 2px 8px oklch(0.68 0.19 155 / 0.3),
    inset 0 1px 0 oklch(0.80 0.18 155 / 0.3);
}

/* Button group */
.ts-btn-group {
  display: inline-flex;
  border-radius: var(--ts-radius-md);
  overflow: hidden;
}
.ts-btn-group .ts-btn {
  border-radius: 0;
  border-right: 1px solid var(--ts-border);
}
.ts-btn-group .ts-btn:first-child {
  border-radius: var(--ts-radius-md) 0 0 var(--ts-radius-md);
}
.ts-btn-group .ts-btn:last-child {
  border-radius: 0 var(--ts-radius-md) var(--ts-radius-md) 0;
  border-right: none;
}

/* Pill button (for filters/tags) */
.ts-btn-pill {
  border-radius: var(--ts-radius-full);
  padding: 6px var(--ts-space-4);
  font-size: var(--ts-text-xs);
  font-weight: 500;
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-card {
  position: relative;
  background: var(--ts-bg-surface);
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-lg);
  padding: var(--ts-space-6);
  box-shadow: var(--ts-shadow-card);
  transition:
    border-color var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out)),
    box-shadow var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out)),
    transform var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out)),
    background var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out));
}

.ts-card:hover {
  border-color: var(--ts-border-strong);
}

/* Interactive card: subtle lift on hover */
.ts-card-interactive {
  cursor: pointer;
}
.ts-card-interactive:hover {
  border-color: var(--ts-border-hover, var(--ts-primary));
  box-shadow: var(--ts-shadow-lg);
  transform: translateY(-2px);
}
.ts-card-interactive:active {
  transform: translateY(0);
  box-shadow: var(--ts-shadow-card);
}

/* Glass card (glassmorphism 2.0) */
.ts-card-glass {
  position: relative;
  background: var(--ts-glass-bg);
  backdrop-filter: blur(var(--ts-glass-blur, 16px)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--ts-glass-blur, 16px)) saturate(1.2);
  border: 1px solid var(--ts-glass-border);
  border-radius: var(--ts-radius-lg);
  padding: var(--ts-space-6);
  box-shadow: var(--ts-shadow-md);
}

/* Glow card: subtle accent glow on hover */
.ts-card-glow {
  position: relative;
  overflow: hidden;
}
.ts-card-glow::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: linear-gradient(
    135deg,
    oklch(0.68 0.19 155 / 0.15) 0%,
    transparent 50%,
    oklch(0.68 0.19 155 / 0.08) 100%
  );
  opacity: 0;
  transition: opacity var(--ts-dur-moderate, 300ms) var(--ts-ease-default, var(--ts-ease-out));
  z-index: -1;
}
.ts-card-glow:hover::before {
  opacity: 1;
}

/* Card with gradient top border (status/category indicator) */
.ts-card-accent {
  border-top: 2px solid var(--ts-primary);
}
.ts-card-accent-gold {
  border-top: 2px solid var(--ts-accent);
}
.ts-card-accent-danger {
  border-top: 2px solid var(--ts-danger);
}

/* Card header */
.ts-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ts-space-3);
  margin-bottom: var(--ts-space-4);
}

.ts-card-title {
  font-size: var(--ts-text-base);
  font-weight: 600;
  color: var(--ts-text);
  letter-spacing: var(--ts-tracking-tight, -0.015em);
}

.ts-card-subtitle {
  font-size: var(--ts-text-xs);
  font-weight: 500;
  color: var(--ts-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--ts-tracking-wider, 0.05em);
}

/* Card footer */
.ts-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ts-space-3);
  margin-top: var(--ts-space-4);
  padding-top: var(--ts-space-4);
  border-top: 1px solid var(--ts-border);
}

/* === PREMIUM STAT CARDS (enhanced) === */

.ts-stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--ts-space-2);
  padding: var(--ts-space-5);
  background: var(--ts-bg-surface);
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-lg);
  transition: all var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out));
}

.ts-stat-card:hover {
  border-color: var(--ts-border-strong);
}

/* Stat header row: icon + label */
.ts-stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ts-stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--ts-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.ts-stat-icon-green  { background: var(--ts-success-muted, oklch(0.68 0.19 155 / 0.12)); color: var(--ts-success, var(--ts-green-500)); }
.ts-stat-icon-gold   { background: var(--ts-accent-muted, rgba(212, 165, 116, 0.12));  color: var(--ts-accent);  }
.ts-stat-icon-blue   { background: var(--ts-info-muted, rgba(59, 130, 246, 0.12));    color: var(--ts-info);    }
.ts-stat-icon-red    { background: var(--ts-danger-muted, rgba(239, 68, 68, 0.12));  color: var(--ts-danger);  }

.ts-stat-value {
  font-size: var(--ts-text-3xl);
  font-weight: 700;
  line-height: var(--ts-leading-tight, 1.15);
  color: var(--ts-text);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--ts-tracking-tighter, -0.03em);
}

/* Animated value on load */
.ts-stat-value[data-animate] {
  animation: ts-count-up 500ms var(--ts-ease-out) both;
}

.ts-stat-label {
  font-size: var(--ts-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--ts-tracking-wider, 0.05em);
  color: var(--ts-text-muted);
}

.ts-stat-trend {
  display: inline-flex;
  align-items: center;
  gap: var(--ts-space-1);
  font-size: var(--ts-text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--ts-radius-full);
}
/* Legacy compat */
.ts-stat-trend.up   { color: var(--ts-green-500); }
.ts-stat-trend.down { color: var(--ts-red-500); }
/* New named variants */
.ts-stat-trend-up {
  color: var(--ts-success, var(--ts-green-500));
  background: var(--ts-success-muted, oklch(0.68 0.19 155 / 0.12));
}
.ts-stat-trend-down {
  color: var(--ts-danger);
  background: var(--ts-danger-muted, rgba(239, 68, 68, 0.12));
}
.ts-stat-trend-flat {
  color: var(--ts-text-muted);
  background: var(--ts-bg-hover);
}

/* Sparkline container (for inline mini charts) */
.ts-stat-sparkline {
  height: 32px;
  margin-top: var(--ts-space-2);
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: FORMS
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-input {
  width: 100%;
  padding: var(--ts-space-3) var(--ts-space-4);
  font-family: var(--ts-font-sans);
  font-size: var(--ts-text-base);
  line-height: 1.5;
  color: var(--ts-text);
  background: var(--ts-bg-surface);
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-md);
  outline: none;
  transition:
    border-color var(--ts-dur-fast) var(--ts-ease-out),
    box-shadow var(--ts-dur-fast) var(--ts-ease-out);
}

.ts-input::placeholder {
  color: var(--ts-text-muted);
}

.ts-input:hover {
  border-color: var(--ts-border-strong);
}

.ts-input:focus {
  border-color: var(--ts-primary);
  box-shadow: 0 0 0 3px var(--ts-primary-muted);
}

.ts-input-error {
  border-color: var(--ts-danger);
}
.ts-input-error:focus {
  box-shadow: 0 0 0 3px oklch(0.63 0.22 25 / 0.15);
}

.ts-label {
  display: block;
  font-size: var(--ts-text-sm);
  font-weight: 600;
  color: var(--ts-text);
  margin-bottom: var(--ts-space-2);
}

.ts-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23a09888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

/* === ENHANCED FORM COMPONENTS === */

/* Input group (label + input + helper text) */
.ts-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ts-field-label {
  font-size: var(--ts-text-sm);
  font-weight: 500;
  color: var(--ts-text);
}

.ts-field-required::after {
  content: ' *';
  color: var(--ts-danger);
}

.ts-field-helper {
  font-size: var(--ts-text-xs);
  color: var(--ts-text-muted);
}

.ts-field-error {
  font-size: var(--ts-text-xs);
  color: var(--ts-danger);
  display: flex;
  align-items: center;
  gap: var(--ts-space-1);
}

/* Enhanced input with inner left icon */
.ts-input-wrapper {
  position: relative;
}
.ts-input-wrapper .ts-input {
  padding-left: 40px;
}
.ts-input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ts-text-muted);
  font-size: 16px;
  pointer-events: none;
  transition: color var(--ts-dur-fast);
}
.ts-input-wrapper:focus-within .ts-input-icon {
  color: var(--ts-primary);
}

/* Search input specific */
.ts-search-input {
  background: var(--ts-bg-subtle, var(--ts-bg-surface));
  border-color: transparent;
}
.ts-search-input:focus {
  background: var(--ts-bg-surface);
  border-color: var(--ts-primary);
}

/* Toggle switch */
.ts-toggle {
  position: relative;
  width: 44px;
  height: 24px;
  appearance: none;
  background: var(--ts-bg-overlay, var(--ts-bg-elevated));
  border-radius: var(--ts-radius-full);
  border: 1px solid var(--ts-border);
  cursor: pointer;
  transition: all var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out));
}
.ts-toggle::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  top: 2px;
  left: 2px;
  background: var(--ts-text-secondary);
  border-radius: 50%;
  transition: all var(--ts-dur-normal) var(--ts-ease-spring);
}
.ts-toggle:checked {
  background: var(--ts-primary);
  border-color: var(--ts-primary);
}
.ts-toggle:checked::after {
  left: 22px;
  background: white;
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: BADGES & CHIPS
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--ts-space-1);
  padding: 2px var(--ts-space-2);
  font-size: var(--ts-text-xs);
  font-weight: 600;
  border-radius: var(--ts-radius-full);
  line-height: 1.4;
}

.ts-badge-green  { background: oklch(0.68 0.19 155 / 0.15); color: var(--ts-green-400); }
.ts-badge-red    { background: oklch(0.63 0.22 25 / 0.15);  color: var(--ts-red-400); }
.ts-badge-amber  { background: oklch(0.79 0.16 80 / 0.15);  color: var(--ts-amber-400); }
.ts-badge-blue   { background: oklch(0.70 0.14 250 / 0.15); color: var(--ts-blue-400); }
.ts-badge-purple { background: oklch(0.65 0.18 290 / 0.15); color: var(--ts-purple-400); }

.ts-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ts-space-2);
  padding: var(--ts-space-2) var(--ts-space-3);
  font-size: var(--ts-text-sm);
  font-weight: 500;
  background: var(--ts-bg-hover);
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-full);
  cursor: pointer;
  transition: all var(--ts-dur-fast) var(--ts-ease-out);
}
.ts-chip:hover {
  border-color: var(--ts-primary);
  background: var(--ts-primary-muted);
}
.ts-chip.active {
  background: var(--ts-primary-muted);
  border-color: var(--ts-primary);
  color: var(--ts-primary);
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: MODAL & OVERLAY
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--ts-bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ts-space-4);
  opacity: 0;
  transition: opacity var(--ts-dur-normal) var(--ts-ease-out);
}
.ts-modal-backdrop.visible {
  opacity: 1;
}

.ts-modal {
  background: var(--ts-bg-elevated);
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-xl);
  box-shadow: var(--ts-shadow-xl);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(8px);
  transition: transform var(--ts-dur-normal) var(--ts-ease-spring);
}
.ts-modal-backdrop.visible .ts-modal {
  transform: scale(1) translateY(0);
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: TOAST NOTIFICATIONS
   Uses @starting-style for CSS-only enter animations (2026 standard).
   Fallback: still works without @starting-style, just no enter anim.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-toast {
  position: fixed;
  bottom: var(--ts-space-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: var(--ts-space-3);
  padding: var(--ts-space-3) var(--ts-space-5);
  background: var(--ts-bg-elevated);
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-lg);
  box-shadow: var(--ts-shadow-lg);
  font-size: var(--ts-text-sm);
  font-weight: 500;
  color: var(--ts-text);
  opacity: 1;
  translate: -50% 0;
  transition:
    opacity var(--ts-dur-normal) var(--ts-ease-out),
    translate var(--ts-dur-normal) var(--ts-ease-spring);
}

/* @starting-style for enter animation (Chrome 117+, Safari 17.5+) */
@supports (selector(:starting-style)) {
  @starting-style {
    .ts-toast {
      opacity: 0;
      translate: -50% 24px;
    }
  }
}

.ts-toast.exit {
  opacity: 0;
  translate: -50% 24px;
}

.ts-toast-success { border-left: 3px solid var(--ts-green-500); }
.ts-toast-error   { border-left: 3px solid var(--ts-red-500); }
.ts-toast-warning { border-left: 3px solid var(--ts-amber-500); }
.ts-toast-info    { border-left: 3px solid var(--ts-blue-500); }


/* ═══════════════════════════════════════════════════════════════════════════
   ANIMATIONS: SKELETON SCREENS
   Replace loading spinners with content-shaped shimmer placeholders.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-skeleton {
  background: linear-gradient(
    110deg,
    var(--ts-bg-hover) 8%,
    var(--ts-bg-elevated) 18%,
    var(--ts-bg-hover) 33%
  );
  background-size: 200% 100%;
  animation: ts-shimmer 1.5s linear infinite;
  border-radius: var(--ts-radius-md);
}

.ts-skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
  border-radius: var(--ts-radius-sm);
}
.ts-skeleton-text:last-child {
  width: 60%;
}

.ts-skeleton-heading {
  height: 1.5em;
  width: 40%;
  margin-bottom: 1em;
}

.ts-skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--ts-radius-full);
}

.ts-skeleton-card {
  height: 120px;
  border-radius: var(--ts-radius-lg);
}

@keyframes ts-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   ANIMATIONS: ENTER / EXIT
   ═══════════════════════════════════════════════════════════════════════════ */

@keyframes ts-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes ts-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ts-slide-down {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ts-scale-in {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes ts-count-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Utility classes for animations */
.ts-animate-fade-in  { animation: ts-fade-in  var(--ts-dur-normal) var(--ts-ease-out) both; }
.ts-animate-slide-up { animation: ts-slide-up  var(--ts-dur-slow) var(--ts-ease-out) both; }
.ts-animate-scale-in { animation: ts-scale-in  var(--ts-dur-slow) var(--ts-ease-spring) both; }

/* Stagger children: apply .ts-stagger to parent, children auto-stagger */
.ts-stagger > * {
  animation: ts-slide-up var(--ts-dur-slow) var(--ts-ease-out) both;
}
.ts-stagger > *:nth-child(1) { animation-delay: 0ms; }
.ts-stagger > *:nth-child(2) { animation-delay: 60ms; }
.ts-stagger > *:nth-child(3) { animation-delay: 120ms; }
.ts-stagger > *:nth-child(4) { animation-delay: 180ms; }
.ts-stagger > *:nth-child(5) { animation-delay: 240ms; }
.ts-stagger > *:nth-child(6) { animation-delay: 300ms; }
.ts-stagger > *:nth-child(7) { animation-delay: 360ms; }
.ts-stagger > *:nth-child(8) { animation-delay: 420ms; }


/* ═══════════════════════════════════════════════════════════════════════════
   ANIMATIONS: VALUE COUNT-UP (for KPI dashboards)
   Apply to .ts-stat-value elements — they slide in when they appear.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-count-up {
  animation: ts-count-up var(--ts-dur-slow) var(--ts-ease-out) both;
}


/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY: FOCUS STATES (WCAG 2.2)
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-reset :focus-visible {
  outline: 2px solid var(--ts-primary);
  outline-offset: 2px;
  border-radius: var(--ts-radius-sm);
}

.ts-reset :focus:not(:focus-visible) {
  outline: none;
}


/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY: REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .ts-skeleton {
    animation: none;
    background: var(--ts-bg-hover);
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   LAYOUT: BENTO GRID
   Responsive grid that auto-adjusts columns based on container width.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-bento {
  display: grid;
  gap: var(--ts-space-4);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.ts-bento-span-2 { grid-column: span 2; }
.ts-bento-span-3 { grid-column: span 3; }

@media (max-width: 640px) {
  .ts-bento {
    grid-template-columns: 1fr;
  }
  .ts-bento-span-2,
  .ts-bento-span-3 {
    grid-column: span 1;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   LAYOUT: STATS ROW
   Horizontal row of stat cards that wraps responsively.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-stats-row {
  display: grid;
  gap: var(--ts-space-4);
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}


/* ═══════════════════════════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-text-center  { text-align: center; }
.ts-text-right   { text-align: right; }
.ts-font-mono    { font-family: var(--ts-font-mono); font-variant-numeric: tabular-nums; }
.ts-truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ts-sr-only      { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.ts-flex         { display: flex; }
.ts-flex-col     { display: flex; flex-direction: column; }
.ts-items-center { align-items: center; }
.ts-justify-between { justify-content: space-between; }
.ts-gap-2        { gap: var(--ts-space-2); }
.ts-gap-3        { gap: var(--ts-space-3); }
.ts-gap-4        { gap: var(--ts-space-4); }
.ts-gap-6        { gap: var(--ts-space-6); }

.ts-mt-2  { margin-top: var(--ts-space-2); }
.ts-mt-4  { margin-top: var(--ts-space-4); }
.ts-mt-6  { margin-top: var(--ts-space-6); }
.ts-mb-2  { margin-bottom: var(--ts-space-2); }
.ts-mb-4  { margin-bottom: var(--ts-space-4); }
.ts-mb-6  { margin-bottom: var(--ts-space-6); }
.ts-p-4   { padding: var(--ts-space-4); }
.ts-p-6   { padding: var(--ts-space-6); }


/* ═══════════════════════════════════════════════════════════════════════════
   SCROLLBAR (subtle, themed)
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-reset ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.ts-reset ::-webkit-scrollbar-track {
  background: transparent;
}
.ts-reset ::-webkit-scrollbar-thumb {
  background: var(--ts-border);
  border-radius: var(--ts-radius-full);
}
.ts-reset ::-webkit-scrollbar-thumb:hover {
  background: var(--ts-border-strong);
}


/* ═══════════════════════════════════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════════════════════════════════ */

@media print {
  .ts-card, .ts-card-glass {
    box-shadow: none;
    border: 1px solid #ddd;
    break-inside: avoid;
  }
  .ts-skeleton { display: none; }
  .ts-toast { display: none; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: PREMIUM DATA TABLE
   Clean, scannable, compact. Inspired by Vercel/Stripe patterns.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--ts-border);
  border-radius: var(--ts-radius-lg);
  background: var(--ts-bg-surface);
}

.ts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--ts-text-sm);
  font-variant-numeric: tabular-nums;
}

/* Header */
.ts-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.ts-table th {
  padding: var(--ts-space-3) var(--ts-space-4);
  text-align: left;
  font-size: var(--ts-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--ts-tracking-wider, 0.05em);
  color: var(--ts-text-muted);
  background: var(--ts-bg-elevated);
  border-bottom: 1px solid var(--ts-border-strong);
  white-space: nowrap;
  user-select: none;
}

/* Sortable header */
.ts-table th[data-sortable] {
  cursor: pointer;
  transition: color var(--ts-dur-fast) var(--ts-ease-default, var(--ts-ease-out));
}
.ts-table th[data-sortable]:hover {
  color: var(--ts-text);
}
.ts-table th[data-sortable]::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: var(--ts-space-2);
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ts-text-muted);
  opacity: 0.4;
  transition: opacity var(--ts-dur-fast);
}
.ts-table th[data-sortable]:hover::after {
  opacity: 0.8;
}

/* Rows */
.ts-table td {
  padding: var(--ts-space-3) var(--ts-space-4);
  color: var(--ts-text);
  border-bottom: 1px solid var(--ts-border);
  vertical-align: middle;
}

.ts-table tbody tr {
  transition: background var(--ts-dur-fast) var(--ts-ease-default, var(--ts-ease-out));
}

.ts-table tbody tr:hover {
  background: var(--ts-bg-hover);
}

.ts-table tbody tr:last-child td {
  border-bottom: none;
}

/* Compact variant (36px row height for dense data) */
.ts-table-compact th,
.ts-table-compact td {
  padding: var(--ts-space-2) var(--ts-space-3);
  font-size: var(--ts-text-xs);
}

/* Numeric cells: right-aligned, monospace */
.ts-table .ts-cell-num {
  text-align: right;
  font-family: var(--ts-font-mono);
  font-size: var(--ts-text-xs);
}

/* Currency cells */
.ts-table .ts-cell-currency {
  text-align: right;
  font-family: var(--ts-font-mono);
  font-weight: 600;
}
.ts-cell-currency.positive { color: var(--ts-success, var(--ts-green-500)); }
.ts-cell-currency.negative { color: var(--ts-danger); }

/* Status cell */
.ts-table .ts-cell-status {
  display: flex;
  align-items: center;
  gap: var(--ts-space-2);
}
.ts-cell-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ts-cell-status-dot.active   { background: var(--ts-success, var(--ts-green-500)); }
.ts-cell-status-dot.pending  { background: var(--ts-warning, var(--ts-amber-500)); }
.ts-cell-status-dot.inactive { background: var(--ts-text-muted); }
.ts-cell-status-dot.error    { background: var(--ts-danger); }

/* Responsive: convert to card layout on mobile */
@media (max-width: 768px) {
  .ts-table-responsive thead {
    display: none;
  }
  .ts-table-responsive tbody tr {
    display: block;
    padding: var(--ts-space-4);
    border-bottom: 1px solid var(--ts-border);
  }
  .ts-table-responsive td {
    display: flex;
    justify-content: space-between;
    padding: var(--ts-space-1) 0;
    border-bottom: none;
    font-size: var(--ts-text-sm);
  }
  .ts-table-responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--ts-text-muted);
    font-size: var(--ts-text-xs);
    text-transform: uppercase;
    letter-spacing: var(--ts-tracking-wider, 0.05em);
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: TOP NAVIGATION BAR
   Consistent across all admin pages. Glassmorphism effect.
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-nav {
  position: sticky;
  top: 0;
  z-index: var(--ts-z-sticky, 20);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ts-space-4);
  padding: var(--ts-space-3) var(--ts-space-6);
  background: var(--ts-glass-bg);
  backdrop-filter: blur(var(--ts-glass-blur, 16px)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--ts-glass-blur, 16px)) saturate(1.2);
  border-bottom: 1px solid var(--ts-glass-border);
  min-height: 56px;
}

.ts-nav-brand {
  display: flex;
  align-items: center;
  gap: var(--ts-space-3);
  text-decoration: none;
  color: var(--ts-text);
  font-weight: 600;
  font-size: var(--ts-text-base);
  white-space: nowrap;
}

.ts-nav-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--ts-radius-md);
  background: var(--ts-gradient-primary, var(--ts-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* Tab navigation (horizontal tabs within page) */
.ts-nav-tabs {
  display: flex;
  align-items: center;
  gap: var(--ts-space-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.ts-nav-tabs::-webkit-scrollbar { display: none; }

.ts-nav-tab {
  position: relative;
  padding: var(--ts-space-2) var(--ts-space-4);
  font-size: var(--ts-text-sm);
  font-weight: 500;
  color: var(--ts-text-muted);
  text-decoration: none;
  border-radius: var(--ts-radius-md);
  white-space: nowrap;
  transition: all var(--ts-dur-fast) var(--ts-ease-default, var(--ts-ease-out));
  cursor: pointer;
  border: none;
  background: none;
}
.ts-nav-tab:hover {
  color: var(--ts-text);
  background: var(--ts-bg-hover);
}
.ts-nav-tab.active {
  color: var(--ts-text);
  background: var(--ts-bg-active, var(--ts-bg-hover));
}
.ts-nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: var(--ts-space-4);
  right: var(--ts-space-4);
  height: 2px;
  background: var(--ts-primary);
  border-radius: 2px 2px 0 0;
}

/* Navigation actions (right side) */
.ts-nav-actions {
  display: flex;
  align-items: center;
  gap: var(--ts-space-2);
}

/* Legacy aliases for tab navigation */
.ts-tab-nav  { /* alias */ }
.ts-tab-btn  { /* alias */ }


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: ENHANCED MODAL / DIALOG
   Smooth entrance, backdrop blur, responsive sizing
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ts-space-5) var(--ts-space-6);
  border-bottom: 1px solid var(--ts-border);
}

.ts-modal-title {
  font-size: var(--ts-text-lg);
  font-weight: 600;
  color: var(--ts-text);
}

.ts-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ts-radius-md);
  border: none;
  background: transparent;
  color: var(--ts-text-muted);
  cursor: pointer;
  transition: all var(--ts-dur-fast);
}
.ts-modal-close:hover {
  background: var(--ts-bg-hover);
  color: var(--ts-text);
}

.ts-modal-body {
  padding: var(--ts-space-6);
  overflow-y: auto;
  flex: 1;
}

.ts-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--ts-space-3);
  padding: var(--ts-space-4) var(--ts-space-6);
  border-top: 1px solid var(--ts-border);
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: ENHANCED TOAST NOTIFICATION STACK
   Bottom-right position, stacking, auto-dismiss progress bar
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-toast-container {
  position: fixed;
  bottom: var(--ts-space-6);
  right: var(--ts-space-6);
  z-index: var(--ts-z-toast, 10000);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--ts-space-2);
  pointer-events: none;
  max-width: 420px;
  width: calc(100% - var(--ts-space-12));
}

/* Auto-dismiss progress bar */
.ts-toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--ts-primary);
  animation: ts-toast-progress 5s linear both;
}

/* Toast variants (enhanced icons) */
.ts-toast-success .ts-toast-icon { color: var(--ts-success, var(--ts-green-500)); }
.ts-toast-error   .ts-toast-icon { color: var(--ts-danger); }
.ts-toast-warning .ts-toast-icon { color: var(--ts-warning, var(--ts-amber-500)); }
.ts-toast-info    .ts-toast-icon { color: var(--ts-info); }

.ts-toast-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.ts-toast-content {
  flex: 1;
  min-width: 0;
}

.ts-toast-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.ts-toast-message {
  color: var(--ts-text-secondary);
  font-size: var(--ts-text-xs);
}

.ts-toast-dismiss {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ts-text-muted);
  border-radius: var(--ts-radius-sm);
  cursor: pointer;
  font-size: 14px;
}
.ts-toast-dismiss:hover {
  background: var(--ts-bg-hover);
  color: var(--ts-text);
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: EMPTY STATES
   Illustrated, helpful, never "no data"
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--ts-space-16) var(--ts-space-6);
  gap: var(--ts-space-4);
}

.ts-empty-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--ts-radius-xl);
  background: var(--ts-bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--ts-text-muted);
}

.ts-empty-title {
  font-size: var(--ts-text-lg);
  font-weight: 600;
  color: var(--ts-text);
}

.ts-empty-description {
  font-size: var(--ts-text-sm);
  color: var(--ts-text-muted);
  max-width: 360px;
  line-height: var(--ts-leading-relaxed, 1.625);
}


/* ═══════════════════════════════════════════════════════════════════════════
   COMPONENTS: STATUS INDICATOR (pulse dot)
   ═══════════════════════════════════════════════════════════════════════════ */

.ts-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--ts-space-2);
  font-size: var(--ts-text-xs);
  font-weight: 500;
}

.ts-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ts-status-dot-active {
  background: var(--ts-success, var(--ts-green-500));
  box-shadow: 0 0 0 3px var(--ts-success-muted, oklch(0.68 0.19 155 / 0.12));
}

.ts-status-dot-warning {
  background: var(--ts-warning, var(--ts-amber-500));
  box-shadow: 0 0 0 3px var(--ts-warning-muted, rgba(245, 158, 11, 0.12));
}

.ts-status-dot-error {
  background: var(--ts-danger);
  box-shadow: 0 0 0 3px var(--ts-danger-muted, rgba(239, 68, 68, 0.12));
}

.ts-status-dot-inactive {
  background: var(--ts-text-muted);
}

/* Pulsing animation for active status */
.ts-status-dot-pulse {
  animation: ts-pulse-subtle 2s ease-in-out infinite;
}


/* ═══════════════════════════════════════════════════════════════════════════
   MICRO-INTERACTION LIBRARY
   GPU-accelerated, purposeful, 120-400ms range
   ═══════════════════════════════════════════════════════════════════════════ */

/* --- Additional page entrance animations --- */
@keyframes ts-slide-up-fade {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ts-slide-down-fade {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ts-slide-left-fade {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes ts-scale-bounce {
  0%   { transform: scale(0.9); opacity: 0; }
  60%  { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Continuous animations --- */
@keyframes ts-pulse-subtle {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

@keyframes ts-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}

@keyframes ts-spin {
  to { transform: rotate(360deg); }
}

@keyframes ts-progress-indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

/* --- Toast animations --- */
@keyframes ts-toast-enter {
  from {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes ts-toast-exit {
  to {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }
}

@keyframes ts-toast-progress {
  from { width: 100%; }
  to   { width: 0%; }
}

/* --- Success checkmark SVG animation --- */
@keyframes ts-check-draw {
  from { stroke-dashoffset: 24; }
  to   { stroke-dashoffset: 0; }
}
.ts-check-animated {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  animation: ts-check-draw 400ms var(--ts-ease-out) 200ms both;
}

/* --- Extended utility classes for animations --- */
.ts-enter-fade       { animation: ts-fade-in 200ms var(--ts-ease-default, var(--ts-ease-out)) both; }
.ts-enter-slide-up   { animation: ts-slide-up-fade 300ms var(--ts-ease-out) both; }
.ts-enter-slide-down { animation: ts-slide-down-fade 300ms var(--ts-ease-out) both; }
.ts-enter-slide-left { animation: ts-slide-left-fade 300ms var(--ts-ease-out) both; }
.ts-enter-scale      { animation: ts-scale-in 250ms var(--ts-ease-spring) both; }
.ts-enter-bounce     { animation: ts-scale-bounce 400ms var(--ts-ease-spring) both; }

/* --- Interactive micro-interactions --- */

/* Button press feedback */
.ts-press:active {
  transform: scale(0.97);
  transition: transform 80ms var(--ts-ease-default, var(--ts-ease-out));
}

/* Hover lift (for cards, items) */
.ts-hover-lift {
  transition: transform var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out)),
              box-shadow var(--ts-dur-normal) var(--ts-ease-default, var(--ts-ease-out));
}
.ts-hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: var(--ts-shadow-lg);
}

/* Hover glow (for accent elements) */
.ts-hover-glow:hover {
  box-shadow: var(--ts-glow-green);
}
.ts-hover-glow-gold:hover {
  box-shadow: var(--ts-glow-gold);
}

/* Smooth expand/collapse */
.ts-collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--ts-dur-moderate, 300ms) var(--ts-ease-default, var(--ts-ease-out));
}
.ts-collapse.open {
  grid-template-rows: 1fr;
}
.ts-collapse-inner {
  overflow: hidden;
}


/* ═══════════════════════════════════════════════════════════════════════════
   TYPOGRAPHY SYSTEM
   Inter-based, with clear hierarchy for dashboards and content
   ═══════════════════════════════════════════════════════════════════════════ */

/* Display headings (hero, landing pages) */
.ts-display-xl {
  font-size: var(--ts-text-5xl, 3rem);
  font-weight: 700;
  line-height: var(--ts-leading-none, 1);
  letter-spacing: var(--ts-tracking-tighter, -0.03em);
}

.ts-display-lg {
  font-size: var(--ts-text-4xl);
  font-weight: 700;
  line-height: var(--ts-leading-tight, 1.15);
  letter-spacing: var(--ts-tracking-tighter, -0.03em);
}

/* Page headings */
.ts-heading-xl {
  font-size: var(--ts-text-3xl);
  font-weight: 700;
  line-height: var(--ts-leading-tight, 1.15);
  letter-spacing: var(--ts-tracking-tight, -0.015em);
  color: var(--ts-text);
}

.ts-heading-lg {
  font-size: var(--ts-text-2xl);
  font-weight: 600;
  line-height: var(--ts-leading-snug, 1.3);
  letter-spacing: var(--ts-tracking-tight, -0.015em);
  color: var(--ts-text);
}

.ts-heading-md {
  font-size: var(--ts-text-xl);
  font-weight: 600;
  line-height: var(--ts-leading-snug, 1.3);
  color: var(--ts-text);
}

.ts-heading-sm {
  font-size: var(--ts-text-base);
  font-weight: 600;
  line-height: var(--ts-leading-snug, 1.3);
  color: var(--ts-text);
}

/* Section label (small uppercase) */
.ts-section-label {
  font-size: var(--ts-text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--ts-tracking-widest, 0.1em);
  color: var(--ts-text-muted);
  margin-bottom: var(--ts-space-3);
}

/* Body text variants */
.ts-body-lg {
  font-size: var(--ts-text-lg);
  line-height: var(--ts-leading-relaxed, 1.625);
  color: var(--ts-text-secondary);
}

.ts-body {
  font-size: var(--ts-text-base);
  line-height: var(--ts-leading-normal, 1.5);
  color: var(--ts-text);
}

.ts-body-sm {
  font-size: var(--ts-text-sm);
  line-height: var(--ts-leading-normal, 1.5);
  color: var(--ts-text-secondary);
}

.ts-caption {
  font-size: var(--ts-text-xs);
  line-height: var(--ts-leading-normal, 1.5);
  color: var(--ts-text-muted);
}

/* Numeric display (financial data, KPIs) */
.ts-numeric {
  font-family: var(--ts-font-mono);
  font-variant-numeric: tabular-nums;
}

.ts-numeric-lg {
  font-family: var(--ts-font-mono);
  font-size: var(--ts-text-3xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--ts-tracking-tighter, -0.03em);
}

/* Link styles */
.ts-link {
  color: var(--ts-primary);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--ts-dur-fast);
}
.ts-link:hover {
  color: var(--ts-primary-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Paragraph spacing */
.ts-prose > * + * {
  margin-top: var(--ts-space-4);
}
.ts-prose > h2 + * { margin-top: var(--ts-space-3); }
.ts-prose > h3 + * { margin-top: var(--ts-space-2); }


/* ═══════════════════════════════════════════════════════════════════════════
   QUICK-WIN UTILITIES
   Instant visual improvements from the research document.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Selection color - branded */
.ts-reset ::selection {
  background: oklch(0.68 0.19 155 / 0.3);
  color: var(--ts-text);
}

/* Smooth page entrance (opt-in via .ts-page-enter on body) */
.ts-page-enter {
  animation: ts-fade-in 400ms ease-out;
}

/* Background with subtle gradient glow (opt-in) */
.ts-bg-glow {
  background:
    var(--ts-gradient-glow, radial-gradient(ellipse at top, oklch(0.68 0.19 155 / 0.08) 0%, transparent 70%)),
    var(--ts-bg-base);
}
