/* =====================================================================
   Warranty & RMA Management SaaS — Design System
   Version: 1.0.0
   Features: Dark/Light theme, glassmorphism, micro-animations, responsive
   ===================================================================== */

/* ─── Google Fonts ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── CSS Custom Properties (Theme Tokens) ─────────────────────── */
:root {
    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    /* 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: 400ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

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

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --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-glow: 0 0 20px rgba(99, 102, 241, 0.3);

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 64px;
    --content-max-width: 1400px;
}

/* ─── Dark Theme (Default) ─────────────────────────────────────── */
[data-theme="dark"], :root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1e2538;
    --bg-card: #161d2e;
    --bg-card-hover: #1c2540;
    --bg-input: #1a2235;
    --bg-sidebar: #0d1117;
    --bg-topbar: rgba(13, 17, 23, 0.85);
    --bg-modal-overlay: rgba(0, 0, 0, 0.6);
    --bg-glass: rgba(22, 29, 46, 0.75);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    --border-color: #1e293b;
    --border-light: #2d3a50;
    --border-focus: #6366f1;

    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-primary-rgb: 99, 102, 241;
    --accent-secondary: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #06b6d4 100%);
    --accent-gradient-subtle: linear-gradient(135deg, rgba(99,102,241,0.15) 0%, rgba(139,92,246,0.1) 100%);

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.12);

    --scrollbar-bg: #111827;
    --scrollbar-thumb: #334155;
}

/* ─── Light Theme ──────────────────────────────────────────────── */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-input: #f1f5f9;
    --bg-sidebar: #ffffff;
    --bg-topbar: rgba(255, 255, 255, 0.88);
    --bg-modal-overlay: rgba(15, 23, 42, 0.4);
    --bg-glass: rgba(255, 255, 255, 0.8);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #f8fafc;

    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    --border-focus: #6366f1;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

    --scrollbar-bg: #f1f5f9;
    --scrollbar-thumb: #cbd5e1;
}

/* ─── Global Reset & Base ──────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

/* Selection */
::selection { background: rgba(var(--accent-primary-rgb), 0.3); color: var(--text-primary); }

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

img { max-width: 100%; height: auto; display: block; }

/* ─── Layout ───────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left var(--transition-base);
}

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

.app-content {
    padding: var(--space-xl);
    padding-top: calc(var(--topbar-height) + var(--space-xl));
    max-width: var(--content-max-width);
    margin: 0 auto;
    animation: fadeInUp 0.4s ease-out;
}

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

/* ─── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-base), transform var(--transition-base);
    overflow: hidden;
}

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

.sidebar-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 var(--space-lg);
    gap: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
}

.sidebar-brand-text {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .sidebar-brand-text { opacity: 0; width: 0; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md) 0;
}

.sidebar-section {
    padding: var(--space-sm) var(--space-lg);
    margin-top: var(--space-sm);
}

.sidebar-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .sidebar-section-title { opacity: 0; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0.6rem var(--space-lg);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0;
    transition: all var(--transition-fast);
    position: relative;
    white-space: nowrap;
    text-decoration: none;
}

.sidebar-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.sidebar-link.active {
    color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb), 0.08);
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent-primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.sidebar-link-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.sidebar-link-text {
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .sidebar-link-text { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding-left: 0; padding-right: 0; }

.sidebar-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* ─── Topbar ───────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-topbar);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 var(--space-xl);
    z-index: 900;
    transition: left var(--transition-base);
}

.topbar.sidebar-collapsed {
    left: var(--sidebar-collapsed);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex: 1;
}

.topbar-toggle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 1.2rem;
}

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

/* Global Search */
.global-search {
    position: relative;
    max-width: 420px;
    flex: 1;
}

.global-search-input {
    width: 100%;
    padding: 0.55rem 1rem 0.55rem 2.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-primary);
    transition: all var(--transition-fast);
    outline: none;
}

.global-search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.15);
    background: var(--bg-secondary);
}

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

.global-search-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

.global-search-shortcut {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-family: var(--font-mono);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* Theme Toggle */
.theme-toggle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 1.1rem;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--warning);
    transform: rotate(15deg);
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.35rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    cursor: pointer;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.user-menu-trigger:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.user-menu-name {
    font-size: 0.8rem;
    font-weight: 600;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.96);
    transition: all var(--transition-fast);
    z-index: 1100;
    overflow: hidden;
}

.user-menu-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.user-menu-dropdown a,
.user-menu-dropdown button {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 0.65rem var(--space-lg);
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-fast);
    text-decoration: none;
    font-family: var(--font-primary);
}

.user-menu-dropdown a:hover,
.user-menu-dropdown button:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.user-menu-dropdown .divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

/* ─── Typography ───────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.page-title-icon {
    font-size: 1.3rem;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.page-actions {
    display: flex;
    gap: var(--space-sm);
}

/* ─── Cards ────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition-base);
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.card-body {
    padding: var(--space-xl);
}

.card-footer {
    padding: var(--space-md) var(--space-xl);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* Glass Card */
.card-glass {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.08);
}

/* Stat Card */
.stat-card {
    padding: var(--space-xl);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: -30%;
    right: -20%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    opacity: 0.06;
    transition: all var(--transition-slow);
}

.stat-card:hover::after {
    opacity: 0.12;
    transform: scale(1.2);
}

.stat-card.accent-blue::after { background: var(--info); }
.stat-card.accent-green::after { background: var(--success); }
.stat-card.accent-yellow::after { background: var(--warning); }
.stat-card.accent-purple::after { background: var(--accent-primary); }

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-bottom: var(--space-md);
}

.stat-icon.blue { background: var(--info-bg); color: var(--info); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-icon.purple { background: rgba(var(--accent-primary-rgb), 0.12); color: var(--accent-primary); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-change {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: var(--space-sm);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.stat-change.positive { color: var(--success); background: var(--success-bg); }
.stat-change.negative { color: var(--danger); background: var(--danger-bg); }

.stat-card-compact {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon-compact {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .stat-card-compact { padding: 1rem; gap: 0.75rem; }
    .stat-icon-compact { width: 40px; height: 40px; font-size: 1.1rem; }
}


/* ─── Buttons ──────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.2rem;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Ripple effect */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.2);
    border-radius: inherit;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.btn:active::after { opacity: 1; }

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(var(--accent-primary-rgb), 0.3);
}
.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(var(--accent-primary-rgb), 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--accent-primary); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; transform: translateY(-1px); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }

.btn-warning { background: var(--warning); color: #1a1a2e; }
.btn-warning:hover { background: #d97706; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-tertiary); }

.btn-sm { padding: 0.35rem 1rem; font-size: 0.78rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 0.75rem 1.75rem; font-size: 0.95rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-icon.sm { width: 30px; height: 30px; }

/* ─── Forms ────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    letter-spacing: 0.02em;
}

.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
    outline: none;
}

.form-control:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.12);
    background: var(--bg-secondary);
}

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

.form-control.error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

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

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-lg);
}

.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.form-check-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

/* ─── Dark Mode Form Overrides ───────────────────────────────────── */
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover, 
[data-theme="dark"] input:-webkit-autofill:focus, 
[data-theme="dark"] input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--bg-input) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s;
}

[data-theme="dark"] select.form-control option {
    background-color: var(--bg-card);
    color: var(--text-primary);
}

[data-theme="dark"] .ts-wrapper .ts-control > input {
    color: var(--text-primary) !important;
}

/* Fix TomSelect Focus overriding background to white */
[data-theme="dark"] .ts-wrapper.focus .ts-control,
[data-theme="dark"] .ts-wrapper.single.focus .ts-control {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .ts-dropdown,
[data-theme="dark"] .ts-dropdown.single {
    background-color: var(--bg-card) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .ts-dropdown .option {
    color: var(--text-secondary);
}
[data-theme="dark"] .ts-dropdown .option:hover,
[data-theme="dark"] .ts-dropdown .option.active {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}
[data-theme="dark"] .ts-wrapper.single .ts-control .item {
    color: var(--text-primary) !important;
}

/* ─── Tables ───────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.table thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

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

.table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

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

.table-actions {
    display: flex;
    gap: 0.35rem;
}

/* ─── Badges ───────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.65rem;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.badge-primary { background: rgba(var(--accent-primary-rgb), 0.15); color: var(--accent-primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--bg-tertiary); color: var(--text-muted); }

.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Priority Badges */
.priority-low { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.priority-medium { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.priority-high { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.priority-urgent { background: rgba(239, 68, 68, 0.15); color: #ef4444; animation: urgentPulse 1.5s infinite; }

@keyframes urgentPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* ─── Modals ───────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: all var(--transition-spring);
}

.modal-overlay.open .modal {
    transform: scale(1) translateY(0);
}

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

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 1.2rem;
    transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.modal-body { padding: var(--space-xl); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border-top: 1px solid var(--border-color);
}

/* ─── Toast Notifications ──────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: calc(var(--topbar-height) + var(--space-md));
    right: var(--space-xl);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 320px;
    max-width: 450px;
    padding: 0.85rem var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    pointer-events: auto;
    animation: toastSlideIn 0.4s var(--transition-spring);
    position: relative;
    overflow: hidden;
}

.toast.hiding {
    animation: toastSlideOut 0.3s ease-in forwards;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(50px) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastSlideOut {
    to { opacity: 0; transform: translateX(50px) scale(0.95); }
}

.toast::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.toast.toast-success::before { background: var(--success); }
.toast.toast-error::before { background: var(--danger); }
.toast.toast-warning::before { background: var(--warning); }
.toast.toast-info::before { background: var(--info); }

.toast-icon { font-size: 1.2rem; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }

.toast-message { font-size: 0.85rem; flex: 1; }

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    font-size: 1rem;
    flex-shrink: 0;
}
.toast-close:hover { color: var(--text-primary); background: var(--bg-tertiary); }

/* Toast progress bar */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: var(--accent-primary);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    animation: toastProgress 4s linear forwards;
}

@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

/* ─── Pagination ───────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    margin-top: var(--space-xl);
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    text-decoration: none;
}

.pagination a {
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.pagination a:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.pagination .active {
    background: var(--accent-primary);
    color: white;
    border: 1px solid var(--accent-primary);
}

/* ─── Filters Bar ──────────────────────────────────────────────── */
.filters-bar {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.filter-group .form-control {
    max-width: 200px;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
}

/* ─── Timeline ─────────────────────────────────────────────────── */
.timeline-scroll-container {
    max-height: 450px;
    overflow-y: auto;
    padding-right: var(--space-sm);
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.timeline-scroll-container::-webkit-scrollbar {
    width: 6px;
}
.timeline-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}
.timeline-scroll-container::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--radius-full);
}
.timeline-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item {
    position: relative;
    padding-bottom: var(--space-xl);
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
    position: absolute;
    left: -1.6rem;
    top: 0.25rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.2);
}

.timeline-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
}

.timeline-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.timeline-content strong { color: var(--text-primary); }

/* ─── Empty States ─────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-xl);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.3;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.empty-state-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: var(--space-lg);
}

/* ─── Loading Spinner ──────────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(var(--accent-primary-rgb), 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    z-index: 10;
}

/* ─── Tabs ─────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    gap: 0;
    margin-bottom: var(--space-xl);
    overflow-x: auto;
}

.tab {
    padding: 0.75rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    font-family: var(--font-primary);
}

.tab:hover { color: var(--text-primary); }

.tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

/* ─── Alert Banners ────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    margin-bottom: var(--space-lg);
    animation: fadeInUp 0.3s ease-out;
}

.alert-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }

.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(59,130,246,0.2); }

/* ─── Detail View Grid ─────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.detail-value {
    font-weight: 500;
    text-align: right;
}

.detail-item label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.detail-item .value {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* ─── Notes Panel ──────────────────────────────────────────────── */
.note-card {
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    border-left: 3px solid var(--accent-primary);
}

.note-card.internal { border-left-color: var(--warning); }

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.note-author { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); }
.note-date { font-size: 0.72rem; color: var(--text-muted); }
.note-body { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }

/* ─── Grid Helpers ─────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-lg); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-lg); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-lg); }
.grid-sidebar { display: grid; grid-template-columns: 2fr 1fr; gap: var(--space-lg); }

/* ─── Utility Classes ──────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--accent-primary); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }
.font-bold { font-weight: 700; }
.font-mono { font-family: var(--font-mono); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }
.mt-3 { margin-top: var(--space-lg); }
.mt-4 { margin-top: var(--space-xl); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-sm); }
.mb-2 { margin-bottom: var(--space-md); }
.mb-3 { margin-bottom: var(--space-lg); }
.mb-4 { margin-bottom: var(--space-xl); }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: var(--space-sm); }
.gap-2 { gap: var(--space-md); }
.gap-3 { gap: var(--space-lg); }

.hidden { display: none !important; }
.hide-mobile { display: block; }
.hide-desktop { display: none; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.cursor-pointer { cursor: pointer; }

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    
    .app-main { margin-left: 0; }
    .topbar { left: 0; }
    
    .sidebar {
        transform: translateX(-100%);
        z-index: 1100;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1050;
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-base);
    }
    
    .sidebar-overlay.visible {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 768px) {
    .app-content {
        padding: var(--space-md);
        padding-top: calc(var(--topbar-height) + var(--space-md));
    }

    .page-header { flex-direction: column; align-items: flex-start; }
    .grid-2, .grid-3, .grid-4, .grid-sidebar { grid-template-columns: 1fr; }
    .hide-mobile { display: none !important; }
    .hide-desktop { display: block !important; }
    .form-row { grid-template-columns: 1fr; }
    .filters-bar { flex-direction: column; align-items: stretch; }
    
    .global-search-shortcut { display: none; }
    .user-menu-name { display: none; }
    
    .table { font-size: 0.88rem; }
    .table thead th { white-space: nowrap; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
    .table thead th, .table tbody td { padding: 0.75rem 0.85rem; }
    
    .stat-card { padding: var(--space-lg); }
    .stat-icon { width: 48px; height: 48px; font-size: 1.4rem; margin-bottom: var(--space-sm); }
    .stat-value { font-size: 1.8rem; }
    .stat-label { font-size: 0.85rem; }
}

@media (max-width: 480px) {
    .topbar { padding: 0 var(--space-md); }
    .stat-value { font-size: 2rem; }
    .stat-card { padding: var(--space-md); }
    .detail-row { flex-direction: column; align-items: flex-start; }
    .detail-value { text-align: left; max-width: 100% !important; }
    
    /* Increase base scale for very small screens */
    html { font-size: 16px; }
}

/* ─── Print Styles ─────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .toast-container, .modal-overlay { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }
    body { background: white; color: black; }
}

/* ─── Collapsible Cards ────────────────────────────────────────── */
.card-collapsible .card-header {
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
}
.card-collapsible .card-header:hover {
    background: var(--bg-tertiary);
}
.card-collapsible .collapse-icon {
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform var(--transition-base);
}
.card-collapsible.collapsed .collapse-icon {
    transform: rotate(-90deg);
}
.card-collapsible.collapsed .card-body {
    display: none;
}
.card-collapsible.collapsed {
    border-color: var(--border-color);
}
