/* ================= Variáveis de Tema ================= */
:root {
    --bg-color: #0a0a0c;
    --text-main: #ffffff;
    --text-muted: #888891;
    --primary-purple: #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.3);
    --surface: #131318;
    --border: #272730;
    --input-bg: #1c1c24;
    --danger: #ef4444;
}

[data-theme="light"] {
    --bg-color: #f8f9fa;
    --text-main: #111115;
    --text-muted: #6b6b75;
    --primary-purple: #7c3aed;
    --primary-glow: rgba(124, 58, 237, 0.2);
    --surface: #ffffff;
    --border: #e2e8f0;
    --input-bg: #f1f5f9;
    --danger: #dc2626;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', system-ui, sans-serif; }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden; 
    transition: background-color 0.3s ease, color 0.3s ease;
}

#mesh-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 0;
    pointer-events: none;
}

.ambient-blob {
    position: absolute;
    width: 50vw; height: 50vw;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 60%);
    border-radius: 50%;
    filter: blur(60px);
    z-index: 0;
    animation: float 40s infinite alternate ease-in-out;
    pointer-events: none;
}
.blob-1 { top: -10%; left: -10%; }
.blob-2 { bottom: -10%; right: -10%; animation-delay: -20s; }

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(10%, 15%) scale(1.2); }
}

#app {
    position: relative;
    z-index: 10;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ================= Header da Home (Invisível e Limitado a 1000px) ================= */
.home-header {
    max-width: 1000px !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 1.5rem 1.5rem !important;
    background: transparent !important;
    border: none !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    position: relative !important;
    z-index: 100 !important;
}

/* Header Padrão da Sala (sala.html) */
#main-header:not(.home-header) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-logo { font-size: 1.4rem; font-weight: 800; user-select: none; }
.header-logo .go { color: var(--primary-purple); }
.header-logo .liivee { color: var(--text-main); }

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.room-badge {
    background: var(--input-bg);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    border: 1px solid var(--border);
}
.room-badge span { color: var(--primary-purple); }

.nick-wrapper {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.nick-wrapper input {
    width: 130px;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
    border-radius: 8px;
}

/* ================= Telas Iniciais (index.html) ================= */
.screen {
    position: absolute;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.6s ease, opacity 0.6s ease;
}

.giant-logo { font-weight: 900; line-height: 0.85; user-select: none; }
.giant-logo .go { font-size: 7rem; color: var(--primary-purple); display: block; }
.giant-logo .liivee { font-size: 6.5rem; color: var(--text-main); display: block; letter-spacing: -2px; }

.action-box {
    background: var(--surface); padding: 2rem; border-radius: 20px;
    border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    display: flex; flex-direction: column; gap: 1rem;
}

input {
    width: 100%; padding: 0.8rem 1rem; border-radius: 10px;
    border: 1px solid var(--border); background: var(--input-bg);
    color: var(--text-main); font-size: 0.95rem; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus { border-color: var(--primary-purple); box-shadow: 0 0 0 3px var(--primary-glow); }

button.btn-primary {
    background: var(--primary-purple); color: #fff; border: none; padding: 0.8rem 1.2rem;
    border-radius: 10px; font-size: 0.95rem; font-weight: bold; cursor: pointer; transition: all 0.2s;
}
button.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
button.btn-primary:active { transform: scale(0.98); }

button.btn-secondary {
    background: transparent; color: var(--text-main); border: 1px solid var(--border);
    padding: 0.8rem 1.2rem; border-radius: 10px; font-size: 0.95rem; font-weight: bold; cursor: pointer; transition: all 0.2s;
}
button.btn-secondary:hover { border-color: var(--primary-purple); color: var(--primary-purple); }

.btn-sm { padding: 0.4rem 0.8rem !important; font-size: 0.85rem !important; }

/* ================= Botão de Tema Animado (Sol / Lua) ================= */
#theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.3s ease;
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}

#theme-toggle:hover {
    transform: scale(1.08);
    border-color: var(--primary-purple);
}

#theme-toggle svg {
    position: absolute;
    width: 20px;
    height: 20px;
    transition: all 0.5s cubic-bezier(0.65, 0, 0.35, 1);
}

/* Animação de Giro e Troca dos Ícones */
.moon-icon { opacity: 0; transform: translateY(25px) rotate(45deg); }
.sun-icon { opacity: 1; transform: translateY(0) rotate(0); }

[data-theme="light"] .moon-icon { opacity: 1; transform: translateY(0) rotate(0); }
[data-theme="light"] .sun-icon { opacity: 0; transform: translateY(-25px) rotate(-45deg); }

/* ================= SALA DE VÍDEO (sala.html) ================= */
.room-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - 65px);
    padding: 1rem;
    gap: 1rem;
}

.video-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 0;
    height: 100%;
}

.spotlight-container {
    flex: 1;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-placeholder { color: var(--text-muted); font-size: 1.1rem; }

.video-slot {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #050508;
}

.video-slot video, .video-slot canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Picture-in-Picture (PiP no Canto Superior Direito) */
.pip-overlay {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 220px;
    height: 125px;
    background: #0a0a0f;
    border: 2px solid var(--primary-purple);
    border-radius: 12px;
    overflow: hidden;
    z-index: 40;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0,0,0,0.7);
    transition: transform 0.2s, border-color 0.2s;
}
.pip-overlay:hover {
    transform: scale(1.04);
    border-color: #fff;
}
.pip-overlay video, .pip-overlay canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ================= MODO GRADE DINÂMICA (1, 2, 3, 4) ================= */
.spotlight-container.grid-mode {
    display: grid !important;
    gap: 8px;
    padding: 8px;
}

/* 1 Vídeo */
.spotlight-container.grid-mode.grid-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

/* 2 Vídeos (Lado a lado) */
.spotlight-container.grid-mode.grid-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

/* 3 Vídeos (2 em cima, 1 centralizado embaixo) */
.spotlight-container.grid-mode.grid-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}
.spotlight-container.grid-mode.grid-3 .video-slot:nth-child(3) {
    grid-column: span 2;
    max-width: 50%;
    margin: 0 auto;
}

/* 4 Vídeos (2x2 Perfeito) */
.spotlight-container.grid-mode.grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* Carousel de Miniaturas */
.participants-queue {
    display: flex;
    gap: 0.8rem;
    height: 90px;
    overflow-x: auto;
}
.participants-queue::-webkit-scrollbar { height: 6px; }
.participants-queue::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.mini-video-card {
    min-width: 140px;
    height: 100%;
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    transition: transform 0.2s, border-color 0.2s;
}
.mini-video-card:hover { transform: translateY(-2px); border-color: var(--primary-purple); }
.mini-video-card.active-focus { border-color: var(--primary-purple); box-shadow: 0 0 0 2px var(--primary-glow); }
.mini-video-card video, .mini-video-card canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
}
.mini-video-card .card-tag {
    position: relative;
    z-index: 2;
    background: rgba(0,0,0,0.7);
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-tag {
    position: absolute;
    bottom: 0.8rem;
    left: 0.8rem;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    color: #fff;
    font-size: 0.8rem;
    z-index: 10;
}

/* Barra de Controles Inferior */
.control-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem;
    background: var(--surface);
    border-radius: 14px;
    border: 1px solid var(--border);
}

.control-btn {
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}
.control-btn:hover { background: var(--border); transform: translateY(-2px); }
.control-btn svg { width: 18px; height: 18px; stroke-width: 2; }
.control-btn.danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.control-btn.danger:hover { background: var(--danger); color: #fff; }
.control-btn.active { background: var(--primary-purple); color: #fff; border-color: var(--primary-purple); }

.control-separator { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* ================= Sidebar (Chat e Arquivos) ================= */
.sidebar-panel {
    width: 320px;
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.sidebar-header {
    display: flex;
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    flex: 1; padding: 0.8rem; background: transparent; border: none; color: var(--text-muted); font-weight: bold; font-size: 0.85rem; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary-purple); border-bottom-color: var(--primary-purple); }

.participants-bar {
    background: var(--input-bg);
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.participants-list {
    max-height: 0;
    overflow-y: auto;
    transition: max-height 0.3s ease;
    background: var(--surface);
}
.participants-list.expanded { max-height: 130px; border-bottom: 1px solid var(--border); }
.participant-item { padding: 0.4rem 0.8rem; font-size: 0.8rem; color: var(--text-main); }

.sidebar-body-wrapper {
    flex: 1;
    display: flex;
    width: 200%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-body-wrapper.show-files { transform: translateX(-50%); }

.sidebar-tab { width: 50%; display: flex; flex-direction: column; height: 100%; }

.chat-area { flex: 1; padding: 0.8rem; display: flex; flex-direction: column; overflow-y: auto; gap: 0.6rem; }
.chat-message { background: var(--input-bg); padding: 0.6rem 0.8rem; border-radius: 10px; font-size: 0.85rem; }
.chat-message .author { font-weight: bold; color: var(--primary-purple); margin-bottom: 0.2rem; display: block; font-size: 0.75rem; }

.chat-input-wrapper { padding: 0.8rem; border-top: 1px solid var(--border); display: flex; gap: 0.4rem; }
.chat-input-wrapper input { padding: 0.6rem 0.8rem; font-size: 0.85rem; border-radius: 8px; }
.btn-send { width: 38px !important; height: 38px !important; border-radius: 8px !important; }

#file-list-container { flex: 1; padding: 0.8rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.6rem; }
#empty-files-msg { text-align: center; color: var(--text-muted); margin-top: 2rem; font-size: 0.85rem; }
.file-upload-btn { margin: 0.8rem; padding: 0.6rem; font-size: 0.85rem; }

/* ================= RESPONSIVIDADE MOBILE ================= */
@media (max-width: 850px) {
    body { overflow-y: auto; }
    #app { height: auto; min-height: 100vh; }
    
    #main-header { flex-direction: column; gap: 0.6rem; align-items: stretch; }
    .header-controls { flex-wrap: wrap; justify-content: center; }
    
    .room-layout { flex-direction: column; height: auto; padding: 0.5rem; }
    .video-panel { height: auto; min-height: 55vh; }
    .spotlight-container { min-height: 260px; height: 45vh; }
    
    .pip-overlay { width: 130px; height: 80px; }
    .sidebar-panel { width: 100%; height: 420px; }
}

/* ================= DROPDOWN DE QUALIDADE ================= */
.quality-dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.quality-selector {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    transition: all 0.2s;
}
.quality-selector:hover {
    color: var(--text-main);
    background: var(--input-bg);
}

.quality-menu {
    display: none;
    position: absolute;
    bottom: 55px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.6);
    min-width: 240px;
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
}
.quality-menu.show { display: block; }
.quality-menu::-webkit-scrollbar { width: 5px; }
.quality-menu::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.quality-opt-header {
    padding: 0.5rem 0.9rem 0.2rem 0.9rem;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--primary-purple);
    letter-spacing: 0.5px;
}

.quality-opt {
    padding: 0.5rem 0.9rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
}
.quality-opt:hover {
    background: var(--input-bg);
    color: var(--text-main);
}
.quality-opt.active {
    color: var(--primary-purple);
    font-weight: bold;
    background: rgba(139, 92, 246, 0.12);
}
/* ================= HUD de stats + transporte ================= */
.quality-opt-hint {
    padding: 0.15rem 0.9rem 0.65rem 0.9rem;
    font-size: 0.68rem;
    color: var(--text-muted);
    line-height: 1.35;
}

#stats-hud {
    position: absolute;
    top: 0.8rem;
    left: 0.8rem;
    z-index: 50;
    margin: 0;
    padding: 0.45rem 0.6rem;
    background: rgba(0, 0, 0, 0.62);
    color: #d6d6de;
    font: 600 0.68rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
    border-radius: 8px;
    border: 1px solid rgba(139, 92, 246, 0.35);
    backdrop-filter: blur(8px);
    pointer-events: none;
    white-space: pre;
    max-width: min(90%, 320px);
    display: none;
}
#stats-hud.warn {
    border-color: rgba(239, 68, 68, 0.55);
    color: #fecaca;
}

@media (max-width: 850px) {
    #stats-hud { font-size: 0.62rem; top: 0.5rem; left: 0.5rem; }
    .control-bar { flex-wrap: wrap; }
}
