:root {
    /* === DENSITY TOKENS (High Density SaaS) === */
    --navbar-height: 60px;
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 72px;
    
    /* Spacing System - Desktop Default */
    --sp-xs: 0.25rem;  /* 4px */
    --sp-sm: 0.5rem;   /* 8px */
    --sp-md: 1rem;     /* 16px */
    --sp-lg: 1.5rem;   /* 24px */
    
    /* Control Heights */
    --ctl-h: 38px;      
    --ctl-h-sm: 32px;   
    
    /* Radii */
    --radius: 10px;     
    --radius-sm: 6px;
    --pill: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-card: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
    --shadow-elev: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --shadow-search: 0 0 0 1px rgba(0,0,0,0.05), 0 10px 15px -3px rgba(0,0,0,0.1);

    /* Animation */
    --t-fast: 0.15s ease-out;
    --t-med: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* === PALETTE === */
    --primary: #4f46e5;         /* Indigo 600 */
    --primary-hover: #4338ca;   /* Indigo 700 */
    --primary-soft: #eef2ff;    /* Indigo 50 */
    --accent: #0ea5e9;          /* Sky 500 */
    
    --bg-page: #f8fafc;         /* Slate 50 */
    --bg-surface: #ffffff;      /* White */
    --bg-surface-2: #f1f5f9;    /* Slate 100 */
    --bg-hover: #e2e8f0;        /* Slate 200 */
    
    --text-main: #0f172a;       /* Slate 900 */
    --text-sec: #475569;        /* Slate 600 */
    --text-muted: #94a3b8;      /* Slate 400 */
    
    --border: #e2e8f0;          /* Slate 200 */
    --border-strong: #cbd5e1;   /* Slate 300 */

    /* Semantic */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Fonts */
    --font-ui: 'Montserrat', sans-serif;
    --font-data: 'Inter', system-ui, -apple-system, sans-serif;

    /* === STATE VARIABLES === */
    --banner-height: 0px;
    --current-sidebar-width: var(--sidebar-width);

    /* === LEGACY COMPATIBILITY LAYER === */
    --bg: var(--bg-page);
    --bg-2: var(--bg-surface-2);
    --card: var(--bg-surface);
    --text: var(--text-main);
    --muted: var(--text-muted);
    --icon-btn: 38px;
}

/* === STATE: Sidebar Collapsed === */
body.sidebar-compact {
    --current-sidebar-width: var(--sidebar-width-collapsed);
}

/* --- Global Resets & Typography --- */
html { scroll-behavior: smooth; }
body {
    background-color: var(--bg-page);
    color: var(--text-main);
    font-family: var(--font-data);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Apply Montserrat to UI Elements */
h1, h2, h3, h4, h5, h6, 
.navbar-brand, .sidebar-header, .nav-header, .btn, .form-label, 
.modal-title, .dropdown-header, .tooltip, .badge, .nav-link, .side-link {
    font-family: var(--font-ui);
}

a { text-decoration: none; color: inherit; transition: color var(--t-fast); }
ul { list-style: none; padding: 0; margin: 0; }

/* Icon Alignment */
i.fas, i.far, i.fab {
    display: inline-block; text-align: center; vertical-align: middle; line-height: 1;
}

/* --- Scrollbars --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--pill); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Layout Architecture --- */
.app-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--current-sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    z-index: 1040; 
    transition: width var(--t-med);
    display: flex; flex-direction: column; overflow: hidden;
}

.sidebar-content {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: var(--sp-sm); display: flex; flex-direction: column; gap: 4px;
}

.app-main, .main {
    flex: 1;
    margin-left: var(--current-sidebar-width);
    margin-top: calc(var(--navbar-height) + var(--banner-height));
    min-height: calc(100vh - var(--navbar-height) - var(--banner-height));
    transition: margin-left var(--t-med), margin-top var(--t-med);
    display: flex; flex-direction: column;
    width: calc(100% - var(--current-sidebar-width));
    padding-bottom: 2rem;
}

.app-navbar {
    position: fixed; top: 0; right: 0;
    left: var(--current-sidebar-width);
    height: var(--navbar-height);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 1030;
    padding: 0 var(--sp-lg);
    display: flex; align-items: center; justify-content: space-between;
    transition: left var(--t-med);
    box-shadow: var(--shadow-sm);
}

.content-container {
    padding: var(--sp-lg); width: 100%; max-width: 1600px; margin: 0 auto;
}

/* --- Branding --- */
/* Sidebar Brand */
.sidebar-header {
    height: var(--navbar-height);
    display: flex; align-items: center;
    padding: 0 var(--sp-md);
    border-bottom: 1px solid transparent;
    white-space: nowrap; text-decoration: none !important; color: var(--text-main);
}
.brand-logo { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; object-fit: contain; }
.brand-text { 
    font-weight: 700; font-size: 15px; margin-left: 12px; 
    opacity: 1; transition: opacity var(--t-fast);
}

/* Mobile Brand (Navbar) */
.mobile-brand {
    display: flex; align-items: center; gap: 8px;
    font-family: var(--font-ui); font-weight: 700; color: var(--text-main);
    text-decoration: none !important;
}
.mobile-brand-sep { opacity: 0.3; }

/* Navbar Platform Brand (Desktop) */
.navbar-platform-brand {
    font-family: var(--font-ui); font-weight: 700; font-size: 1.1rem;
    color: var(--text-main); letter-spacing: -0.02em;
    display: flex; align-items: center;
}

/* --- Sidebar Items --- */
.mobile-sidebar-header {
    padding: 1.25rem 1rem;
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
}
.mobile-sidebar-header .avatar { width: 44px; height: 44px; }

/* Collapsed State */
body.sidebar-compact .brand-text,
body.sidebar-compact .nav-header,
body.sidebar-compact .link-text,
body.sidebar-compact .usage-card,
body.sidebar-compact .sidebar-footer .d-lg-none { 
    opacity: 0; width: 0; display: none;
}
body.sidebar-compact .sidebar-header { padding: 0; justify-content: center; }
body.sidebar-compact .side-link { justify-content: center; padding: 0; }
body.sidebar-compact .side-link i { margin: 0; font-size: 1.25em; }
body.sidebar-compact .sidebar-footer { padding: var(--sp-sm) 0; align-items: center; }

.nav-header {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); font-weight: 700;
    margin: 18px 0 6px 14px;
}
.side-link {
    display: flex; align-items: center;
    height: 38px; padding: 0 14px;
    color: var(--text-sec); border-radius: var(--radius);
    font-weight: 500; transition: all var(--t-fast); white-space: nowrap;
    text-decoration: none; margin-bottom: 2px;
}
.side-link i { 
    width: 20px; text-align: center; margin-right: 12px; 
    color: var(--text-muted); flex-shrink: 0; transition: color var(--t-fast);
}
.side-link:hover { background: var(--bg-surface-2); color: var(--text-main); }
.side-link:hover i { color: var(--text-main); }
.side-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-link.active i { color: var(--primary); }
.side-link.text-danger:hover { background: #fef2f2; color: var(--danger); }

/* Sidebar Footer */
.sidebar-footer {
    padding: var(--sp-md);
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    display: flex; flex-direction: column; gap: var(--sp-xs);
    margin-top: auto;
}

/* Collapse Toggle Button (Improved) */
#sidebar-collapse-toggle {
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    color: var(--text-sec);
    height: 32px;
    border-radius: var(--radius-sm);
    transition: all var(--t-fast);
}
#sidebar-collapse-toggle:hover {
    background: var(--bg-hover);
    color: var(--primary);
    border-color: var(--border-strong);
}

/* --- Surfaces & Cards --- */
.surface, .card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.surface:hover, .card:hover {
    box-shadow: var(--shadow-card);
    border-color: var(--border-strong);
}

/* --- Buttons & Inputs --- */
.btn {
    height: var(--ctl-h); padding: 0 18px; font-size: 13px; font-weight: 600;
    border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; transition: all var(--t-fast); border: 1px solid var(--border);
    background: var(--bg-surface); color: var(--text-sec); cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.btn-sm { height: var(--ctl-h-sm); padding: 0 14px; font-size: 12px; }
.btn:hover { background: var(--bg-surface-2); border-color: var(--border-strong); color: var(--text-main); transform: translateY(-1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: white; box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3); }

.form-control, .form-select {
    height: var(--ctl-h); font-size: 14px; border-radius: var(--radius);
    border: 1px solid var(--border); padding: 0 14px; color: var(--text-main);
    background: var(--bg-surface); width: 100%; transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
    outline: none;
}

/* --- Search UI (Fixed Alignment & Mobile Hiding) --- */
.global-search-container { 
    width: 480px; max-width: 100%; position: relative; 
}
.search-input-wrapper {
    position: relative; display: flex; align-items: center;
    background: var(--bg-surface-2); border-radius: var(--radius);
    padding: 0 10px 0 14px; /* Right padding slightly less for badge */
    border: 1px solid transparent; transition: all var(--t-fast);
    height: 40px; /* Fixed height for alignment */
}
.search-input-wrapper:focus-within {
    background: var(--bg-surface); border-color: var(--primary);
    box-shadow: var(--shadow-search);
}
.search-input-wrapper i { color: var(--text-muted); font-size: 14px; }
.search-input-wrapper input {
    border: none; background: transparent; height: 100%; width: 100%; 
    outline: none; font-size: 14px; font-family: var(--font-ui); margin-left: 8px;
}
/* Fixed Badge Alignment */
.kbd-shortcut { 
    font-size: 10px; border: 1px solid var(--border-strong); border-radius: 4px; 
    padding: 3px 6px; color: var(--text-muted); font-weight: 600; 
    font-family: var(--font-data); white-space: nowrap; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    height: 20px;
}

/* --- Mobile Responsiveness (The Fix) --- */
@media (max-width: 992px) {
    :root {
        /* Override variables for smaller screens to ensure density */
        --sp-lg: 1rem;  /* Reduce padding from 1.5rem to 1rem */
        --sp-md: 0.75rem;
    }
    
    .app-sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .app-main, .main, .app-navbar {
        margin-left: 0; left: 0; width: 100%;
    }
    body.mobile-sidebar-open .app-sidebar { transform: translateX(0); box-shadow: var(--shadow-elev); }
    body.mobile-sidebar-open #sidebar-backdrop { opacity: 1; pointer-events: auto; }
    
    /* Hide Global Search on Mobile to fit Branding */
    .global-search-container { display: none !important; }
    
    .app-navbar { padding: 0 1rem; }
    
    /* Ensure content is full width on mobile */
    .content-container { padding: 1rem; }
}

/* Avatar & Utilities */
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--bg-surface); box-shadow: var(--shadow-sm); }
.plan-expiry-banner {
    background: var(--warning); color: #111; padding: 0.6rem; text-align: center; font-weight: 600; font-size: 13px; font-family: var(--font-ui);
}
body.has-expiry-banner { --banner-height: 38px; }

/* Select2 Overrides */
.select2-container .select2-selection {
    height: var(--ctl-h) !important; min-height: var(--ctl-h) !important;
    border-color: var(--border) !important; border-radius: var(--radius) !important;
    display: flex; align-items: center;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: normal !important; padding-left: 14px; color: var(--text-main) !important;
}
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 100%; }