/* ==============================================
   SIDEBAR & DASHBOARD LAYOUT
   ============================================== */

/* Sidebar Navigation */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    border: none;
    border-right: 1px solid var(--glass-border);
    background: rgba(8, 8, 12, 0.8);
    backdrop-filter: blur(40px);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: width 0.3s ease;
}

.sidebar-header {
    padding: 24px 28px;
    margin-bottom: 8px;
}

.sidebar-header .branding {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    height: 32px;
    width: auto;
}

.brand-name {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, var(--gold), var(--cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0 16px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-radius: 14px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item i {
    width: 20px;
    font-size: 1.1rem;
    text-align: center;
    opacity: 0.7;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: rgba(243, 194, 106, 0.1);
    color: var(--gold);
}

.nav-item.active i {
    opacity: 1;
}

.nav-item.add-btn {
    color: var(--gold);
    margin-top: 4px;
}

.nav-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 0 16px 20px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 20px 16px;
    border-top: 1px solid var(--glass-border);
}

.lang-selector-minimal {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    outline: none;
}

/* Top Bar Styling */
.top-bar {
    height: var(--top-bar-height);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    background: rgba(5, 5, 8, 0.7);
    backdrop-filter: blur(20px);
    z-index: 900;
    border-bottom: 1px solid var(--glass-border);
}

.search-container {
    flex: 1;
    max-width: 800px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    padding: 0 20px;
    height: 44px;
    border-radius: 22px;
    transition: all 0.3s ease;
}

.search-box:focus-within {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(243, 194, 106, 0.1);
}

.search-box i {
    color: var(--text-muted);
}

.search-box input {
    background: none;
    border: none;
    color: white;
    width: 100%;
    font-size: 0.95rem;
    outline: none;
}

.top-bar-actions {
    position: absolute;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-create-short {
    background: var(--gold);
    color: #000;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-create-short:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px var(--gold-glow);
}

.btn-login-round {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-login-round:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Category Filter Bar */
.filter-bar {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: none;
    /* Hide scrollbar Firefox */
}

.filter-bar::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar Chrome/Safari */
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-chip:hover {
    background: rgba(255, 255, 255, 0.1);
}

.filter-chip.active {
    background: white;
    color: black;
    border-color: white;
}

.content-header {
    margin-bottom: 0;
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}

.view-header h2 {
    font-size: 1.8rem;
    font-weight: 800;
}

.btn-icon-ref {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
}

/* Loading States */
.loader-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 100px 0;
    gap: 20px;
    color: var(--text-muted);
}

.pulse-ring {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gold);
    border-radius: 50%;
    animation: ripple 1.5s infinite;
}

@keyframes ripple {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }

    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* Responsive Overrides within layout.css */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-collapsed-width);
    }
    .app-stage {
        margin-left: var(--sidebar-collapsed-width);
    }
    .sidebar .brand-name,
    .sidebar .nav-item span,
    .sidebar .nav-section-title {
        display: none;
    }
    .sidebar .nav-item {
        justify-content: center;
        padding: 12px;
    }
}

.mobile-lang-zone {
    display: none;
}

/* Mobile: Fully Hide Sidebar, Use Bottom Nav */
@media (max-width: 768px) {
    .sidebar {
        display: none !important;
    }
    
    .app-stage {
        margin-left: 0;
        /* Padding bottom to make room for fixed bottom nav + safe area */
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    }

    body.in-live-room .app-stage {
        /* Remove padding when bottom nav is hidden inside a live room */
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .top-bar {
        padding: 0 16px;
        height: 60px;
    }

    /* ═══ iOS Capacitor: Robust fixed layout (WebKit workaround) ═══
       iOS WebView doesn't reliably support position:fixed/sticky.
       Fix: lock body to viewport, use flex layout for header + scrollable content. */
    
    body.ios-app {
        overflow: hidden !important;
        height: 100vh;
        height: 100dvh;
    }

    body.ios-app .app-stage {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
        padding-bottom: 0;
    }

    body.ios-app .top-bar {
        flex-shrink: 0;
        position: relative;
        padding-top: env(safe-area-inset-top, 0px);
        height: auto;
        min-height: calc(50px + env(safe-area-inset-top, 0px));
        z-index: 1100;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    /* Scroll-to-hide: collapse top-bar but keep safe-area background */
    body.ios-app .top-bar.top-bar-hidden {
        transform: translateY(calc(-100% + env(safe-area-inset-top, 0px)));
        opacity: 0;
        pointer-events: none;
        min-height: env(safe-area-inset-top, 0px);
    }

    /* Scrollable content area — only this part scrolls */
    body.ios-app .app-container {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }

    /* In live room: bottom nav is hidden, remove extra padding */
    body.ios-app.in-live-room .app-container {
        padding-bottom: 0;
        overflow: visible;
    }

    /* When top-bar is hidden, content needs its own safe-area top padding */
    body.ios-app .app-container .room-list-container,
    body.ios-app .app-container .management-container {
        padding-top: env(safe-area-inset-top, 0px);
    }

    /* Category filter bar — relocated via JS to be a flex sibling, always visible */
    body.ios-app .ios-fixed-filter {
        flex-shrink: 0;
        background: var(--bg-dark);
        padding: 8px 16px;
        z-index: 100;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    /* Vertically center items within the content area below the safe-area */
    body.ios-app .top-bar .search-container,
    body.ios-app .top-bar-actions {
        align-self: center;
    }

    /* Logo must center within the content area, not the full bar */
    body.ios-app .top-bar::before {
        top: calc(env(safe-area-inset-top, 0px) + 25px);
    }
    
    .search-container {
        /* Hide full search box, keep only an icon or shrink it */
    }
    
    .search-box {
        padding: 0 12px;
    }
    
    .search-box input {
        display: none; /* In MVP, hide the text input completely on phone to save space */
    }

    /* Keep Search Icon Clickable maybe to trigger modal later */
    .search-box i {
        font-size: 1.2rem;
    }

    /* We need to show the brand logo in the top bar on mobile since sidebar is gone */
    .top-bar::before {
        content: '';
        background-image: url('../../assets/logo.svg?v=3');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center left;
        width: 100px;
        height: 28px;
        position: absolute;
        left: 20px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    .search-container {
        margin-left: 130px; /* Clear the 100px logo */
        margin-right: 120px; /* Prevent overlap with absolute actions */
    }

    .mobile-lang-zone {
        display: block;
    }

    /* Hide user profile from top bar on mobile — accessed via bottom nav instead */
    .top-bar-actions .user-profile-zone {
        display: none !important;
    }
}

/* ═══════ Mobile User Popup Menu ═══════ */
.mobile-user-menu {
    display: none;
    position: fixed;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    width: 220px;
    background: rgba(20, 20, 28, 0.96);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 8px 0;
    z-index: 2100;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    animation: mobileMenuSlideUp 0.2s ease-out;
}

.mobile-user-menu.open {
    display: block;
}

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

.mobile-user-menu-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mobile-user-menu-header img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.mobile-user-menu-header .mu-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
}

.mobile-user-menu-header .mu-credits {
    font-size: 0.75rem;
    color: var(--gold);
    font-family: 'JetBrains Mono', monospace;
}

.mobile-user-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
}

.mobile-user-menu-item:hover,
.mobile-user-menu-item:active {
    background: rgba(255, 255, 255, 0.06);
    color: white;
}

.mobile-user-menu-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    opacity: 0.7;
}

.mobile-user-menu-item.danger {
    color: #f87171;
}

.mobile-user-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 4px 16px;
}

.mobile-user-menu-item select {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: white;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.82rem;
    cursor: pointer;
    outline: none;
}

/* Backdrop overlay to close menu */
.mobile-user-menu-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2050;
}

.mobile-user-menu-backdrop.open {
    display: block;
}