/* ============================================================================
   HBS MEET - CORE STYLES (LAYOUT, RESPONSIVIDADE E CHAT)
============================================================================ */

:root {
  --bg-main: #0f172a;
  --bg-secondary: #1e293b;
  --text-light: #f8fafc;
  --accent-blue: #2563eb;
  --danger-red: #ef4444;
  --sidebar-width: 350px;
  --glass: rgba(30, 41, 59, 0.7);
}

/* RESET BÁSICO */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body, html {
  height: 100dvh; 
  width: 100%;
  background: radial-gradient(circle at top left, #1e293b, #0f172a);
  color: var(--text-light);
  overflow: hidden;
}

/* =========================================
   1. ESTRUTURA PRINCIPAL (BASE DO EJS)
========================================= */
.app-container { 
  display: flex; 
  height: 100dvh; 
  width: 100vw; 
  max-height: 100dvh;
}

.video-stage { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  position: relative;
  min-height: 0; 
  width: 100%;
}

/* =========================================
   2. O GRID DE VÍDEO (MÁGICA DO GOOGLE MEET)
========================================= */
#video-grid { 
  flex: 1; 
  display: flex; 
  flex-wrap: wrap; 
  justify-content: center; 
  align-content: center; 
  gap: 16px; 
  padding: 16px; 
  box-sizing: border-box;
  min-height: 0; 
  overflow-y: auto;
  transition: all 0.3s ease;
}

/* MODO GRID NORMAL */
#video-grid:not(.presentation-mode) .video-container {
  flex: 1 1 400px; 
  max-width: 80vw; 
  max-height: 75vh; 
  aspect-ratio: 16 / 9; 
  border-radius: 12px;
  background: #000; 
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
}

#video-grid .video-container video { 
  width: 100%;
  height: 100%;
  object-fit: cover; 
}

/* Espelha apenas a sua própria câmera, e nunca a tela compartilhada */
#video-grid .video-container:not(.featured) video {
  transform: scaleX(-1);
}

/* MODO APRESENTAÇÃO / FIXADO (Desktop) */
#video-grid.presentation-mode {
  flex-direction: row;
  align-items: center;
}

.presentation-mode .featured {
  flex: 1; 
  height: 100%; 
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  position: relative;
}

.presentation-mode .featured video { 
  object-fit: contain !important; 
  transform: scaleX(1) !important; /* Garante que texto de tela compartilhada dê pra ler */
}

/* BARRA LATERAL (Participantes no Desktop) */
#sidebar-wrapper {
  width: 320px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 8px;
}

#sidebar-wrapper::-webkit-scrollbar { width: 6px; height: 6px; }
#sidebar-wrapper::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }

.sidebar-item {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 16 / 9 !important; 
  flex-shrink: 0;
  border-radius: 12px;
  background: #000;
  position: relative;
  overflow: hidden;
}

/* BOTÃO DE FIXAR (PIN) e PAGINAÇÃO */
.pin-btn {
  position: absolute; top: 12px; right: 12px; background: rgba(15, 23, 42, 0.7); border: 1px solid rgba(255,255,255,0.2);
  color: white; border-radius: 8px; width: 36px; height: 36px; cursor: pointer; z-index: 10; display: none;
  font-size: 1.1rem; backdrop-filter: blur(4px); transition: 0.2s;
}
.pin-btn:hover { background: rgba(52, 211, 153, 0.8); }
.video-container:hover .pin-btn { display: block; }
.featured .pin-btn { display: block; background: rgba(52, 211, 153, 0.9); }

.hidden-page {
  position: absolute !important; top: -9999px !important; left: -9999px !important;
  visibility: hidden !important; width: 1px !important; height: 1px !important;
}

/* =========================================
   3. BOTÕES E RODAPÉ
========================================= */
.controls-footer { 
  height: 90px; 
  min-height: 90px; 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  gap: 15px; 
  padding-bottom: 10px; 
  z-index: 10;
  background: var(--bg-main);
  flex-wrap: wrap;
}

.control-btn {
  background-color: var(--bg-secondary); border: 1px solid rgba(255,255,255,0.1); color: white; width: 52px; height: 52px;
  border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; font-size: 1.3rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.control-btn:hover { background-color: #334155; transform: translateY(-3px); }
.control-btn.active { background-color: var(--accent-blue); }
.control-btn.danger { background-color: var(--danger-red); }
.recording-active { background-color: var(--danger-red) !important; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.1); opacity: 0.8; } }

/* =========================================
   4. MODAIS E LOBBY
========================================= */
#lobby-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-main); z-index: 9999; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(10px); }
.lobby-card { background: var(--glass); padding: 40px; border-radius: 24px; border: 1px solid rgba(255,255,255,0.1); text-align: center; max-width: 400px; width: 90%; }
.lobby-card input { width: 100%; padding: 14px; margin: 20px 0; border-radius: 12px; border: 1px solid var(--accent-blue); background: #0f172a; color: white; outline: none; box-sizing: border-box; }

#host-modal {
  display: none; position: fixed; top: 20px; right: 20px; background: #fff; padding: 20px; border-radius: 16px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.4); z-index: 10000; color: #1e293b; width: 300px;
  border-left: 6px solid var(--accent-blue); animation: slideLeft 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes slideLeft { from { opacity: 0; transform: translateX(50px); } to { opacity: 1; transform: translateX(0); } }
.modal-btns { display: flex; gap: 10px; margin-top: 15px; }
.modal-btn { flex: 1; padding: 12px; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.btn-allow { background: var(--accent-blue); color: white; }
.btn-deny { background: #f1f5f9; color: #64748b; }

/* =========================================
   5. CHAT LATERAL (DESKTOP)
========================================= */
.chat-aside { 
  width: var(--sidebar-width); 
  background-color: #fff; 
  height: 100%; 
  display: flex; 
  flex-direction: column; 
  box-shadow: -10px 0 30px rgba(0,0,0,0.2); 
  transition: transform 0.3s ease; 
  color: #1e293b; 
  z-index: 100;
}
.chat-aside.hidden { transform: translateX(100%); position: absolute; right: 0; }
#chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px;}
.chat-input-area { padding: 20px; display: flex; gap: 10px; border-top: 1px solid #e2e8f0; }
.chat-input-area input { flex: 1; border: 1px solid #cbd5e1; padding: 12px; border-radius: 25px; outline: none; }
.chat-input-area button { background-color: var(--accent-blue); color: white; border: none; padding: 0 20px; border-radius: 25px; cursor: pointer; }

/* =========================================================
   6. 📱 MODO RESPONSIVO (CELULARES E TABLETS)
========================================================= */
@media (max-width: 768px) {
  /* 6.1 - Grid empilha na vertical com rolagem */
  #video-grid {
    align-content: flex-start;
  }
  #video-grid:not(.presentation-mode) .video-container {
      flex: 0 0 auto; 
      width: 100% !important;
      max-width: 100%;
      height: auto;
      aspect-ratio: 16 / 9;
  }

  /* 6.2 - Modo Apresentação: Vídeo Principal em cima, rolo embaixo */
  #video-grid.presentation-mode {
      flex-direction: column;
      padding: 8px;
  }
  .presentation-mode .featured {
      width: 100%;
      height: 50vh; 
      flex: none;
  }
  #sidebar-wrapper {
      width: 100%;
      height: 140px;
      flex-direction: row;
      overflow-x: auto;
      overflow-y: hidden;
      padding-right: 0;
  }
  .sidebar-item {
      height: 100% !important;
      width: auto !important;
  }
  
  .pin-btn { display: block; opacity: 0.6; }
  .pin-btn:active { opacity: 1; }

  /* 6.3 - Botões menores para caber na tela */
  .controls-footer {
    gap: 8px;
    padding: 0 5px;
    height: 70px;
    min-height: 70px;
  }
  .control-btn {
    width: 44px; height: 44px; font-size: 1.1rem;
  }

  /* 6.4 - CHAT FLUTUANTE (OVERLAY) NO CELULAR */
  .chat-aside {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw; /* Ocupa a tela toda horizontalmente */
    height: calc(100vh - 70px); /* Fica acima dos botões */
  }
  /* Quando o botão é clicado, o JS remove a classe .hidden e ele desliza pra dentro da tela */
}

/* =========================================================
   7. TELA DE LOGIN (LOGIN.EJS) E ESTILOS COMPARTILHADOS
========================================================= */
.login-body {
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
    animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-card { 
    background: var(--card-bg, rgba(30, 41, 59, 0.7)); 
    backdrop-filter: blur(12px);
    padding: 40px; 
    border-radius: 20px; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); 
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.login-card .header { text-align: center; margin-bottom: 32px; }

.login-card .header h2 { 
    margin: 0; font-size: 1.85rem; font-weight: 700; letter-spacing: -0.025em;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.login-card .header p { color: var(--text-muted, #94a3b8); font-size: 0.95rem; margin-top: 8px; }

.input-group { margin-bottom: 20px; }
.input-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 8px; color: var(--text-muted, #94a3b8); }

.input-group input { 
    width: 100%; padding: 12px 16px; border: 1px solid var(--input-border, #334155); 
    border-radius: 10px; background: var(--input-bg, #1e293b); color: white; 
    box-sizing: border-box; font-size: 1rem; transition: all 0.2s ease;
}

.input-group input:focus {
    outline: none; border-color: var(--accent-blue);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15); background: #171f2e;
}

.auth-btn { 
    width: 100%; padding: 14px; background: var(--accent-blue); border: none; 
    border-radius: 10px; color: white; font-weight: 600; font-size: 1rem;
    cursor: pointer; transition: all 0.2s ease; margin-top: 10px;
}
.auth-btn:hover { box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3); }
.auth-btn:active { transform: scale(0.98); }
.auth-btn:disabled { background: #334155; cursor: not-allowed; opacity: 0.7; }

#error-msg { color: var(--danger-red); font-size: 0.85rem; margin-top: 15px; text-align: center; min-height: 20px; font-weight: 500; }

.footer-text { text-align: center; margin-top: 24px; font-size: 0.8rem; color: var(--text-muted, #94a3b8); letter-spacing: 0.025em; }

/* =========================================================
   8. DASHBOARD (DASHBOARD.EJS)
========================================================= */
.dashboard-body {
    display: flex;
    justify-content: center;
    align-items: center;
}

.dashboard-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.dashboard-card {
    background: var(--card-bg, rgba(30, 41, 59, 0.7));
    backdrop-filter: blur(12px);
    padding: 48px 40px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.welcome-icon {
    font-size: 3.5rem;
    margin-bottom: 24px;
    display: inline-block;
    animation: wave 2s infinite ease-in-out;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(15deg); }
}

.dashboard-card h1 { 
    margin: 0; font-size: 2rem; font-weight: 700; letter-spacing: -0.025em;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

.dashboard-card p { 
    color: var(--text-muted, #94a3b8); margin: 12px 0 32px 0; font-size: 1rem; line-height: 1.5;
}

.start-btn {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-hover, #1d4ed8));
    color: white; border: none; padding: 18px 32px; font-size: 1.1rem; font-weight: 600;
    border-radius: 14px; cursor: pointer; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 12px;
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

.start-btn:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 20px 25px -5px rgba(37, 99, 235, 0.4); }
.start-btn:active { transform: translateY(-1px) scale(0.98); }

.logout-link {
    display: inline-block; margin-top: 32px; color: var(--text-muted, #94a3b8);
    text-decoration: none; font-size: 0.9rem; font-weight: 500; transition: color 0.2s;
    padding: 8px 16px; border-radius: 8px;
}
.logout-link:hover { color: var(--danger-red); background: rgba(239, 68, 68, 0.1); }

.footer-brand { margin-top: 24px; font-size: 0.8rem; color: rgba(148, 163, 184, 0.5); text-align: center; }

/* =========================================================
   9. TELA DE ADMIN (ADMIN-CREATE-USER.EJS)
========================================================= */
.admin-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    box-sizing: border-box;
}

.admin-container {
    width: 100%;
    max-width: 480px;
    animation: fadeIn 0.6s ease-out;
}

.admin-card {
    background: var(--card-bg, rgba(30, 41, 59, 0.7));
    backdrop-filter: blur(12px);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-card .header { text-align: center; margin-bottom: 30px; }
.admin-card .header h2 { margin: 0; font-size: 1.6rem; font-weight: 700; color: #fff; }
.admin-card .header p { color: var(--text-muted, #94a3b8); font-size: 0.9rem; margin-top: 5px; }

.form-group { margin-bottom: 18px; display: flex; flex-direction: column; }
.form-group label { font-size: 0.85rem; font-weight: 500; margin-bottom: 8px; color: var(--text-muted, #94a3b8); }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"] {
    width: 100%; padding: 12px 16px; border: 1px solid var(--input-border, #334155);
    border-radius: 10px; background: var(--input-bg, #1e293b); color: white;
    box-sizing: border-box; font-size: 0.95rem; transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none; border-color: var(--accent-blue);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.checkbox-group { flex-direction: row; align-items: center; gap: 10px; margin-top: 10px; cursor: pointer; user-select: none; }
.checkbox-group input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent-blue); }
.checkbox-group label { margin-bottom: 0; color: var(--text-light); cursor: pointer; }

#msg { margin-top: 20px; text-align: center; font-size: 0.9rem; min-height: 20px; }

.back-link {
    display: inline-block; margin-top: 25px; color: var(--text-muted, #94a3b8);
    text-decoration: none; font-size: 0.85rem; transition: color 0.2s;
}
.back-link:hover { color: #fff; }