/**
 * The Flock - Design Tokens
 * Centralized design system variables for consistent styling
 * Version: 2.0.0 - Unified with Hangout
 */

/* Allow both light and dark colour schemes */
:root {
    color-scheme: light dark;
}

:root {
    /* ===== COLOR PALETTE ===== */

    /* Primary Colors — mapped from brand palette (set via <style id="brand-theme">) */
    --primary: var(--brand-500, #9333ea);
    --primary-light: var(--brand-400, #a855f7);
    --primary-dark: var(--brand-600, #7c3aed);
    --primary-50: var(--brand-50, #faf5ff);
    --primary-100: var(--brand-100, #f3e8ff);
    --primary-200: var(--brand-200, #e9d5ff);
    --primary-300: var(--brand-300, #d8b4fe);
    --primary-400: var(--brand-400, #c084fc);
    --primary-500: var(--brand-500, #a855f7);
    --primary-600: var(--brand-600, #9333ea);
    --primary-700: var(--brand-700, #7c3aed);
    --primary-800: var(--brand-800, #6b21a8);
    --primary-900: var(--brand-900, #581c87);
    --primary-soft: var(--brand-soft, rgba(147, 51, 234, 0.1));

    /* Secondary/Accent Colors - Electric Blue (Community, Connection) */
    --secondary: #3b82f6;
    --secondary-light: #60a5fa;
    --secondary-dark: #2563eb;
    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.1);

    /* Semantic Colors */
    --success: #22c55e;
    --success-light: #4ade80;
    --success-dark: #16a34a;
    --success-50: #f0fdf4;
    --success-soft: rgba(34, 197, 94, 0.1);

    --warning: #f59e0b;
    --warning-light: #fbbf24;
    --warning-dark: #d97706;
    --warning-50: #fffbeb;
    --warning-soft: rgba(245, 158, 11, 0.1);

    --danger: #ef4444;
    --danger-light: #f87171;
    --danger-dark: #dc2626;
    --danger-50: #fef2f2;
    --danger-soft: rgba(239, 68, 68, 0.1);

    --info: #06b6d4;
    --info-light: #22d3ee;
    --info-dark: #0891b2;
    --info-50: #ecfeff;
    --info-soft: rgba(6, 182, 212, 0.1);

    /* Neutral Colors (Gray Scale) */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Text Colors - WCAG AA Compliant */
    --text-primary: #1f2937;
    --text-secondary: #374151;
    --text-muted: #4b5563;
    --text-inverse: #ffffff;
    --text-link: var(--brand-700, #7c3aed);
    --text-link-hover: var(--brand-500, #9333ea);

    /* Background Colors */
    --background: #ffffff;
    --background-secondary: #f8fafc;
    --background-tertiary: #f1f5f9;
    --background-overlay: rgba(0, 0, 0, 0.5);

    /* Border Colors */
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --border-dark: #cbd5e1;
    --border-focus: var(--brand-400, #a855f7);

    /* Gradients - Purple to Blue for depth */
    --gradient-primary: linear-gradient(135deg, #9333ea 0%, #3b82f6 100%);
    --gradient-primary-hover: linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
    --gradient-accent: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --gradient-success: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --gradient-info: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
    --gradient-dark: linear-gradient(135deg, #374151 0%, #1f2937 100%);

    /* ===== CHART COLORS ===== */
    /* Used by getChartColors() in chart-utils.js */
    --chart-primary: #7c3aed;
    --chart-primary-light: rgba(124, 58, 237, 0.1);
    --chart-success: #10b981;
    --chart-info: #0ea5e9;
    --chart-warning: #f59e0b;
    --chart-danger: #ef4444;
    --chart-neutral: #6b7280;
    --chart-text: #374151;
    --chart-grid: rgba(0, 0, 0, 0.08);
    --chart-bg: #ffffff;

    /* ===== TYPOGRAPHY ===== */

    /* Font Families - Inter for consistency with Hangout */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-primary: var(--font-sans);
    --font-display: var(--brand-font-display), 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

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

    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line Heights */
    --leading-none: 1;
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
    --leading-loose: 2;

    /* Letter Spacing */
    --tracking-tighter: -0.05em;
    --tracking-tight: -0.025em;
    --tracking-normal: 0;
    --tracking-wide: 0.025em;
    --tracking-wider: 0.05em;
    --tracking-widest: 0.1em;

    /* ===== SPACING ===== */

    --space-0: 0;
    --space-1: 0.25rem;      /* 4px */
    --space-2: 0.5rem;       /* 8px */
    --space-3: 0.75rem;      /* 12px */
    --space-4: 1rem;         /* 16px */
    --space-5: 1.25rem;      /* 20px */
    --space-6: 1.5rem;       /* 24px */
    --space-8: 2rem;         /* 32px */
    --space-10: 2.5rem;      /* 40px */
    --space-12: 3rem;        /* 48px */
    --space-16: 4rem;        /* 64px */
    --space-20: 5rem;        /* 80px */
    --space-24: 6rem;        /* 96px */

    /* ===== BORDER RADIUS ===== */

    --radius-none: 0;
    --radius-sm: 0.25rem;    /* 4px */
    --radius: 0.375rem;      /* 6px */
    --radius-md: 0.5rem;     /* 8px */
    --radius-lg: 0.75rem;    /* 12px */
    --radius-xl: 1rem;       /* 16px */
    --radius-2xl: 1.25rem;   /* 20px */
    --radius-full: 9999px;

    /* ===== SHADOWS ===== */

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);

    /* Colored Shadows */
    --shadow-primary: 0 4px 12px rgba(147, 51, 234, 0.3);
    --shadow-accent: 0 4px 12px rgba(59, 130, 246, 0.3);
    --shadow-success: 0 4px 12px rgba(34, 197, 94, 0.3);
    --shadow-warning: 0 4px 12px rgba(245, 158, 11, 0.3);
    --shadow-danger: 0 4px 12px rgba(239, 68, 68, 0.3);

    /* ===== TRANSITIONS ===== */

    --transition-fast: 150ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;
    --transition-colors: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
    --transition-transform: transform 200ms ease;
    --transition-all: all 200ms ease;

    /* ===== Z-INDEX SCALE =====
       Standardized z-index layers for predictable stacking order.
       Use these variables instead of hardcoded numbers.
       Within a stacking context, use z-index: 1/2/3 for local ordering. */

    /* Base layers */
    --z-base: 0;

    /* Content-level layers (inside components) */
    --z-content: 1;
    --z-content-above: 2;

    /* Hangout-specific layers */
    --z-hangout-header: 50;
    --z-hangout-nav: 100;
    --z-hangout-flash: 200;

    /* Application-level layers */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-overlay: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-toast: 700;
    --z-tooltip: 800;

    /* CRM Navigation layers */
    --z-sidebar-overlay: 999;
    --z-sidebar: 1000;
    --z-mobile-header: 1001;
    --z-sidebar-toggle: 1003;
    --z-mobile-nav: 1020;
    --z-navbar: 1030;

    /* Bootstrap modal layers */
    --z-modal-backdrop: 1040;
    --z-modal-window: 1050;
    --z-modal-dialog: 1055;
    --z-modal-custom: 1060;

    /* Onboarding tour layers */
    --z-tour-overlay: 990;
    --z-tour-step: 995;

    /* Quick actions layers */
    --z-quick-overlay: 996;
    --z-quick-modal: 997;
    --z-quick-menu: 998;
    --z-quick-fab: 999;

    /* Highest-priority overlays */
    --z-notification: 9999;
    --z-command-palette: 10000;
    --z-cookie-banner: 9999;
    --z-cookie-modal: 10001;
    --z-whats-new: 10001;
    --z-max: 9999;

    /* ===== LAYOUT ===== */

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

    /* Sidebar */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 80px;

    /* Header */
    --header-height: 64px;
    --mobile-header-height: 60px;

    /* ===== COMPONENT-SPECIFIC ===== */

    /* Buttons — flat solid, standardized heights */
    --btn-height: 40px;
    --btn-height-sm: 36px;
    --btn-height-lg: 44px;
    --btn-padding-x: 18px;
    --btn-padding-y: 10px;
    --btn-padding-x-sm: 14px;
    --btn-padding-y-sm: 8px;
    --btn-padding-x-lg: 24px;
    --btn-padding-y-lg: 12px;
    --btn-border-radius: var(--radius-md);
    --btn-font-size: var(--text-sm);
    --btn-font-weight: var(--font-semibold);

    /* Cards */
    --card-padding: var(--space-6);
    --card-border-radius: var(--radius-lg);
    --card-shadow: var(--shadow-sm);
    --card-shadow-hover: var(--shadow-md);

    /* Forms */
    --input-height: 40px;
    --input-padding-x: 14px;
    --input-padding-y: 10px;
    --input-border-radius: var(--radius-md);
    --input-border-color: var(--gray-300);
    --input-focus-ring: 0 0 0 3px var(--brand-ring, rgba(147, 51, 234, 0.15));

    /* Tables — comfortable density */
    --table-cell-padding-x: 20px;
    --table-cell-padding-y: 16px;
    --table-header-bg: var(--gray-50);

    /* Badges */
    --badge-padding-x: 10px;
    --badge-padding-y: 4px;
    --badge-border-radius: 6px;
    --badge-font-size: var(--text-xs);
    --badge-font-weight: var(--font-semibold);

    /* Avatars */
    --avatar-sm: 32px;
    --avatar-md: 40px;
    --avatar-lg: 56px;
    --avatar-xl: 80px;

    /* Modals */
    --modal-padding: var(--space-6);
    --modal-border-radius: var(--radius-xl);
    --modal-max-width: 600px;
    --modal-backdrop-bg: rgba(0, 0, 0, 0.5);

    /* ===== CRM NAVIGATION ===== */

    /* Mobile top bar */
    --nav-bg: #ffffff;
    --nav-text: #111827;
    --nav-text-muted: #6b7280;
    --nav-border: #e5e7eb;
    --nav-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);

    /* Sidebar toggle & close */
    --nav-toggle-text: #374151;
    --nav-close-text: #6b7280;
    --nav-close-hover-bg: #f3f4f6;
    --nav-close-hover-text: #374151;

    /* Nav items (link overrides) */
    --nav-item-text: #374151;
    --nav-item-hover-bg: var(--primary-soft, rgba(147, 51, 234, 0.08));
    --nav-item-active-bg: var(--primary-soft, rgba(147, 51, 234, 0.1));
    --nav-item-active-text: #7c3aed;

    /* Notification bell & dropdown */
    --notification-bell-text: #6b7280;
    --notification-bell-hover: #7c3aed;
    --notification-badge-bg: #ef4444;
    --notification-dot-bg: #3b82f6;

    /* Notification dropdown */
    --dropdown-bg: #ffffff;
    --dropdown-border: #e5e7eb;
    --dropdown-border-light: #f3f4f6;
    --dropdown-hover-bg: #f9fafb;
    --dropdown-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    --dropdown-header-text: #111827;
    --dropdown-link-text: #7c3aed;
    --dropdown-link-hover: #6d28d9;

    /* Notification items */
    --notification-title-text: #111827;
    --notification-message-text: #6b7280;
    --notification-time-text: #9ca3af;
    --notification-unread-bg: #f0f9ff;
    --notification-unread-hover-bg: #e0f2fe;
    --notification-icon-bg: #ede9fe;
    --notification-icon-text: #7c3aed;

    /* Scrollbar (navigation sidebar) */
    --scrollbar-bg: #f9fafb;
    --scrollbar-thumb: #d1d5db;
    --scrollbar-thumb-hover: #9ca3af;

    /* ===== CRM MODALS ===== */

    --modal-bg: #ffffff;
    --modal-header-bg: linear-gradient(135deg, #9333ea 0%, #7c3aed 100%);
    --modal-header-hover-bg: linear-gradient(135deg, #6d28d9 0%, #2563eb 100%);
    --modal-border: #e5e7eb;
    --modal-footer-bg: #f9fafb;
    --modal-body-bg: #ffffff;

    /* Modal scrollbar */
    --modal-scrollbar-thumb: rgba(147, 51, 234, 0.25);
    --modal-scrollbar-thumb-hover: rgba(147, 51, 234, 0.4);
    --modal-scrollbar-thumb-legacy: rgba(147, 51, 234, 0.3);
    --modal-scrollbar-thumb-legacy-hover: rgba(147, 51, 234, 0.5);

    /* Modal forms */
    --modal-label-text: #374151;
    --modal-input-border: #e5e7eb;
    --modal-input-focus-border: #7c3aed;
    --modal-input-focus-ring: 0 0 0 3px rgba(124, 58, 237, 0.1);
    --modal-input-placeholder: #4b5563;
    --modal-input-bg: #ffffff;

    /* Modal buttons */
    --modal-btn-secondary-bg: #f3f4f6;
    --modal-btn-secondary-border: #e5e7eb;
    --modal-btn-secondary-text: #4b5563;
    --modal-btn-secondary-hover-bg: #e5e7eb;
    --modal-btn-secondary-hover-border: #d1d5db;
    --modal-btn-secondary-hover-text: #374151;
    --modal-btn-outline-text: #6b7280;
    --modal-btn-outline-hover-bg: #f3f4f6;
    --modal-btn-outline-hover-border: #d1d5db;
    --modal-btn-outline-hover-text: #374151;

    /* Modal close button (legacy / non-gradient header) */
    --modal-close-text: #6b7280;
    --modal-close-hover-bg: #f3f4f6;
    --modal-close-hover-text: #1f2937;
    --modal-legacy-header-text: #1f2937;

    /* Modal variants */
    --modal-confirm-header-bg: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --modal-confirm-icon-bg: #fef2f2;
    --modal-confirm-icon-text: #ef4444;
    --modal-success-header-bg: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --modal-success-icon-bg: #ecfdf5;
    --modal-success-icon-text: #10b981;
    --modal-danger-btn-bg: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --modal-danger-btn-hover-bg: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);

    /* Toast notifications */
    --toast-bg: #ffffff;
    --toast-text: #111827;
    --toast-border: #e5e7eb;

    /* Skeleton loaders */
    --skeleton-bg: #e5e7eb;
    --skeleton-shimmer: linear-gradient(90deg, #e5e7eb 0%, #f3f4f6 50%, #e5e7eb 100%);

    /* Custom modal focus (uses #9333ea in some places) */
    --modal-focus-border: #9333ea;
    --modal-focus-ring: 0 0 0 3px rgba(147, 51, 234, 0.1);
    --modal-checkbox-accent: #9333ea;
}


/* ===== ACCESSIBILITY ===== */

/* Focus visible styles */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

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

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
    :root {
        --border: #000000;
        --text-muted: var(--text-secondary);
    }
}
