:root {
    /* Core Colors - Premium Slate & Purple Palette */
    --glass-primary: #8b5cf6;
    --glass-primary-glow: rgba(139, 92, 246, 0.4);
    --glass-secondary: #ec4899;
    --glass-bg-dark: #0f172a;
    --glass-bg-card: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-text-dark: #1e293b;
    --glass-text-muted: #64748b;
    --glass-body-bg: radial-gradient(circle at top right, #f8fafc, #f1f5f9);
    
    /* Layout Tokens */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    --header-height: 70px;
    
    /* Glassmorphism Tokens */
    --glass-blur: blur(16px);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    --glass-card-border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --glass-bg-card: rgba(30, 41, 59, 0.8) !important;
    --glass-border: rgba(255, 255, 255, 0.12) !important;
    --glass-text-dark: #f8fafc !important;
    --glass-text-muted: #94a3b8 !important;
    --glass-body-bg: #0f172a !important;
    --glass-card-border: 1px solid rgba(255, 255, 255, 0.1) !important;
    --glass-shadow: 0 12px 48px 0 rgba(0, 0, 0, 0.6) !important;
}

/* Base Styles */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    height: 100%;
    width: 100%;
}

* {
    box-sizing: border-box;
}

body {
    background: var(--glass-body-bg);
    font-family: 'Inter', sans-serif;
    transition: background 0.3s ease;
    overflow-x: hidden;
}

/* --- MODERN SAAS LAYOUT --- */

.app-layout {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
}

/* Premium Sidebar */
.user-sidebar {
    width: var(--sidebar-width) !important;
    background: var(--glass-bg-dark);
    backdrop-filter: var(--glass-blur);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed !important; /* Force fixed */
    left: 0;
    top: 0;
    z-index: 3000;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    overflow-y: auto;
    overflow-x: hidden;
}

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

/* Main Content Wrapper */
.main-content {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width); /* Space for fixed sidebar */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--glass-body-bg);
    transition: margin-left 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

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

.sidebar-logo {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.sidebar-logo .logo-img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--glass-primary), var(--glass-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.sidebar-logo .logo-text {
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.5px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s;
}

.user-sidebar.collapsed .logo-text {
    opacity: 0;
    pointer-events: none;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 25px;
    color: #94a3b8;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav a i {
    font-size: 1.2rem;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav a span {
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s;
}

.user-sidebar.collapsed .sidebar-nav a span {
    opacity: 0;
    pointer-events: none;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.03);
    color: #fff;
}

.sidebar-nav a.active {
    background: rgba(139, 92, 246, 0.1);
    color: #fff;
    border-left-color: var(--glass-primary);
}

.sidebar-nav a.active i {
    color: var(--glass-primary);
}

/* User Profile Section */
.sidebar-footer {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.profile-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    padding: 10px;
    border-radius: 12px;
    transition: all 0.3s;
    overflow: hidden;
}

.user-sidebar.collapsed .profile-card {
    padding: 10px 0;
    justify-content: center;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--glass-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.profile-meta {
    overflow: hidden;
    white-space: nowrap;
}

.user-sidebar.collapsed .profile-meta {
    display: none;
}

.profile-name {
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    display: block;
}

.profile-role {
    color: #64748b;
    font-size: 0.7rem;
    display: block;
}

/* --- LIGHT SIDEBAR THEME --- */
.user-sidebar.light-sidebar {
    background: #ffffff !important;
    border-right: 1px solid #e2e8f0 !important;
    backdrop-filter: none !important;
}

.user-sidebar.light-sidebar .sidebar-logo {
    border-bottom: 1px solid #f1f5f9;
}

.user-sidebar.light-sidebar .logo-text {
    color: #1e293b !important;
}

.user-sidebar.light-sidebar .sidebar-nav a {
    color: #64748b;
}

.user-sidebar.light-sidebar .sidebar-nav a:hover {
    background: #f8fafc;
    color: var(--glass-primary);
}

.user-sidebar.light-sidebar .sidebar-nav a.active {
    background: rgba(139, 92, 246, 0.05);
    color: var(--glass-primary);
}

.user-sidebar.light-sidebar .sidebar-footer {
    border-top: 1px solid #f1f5f9;
}

.user-sidebar.light-sidebar .profile-card {
    background: #f8fafc;
}

.user-sidebar.light-sidebar .profile-name {
    color: #1e293b;
}

.user-sidebar.light-sidebar .profile-role {
    color: #94a3b8;
}

.user-sidebar.light-sidebar .sidebar-nav div[style*="Management"] {
    color: #94a3b8 !important;
}

.dl-widget {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.user-sidebar.light-sidebar .dl-widget {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

.user-sidebar.light-sidebar .dl-bar-bg {
    background: #cbd5e1 !important;
}


/* Premium Header */
.app-header {
    min-height: var(--header-height);
    height: auto;
    padding: 10px 30px;
    background: var(--glass-bg-card);
    backdrop-filter: var(--glass-blur);
    border-bottom: var(--glass-card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 2000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.sidebar-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(0,0,0,0.03);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--glass-primary);
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: var(--glass-primary);
    color: white;
}

.page-title {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--glass-text-dark);
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-action {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(0,0,0,0.03);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--glass-text-muted);
    transition: all 0.3s;
}

.header-action:hover {
    color: var(--glass-primary);
    border-color: var(--glass-primary);
    background: white;
}

/* Re-using Glass Card and other components from before */
.glass-card {
    background: var(--glass-bg-card);
    backdrop-filter: var(--glass-blur);
    border: var(--glass-card-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    padding: 30px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Mobile Responsive Overrides */
@media (max-width: 992px) {
    :root {
        --sidebar-width: 280px;
        --header-height: 60px;
    }

    .app-layout {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .user-sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
        height: 100vh;
        z-index: 5000;
        transition: transform 0.3s ease;
    }
    
    .user-sidebar.open {
        transform: translateX(0);
    }
    
    .user-sidebar.collapsed + .main-content,
    .app-layout.sidebar-collapsed .main-content {
        margin-left: 0 !important;
    }

    .main-content-wrapper {
        padding: 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        display: block !important; /* block so children stretch to full width */
    }

    .dashboard-container,
    .profile-settings-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        min-width: 100% !important;
        padding: 0 !important;
        display: block !important;
    }

    .app-header {
        width: 100% !important;
        padding: 0 10px !important;
        box-sizing: border-box !important;
    }

    .page-title { 
        font-size: 1.1rem !important;
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        backdrop-filter: blur(4px);
        z-index: 4500;
        display: none;
    }
    
    .sidebar-overlay.show {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }
}

@media (max-width: 768px) {
    .profiles-manager {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 15px !important;
    }
    
    .profiles-manager > div:last-child {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 8px;
        display: flex !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }

    .posterlo-greeting-header {
        flex-direction: column;
        text-align: center;
        gap: 10px !important;
    }
}

/* Base Styles */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    min-height: 100%;
    width: 100%;
    max-width: 100% !important;
    overflow-x: hidden !important;
    position: relative;
}

/* Absolute container containment for responsive stability */
*, *::before, *::after {
    box-sizing: border-box !important;
}

img, video, iframe, embed, object {
    max-width: 100% !important;
}

.table-responsive {
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
}

.btn-premium {
    background: linear-gradient(135deg, var(--glass-primary), var(--glass-secondary));
    color: white;
    padding: 14px 28px;
    border-radius: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--glass-primary-glow);
    transition: all 0.3s ease;
}
