/* CSS Custom Properties (Variables) */
:root {
  /* Colors - Primary Palette (Green Theme) */
  --color-primary: #8bc53f;
  --color-primary-light: #9fd356;
  --color-primary-dark: #77b02c;

  /* Colors - Secondary Palette (Dark Green) */
  --color-secondary: #004b3c;
  --color-secondary-light: #006b54;
  --color-secondary-dark: #003329;

  /* Theme Colors - Orange */
  --color-orange: #ff6b35;
  --color-orange-light: #ff8555;
  --color-orange-dark: #e55520;

  /* Theme Colors - Magenta */
  --color-magenta: #d81b60;
  --color-magenta-light: #e91e63;
  --color-magenta-dark: #ad1457;

  /* Colors - Neutral */
  --color-white: #ffffff;
  --color-black: #000000;
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-400: #9ca3af;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;
  --color-gray-900: #111827;

  /* Semantic Colors */
  --color-success: #10b981;
  --color-success-light: #d1fae5;
  --color-success-dark: #059669;
  --color-warning: #f59e0b;
  --color-warning-light: #fef3c7;
  --color-warning-dark: #d97706;
  --color-error: #ef4444;
  --color-error-light: #fee2e2;
  --color-error-dark: #dc2626;
  --color-info: #3b82f6;
  --color-info-light: #dbeafe;
  --color-info-dark: #2563eb;

  /* Extended Palette — frequently used accents */
  --color-purple: #7c3aed;
  --color-purple-light: #ede9fe;
  --color-teal: #0891b2;
  --color-teal-light: #ecfeff;

  /* Background Colors */
  --color-background: var(--color-white);
  --color-background-alt: var(--color-gray-50);
  --color-background-dark: var(--color-gray-900);

  /* Text Colors */
  --color-text-primary: var(--color-gray-900);
  --color-text-secondary: var(--color-gray-600);
  --color-text-muted: var(--color-gray-400);
  --color-text-inverse: var(--color-white);

  /* Border Colors */
  --color-border: var(--color-gray-200);
  --color-border-dark: var(--color-gray-300);

  /* Spacing Scale */
  --spacing-xs: 0.25rem; /* 4px */
  --spacing-sm: 0.5rem; /* 8px */
  --spacing-md: 1rem; /* 16px */
  --spacing-lg: 1.5rem; /* 24px */
  --spacing-xl: 2rem; /* 32px */
  --spacing-2xl: 3rem; /* 48px */
  --spacing-3xl: 4rem; /* 64px */
  --spacing-4xl: 6rem; /* 96px */

  /* Typography */
  --font-family-primary: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-family-secondary: 'Cairo', sans-serif;

  /* Font Sizes */
  --font-size-xs: 0.75rem; /* 12px */
  --font-size-sm: 0.875rem; /* 14px */
  --font-size-base: 1rem; /* 16px */
  --font-size-lg: 1.125rem; /* 18px */
  --font-size-xl: 1.25rem; /* 20px */
  --font-size-2xl: 1.5rem; /* 24px */
  --font-size-3xl: 1.875rem; /* 30px */
  --font-size-4xl: 2.25rem; /* 36px */
  --font-size-5xl: 3rem; /* 48px */

  /* Font Weights */
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;
  --line-height-loose: 2;

  /* Border Radius */
  --radius-sm: 0.25rem; /* 4px */
  --radius-md: 0.5rem; /* 8px */
  --radius-lg: 0.75rem; /* 12px */
  --radius-xl: 1rem; /* 16px */
  --radius-2xl: 1.5rem; /* 24px */
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 250ms ease-in-out;
  --transition-slow: 350ms ease-in-out;

  /* Z-Index Scale */
  --z-index-dropdown: 1000;
  --z-index-sticky: 1020;
  --z-index-fixed: 1030;
  --z-index-modal-backdrop: 1040;
  --z-index-modal: 1050;
  --z-index-popover: 1060;
  --z-index-tooltip: 1070;

  /* Container Widths */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1280px;
  --container-2xl: 1536px;

  /* Breakpoints (for reference in JS) */
  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
  --breakpoint-2xl: 1536px;

  /* Sidebar */
  --sidebar-width-collapsed: 60px;
  --sidebar-width-expanded: 240px;
  --sidebar-bg: #004b3c;
  --sidebar-text: rgba(255, 255, 255, 0.92);
  --sidebar-active: rgba(139, 197, 63, 0.2);
  --sidebar-hover: rgba(255, 255, 255, 0.1);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.2);
  --glass-blur: 12px;

  /* Surface colors (light mode) */
  --color-surface: var(--color-white);
  --color-surface-hover: var(--color-gray-50);
  --color-surface-active: var(--color-gray-100);

  /* Table tokens (light mode) */
  --table-header-bg: var(--color-gray-50);
  --table-row-hover: var(--color-gray-50);
  --table-border: var(--color-border);
  --table-stripe: var(--color-gray-50);

  /* Form tokens (light mode) */
  --input-bg: var(--color-white);
  --input-border: var(--color-gray-300);
  --input-text: var(--color-text-primary);
  --input-placeholder: var(--color-gray-400);

  /* Modal tokens (light mode) */
  --modal-bg: var(--color-white);
  --modal-overlay: rgba(0, 0, 0, 0.5);

  /* Stat card tokens (light mode) */
  --stat-bg: var(--color-white);
  --stat-border: var(--color-border);

  /* Badge tokens (light mode) */
  --badge-bg: var(--color-gray-100);

  /* Shared component tokens */
  --sc-card-bg: #ffffff;
  --sc-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --sc-card-shadow-hover: 0 10px 25px rgba(0, 0, 0, 0.1);
  --sc-skeleton-bg: #e5e7eb;
  --sc-skeleton-shine: #f3f4f6;
  --sc-input-focus-ring: rgba(37, 99, 235, 0.4);

  /* Animation — Impeccable: no bounce, strong ease-out only */
  --anim-stagger: 50ms;
  --anim-entrance: 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  --anim-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --anim-ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* Portal accent (overridden per portal) */
  --portal-accent: #8bc53f;
  --portal-accent-light: #d4edbc;
  --portal-accent-rgb: 139, 197, 63;
}

/* ── Dark Mode ── */
[data-theme='dark'] {
  --color-background: #0f1117;
  --color-background-alt: #1a1d27;
  --color-text-primary: #e5e7eb;
  --color-text-secondary: #9ca3af;
  --color-border: #2d3240;
  --sc-card-bg: #1e2130;
  --sc-card-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --sc-skeleton-bg: #2d3240;
  --sc-skeleton-shine: #3d4255;
  --glass-bg: rgba(30, 33, 48, 0.8);
  --glass-border: rgba(255, 255, 255, 0.06);

  /* Semantic colors adjusted for dark backgrounds */
  --color-primary: #a3d65f;
  --color-primary-dark: #8bc53f;
  --color-success: #34d399;
  --color-warning: #fbbf24;
  --color-error: #f87171;
  --color-info: #60a5fa;

  /* Surface colors */
  --color-surface: #1e1e2e;
  --color-surface-hover: #2a2a3e;
  --color-surface-active: #353550;

  /* Table */
  --table-header-bg: #2a2a3e;
  --table-row-hover: #353550;
  --table-border: #404060;
  --table-stripe: #252540;

  /* Form */
  --input-bg: #2a2a3e;
  --input-border: #404060;
  --input-text: #e0e0e0;
  --input-placeholder: #888;

  /* Modal */
  --modal-bg: #1e1e2e;
  --modal-overlay: rgba(0, 0, 0, 0.7);

  /* Stat cards */
  --stat-bg: #2a2a3e;
  --stat-border: #404060;

  /* Badge */
  --badge-bg: #353550;

  /* Sidebar */
  --sidebar-bg: #0a2e24;
  --sidebar-hover: rgba(255, 255, 255, 0.12);
  --sidebar-active: rgba(163, 214, 95, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-background: #0f1117;
    --color-background-alt: #1a1d27;
    --color-text-primary: #e5e7eb;
    --color-text-secondary: #9ca3af;
    --color-border: #2d3240;
    --sc-card-bg: #1e2130;
    --sc-card-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --sc-skeleton-bg: #2d3240;
    --sc-skeleton-shine: #3d4255;
    --glass-bg: rgba(30, 33, 48, 0.8);
    --glass-border: rgba(255, 255, 255, 0.06);

    /* Semantic colors adjusted for dark backgrounds */
    --color-primary: #a3d65f;
    --color-primary-dark: #8bc53f;
    --color-success: #34d399;
    --color-warning: #fbbf24;
    --color-error: #f87171;
    --color-info: #60a5fa;

    /* Surface colors */
    --color-surface: #1e1e2e;
    --color-surface-hover: #2a2a3e;
    --color-surface-active: #353550;

    /* Table */
    --table-header-bg: #2a2a3e;
    --table-row-hover: #353550;
    --table-border: #404060;
    --table-stripe: #252540;

    /* Form */
    --input-bg: #2a2a3e;
    --input-border: #404060;
    --input-text: #e0e0e0;
    --input-placeholder: #888;

    /* Modal */
    --modal-bg: #1e1e2e;
    --modal-overlay: rgba(0, 0, 0, 0.7);

    /* Stat cards */
    --stat-bg: #2a2a3e;
    --stat-border: #404060;

    /* Badge */
    --badge-bg: #353550;

    /* Sidebar */
    --sidebar-bg: #0a2e24;
    --sidebar-hover: rgba(255, 255, 255, 0.12);
    --sidebar-active: rgba(163, 214, 95, 0.2);
  }
}

/* ── Impeccable: Universal Focus & Accessibility ── */
:focus-visible {
  outline: 2px solid var(--color-primary, #8bc53f);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Impeccable: Button press feedback — universal */
button:active:not(:disabled),
[role='button']:active:not(:disabled),
.btn:active:not(:disabled) {
  transform: scale(0.97);
}

/* Impeccable: Hover states only for pointer devices */
@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled),
  [role='button']:hover:not(:disabled) {
    transition:
      background-color 200ms cubic-bezier(0.23, 1, 0.32, 1),
      transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
  }
}

/* Impeccable: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
