/**
 * Interlock Platform — Unified Design System
 * Single source of truth for all Platform applications.
 *
 * ARCHITECTURE: Dark-first
 *   :root              = dark mode values (default)
 *   [data-theme="light"] = light mode overrides
 *
 * TOKEN SECTIONS:
 *   1.  Primitives & Layout
 *   2.  Backgrounds
 *   3.  Text
 *   4.  Borders
 *   5.  Primary Brand (Platform cerulean #008CCE)
 *   6.  Semantic Colors
 *   7.  Full Accent Palette
 *   8.  Gradients
 *   9.  Shadows / Radii / Transitions
 *   10. Typography Scale
 *   11. Workflow Stage Tokens
 *   12. Interactive State Overlays
 *   13. Spacing Scale
 *   14. Motion Scale
 *   15. Bootstrap Variable Bridge
 */

/* ============================================================
   @font-face — JetBrains Mono (vendor fallback for FedRAMP mode)
   ============================================================ */
@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../vendor/fonts/jetbrains-mono-regular.woff2') format('woff2');
}

/* ============================================================
   1. DESIGN TOKENS — DARK (default / :root)
   ============================================================ */
:root {
    /* --- Primitives --- */
    --white: #ffffff;
    --black: #000000;

    /* --- Layout --- */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
    --header-height: 56px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* --- 2. Backgrounds (dark defaults) --- */
    --bg-base: #0F1117;
    --bg-dark: #070a12;
    --bg-surface: #1A1D27;
    --bg-nested: #1E2130;
    --bg-panel: #1a2236;
    --bg-elevated: #1f2a40;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-overlay: #1a2236;
    --bg-subtle: rgba(255, 255, 255, 0.03);

    /* Legacy aliases (kept for backward compat with existing templates) */
    --bg-body: var(--bg-base);
    --bg-muted: var(--bg-panel);
    --bg-surface-hover: var(--bg-elevated);

    /* --- 3. Text (dark defaults) --- */
    --text-primary: #E8E9ED;
    --text-main: #E8E9ED;
    --text-secondary: #c2cce0;
    --text-muted: #8896b3;
    --text-tertiary: #4d5e7a;
    --text-placeholder: #4d5e7a;
    --text-inverse: #0F1117;

    /* --- 4. Borders (dark defaults) --- */
    --border-color: rgba(255, 255, 255, 0.08);
    --border-subtle: rgba(255, 255, 255, 0.04);
    --border-default: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --border-focus: rgba(0, 140, 206, 0.5);
    --border-hover: rgba(255, 255, 255, 0.16);

    /* --- 5. Primary Brand — Platform cerulean --- */
    --primary-color: #008cce;
    --primary-hover: #0073a8;
    --primary-light: #38bdf8;
    --primary-dark: #006ba3;
    --primary-surface: rgba(0, 140, 206, 0.12);
    --primary-border: rgba(0, 140, 206, 0.25);

    /* --- 6. Semantic Colors --- */
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.15);
    --success-dark: #059669;
    --success-text: #34d399;
    --success-dim: rgba(16, 185, 129, 0.08);

    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.15);
    --warning-dark: #d97706;
    --warning-text: #fbbf24;
    --warning-dim: rgba(245, 158, 11, 0.08);

    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.15);
    --danger-dark: #dc2626;
    --danger-text: #f87171;
    --danger-dim: rgba(239, 68, 68, 0.08);
    --error: var(--danger);

    --info: #3b82f6;
    --info-light: rgba(59, 130, 246, 0.15);
    --info-dark: #2563eb;
    --info-text: #60a5fa;
    --info-dim: rgba(59, 130, 246, 0.08);

    /* Legacy status aliases */
    --emerald-bg: var(--success-light);
    --emerald-text: var(--success-text);
    --amber-bg: var(--warning-light);
    --amber-text: var(--warning-text);
    --red-bg: var(--danger-light);
    --red-text: var(--danger-text);
    --blue-bg: var(--info-light);
    --blue-text: var(--info-text);
    --orange-bg: rgba(249, 115, 22, 0.15);
    --orange-text: #fb923c;
    --purple-bg: rgba(139, 92, 246, 0.15);
    --purple-text: #a78bfa;
    --slate-bg: rgba(100, 116, 139, 0.15);
    --slate-text: #94a3b8;

    /* --- 7. Full Accent Palette --- */
    --accent-violet: #7c3aed;
    --accent-purple: #9333ea;
    --accent-fuchsia: #d946ef;
    --accent-pink: #ec4899;
    --accent-rose: #f43f5e;
    --accent-red: #ef4444;
    --accent-orange: #f97316;
    --accent-amber: #f59e0b;
    --accent-yellow: #eab308;
    --accent-lime: #84cc16;
    --accent-green: #22c55e;
    --accent-emerald: #10b981;
    --accent-teal: #14b8a6;
    --accent-cyan: #06b6d4;
    --accent-sky: #0ea5e9;
    --accent-blue: #3b82f6;
    --accent-indigo: #6366f1;

    /* Admin / accent-primary (purple) */
    --accent-primary: #a78bfa;
    --accent-primary-hover: #8b5cf6;
    --accent-bg: rgba(139, 92, 246, 0.15);
    --accent-bg-hover: rgba(139, 92, 246, 0.25);

    /* --- 8. Gradients --- */
    --gradient-primary: linear-gradient(135deg, #008cce 0%, #006ba3 100%);
    --gradient-primary-hover: linear-gradient(135deg, #0073a8 0%, #005a8a 100%);
    --gradient-ai: linear-gradient(135deg, #7c3aed 0%, #ec4899 100%);
    --gradient-premium: linear-gradient(135deg, #7c3aed 0%, #06b6d4 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --gradient-info: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --gradient-sunset: linear-gradient(135deg, #f43f5e 0%, #f97316 100%);
    --gradient-ocean: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    --gradient-forest: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);
    --gradient-aurora: linear-gradient(135deg, #7c3aed 0%, #06b6d4 50%, #10b981 100%);

    /* --- 9. Shadows / Radii / Transitions --- */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5);

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);

    --shadow-glow-primary: 0 0 20px rgba(0, 140, 206, 0.3);
    --shadow-glow-success: 0 0 20px rgba(16, 185, 129, 0.3);
    --shadow-glow-warning: 0 0 20px rgba(245, 158, 11, 0.3);
    --shadow-glow-danger: 0 0 20px rgba(239, 68, 68, 0.3);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shorthand aliases */
    --r-sm: var(--radius-sm);
    --r-md: var(--radius-md);
    --r-lg: var(--radius-lg);
    --r-xl: var(--radius-xl);

    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
    --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);

    /* --- 10. Typography Scale --- */
    --text-display: 36px;   /* weight 700 */
    --text-heading: 24px;   /* weight 700 */
    --text-subheading: 20px;/* weight 600 */
    --text-title: 18px;     /* weight 600 */
    --text-body-lg: 16px;   /* weight 400 */
    --text-body: 14px;      /* weight 400 */
    --text-body-sm: 13px;   /* weight 400 */
    --text-caption: 12px;   /* weight 400 */
    --text-overline: 11px;  /* weight 700, letter-spacing 0.08em */

    /* CLAUDE.md canonical aliases */
    --text-h1: 1.75rem;
    --text-h2: 1.375rem;
    --text-h3: 1.125rem;
    --text-h4: 1rem;
    --text-body-strong: 0.875rem;
    --text-small: 0.75rem;
    --text-micro: 0.6875rem;

    --font-mono: 'JetBrains Mono', monospace;
    --text-mono: 13px; /* weight 400, JetBrains Mono */

    /* --- 11. Workflow Stage Tokens (CLAUDE.md spec) --- */
    --stage-new:      #6366f1;  /* indigo  — New / Draft / Open */
    --stage-active:   #8b5cf6;  /* purple  — Active / In Progress */
    --stage-review:   #3b82f6;  /* blue    — Review / Pending Approval */
    --stage-pending:  #f59e0b;  /* amber   — Pending / Stalled / On Hold */
    --stage-complete: #22c55e;  /* green   — Won / Paid / Approved */
    --stage-closed:   #ef4444;  /* red     — Lost / Overdue / Rejected */

    /* Legacy stage aliases (maps to new names for backward compat) */
    --stage-qualified:   var(--stage-active);
    --stage-proposal:    var(--stage-pending);
    --stage-negotiation: var(--stage-pending);
    --stage-closed-won:  var(--stage-complete);
    --stage-closed-lost: var(--stage-closed);

    /* --- 12. Interactive State Overlays --- */
    --hover-overlay: rgba(255, 255, 255, 0.04);
    --active-overlay: rgba(255, 255, 255, 0.08);
    --selected-overlay: rgba(0, 140, 206, 0.15);
    --focus-ring: rgba(0, 140, 206, 0.5);

    /* --- 13. Spacing Scale --- */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-14: 56px;
    --space-16: 64px;

    /* --- 14. Motion Scale --- */
    --duration-instant: 100ms;
    --duration-fast: 150ms;
    --duration-normal: 200ms;
    --duration-moderate: 300ms;
    --duration-slow: 500ms;
    --duration-slower: 500ms;

    --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-decelerate: cubic-bezier(0, 0, 0.2, 1);
    --ease-accelerate: cubic-bezier(0.4, 0, 1, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ============================================================
   LIGHT THEME OVERRIDES
   ============================================================ */
[data-theme="light"] {
    /* --- 2. Backgrounds --- */
    --bg-base: #f3f4f6;
    --bg-dark: #e5e7eb;
    --bg-surface: #ffffff;
    --bg-nested: #f9fafb;
    --bg-panel: #f9fafb;
    --bg-elevated: #ffffff;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --bg-overlay: #ffffff;
    --bg-subtle: rgba(0, 0, 0, 0.02);

    /* Legacy aliases */
    --bg-body: var(--bg-base);
    --bg-muted: var(--bg-panel);
    --bg-surface-hover: #f9fafb;

    /* --- 3. Text --- */
    --text-primary: #111827;
    --text-main: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --text-tertiary: #9ca3af;
    --text-placeholder: #9ca3af;
    --text-inverse: #ffffff;

    /* --- 4. Borders --- */
    --border-color: rgba(0, 0, 0, 0.08);
    --border-subtle: rgba(0, 0, 0, 0.04);
    --border-default: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.16);
    --border-focus: rgba(0, 140, 206, 0.4);
    --border-hover: rgba(0, 0, 0, 0.16);

    /* --- 5. Primary Brand — same hue, light-mode adjustments --- */
    --primary-color: #008cce;
    --primary-hover: #0073a8;
    --primary-light: #38bdf8;
    --primary-dark: #006ba3;
    --primary-surface: #f0f9ff;
    --primary-border: #bae6fd;

    /* --- 6. Semantic Colors (light-mode surfaces) --- */
    --success-light: #d1fae5;
    --success-text: #059669;
    --success-dim: #ecfdf5;

    --warning-light: #fef3c7;
    --warning-text: #d97706;
    --warning-dim: #fffbeb;

    --danger-light: #fee2e2;
    --danger-text: #dc2626;
    --danger-dim: #fff5f5;

    --info-light: #dbeafe;
    --info-text: #2563eb;
    --info-dim: #eff6ff;

    /* Legacy status aliases */
    --emerald-bg: var(--success-light);
    --emerald-text: var(--success-text);
    --amber-bg: var(--warning-light);
    --amber-text: var(--warning-text);
    --red-bg: var(--danger-light);
    --red-text: var(--danger-text);
    --blue-bg: var(--info-light);
    --blue-text: var(--info-text);
    --orange-bg: #ffedd5;
    --orange-text: #ea580c;
    --purple-bg: #f3e8ff;
    --purple-text: #7c3aed;
    --slate-bg: #f1f5f9;
    --slate-text: #64748b;

    /* --- 8. Shadows (lighter for light mode) --- */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.06);

    --shadow-glow-primary: 0 0 20px rgba(0, 140, 206, 0.15);
    --shadow-glow-success: 0 0 20px rgba(16, 185, 129, 0.15);
    --shadow-glow-warning: 0 0 20px rgba(245, 158, 11, 0.15);
    --shadow-glow-danger: 0 0 20px rgba(239, 68, 68, 0.15);

    /* --- 12. Interactive State Overlays --- */
    --hover-overlay: rgba(0, 0, 0, 0.04);
    --active-overlay: rgba(0, 0, 0, 0.08);
    --selected-overlay: rgba(0, 140, 206, 0.08);
    --focus-ring: rgba(0, 140, 206, 0.25);

    /* --- Accent-primary (light-mode purple) --- */
    --accent-primary: #7c3aed;
    --accent-primary-hover: #6d28d9;
    --accent-bg: #f3e8ff;
    --accent-bg-hover: #faf5ff;
}

/* ============================================================
   15. BOOTSTRAP VARIABLE BRIDGE
   Maps Bootstrap 5 --bs-* vars to Interlock design tokens
   so utility classes (text-success, bg-danger, etc.) render
   using our design system colors in both themes.
   ============================================================ */
:root,
[data-theme="light"] {
    --bs-primary: var(--primary-color);
    --bs-primary-rgb: 0, 140, 206;
    --bs-success: var(--success);
    --bs-success-rgb: 16, 185, 129;
    --bs-warning: var(--warning);
    --bs-warning-rgb: 245, 158, 11;
    --bs-danger: var(--danger);
    --bs-danger-rgb: 239, 68, 68;
    --bs-info: var(--info);
    --bs-info-rgb: 59, 130, 246;
    --bs-secondary: var(--text-secondary);
    --bs-body-bg: var(--bg-base);
    --bs-body-color: var(--text-primary);
    --bs-border-color: var(--border-color);
    --bs-border-radius: var(--radius-md);
    --bs-border-radius-sm: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-lg);
}

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

/* ============================================================
   BASE RESET & GLOBAL STYLES
   ============================================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-body);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color var(--transition-normal), color var(--transition-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   SKIP TO CONTENT (Accessibility)
   ============================================================ */
.skip-to-content {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 9999;
    padding: 0.75rem 1.25rem;
    background: var(--primary-color);
    color: var(--white);
    font-weight: 600;
    font-size: var(--text-body);
    border-radius: 0 0 var(--radius-md) 0;
    text-decoration: none;
    transition: top var(--duration-fast) ease;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid var(--white);
    outline-offset: 2px;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-normal);
}

.main.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

@media (max-width: 768px) {
    .main {
        margin-left: 0;
    }
}

.content {
    padding: 2rem;
    flex: 1;
}

/* ============================================================
   HEADER / TOP BAR
   ============================================================ */
.header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 2rem;
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.auth-page .header {
    display: none !important;
}

.auth-page .main {
    margin-left: 0 !important;
    padding: 0;
}

.auth-page .sidebar {
    display: none !important;
}

.header-title h1 {
    font-size: var(--text-title);
    font-weight: 600;
    color: var(--text-primary);
}

.header-title p {
    font-size: var(--text-body);
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* ============================================================
   MODE TOGGLES
   ============================================================ */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    overflow: hidden;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.theme-toggle svg,
.theme-toggle i {
    width: 18px;
    height: 18px;
    display: block;
}

/* ============================================================
   UTILITY
   ============================================================ */
[x-cloak] {
    display: none !important;
}

.icon {
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.icon-button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

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

/* ============================================================
   PAGE HEADER COMPONENT
   ============================================================ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header__title {
    font-size: var(--text-heading);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.02em;
}

.page-header__subtitle {
    font-size: var(--text-body);
    color: var(--text-muted);
    margin: 0.25rem 0 0;
}

.page-header__actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Gradient page-header variant */
.page-header--gradient {
    background: var(--gradient-primary);
    border-radius: var(--radius-xl);
    padding: 2rem;
    margin-bottom: 1.5rem;
    color: var(--white);
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--white);
    margin: 0;
}

.page-subtitle {
    font-size: 0.9375rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 0.25rem;
}

.page-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header-actions {
    display: flex;
    gap: 0.75rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: var(--text-body);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast), box-shadow var(--transition-fast),
                transform var(--transition-fast), border-color var(--transition-fast),
                color var(--transition-fast);
    border: 1px solid transparent;
    line-height: 1.5;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

.btn svg, .btn i {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Primary */
.btn-primary, .btn--primary {
    background: var(--primary-color);
    color: var(--white);
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover, .btn--primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-glow-primary);
    transform: translateY(-1px);
}

/* Secondary */
.btn-secondary, .btn--secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-secondary:hover, .btn--secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* Ghost */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--hover-overlay);
    color: var(--text-primary);
}

/* Danger */
.btn-danger, .btn--danger {
    background: var(--danger);
    color: var(--white);
    box-shadow: var(--shadow-sm);
}
.btn-danger:hover, .btn--danger:hover {
    background: var(--danger-dark);
    box-shadow: var(--shadow-glow-danger);
    transform: translateY(-1px);
}

/* Success */
.btn-success, .btn--success {
    background: var(--success);
    color: var(--white);
    box-shadow: var(--shadow-sm);
}
.btn-success:hover, .btn--success:hover {
    background: var(--success-dark);
    box-shadow: var(--shadow-glow-success);
    transform: translateY(-1px);
}

/* Warning */
.btn-warning {
    background: var(--warning);
    color: var(--white);
    box-shadow: var(--shadow-sm);
}
.btn-warning:hover {
    background: var(--warning-dark);
    box-shadow: var(--shadow-glow-warning);
    transform: translateY(-1px);
}

/* Link */
.btn-link, .btn--link {
    background: transparent;
    color: var(--primary-color);
    padding: 0;
    border: none;
    font-weight: 500;
}
.btn-link:hover, .btn--link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Gradient (primary CTA) */
.btn-gradient {
    background: var(--gradient-primary);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-sm);
}
.btn-gradient:hover {
    background: var(--gradient-primary-hover);
    box-shadow: var(--shadow-glow-primary);
    transform: translateY(-1px);
}

/* AI */
.btn-ai {
    background: var(--gradient-ai);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-sm);
}
.btn-ai:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Sizes */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: var(--text-body-sm);
    border-radius: var(--radius-sm);
    gap: 0.375rem;
}
.btn-sm svg, .btn-sm i { width: 14px; height: 14px; }

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: var(--text-body-lg);
    border-radius: var(--radius-lg);
}

/* Icon-only */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-elevated);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}
.btn-icon svg, .btn-icon i { width: 16px; height: 16px; }

/* Header primary (white on gradient bg) */
.btn-header-primary {
    background: var(--white);
    color: var(--primary-color);
    font-weight: 600;
    border: none;
}
.btn-header-primary:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateY(-1px);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.card-header {
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.card--interactive:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
    cursor: pointer;
}

/* ============================================================
   BADGES / STATUS PILLS
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-caption);
    font-weight: 600;
    line-height: 1.4;
}

.badge-emerald, .badge-success {
    background: var(--emerald-bg);
    color: var(--emerald-text);
}
.badge-amber, .badge-warning {
    background: var(--amber-bg);
    color: var(--amber-text);
}
.badge-red, .badge-danger {
    background: var(--red-bg);
    color: var(--red-text);
}
.badge-blue, .badge-info {
    background: var(--blue-bg);
    color: var(--blue-text);
}
.badge-purple {
    background: var(--purple-bg);
    color: var(--purple-text);
}
.badge-slate {
    background: var(--slate-bg);
    color: var(--slate-text);
}
.badge-orange {
    background: var(--orange-bg);
    color: var(--orange-text);
}

/* AI badge */
.ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 2px 8px;
    background: var(--gradient-ai);
    color: var(--white);
    border-radius: var(--radius-full);
    font-size: var(--text-caption);
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: var(--text-body-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.form-input,
.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--text-body);
    font-family: var(--font-family);
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input::placeholder,
.form-control::placeholder {
    color: var(--text-placeholder);
}

.form-input:focus,
.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Select */
select.form-control,
select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

/* Validation error state */
.form-input--error,
.form-control--error {
    border-color: var(--danger);
    background: var(--danger-light);
}

.form-error {
    font-size: var(--text-caption);
    color: var(--danger);
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ============================================================
   TABLES
   ============================================================ */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: var(--text-overline);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-elevated);
}

.table td {
    padding: 0.875rem 1rem;
    font-size: var(--text-body);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

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

/* ============================================================
   MODALS
   ============================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 199;
}

.modal-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}

/* Legacy class-based modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-xl);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.modal-close {
    padding: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============================================================
   STATS / KPI CARDS
   ============================================================ */
.stats-grid,
.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-card);
}

.stat-value {
    font-size: var(--text-subheading);
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: var(--text-body-sm);
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.panel__header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-elevated);
}

.panel__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panel__title svg,
.panel__title i {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.panel__badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.panel__link {
    font-size: var(--text-body-sm);
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.panel__link:hover {
    text-decoration: underline;
}

.panel__body {
    padding: 1.5rem;
}

.panel__footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
}

/* ============================================================
   AI COMPONENTS
   ============================================================ */
.ai-insight-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
}

.ai-insight-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-ai);
}

.ai-suggestion {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: rgba(124, 58, 237, 0.06);
    border: 1px solid rgba(124, 58, 237, 0.15);
    border-radius: var(--radius-md);
    font-size: var(--text-body);
    color: var(--text-secondary);
}

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

.ai-pulse {
    animation: ai-pulse 2s ease-in-out infinite;
}

/* ============================================================
   QUICK ACTIONS
   ============================================================ */
.quick-actions {
    margin-bottom: 1.5rem;
}

.quick-actions__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
}

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: var(--text-body-sm);
    font-weight: 500;
    transition: border-color var(--transition-fast), color var(--transition-fast),
                box-shadow var(--transition-fast), transform var(--transition-fast);
    cursor: pointer;
}

.quick-action:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-2px);
}

.quick-action i,
.quick-action svg {
    width: 24px;
    height: 24px;
    color: var(--primary-color);
}

/* ============================================================
   DASHBOARD GRIDS
   ============================================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-state i,
.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: var(--text-title);
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 0.5rem;
}

.empty-state p {
    font-size: var(--text-body);
    margin: 0 0 1.5rem;
}

/* ============================================================
   LOADING / SKELETON
   ============================================================ */
.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

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

.table-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem;
    color: var(--text-muted);
    font-size: var(--text-body);
}

/* ============================================================
   TOAST NOTIFICATION REGION
   ============================================================ */
[role="status"],
[role="alert"] {
    /* Ensure live regions are accessible to AT */
}

/* ============================================================
   TABS (WCAG role=tablist)
   ============================================================ */
[role="tab"] {
    cursor: pointer;
}

[role="tab"][aria-selected="true"] {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}

[role="tabpanel"]:focus {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ============================================================
   FOCUS VISIBLE (universal)
   ============================================================ */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes slideInUp {
    from { transform: translateY(8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid,
    .grid-4 {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .quick-actions__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
