/* 0. Variables */
body.glos-pwa {
    --glos-pwa-header-height: 56px;
}

/**
 * GridLoungeOS PWA Minimal Landing System
 * 
 * Implements strict separation between PWA and Desktop UI via dual-root containers.
 * Only the minimal landing page is shown in PWA mode.
 */

/* ==========================================
   ROOT CONTAINER VISIBILITY RULES
   ========================================== */

/* Default state (Desktop/Non-PWA mode) - strongest possible hide */
#glos-pwa-root {
    display: none !important;
}

#glos-desktop-root {
    display: block;
}

/* Immediate hide in standalone mode (before JS runs) */
@media (display-mode: standalone) {
    #glos-desktop-root {
        display: none !important;
    }

    #glos-pwa-root {
        display: flex !important;
        flex-direction: column;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
    }
}

/* PWA Mode (body.glos-pwa present - after JS runs for extra safety) */
body.glos-pwa #glos-pwa-root {
    display: flex !important;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

body.glos-pwa #glos-desktop-root {
    display: none !important;
}

/* Force hide PWA root when NOT in PWA mode */
body:not(.glos-pwa) #glos-pwa-root {
    display: none !important;
}

/* ==========================================
   PWA MINIMAL LANDING UI
   ========================================== */

/* PWA Fixed Header */
body.glos-pwa .glos-pwa-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding-top: env(safe-area-inset-top, 0);
    background: var(--gl-surface, #ffffff);
    border-bottom: 1px solid var(--gl-border, #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 16px;
    padding-right: 16px;
    z-index: 100;
}

body.glos-pwa .glos-pwa-header-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--gl-text, #101828);
    letter-spacing: -0.3px;
}

body.glos-pwa .glos-pwa-header-icon {
    background: none;
    border: none;
    color: var(--gl-text-muted, #667085);
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.glos-pwa .glos-pwa-header-icon .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
}

/* PWA Profile Menu (Side/Dropdown) */
body.glos-pwa .glos-pwa-profile-menu {
    position: fixed;
    top: 57px;
    /* Below header */
    right: 10px;
    width: 260px;
    background: var(--gl-surface, #ffffff);
    border: 1px solid var(--gl-border, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 200;
    display: none;
    flex-direction: column;
    padding: 8px;
    transform-origin: top right;
    animation: glosScaleIn 0.2s ease-out;
}

/* ==========================================
   PWA SLIDE-OUT NAVIGATION
   ========================================== */
body.glos-pwa .glos-pwa-nav-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--gl-surface, #ffffff);
    z-index: 1000;
    /* Above Header */
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
}

body.glos-pwa .glos-pwa-nav-menu.open {
    transform: translateX(0);
}

body.glos-pwa .glos-pwa-nav-header {
    height: 56px;
    padding-top: env(safe-area-inset-top, 0);
    display: flex;
    align-items: center;
    padding-left: 20px;
    border-bottom: 1px solid var(--gl-border, #e2e8f0);
}

body.glos-pwa .glos-pwa-nav-logo {
    height: 32px;
    width: auto;
}

body.glos-pwa .glos-pwa-nav-header h2 {
    font-size: 18px;
    margin: 0;
    color: var(--gl-text, #101828);
}

body.glos-pwa .glos-pwa-nav-links {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

body.glos-pwa .glos-pwa-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--gl-text, #101828);
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    border-radius: 8px;
    transition: background 0.2s;
}

body.glos-pwa .glos-pwa-nav-item:hover,
body.glos-pwa .glos-pwa-nav-item.active {
    background: var(--gl-bg, #f8fafc);
    color: #1997FF;
}

body.glos-pwa .glos-pwa-nav-item .dashicons {
    font-size: 20px;
    color: var(--gl-text-muted, #667085);
}

body.glos-pwa .glos-pwa-nav-item.active .dashicons {
    color: #1997FF;
}

body.glos-pwa .glos-pwa-nav-separator {
    height: 1px;
    background: var(--gl-border, #e2e8f0);
    margin: 8px 0;
}

body.glos-pwa .glos-pwa-profile-menu.open {
    display: flex;
}

/* Backdrop for outside click */
body.glos-pwa .glos-pwa-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 150;
    background: transparent;
    /* Invisible backdrop to catch clicks */
}

body.glos-pwa .glos-pwa-backdrop.active {
    display: block;
}

/* Menu Items */
body.glos-pwa .glos-pwa-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--gl-text, #101828);
    text-decoration: none;
    font-size: 16px;
    border-radius: 8px;
    transition: background 0.2s;
    min-height: 20px;
    /* Ensure 44px total click target */
}

body.glos-pwa .glos-pwa-menu-item:hover,
body.glos-pwa .glos-pwa-menu-item:active {
    background: var(--gl-bg, #f8fafc);
}

body.glos-pwa .glos-pwa-menu-item .dashicons {
    color: var(--gl-text-muted, #667085);
    font-size: 20px;
}

body.glos-pwa .glos-pwa-logout {
    color: #dc2626;
    /* Red for logout */
}

body.glos-pwa .glos-pwa-logout .dashicons {
    color: #dc2626;
}

/* Separator */
body.glos-pwa .glos-pwa-menu-separator {
    height: 1px;
    background: var(--gl-border, #e2e8f0);
    margin: 8px 0;
}

/* PWA Version in Menu */
body.glos-pwa .glos-pwa-version-display {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--gl-text-muted, #667085);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

body.glos-pwa .glos-pwa-ver-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Update Button (Small, inline-ish) */
body.glos-pwa .glos-pwa-update-btn {
    margin-top: 6px;
    background: #1997FF;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    align-self: flex-start;
}

body.glos-pwa .glos-pwa-update-btn:hover {
    background: #0073e6;
}

@keyframes glosScaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* PWA Scrollable Content */
body.glos-pwa .glos-pwa-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Header (56px) + 15px Gap + Safe Area */
    /* Note: Header is fixed. Content flows under it. */
    /* We add 15px gap explicitly. */
    /* Header (56px) + Safe Area ONLY */
    /* Spacing: Header (56px) + Gap (15px) + Safe Area */
    padding-top: calc(71px + env(safe-area-inset-top, 0));
    padding-left: 15px;
    padding-right: 15px;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    background: var(--gl-bg, #f8fafc);
}

body.glos-pwa .glos-pwa-content h1 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--gl-text, #101828);
    margin: 0 0 15px 0;
    /* 0 Top, 15px Bottom */
    padding-top: 0;
}

body.glos-pwa .glos-pwa-content p {
    font-size: 16px;
    line-height: 1.5;
    color: var(--gl-text-muted, #667085);
    margin: 0;
}

/* ==========================================
   PWA NAVIGATION DRAWER
   ========================================== */
body.glos-pwa #glos-pwa-nav-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: #ffffff;
    z-index: 9999;
    transition: left 0.3s ease;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
}

body.glos-pwa #glos-pwa-nav-menu.open {
    left: 0;
}

body.glos-pwa .glos-pwa-nav-header {
    padding: 24px 20px;
    border-bottom: 1px solid #e0e0e0;
}

body.glos-pwa .glos-pwa-nav-logo {
    max-width: 120px;
    height: auto;
}

body.glos-pwa .glos-pwa-nav-links {
    padding: 12px 0;
}

body.glos-pwa .glos-pwa-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    text-decoration: none;
    color: #333;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.2s;
    position: relative;
    /* For gradient bar positioning */
}

body.glos-pwa .glos-pwa-nav-item .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
}

body.glos-pwa .glos-pwa-nav-item:hover {
    background: #f5f5f5;
}

/* Active State with Gradient Bar */
body.glos-pwa .glos-pwa-nav-item.active {
    font-weight: 700;
    padding-left: 30px;
    /* 20px base + 10px indent */
    color: #1976d2;
}

body.glos-pwa .glos-pwa-nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to bottom, #157acc, #373766);
}

/* Menu Backdrop */
body.glos-pwa #glos-pwa-menu-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
}

body.glos-pwa #glos-pwa-menu-backdrop.open {
    display: block;
}

/* Prevent background scroll when drawer is open */
body.drawer-open {
    overflow: hidden !important;
}

/* ==========================================
   PWA VIEW CONTAINERS
   ========================================== */
body.glos-pwa .glos-pwa-view {
    display: none;
}

body.glos-pwa .glos-pwa-view.active {
    display: block;
}

/* Placeholder View Styling */
body.glos-pwa .glos-pwa-view-title {
    font-size: 28px;
    font-weight: 700;
    color: #101828;
    margin: 0 0 12px 0;
    padding-left: 15px;
}

body.glos-pwa .glos-pwa-view-subtitle {
    font-size: 16px;
    color: #667085;
    margin: 0;
    padding-left: 15px;
}

/* ========================================