:root {
    --bg-primary: #0f0c29;
    --bg-secondary: #302b63;
    --bg-tertiary: #24243e;
    --accent: #00d2ff;
    --accent-glow: #3a7bd5;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --danger: #ff416c;
    --success: #00b09b;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }

body {
    background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary), var(--bg-tertiary));
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#background-canvas {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    opacity: 0.3;
    background-image: radial-gradient(circle at 50% 50%, rgba(76, 29, 149, 0.3) 0%, transparent 60%);
    animation: pulse 15s infinite alternate ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.2; }
    100% { transform: scale(1.1); opacity: 0.4; }
}

.view {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0; left: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.view.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
    transform: scale(0.98);
}

.view.active {
    opacity: 1;
    pointer-events: all;
    z-index: 1;
    transform: scale(1);
}

.hidden { display: none !important; }

/* Glassmorphism */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Auth */
#auth-view {
    justify-content: center;
    align-items: center;
}

.auth-container {
    padding: 3rem;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.logo {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.2rem;
    letter-spacing: -1px;
}

.tagline { color: var(--text-secondary); margin-bottom: 2.5rem; font-weight: 300; }

.tabs { display: flex; gap: 1rem; padding: 0.5rem; background: rgba(0,0,0,0.2); border-radius: 12px; margin-bottom: 1.5rem; }
.tab-btn {
    flex: 1;
    background: none; border: none; color: var(--text-secondary); padding: 0.6rem; cursor: pointer; font-size: 0.95rem; font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s;
}
.tab-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.tab-btn.active { color: white; background: var(--accent); box-shadow: 0 4px 12px rgba(0, 210, 255, 0.3); }

.input-group { margin-bottom: 1.2rem; }
input {
    width: 100%;
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
input:focus { border-color: var(--accent); background: rgba(0,0,0,0.3); }

.cta-btn {
    width: 100%; padding: 1rem; border: none; border-radius: 12px;
    background: linear-gradient(90deg, var(--accent), var(--accent-glow));
    color: white; font-weight: 700; cursor: pointer; margin-top: 1rem; font-size: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.cta-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0, 210, 255, 0.4); }
.cta-btn:active { transform: translateY(0); }
.cta-btn.small { width: auto; padding: 0.6rem 1.2rem; margin: 0; font-size: 0.9rem; }
.cta-btn.tiny { width: auto; padding: 0.3rem 0.6rem; margin: 0; font-size: 0.75rem; border-radius: 6px; }

/* Lobby */
.top-bar {
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1.5rem auto;
    max-width: 1600px;
    width: calc(100% - 3rem);
}
.logo-small { font-weight: 800; font-size: 1.5rem; letter-spacing: -0.5px; }
.user-info { 
    display: flex; 
    align-items: center; 
    gap: 0.8rem; 
    flex-wrap: wrap;
    justify-content: flex-end;
}
.icon-btn { 
    background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); color: var(--text-secondary); 
    padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; transition: all 0.2s; font-size: 0.9rem;
    display: flex; align-items: center; gap: 0.5rem;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: white; border-color: rgba(255,255,255,0.3); }

.lobby-content {
    flex: 1;
    display: flex;
    gap: 1.5rem;
    padding: 0 1.5rem 1.5rem 1.5rem;
    overflow: hidden;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.create-room-panel { width: 350px; padding: 2rem; display: flex; flex-direction: column; gap: 1.2rem; h2 { margin-bottom: 0.5rem; } }
.rooms-list-panel { flex: 1; padding: 2rem; display: flex; flex-direction: column; }
.scroll-area { 
    flex: 1; 
    overflow-y: auto; 
    padding-right: 0.5rem; 
    /* Scrollbar styling for firefox */
    scrollbar-width: thin; 
    scrollbar-color: rgba(255,255,255,0.2) transparent; 
}

.room-item {
    background: linear-gradient(to right, rgba(255,255,255,0.02), rgba(255,255,255,0.04));
    padding: 1.2rem;
    border-radius: 12px;
    margin-bottom: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
    transition: all 0.2s;
    cursor: pointer;
}
.room-item:hover { 
    background: rgba(255,255,255,0.08); 
    border-color: rgba(255,255,255,0.1); 
    transform: translateX(4px);
}
.room-join-btn {
    padding: 0.5rem 1.2rem;
    background: rgba(0, 210, 255, 0.1);
    color: var(--accent);
    border: 1px solid rgba(0, 210, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}
.room-item:hover .room-join-btn { background: var(--accent); color: white; }

/* Room Layout - Fixes */
.room-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0.5rem;
    gap: 0.5rem;
    overflow: hidden;
}

.room-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-radius: 16px;
    margin-bottom: 0.25rem;
}

.room-main-content {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    min-height: 0;
}

.main-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    min-height: 0;
}

.video-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
    gap: 1rem;
    align-content: start;
    justify-content: center;
    overflow-y: auto;
    padding: 0.5rem;
    min-height: 0;
    border-radius: 12px;
}

.video-card {
    position: relative;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    aspect-ratio: 16/9;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255,255,255,0.1);
    max-height: 100%;
}
.video-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.video-card video { width: 100%; height: 100%; object-fit: cover; }
.video-card .label {
    position: absolute; bottom: 12px; left: 12px;
    background: rgba(0,0,0,0.6); padding: 4px 10px; border-radius: 20px; font-size: 0.85rem;
    backdrop-filter: blur(4px); font-weight: 500;
    z-index: 5;
}

.stats-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px;
    border-radius: 8px;
    font-size: 0.7rem;
    color: var(--accent);
    backdrop-filter: blur(4px);
    pointer-events: none;
    z-index: 10;
    border: 1px solid rgba(0, 210, 255, 0.2);
}
.stats-overlay.hidden { display: none; }

.controls-overlay {
    position: absolute; bottom: 12px; right: 12px;
    display: flex; gap: 0.5rem;
    opacity: 0; transition: opacity 0.3s;
    background: rgba(0,0,0,0.6); padding: 4px; border-radius: 20px;
    backdrop-filter: blur(4px);
}
.video-card:hover .controls-overlay { opacity: 1; }
.control-btn {
    width: 32px; height: 32px; border-radius: 50%; border: none; background: rgba(255,255,255,0.1); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.control-btn:hover { background: rgba(255,255,255,0.3); }
.control-btn.on { background: var(--accent); color: white; }

/* Room Controls - Fixed visibility */
.room-controls {
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Don't shrink */
    gap: 1rem;
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
}

.save-file-option-chat {
    padding: 10px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}
.save-file-option-chat input { width: auto; margin: 0; cursor: pointer; }

/* Sidebar - Fixed Tabs */
.sidebar { 
    width: 320px; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    transition: width 0.3s ease, padding 0.3s ease, margin 0.3s ease;
}
.sidebar.hidden { width: 0; padding: 0; border: none; margin: 0; }

.sidebar .tabs {
    margin: 0.5rem;
    background: rgba(0,0,0,0.2);
}

.sidebar-content { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    padding: 0 0.5rem 0.5rem 0.5rem; 
}
.sidebar-content.hidden { display: none; } /* CRITICAL FIX */

.admin-tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.admin-tab-content.hidden { display: none !important; }

/* Chat Styling */
#chat-history { 
    flex: 1; 
    overflow-y: auto; 
    margin-bottom: 1rem; 
    display: flex; 
    flex-direction: column; 
    gap: 0.8rem; 
    padding-right: 4px;
}

.message { 
    padding: 0.8rem 1rem; 
    border-radius: 12px; 
    border-bottom-left-radius: 2px;
    background: rgba(255,255,255,0.08); 
    font-size: 0.95rem; 
    max-width: 85%; 
    width: fit-content;
    line-height: 1.4;
    position: relative;
}
.message .sender { 
    font-weight: 600; color: var(--accent); font-size: 0.75rem; 
    display: block; margin-bottom: 4px; opacity: 0.9;
}
.message.self { 
    align-self: flex-end; 
    background: linear-gradient(135deg, rgba(0, 210, 255, 0.15), rgba(58, 123, 213, 0.15));
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 2px;
    border: 1px solid rgba(0, 210, 255, 0.1);
}

.msg-content-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.msg-text {
    word-break: break-word;
}

.msg-delete-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s;
    padding: 0;
    margin-top: -2px;
}

.message:hover .msg-delete-btn {
    opacity: 0.6;
}
.message .msg-delete-btn:hover {
    opacity: 1;
}

#chat-form { 
    display: flex; 
    gap: 0.8rem; 
    background: rgba(0,0,0,0.2);
    padding: 0.8rem;
    border-radius: 12px;
}
#chat-form input { 
    background: transparent; border: none; padding: 0; 
}
#chat-form input:focus { background: transparent; }
#chat-form button { 
    background: var(--accent); border: none; padding: 0.5rem 1rem; 
    border-radius: 8px; color: white; cursor: pointer; font-weight: bold;
    transition: transform 0.1s;
}
#chat-form button:active { transform: scale(0.95); }

/* Logs & Files */
.log-item {
    font-family: 'Consolas', monospace;
    font-size: 0.8rem;
    padding: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background 0.1s;
}
.log-item:hover { background: rgba(255,255,255,0.02); }

.file-item {
    background: rgba(255,255,255,0.05);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    border: 1px solid transparent;
}
.file-item:hover { border-color: rgba(255,255,255,0.1); }
.file-item a { color: var(--accent); text-decoration: none; font-weight: 500; }
.file-item a:hover { text-decoration: underline; }

/* Toast */
.toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: rgba(20, 20, 20, 0.9); 
    backdrop-filter: blur(10px);
    padding: 12px 24px; border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 2000;
    font-weight: 500;
    border: 1px solid rgba(255,255,255,0.1);
}
.toast.hidden { bottom: -60px; opacity: 0; transform: translateX(-50%) scale(0.9); }

.danger-btn { 
    background: rgba(255, 65, 108, 0.15); border: 1px solid rgba(255, 65, 108, 0.3); 
    padding: 0.6rem 1.2rem; color: var(--danger); border-radius: 8px; cursor: pointer; 
    font-weight: 600; transition: all 0.2s;
}
.danger-btn:hover { background: var(--danger); color: white; }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(15, 12, 41, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    opacity: 1;
    transition: opacity 0.3s ease, visibility 0.3s;
    visibility: visible;
}
.modal.hidden { 
    opacity: 0; 
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background: #1a1a2e;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    width: 90%;
    max-width: 600px;
    padding: 2.5rem;
    border-radius: 24px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-content h2 {
    margin-bottom: 2rem;
    font-size: 2rem;
    background: linear-gradient(135deg, #fff 0%, #aaa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.setting-group select {
    width: 100%;
    padding: 0.8rem;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}
.setting-group select:focus {
    border-color: var(--accent);
    background: rgba(0,0,0,0.5);
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 600px) {
    .settings-grid { grid-template-columns: 1fr; }
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2.5rem;
}

/* Settings Preview */
.settings-preview-container {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 12px;
    margin-top: 10px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: inset 0 0 20px rgba(0,0,0,1);
}
.settings-preview-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.audio-level-container {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    margin-top: 10px;
    overflow: hidden;
}
.audio-level-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--success), var(--accent));
    transition: width 0.1s;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* Responsive */

@media (max-width: 900px) {

    .lobby-content { flex-direction: column; overflow-y: auto; }

    .create-room-panel { width: 100%; }

    .top-bar { margin: 1rem; width: calc(100% - 2rem); padding: 0.8rem 1.2rem; }



    .room-main-content { flex-direction: column; }



    .sidebar { width: 100%; height: 400px; flex: none; }

    .main-stage { flex: 1; }

}

/* Admin Console */
.admin-layout {
    display: flex;
    height: 100%;
    width: 100%;
}

.admin-sidebar {
    width: 250px;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.admin-nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 1rem;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.admin-nav-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.admin-nav-btn.active {
    background: linear-gradient(90deg, rgba(0, 210, 255, 0.1), transparent);
    color: var(--accent);
    border-left: 3px solid var(--accent);
}

.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    overflow: hidden;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.stat-card {
    padding: 1.5rem;
    text-align: center;
    border-radius: 16px;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-top: 0.5rem;
    text-shadow: 0 0 20px rgba(0, 210, 255, 0.3);
}

.admin-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border-radius: 16px;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    height: 100%;
    min-height: 600px;
}

.chart-card {
    padding: 1rem;
    height: 100%;
    min-height: 300px;
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

/* Drag & Drop Overlay */
#drag-drop-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 12, 41, 0.85);
    backdrop-filter: blur(20px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

#drag-drop-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.overlay-content {
    text-align: center;
    padding: 3rem;
    border: 3px dashed var(--accent);
    border-radius: 40px;
    background: rgba(255,255,255,0.03);
    box-shadow: 0 0 50px rgba(0, 210, 255, 0.2);
    transform: scale(1.1);
    animation: float 3s infinite ease-in-out;
}

.overlay-content h2 {
    font-size: 2.5rem;
    margin-top: 1rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay-content .icon {
    font-size: 5rem;
    display: block;
}

@keyframes float {
    0%, 100% { transform: translateY(0) scale(1.1); }
    50% { transform: translateY(-20px) scale(1.15); }
}
