/* ============================================================
   BeeHive Enterprise Design System v3
   Design Tokens, Base Styles, Typography
   ============================================================
   This file defines the foundational design tokens that power
   every BeeHive application. It must be loaded first.
   ============================================================ */

/* ---------- 1. Design Tokens ---------- */

:root {
    /* --- Brand Colors --- */
    --color-primary-50:  #eff6ff;
    --color-primary-100: #dbeafe;
    --color-primary-200: #bfdbfe;
    --color-primary-300: #93c5fd;
    --color-primary-400: #60a5fa;
    --color-primary-500: #3b82f6;
    --color-primary-600: #2563eb;
    --color-primary-700: #1d4ed8;
    --color-primary-800: #1e40af;
    --color-primary-900: #1e3a8a;
    --color-primary-950: #172554;

    /* --- Secondary (Emerald) --- */
    --color-secondary-50:  #ecfdf5;
    --color-secondary-100: #d1fae5;
    --color-secondary-200: #a7f3d0;
    --color-secondary-300: #6ee7b7;
    --color-secondary-400: #34d399;
    --color-secondary-500: #10b981;
    --color-secondary-600: #059669;
    --color-secondary-700: #047857;
    --color-secondary-800: #065f46;
    --color-secondary-900: #064e3b;

    /* --- Warning (Amber) --- */
    --color-warning-50:  #fffbeb;
    --color-warning-100: #fef3c7;
    --color-warning-200: #fde68a;
    --color-warning-300: #fcd34d;
    --color-warning-400: #fbbf24;
    --color-warning-500: #f59e0b;
    --color-warning-600: #d97706;
    --color-warning-700: #b45309;
    --color-warning-800: #92400e;
    --color-warning-900: #78350f;

    /* --- Danger (Red) --- */
    --color-danger-50:  #fef2f2;
    --color-danger-100: #fee2e2;
    --color-danger-200: #fecaca;
    --color-danger-300: #fca5a5;
    --color-danger-400: #f87171;
    --color-danger-500: #ef4444;
    --color-danger-600: #dc2626;
    --color-danger-700: #b91c1c;
    --color-danger-800: #991b1b;
    --color-danger-900: #7f1d1d;

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

    /* --- Semantic Colors (Light Theme) --- */
    --bg-app: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f8fafc;
    --bg-surface-active: #f1f5f9;
    --bg-elevated: #ffffff;
    --bg-overlay: rgba(15, 23, 42, 0.5);
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.08);
    --bg-sidebar-active: rgba(59, 130, 246, 0.15);
    --bg-header: #ffffff;
    --bg-status-bar: #f8fafc;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-inverse: #f8fafc;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;
    --text-sidebar-muted: #64748b;

    --border-color: #e2e8f0;
    --border-color-strong: #cbd5e1;
    --border-sidebar: rgba(255, 255, 255, 0.08);

    --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);
    --shadow-2xl: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
    --shadow-glass: 0 8px 32px rgba(15, 23, 42, 0.08);

    /* --- Spacing Scale --- */
    --space-0: 0;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-20: 5rem;
    --space-24: 6rem;

    /* --- Border Radius --- */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;

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

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

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

    /* --- Layout Dimensions --- */
    --header-height: 3.5rem;
    --sidebar-width: 16rem;
    --sidebar-width-collapsed: 4rem;
    --sidebar-width-floating: 16rem;
    --status-bar-height: 2rem;
    --content-max-width: 100rem;

    /* --- Transitions --- */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

    /* --- Z-Index Scale --- */
    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-sidebar: 300;
    --z-header: 400;
    --z-overlay: 500;
    --z-modal: 600;
    --z-toast: 700;
    --z-command-palette: 800;

    /* --- Focus Ring --- */
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.3);
    --focus-ring-danger: 0 0 0 3px rgba(239, 68, 68, 0.3);

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

/* ---------- Dark Theme ---------- */

[data-theme="dark"] {
    --bg-app: #020617;
    --bg-surface: #0f172a;
    --bg-surface-hover: #1e293b;
    --bg-surface-active: #334155;
    --bg-elevated: #1e293b;
    --bg-overlay: rgba(0, 0, 0, 0.6);
    --bg-sidebar: #020617;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.05);
    --bg-sidebar-active: rgba(59, 130, 246, 0.2);
    --bg-header: #0f172a;
    --bg-status-bar: #020617;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #64748b;
    --text-inverse: #0f172a;
    --text-sidebar: #94a3b8;
    --text-sidebar-active: #f1f5f9;
    --text-sidebar-muted: #475569;

    --border-color: #1e293b;
    --border-color-strong: #334155;
    --border-sidebar: rgba(255, 255, 255, 0.05);

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.3);

    --glass-bg: rgba(15, 23, 42, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
}

/* ---------- 2. CSS Reset & Base ---------- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-app);
    transition: background-color var(--transition-base), color var(--transition-base);
    overflow: hidden;
}

/* ---------- 3. Typography ---------- */

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-semibold);
    line-height: var(--leading-tight);
    color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); font-weight: var(--font-weight-bold); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); font-weight: var(--font-weight-medium); }
h6 { font-size: var(--text-sm); font-weight: var(--font-weight-medium); color: var(--text-secondary); }

p { line-height: var(--leading-relaxed); color: var(--text-secondary); }

small { font-size: var(--text-xs); }

code, pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

code {
    background: var(--bg-surface-active);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    color: var(--color-primary-600);
}

pre {
    background: var(--bg-surface-active);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

a {
    color: var(--color-primary-600);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover { color: var(--color-primary-700); }

/* ---------- 4. Scrollbar ---------- */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ---------- 5. Focus Visible ---------- */

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* ---------- 6. Selection ---------- */

::selection {
    background: var(--color-primary-200);
    color: var(--color-primary-900);
}

[data-theme="dark"] ::selection {
    background: rgba(59, 130, 246, 0.3);
    color: var(--text-primary);
}

/* ---------- 7. Utility Classes ---------- */

.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-tertiary { color: var(--text-tertiary) !important; }
.text-brand { color: var(--color-primary-600) !important; }
.text-success { color: var(--color-secondary-600) !important; }
.text-warning { color: var(--color-warning-600) !important; }
.text-danger { color: var(--color-danger-600) !important; }

.bg-surface { background: var(--bg-surface) !important; }
.bg-app { background: var(--bg-app) !important; }
.bg-elevated { background: var(--bg-elevated) !important; }

.font-semibold { font-weight: var(--font-weight-semibold) !important; }
.font-medium { font-weight: var(--font-weight-medium) !important; }
.font-bold { font-weight: var(--font-weight-bold) !important; }

.rounded-sm { border-radius: var(--radius-sm) !important; }
.rounded-md { border-radius: var(--radius-md) !important; }
.rounded-lg { border-radius: var(--radius-lg) !important; }
.rounded-xl { border-radius: var(--radius-xl) !important; }
.rounded-full { border-radius: var(--radius-full) !important; }

.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow-md { box-shadow: var(--shadow-md) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }
.shadow-xl { box-shadow: var(--shadow-xl) !important; }

/* ---------- 8. Animations ---------- */

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

@keyframes bh-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes bh-slide-up {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bh-slide-down {
    from { opacity: 0; transform: translateY(-0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bh-slide-left {
    from { opacity: 0; transform: translateX(0.5rem); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes bh-slide-right {
    from { opacity: 0; transform: translateX(-0.5rem); }
    to { opacity: 1; transform: translateX(0); }
}

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

@keyframes bh-scale-out {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.95); }
}

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

@keyframes bh-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

@keyframes bh-ripple {
    to { transform: scale(2); opacity: 0; }
}

@keyframes bh-toast-in {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes bh-toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

@keyframes bh-drawer-in {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes bh-drawer-out {
    from { transform: translateX(0); }
    to { transform: translateX(100%); }
}

@keyframes bh-sidebar-slide {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* Animation utility classes */
.bh-animate-fade-in { animation: bh-fade-in var(--transition-base) ease-out; }
.bh-animate-slide-up { animation: bh-slide-up var(--transition-base) ease-out; }
.bh-animate-slide-down { animation: bh-slide-down var(--transition-base) ease-out; }
.bh-animate-scale-in { animation: bh-scale-in var(--transition-spring) ease-out; }
.bh-animate-toast-in { animation: bh-toast-in var(--transition-spring) ease-out; }
.bh-animate-drawer-in { animation: bh-drawer-in var(--transition-base) ease-out; }

/* ---------- 9. Glass Effect ---------- */

.bh-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
}

/* ---------- 10. Skeleton Loader ---------- */

.bh-skeleton {
    background: linear-gradient(90deg,
        var(--bg-surface-active) 25%,
        var(--bg-surface-hover) 50%,
        var(--bg-surface-active) 75%
    );
    background-size: 200% 100%;
    animation: bh-shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

/* ---------- 11. Spinner ---------- */

.bh-spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--color-primary-600);
    border-radius: 50%;
    animation: bh-spin 0.7s linear infinite;
}

.bh-spinner-sm { width: 1rem; height: 1rem; border-width: 1.5px; }
.bh-spinner-lg { width: 2rem; height: 2rem; border-width: 3px; }

/* ---------- 12. Loading Overlay ---------- */

.bh-loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-overlay);
    animation: bh-fade-in var(--transition-fast) ease-out;
}

.bh-loading-overlay-content {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
}

/* ---------- 13. Accessibility ---------- */

.bh-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.bh-focus-trap {
    outline: none;
}

.bh-skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    padding: var(--space-2) var(--space-4);
    background: var(--color-primary-600);
    color: white;
    border-radius: var(--radius-md);
    z-index: var(--z-toast);
    transition: top var(--transition-fast);
}

.bh-skip-link:focus {
    top: var(--space-2);
}

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