/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
  --bg-app: #121212;
  --bg-panel: #1e1e1e;
  --bg-surface: #2c2c2c;
  
  --primary: #5865F2; 
  --primary-hover: #4752c4;
  --danger: #ef4444;
  --success: #10b981;
  
  --text-main: #ffffff;
  --text-muted: #a1a1aa;
  
  --border-subtle: rgba(255, 255, 255, 0.1);
  --radius: 8px;
  
  --header-height: 60px;
  --controls-height: 64px;
}

* { box-sizing: border-box; outline: none; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  overflow-x: hidden; 
  font-size: 15px;
}

.hidden { display: none !important; }
.icon-svg { width: 20px; height: 20px; }

/* =========================================
   2. ESTRUCTURA APP
   ========================================= */
.app { 
  display: flex; 
  flex-direction: column; 
  height: 100dvh; 
  width: 100vw; 
}

/* =========================================
   3. LOGIN
   ========================================= */
#auth-container {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, #2a2a2a 0%, #121212 100%);
  padding: 20px;
  overflow-y: auto; 
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--bg-panel);
  border: 1px solid var(--border-subtle); border-radius: 16px;
  padding: 30px; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  margin: auto; 
}
.auth-header h1 { margin: 0; font-size: 2rem; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 20px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
.input-group { position: relative; }
.input-group .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); opacity: 0.7; }
input {
  width: 100%; padding: 12px 12px 12px 40px;
  background: #000; border: 1px solid var(--border-subtle);
  border-radius: var(--radius); color: #fff; font-size: 1rem;
}
.btn-primary {
  background: var(--primary); color: white; border: none; padding: 12px;
  border-radius: var(--radius); font-weight: 600; cursor: pointer; width: 100%;
}
.btn-primary:hover { background: var(--primary-hover); }

/* =========================================
   4. HEADER / SETUP
   ========================================= */
#setup-panel {
  flex-shrink: 0;
  background: var(--bg-panel); border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  z-index: 20;
  min-height: var(--header-height);
  transition: all 0.3s ease;
}

.logo-text { font-weight: 700; font-size: 1.2rem; }

#guest-controls { display: flex; gap: 10px; align-items: center; flex: 1; max-width: 500px; margin: 0 auto; }
#guest-controls input { background: #111; border-color: #444; }

#host-controls { display: flex; gap: 10px; align-items: center; width: 100%; justify-content: flex-end; }

.btn-action { background: var(--success); color: #fff; border:none; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.btn-ghost { background: transparent; border: 1px solid var(--border-subtle); color: var(--text-muted); padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.btn-danger-ghost { background: transparent; border: 1px solid var(--danger); color: var(--danger); padding: 8px 12px; border-radius: 6px; cursor: pointer; }

/* =========================================
   5. BARRA DE CONTROLES
   ========================================= */
.main-content {
  flex: 1; display: flex; flex-direction: column; 
  position: relative; overflow: hidden;
}

.controls-bar {
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  height: var(--controls-height);
  display: flex; align-items: center; justify-content: center;
  padding: 0 16px; flex-shrink: 0; z-index: 30;
  gap: 10px;
  overflow: hidden;
}

.controls-left { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.status-indicator { color: var(--success); font-weight: 500; font-size: 0.9rem; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.status-indicator::before { content:''; display: block; width: 8px; height: 8px; background: currentColor; border-radius: 50%; }
.badge { background: #333; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; color: #aaa; border: 1px solid #444; }

.controls-center-scroll {
  flex: 0 1 auto;
  display: flex;
  justify-content: center;
  min-width: 0;
  width: auto;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  padding: 0 6px;
}
.controls-center-scroll::-webkit-scrollbar { display: none; }
.controls-center { display: flex; align-items: center; gap: 5px; min-width: max-content; }
.controls-right {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  position: relative;
  z-index: 3;
  background: var(--bg-panel);
  padding-left: 8px;
}

.media-controls { display: flex; gap: 5px; background: rgba(0,0,0,0.2); padding: 4px; border-radius: 99px; }
.media-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: #3a3a3a; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.media-btn:hover { background: #4a4a4a; }
.media-btn.off { background: #dc2626; color: #fff; }

.separator { width: 1px; height: 24px; background: var(--border-subtle); margin: 0 2px; }
.control-btn { background: transparent; border: none; color: var(--text-muted); width: 40px; height: 40px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.control-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.host-moderation { display: flex; gap: 5px; margin-left: 5px; }
.mod-btn { width: 36px; height: 36px; border-radius: 50%; background: #2a2a2a; border: 1px solid #444; cursor: pointer; font-size: 1.1rem; }
#btnLeave { margin-left: 6px; }

/* Evita que botones se compriman y desaparezcan iconos */
.media-btn,
.control-btn,
.mod-btn,
.btn-leave {
  flex-shrink: 0;
}

.btn-leave { background: #dc2626; color: white; border: none; height: 36px; padding: 0 20px; border-radius: 18px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.btn-leave .btn-icon { display: none; width: 20px; height: 20px; }
.btn-leave:hover { background: #b91c1c; }

/* Desktop: reservar espacio para estado y evitar recorte del centro */
@media (min-width: 901px) {
  .controls-left {
    flex: 0 1 260px;
    max-width: 260px;
    overflow: hidden;
  }

  .controls-center-scroll {
    justify-content: center;
    padding-inline: 6px;
  }

  .host-moderation {
    margin-right: 10px;
  }
}

/* =========================================
   6. GRID DE VIDEO & PANELES
   ========================================= */
.content-wrapper { flex: 1; display: flex; overflow: hidden; position: relative; background: #000; }
#grid-container { flex: 1; overflow-y: auto; padding: 10px; display: flex; align-items: center; justify-content: center; }

#grid { width: 100%; max-width: 1400px; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; align-content: center; justify-content: center; }
#grid:has(.tile:only-child) { grid-template-columns: 1fr; max-width: 900px; }

/* Modo galeria dinamico (tipo Zoom) cuando NO hay screen share */
#grid.gallery-fit:not(.screen-share-mode) {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: 100%;
  grid-template-columns: repeat(var(--gallery-cols, 1), minmax(0, 1fr));
  grid-auto-rows: auto;
  align-content: center;
  justify-content: center;
}

#grid.gallery-fit:not(.screen-share-mode) .tile {
  width: 100%;
  max-height: 100%;
}

.tile { background: #1a1a1a; border-radius: 8px; overflow: hidden; position: relative; aspect-ratio: 16/9; border: 2px solid transparent; box-shadow: 0 4px 6px rgba(0,0,0,0.3); }
.tile.me { border-color: var(--primary); }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.namepill { position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,0.6); color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 0.8rem; pointer-events: none; }
.state-badges { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.state-badge-icon {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
}
.state-badge-icon.is-on {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(16, 185, 129, 0.55);
  color: #d1fae5;
}
.state-badge-icon.is-off {
  background: rgba(239, 68, 68, 0.24);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fee2e2;
}
.tile .spectator-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50px; height: 50px; fill: #555; display: none; }
.tile.spectator .spectator-icon, .tile.video-paused .spectator-icon { display: block; }
.tile.spectator video, .tile.video-paused video { opacity: 0; }

.side-panel { width: 320px; background: var(--bg-panel); border-left: 1px solid var(--border-subtle); display: flex; flex-direction: column; flex-shrink: 0; }
.panel-header { height: 50px; padding: 0 12px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.panel-header h3 { margin: 0; font-size: 1rem; }
.close-panel-mobile { background: none; border: none; color: #fff; font-size: 1.2rem; cursor: pointer; display: none; }

#chat-messages { flex: 1; padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-message { background: #333; padding: 8px 12px; border-radius: 8px; font-size: 0.9rem; max-width: 90%; word-wrap: break-word; }
.chat-message-wrapper.me .chat-message { background: var(--primary); align-self: flex-end; margin-left: auto; }
#chat-form { padding: 10px; background: var(--bg-surface); display: flex; gap: 8px; align-items: center; }
#chat-input { flex: 1; background: #111; border: none; color: #fff; padding: 8px; border-radius: 20px; resize: none; }
#btn-send-chat, #btn-attach-file { background: transparent; border: none; color: var(--primary); cursor: pointer; font-size: 1.2rem; padding: 4px; }

.lobby-list { padding: 10px; overflow-y: auto; flex: 1; }
.lobby-item { display: flex; justify-content: space-between; align-items: center; background: #333; padding: 8px; margin-bottom: 8px; border-radius: 6px; }
.lobby-btn { border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; }
.lobby-btn.accept { background: rgba(16,185,129,0.2); color: var(--success); }
.lobby-btn.reject { background: rgba(239,68,68,0.2); color: var(--danger); }

#admission-notifications { position: fixed; top: 70px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.notification-card { background: var(--bg-panel); padding: 10px; border: 1px solid var(--border-subtle); border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.5); display: flex; gap: 10px; align-items: center; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg-panel); padding: 20px; border-radius: 12px; border: 1px solid var(--border-subtle); width: 90%; max-width: 400px; position: relative; }
.modal-close-btn { position: absolute; top: 10px; right: 10px; background: none; border: none; color: #fff; font-size: 1.5rem; }
.room-notice-modal {
  max-width: 460px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.5);
}
.room-notice-icon {
  width: 62px;
  height: 62px;
  margin: 4px auto 14px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.65rem;
  color: #f59e0b;
  background: radial-gradient(circle at 30% 30%, rgba(245, 158, 11, 0.2), rgba(245, 158, 11, 0.08));
  border: 1px solid rgba(245, 158, 11, 0.35);
}
#roomNoticeTitle {
  margin: 0 0 8px;
}
#roomNoticeMessage {
  margin: 0 0 16px;
  color: rgba(255, 255, 255, 0.86);
}
.room-notice-actions {
  display: flex;
  justify-content: center;
}
#changePasswordForm { display: flex; flex-direction: column; gap: 10px; margin-top: 15px; }

/* =========================================
   7. RESPONSIVE MOBILE
   ========================================= */
@media (max-width: 768px) {
  
  /* --- SOLUCIÓN INPUT: Panel cubre toda la pantalla y permite scroll --- */
  #setup-panel {
    height: 100vh; 
    min-height: 100vh;
    flex-direction: column;
    justify-content: center;
    padding: 20px;
    position: absolute; 
    top: 0; left: 0; width: 100%;
    background: var(--bg-app); 
    overflow-y: auto; /* Permite scroll vertical */
  }

  /* Si el HOST ya entró, ocultamos este panel */
  #setup-panel:has(#host-controls:not(.hidden)) {
     position: relative;
     min-height: 0; height: auto; display: none;
  }
  
  /* Si el GUEST ya entró, ocultamos este panel */
  #setup-panel:has(#guest-controls.hidden) {
    display: none;
  }

  #guest-controls { flex-direction: column; width: 100%; gap: 15px; }
  #guest-controls input { padding: 15px; font-size: 1.1rem; width: 100%; }
  #guest-controls button { width: 100%; padding: 15px; font-size: 1.1rem; }
  .logo-text { margin-bottom: 30px; font-size: 2rem; }

  /* --- BARRA DE CONTROLES ARRIBA --- */
  .controls-bar {
    order: -1;
    height: auto; min-height: 56px;
    padding: 8px 12px;
    background: #181818;
    border-bottom: 1px solid var(--border-subtle); border-top: none;
  }
  
  .controls-left { flex: 0 0 auto; width: auto; }
  .status-indicator span, .controls-left .badge { display: none; }

  .controls-center-scroll {
    overflow-x: auto; justify-content: flex-start;
    padding: 0 10px;
    scrollbar-width: none; -ms-overflow-style: none;
  }
  .controls-center-scroll::-webkit-scrollbar { display: none; }

  .media-btn, .control-btn, .mod-btn { width: 36px; height: 36px; flex-shrink: 0; }
  .media-controls { padding: 0; background: transparent; gap: 5px; }

  .controls-right { flex: 0 0 auto; }
  .btn-leave { width: 36px; height: 36px; padding: 0; border-radius: 50%; background: #ef4444; }
  .btn-leave .btn-text { display: none; }
  .btn-leave .btn-icon { display: block; width: 18px; height: 18px; }

  #grid { grid-template-columns: 1fr; gap: 8px; align-content: start; padding-bottom: 80px; }
  .tile { aspect-ratio: 4/3; }
  
  .side-panel { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; z-index: 50; border-left: none; }
  .close-panel-mobile { display: block; }
  .welcome-section { display: none; }
}
.tile.speaking {
  border: 3px solid #22c55e;
  box-shadow: 0 0 15px rgba(34,197,94,0.6);
}

/* ================================
   SIDE PANEL (LOBBY + PARTICIPANTS)
================================ */

.side-panel {
  width: 320px;
  height: 100%;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-panel.hidden {
  display: none;
}

/* ================================
   LOBBY
================================ */

.lobby-header {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lobby-title {
  font-weight: 600;
  font-size: 15px;
}

.lobby-admit-all {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
}

.lobby-admit-all:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lobby-list {
  max-height: 35%;
  overflow-y: auto;
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
}

/* ================================
   PARTICIPANTS (DEBAJO DEL LOBBY)
================================ */

.participants-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* Header */
.participants-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Lista */
.participants-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Item */
.participants-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background 0.15s ease;
}

.participants-item:hover {
  background: #f3f4f6;
}

/* Lado izquierdo */
.participants-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Avatar */
.participants-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
  flex-shrink: 0;
}

/* Meta */
.participants-meta .name {
  font-size: 13px;
  font-weight: 500;
  color: #111827;
}

.participants-meta .sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

/* Acciones */
.participants-actions {
  display: flex;
  gap: 6px;
}

/* Botones */
.participants-btn {
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: #e5e7eb;
  color: #111827;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.participants-btn:hover {
  background: #d1d5db;
}

/* Toggle ON */
.participants-btn.on {
  background: #dcfce7;
  color: #065f46;
}

/* Toggle OFF */
.participants-btn.off {
  background: #fee2e2;
  color: #991b1b;
}

/* Badge Admin */
.participants-you {
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #2563eb;
  color: #ffffff;
  font-weight: 600;
}

/* Scrollbar */
.lobby-list::-webkit-scrollbar,
.participants-list::-webkit-scrollbar {
  width: 6px;
}

.lobby-list::-webkit-scrollbar-thumb,
.participants-list::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 6px;
}

/* ================================
   RESPONSIVE
================================ */

@media (max-width: 900px) {
  #setup-panel {
    padding: 10px;
    overflow-x: hidden;
  }

  #guest-controls {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 8px;
    flex-wrap: wrap;
  }

  #guest-controls input {
    min-width: 0;
    flex: 1 1 200px;
  }

  #guest-controls button {
    flex: 0 0 auto;
    max-width: 100%;
  }

  .side-panel {
    width: 100%;
    height: 45%;
    border-left: none;
    border-top: 1px solid #e5e7eb;
  }

  .lobby-list {
    max-height: 40%;
  }
}
/* ================================
   DIFERENCIACIÓN DE ESTADOS
================================ */

/* -------- SALA DE ESPERA -------- */

.lobby-header {
  background: #fff7ed; /* naranja suave */
  border-bottom: 1px solid #fed7aa;
}

.lobby-title {
  color: #9a3412;
  font-weight: 700;
}

.lobby-title::before {
  content: "⏳ ";
}

.lobby-list {
  background: #fffbf5;
}

/* Item lobby */
.lobby-item {
  background: #ffffff;
  border: 1px solid #fed7aa;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Nombre invitado */
.lobby-meta .name {
  font-size: 14px;
  font-weight: 600;
  color: #111827; /* negro real */
}
/* Subtexto */
.lobby-meta .sub {
  font-size: 12px;
  color: #6b7280;
}
.lobby-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;

  /* 🔴 CLAVE: texto blanco para contraste */
  color: #ffffff !important;
}

/* -------- SEPARADOR VISUAL -------- */

.participants-panel {
  border-top: 4px solid #e5e7eb;
  background: #f9fafb;
}

/* Etiqueta separadora */
.participants-header {
  background: #ecfeff; /* azul verdoso */
  border-bottom: 1px solid #67e8f9;
}

.participants-header h3 {
  font-weight: 700;
  color: #0f766e;
}

.participants-header h3::before {
  content: "🟢 ";
}

/* -------- EN SALA -------- */

.participants-list {
  background: #f8fafc;
}

/* Item participante */
.participants-item {
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

/* Participante activo */
.participants-item:hover {
  background: #f0fdfa;
}

/* -------- BADGES DE ESTADO -------- */

/* Badge mic/cam ON */
.participants-meta .sub span {
  font-weight: 600;
}

/* Badge admin */
.participants-you {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

/* -------- BOTONES -------- */

.participants-btn.on {
  background: #dcfce7;
  color: #065f46;
  border: 1px solid #86efac;
}

.participants-btn.off {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* -------- RESPONSIVE -------- */

@media (max-width: 900px) {
  .participants-header h3::before {
    content: "👥 ";
  }

  .lobby-title::before {
    content: "⌛ ";
  }
}
.participants-btn.danger{
  background:#fee2e2;
  color:#991b1b;
  border:1px solid #fecaca;
}
.participants-btn.danger:hover{
  filter:brightness(0.98);
}
/* ===============================
   LOBBY + PARTICIPANTS ALWAYS ON
   (solo Admin)
================================ */
body.is-host #lobby-panel {
  display: flex !important;
}

#lobby-panel {
  display: flex;
  flex-direction: column;
}

/* =========================================
   FIX: NO compartir estilos de side-panel
   Chat (dark) vs Lobby (light)
   Pegar al FINAL del CSS
   ========================================= */

/* --- CHAT: dark premium --- */
#chat-panel.side-panel{
  background: rgba(30,30,30,0.92);
  color: var(--text-main);
  border-left: 1px solid var(--border-subtle);
  backdrop-filter: blur(10px);
}

#chat-panel .panel-header{
  height: 54px;
  background: linear-gradient(180deg, rgba(88,101,242,0.12), transparent);
  border-bottom: 1px solid var(--border-subtle);
}

#chat-panel .panel-header h3{
  font-weight: 700;
  letter-spacing: .2px;
}

#chat-messages{
  padding: 14px 12px;
  gap: 10px;
  background:
    radial-gradient(1200px 300px at 50% 0%, rgba(88,101,242,0.10), transparent 60%),
    linear-gradient(180deg, rgba(0,0,0,0.18), transparent 40%);
  scrollbar-width: thin;
}

#chat-messages::-webkit-scrollbar{ width: 8px; }
#chat-messages::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,0.14);
  border-radius: 999px;
}
#chat-messages::-webkit-scrollbar-thumb:hover{
  background: rgba(255,255,255,0.22);
}

/* Mensajes: layout + burbujas */
.chat-message-wrapper{
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-message{
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.25rem;
  font-size: 0.95rem;
  max-width: 85%;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

/* Yo */
.chat-message-wrapper.me{
  justify-content: flex-end;
}
.chat-message-wrapper.me .chat-message{
  background: linear-gradient(135deg, rgba(88,101,242,1), rgba(71,82,196,1));
  border: 1px solid rgba(255,255,255,0.18);
  margin-left: auto;
}

/* Input bar */
#chat-form{
  padding: 10px;
  background: rgba(44,44,44,0.88);
  border-top: 1px solid var(--border-subtle);
  gap: 10px;
}

#chat-input{
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.10);
  color: #fff;
  padding: 10px 12px;
  border-radius: 14px;
  outline: none;
}
#chat-input:focus{
  border-color: rgba(88,101,242,0.75);
  box-shadow: 0 0 0 4px rgba(88,101,242,0.18);
}

/* Botones chat */
#btn-send-chat,
#btn-attach-file{
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  transition: transform .12s ease, background .12s ease;
}

#btn-send-chat{
  background: rgba(88,101,242,0.18);
  color: #fff;
}
#btn-send-chat:hover{
  background: rgba(88,101,242,0.28);
  transform: translateY(-1px);
}

#btn-attach-file{
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.85);
}
#btn-attach-file:hover{
  background: rgba(255,255,255,0.10);
  transform: translateY(-1px);
}

/* =========================================================
   ✅ MEJORA PRO: SOLO LOBBY + PARTICIPANTS (DARK)
   Pegar AL FINAL del CSS para sobreescribir lo anterior
   ========================================================= */

/* Asegura que lobby use tema oscuro (no blanco) */
#lobby-panel.side-panel{
  background: var(--bg-panel);
  color: var(--text-main);
  border-left: 1px solid var(--border-subtle);
}

/* Header lobby + participants con gradiente */
#lobby-panel .lobby-header,
#lobby-panel .participants-header{
  background: linear-gradient(180deg, rgba(88,101,242,.12), rgba(0,0,0,0));
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 14px;
}

/* Títulos */
#lobby-panel .lobby-title{
  font-weight: 800;
  letter-spacing: .2px;
  color: var(--text-main);
  display:flex;
  align-items:center;
  gap:8px;
}
#lobby-panel .lobby-title::before{
  content:"⏳";
  opacity:.9;
}

/* Contador lobby */
#lobby-count{
  color: var(--text-muted);
  font-weight: 700;
}

/* Botón admitir */
#btnAdmitAll.lobby-admit-all,
#lobby-panel .lobby-admit-all{
  background: rgba(16,185,129,.16);
  color: #d1fae5;
  border: 1px solid rgba(16,185,129,.35);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 800;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
#btnAdmitAll.lobby-admit-all:hover,
#lobby-panel .lobby-admit-all:hover{
  filter: brightness(1.06);
  transform: translateY(-1px);
}
#btnAdmitAll.lobby-admit-all:disabled,
#lobby-panel .lobby-admit-all:disabled{
  opacity:.5;
  cursor:not-allowed;
  transform:none;
}

/* Listas con scroll bonito */
#lobby-panel .lobby-list,
#lobby-panel .participants-list{
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(0,0,0,.18));
  padding: 14px;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

/* Tarjetas (lobby / participants) */
#lobby-panel .lobby-item,
#lobby-panel .participants-item{
  background:
    radial-gradient(120% 160% at 0% 0%, rgba(110,140,255,.10), transparent 46%),
    linear-gradient(145deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 12px;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 12px;
  box-shadow:
    0 12px 28px rgba(0,0,0,.30),
    inset 0 1px 0 rgba(255,255,255,.06);
  transition: transform .14s ease, background .14s ease, border-color .14s ease, box-shadow .14s ease;
  overflow: hidden;
}
#lobby-panel .lobby-item:hover,
#lobby-panel .participants-item:hover{
  transform: translateY(-1px);
  background:
    radial-gradient(120% 160% at 0% 0%, rgba(122,152,255,.14), transparent 46%),
    linear-gradient(145deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
  border-color: rgba(126,150,255,.34);
  box-shadow:
    0 14px 30px rgba(0,0,0,.34),
    inset 0 1px 0 rgba(255,255,255,.08);
}

/* Parte izquierda */
#lobby-panel .participants-left{
  display:flex;
  align-items:flex-start;
  gap:12px;
  min-width: 0;
  flex: 1 1 auto;
  width: auto;
}

/* Avatar con “glow” */
#lobby-panel .lobby-avatar,
#lobby-panel .participants-avatar{
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display:grid;
  place-items:center;
  font-weight: 900;
  color:#f8fafc !important;
  background: linear-gradient(135deg, rgba(88,101,242,1), rgba(71,82,196,1));
  box-shadow:
    0 0 0 4px rgba(88,101,242,.14),
    0 8px 16px rgba(32,42,96,.30);
  flex-shrink:0;
}

/* Meta textos */
#lobby-panel .lobby-meta .name,
#lobby-panel .participants-meta .name{
  color: #f8fafc !important;
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
#lobby-panel .lobby-meta .sub,
#lobby-panel .participants-meta .sub{
  color: #94a3b8 !important;
  font-size: .88rem;
  margin-top: 3px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

/* Acciones */
#lobby-panel .lobby-actions,
#lobby-panel .participants-actions{
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content:flex-end;
  align-content: center;
  flex: 0 0 auto;
}

/* Fila propia (Tu/Admin): layout estable, sin superposiciones */
#lobby-panel .participants-item.is-me-row{
  align-items: center;
}

#lobby-panel .participants-item.is-me-row .participants-left{
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}

#lobby-panel .participants-item.is-me-row .participants-actions-me{
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
  width: auto;
  margin-top: 0;
}

/* Acciones de interacción debajo del nombre del participante */
#lobby-panel .participants-meta .participants-actions.inline-actions{
  justify-content: flex-start;
  align-content: flex-start;
  margin-top: 8px;
  gap: 8px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}

/* Plegado/desplegado disponible en desktop y móvil */
#lobby-panel.lobby-collapsed .lobby-list {
  display: none;
}

#lobby-panel.participants-collapsed .participants-list {
  display: none;
}

#lobby-panel.participants-collapsed .participants-panel {
  flex: 0 0 auto;
}

#lobby-panel .lobby-header,
#lobby-panel .participants-header {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#lobby-panel .lobby-header::after,
#lobby-panel .participants-header::after {
  content: "▾";
  margin-left: auto;
  font-size: 14px;
  opacity: 0.8;
}

#lobby-panel.lobby-collapsed .lobby-header::after,
#lobby-panel.participants-collapsed .participants-header::after {
  content: "▸";
}

/* Desktop: mantiene acciones debajo del nombre y evita superposiciones */
@media (min-width: 901px){
  #lobby-panel .participants-item{
    padding: 14px;
    gap: 12px;
  }

  #lobby-panel .participants-meta{
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  #lobby-panel .participants-meta .name{
    max-width: 260px;
  }

  #lobby-panel .participants-meta .participants-actions.inline-actions .participants-btn.icon-btn{
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
  }
}

/* Botones lobby: aceptar/rechazar (más pro) */
#lobby-panel .lobby-btn{
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.05);
  cursor:pointer;
  display:grid;
  place-items:center;
  font-weight: 900;
  transition: transform .12s ease, filter .12s ease, background .12s ease, border-color .12s ease;
}
#lobby-panel .lobby-btn:hover{
  transform: translateY(-1px);
  background: rgba(255,255,255,.10);
}
#lobby-panel .lobby-btn.accept{
  background: rgba(16,185,129,.16);
  border-color: rgba(16,185,129,.30);
  color: #d1fae5;
}
#lobby-panel .lobby-btn.reject{
  background: rgba(239,68,68,.16);
  border-color: rgba(239,68,68,.30);
  color: #fecaca;
}

/* Botones participants */
#lobby-panel .participants-btn{
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.05);
  color: #e5e7eb;
  cursor:pointer;
  white-space:nowrap;
  transition: transform .12s ease, background .12s ease, filter .12s ease, border-color .12s ease;
}
#lobby-panel .participants-btn:hover{
  background: rgba(255,255,255,.11);
  border-color: rgba(255,255,255,.26);
  transform: translateY(-1px);
}

/* Botones compactos de acciones (icon-only) */
#lobby-panel .participants-btn.icon-btn{
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
}

#lobby-panel .participants-btn.icon-btn i{
  pointer-events: none;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
}

#lobby-panel .lobby-btn i{
  pointer-events: none;
  font-size: 14px;
  line-height: 1;
}
#lobby-panel .participants-btn.on{
  background: rgba(16,185,129,.18);
  border-color: rgba(16,185,129,.42);
  color: #dcfce7;
}
#lobby-panel .participants-btn.off,
#lobby-panel .participants-btn.danger{
  background: rgba(239,68,68,.18);
  border-color: rgba(239,68,68,.42);
  color: #fee2e2;
}

/* Badge “Tú / Admin” */
#lobby-panel .participants-you{
  font-size: 12px;
  padding: 8px 13px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(88,101,242,.28), rgba(71,82,196,.24));
  border: 1px solid rgba(126,150,255,.45);
  color:#e6ebff;
  font-weight: 800;
  letter-spacing: .01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

/* Separador visual entre lobby y participants */
#lobby-panel .participants-panel{
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.10);
}

/* Scrollbar dark */
#lobby-panel .lobby-list::-webkit-scrollbar,
#lobby-panel .participants-list::-webkit-scrollbar{
  width: 8px;
}
#lobby-panel .lobby-list::-webkit-scrollbar-thumb,
#lobby-panel .participants-list::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.14);
  border-radius: 999px;
}
#lobby-panel .lobby-list::-webkit-scrollbar-thumb:hover,
#lobby-panel .participants-list::-webkit-scrollbar-thumb:hover{
  background: rgba(255,255,255,.22);
}

/* Responsive: panel ocupa toda la pantalla en móvil (como ya lo tienes) */
@media (max-width: 900px){
  #lobby-panel.side-panel{
    width: 100%;
    border-left: none;
  }
}
/* =========================================================
   ✅ INVITADO: barra abajo fija
   ========================================================= */

body.is-guest .controls-bar{
  position: fixed !important;
  left: 0;
  right: 0;
  bottom: 0 !important;
  top: auto !important;
  z-index: 1000 !important;
  border-top: 1px solid var(--border-subtle) !important;
  border-bottom: none !important;
  background: var(--bg-panel);
}

/* el que scrollea es grid-container */
body.is-guest #grid-container{
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  height: 100%;
  padding-top: 12px !important;
  padding-bottom: calc(var(--controls-height) + 14px) !important;
}

/* iOS: poder deslizar aunque el dedo toque el video */
@media (max-width: 900px){
  body.is-guest .tile video{ pointer-events:none !important; }
  body.is-guest .controls-bar{
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  body.is-guest #grid-container{
    padding-bottom: calc(var(--controls-height) + env(safe-area-inset-bottom, 0px) + 14px) !important;
  }
}

/* =========================================================
   LAYOUT ESTABLE PRO (anti-overlap desktop/mobile)
   ========================================================= */

/* Estructura principal sin colisiones de alto */
.app,
#main-app-container,
.main-content,
.content-wrapper {
  min-height: 0;
}

#main-app-container {
  height: calc(100dvh - var(--header-height));
  display: flex;
  flex-direction: column;
}

/* Header consistente y profesional */
#setup-panel {
  min-height: var(--header-height);
  height: var(--header-height);
  padding-inline: 18px;
  background: linear-gradient(180deg, #1f2026 0%, #181a20 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#host-controls {
  gap: 8px;
  flex-wrap: wrap;
}

/* Canvas de reunión: 2 columnas limpias en desktop */
.content-wrapper {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0;
  overflow: hidden;
}

#grid-container {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 12px;
  align-items: flex-start;
  justify-content: center;
  background:
    radial-gradient(1200px 320px at 50% 0%, rgba(88, 101, 242, 0.08), transparent 55%),
    #0b0d12;
}

#grid {
  align-content: flex-start;
}

/* Panel lateral siempre dentro del flujo: sin superponerse */
#lobby-panel.side-panel,
#chat-panel.side-panel {
  position: relative;
  width: min(340px, 100%);
  max-width: 340px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

#lobby-panel .lobby-list,
#lobby-panel .participants-list,
#chat-messages {
  min-height: 0;
}

/* Barra de controles no debe invadir contenido */
.controls-bar {
  position: relative;
  z-index: 5;
}

/* Mobile: volver a layout de una columna y panel full-screen */
@media (max-width: 900px) {
  #main-app-container {
    height: 100dvh;
  }

  .content-wrapper {
    display: flex;
    flex-direction: column;
  }

  #grid-container {
    padding: 8px;
  }

  #lobby-panel.side-panel,
  #chat-panel.side-panel {
    position: absolute;
    inset: 0;
    max-width: none;
    width: 100%;
    height: 100%;
    z-index: 50;
  }
}

/* =========================================================
   MOBILE PRO LAYOUT (video-first, panel no intrusivo)
   ========================================================= */
@media (max-width: 900px) {
  /* Grilla móvil auto-ajustable (sin screen share) */
  #grid:not(.screen-share-mode) {
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)) !important;
    gap: 8px !important;
    align-content: start !important;
  }

  #grid.gallery-fit:not(.screen-share-mode) {
    grid-template-columns: repeat(var(--gallery-cols, 1), minmax(0, 1fr)) !important;
    align-content: center !important;
  }

  #grid:not(.screen-share-mode):has(.tile:only-child) {
    grid-template-columns: 1fr !important;
  }

  #grid:not(.screen-share-mode) .tile {
    aspect-ratio: 16 / 9 !important;
    max-height: min(34vh, 240px);
  }

  #grid.gallery-fit[data-tile-count="1"]:not(.screen-share-mode) .tile {
    max-height: 72dvh;
  }

  #grid.gallery-fit[data-tile-count="2"]:not(.screen-share-mode) .tile {
    max-height: 46dvh;
  }

  /* Priorizar video */
  #grid-container {
    min-height: 58dvh;
    height: auto;
    padding: 8px 8px 96px 8px !important;
  }

  #grid {
    gap: 8px;
    grid-template-columns: 1fr;
  }

  /* Barra de controles compacta y legible */
  .controls-bar {
    min-height: 64px;
    height: 64px;
    padding: 8px 10px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 40;
    justify-content: center;
  }

  /* Ocultar mensajes informativos en la barra (van a consola) */
  .controls-left {
    display: none !important;
  }

  .status-indicator {
    font-size: 0.88rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .controls-center-scroll {
    flex: 0 1 auto;
    width: auto;
    max-width: 100%;
    padding: 0 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .controls-center-scroll::-webkit-scrollbar {
    display: none;
  }

  .controls-center {
    gap: 5px;
    min-width: max-content;
    padding-right: 6px;
  }

  .separator {
    display: none;
  }

  .controls-right { display: none; }

  .media-btn,
  .control-btn,
  .mod-btn,
  .btn-leave {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    flex-shrink: 0;
  }

  .btn-leave .btn-icon {
    width: 18px;
    height: 18px;
  }

  /* Estética tipo "fas": iconos más sólidos/legibles */
  .icon-svg {
    stroke-width: 2.4 !important;
  }

  /* Lobby/Participants y Chat como bottom-sheet (no bloquea siempre) */
  body.is-host #lobby-panel {
    display: none !important;
  }

  #lobby-panel.side-panel:not(.hidden),
  #chat-panel.side-panel:not(.hidden) {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    max-height: 56dvh;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 36px rgba(0, 0, 0, 0.45);
    z-index: 90;
  }

  /* Admin en movil: lobby/participants NO flotante sobre video.
     Se renderiza debajo de la grilla dentro del flujo. */
  body.is-host #lobby-panel.side-panel:not(.hidden) {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: 42dvh !important;
    border-radius: 12px !important;
    box-shadow: none !important;
    z-index: 1 !important;
    margin-top: 8px;
  }

  #lobby-panel.side-panel {
    overflow: hidden;
  }

  #lobby-panel .lobby-list {
    max-height: 28dvh;
  }

  /* Tarjetas de participantes: evitar botones amontonados */
  #lobby-panel .participants-item {
    align-items: flex-start;
    padding: 12px;
    gap: 8px;
  }

  #lobby-panel .participants-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px;
    margin-top: 6px;
  }

  #lobby-panel .participants-item.is-me-row .participants-actions-me {
    width: auto;
    margin-top: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
  }

  #lobby-panel .participants-btn {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.88rem;
  }

  #lobby-panel .participants-btn.icon-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 14px;
  }

  #lobby-panel .participants-btn.icon-btn i {
    font-size: 14px;
  }

  #lobby-panel .participants-you {
    justify-self: end;
  }

  /* Estado plegado/desplegado en móvil */
  #lobby-panel.lobby-collapsed .lobby-list {
    display: none;
  }

  #lobby-panel.participants-collapsed .participants-list {
    display: none;
  }

  #lobby-panel.participants-collapsed .participants-panel {
    flex: 0 0 auto;
  }

  #lobby-panel.lobby-collapsed.participants-collapsed {
    max-height: 126px;
  }

  #lobby-panel .lobby-header,
  #lobby-panel .participants-header {
    cursor: pointer;
    user-select: none;
    min-height: 58px;
    width: 100%;
    display: flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  #lobby-panel .lobby-header::after,
  #lobby-panel .participants-header::after {
    content: "▾";
    margin-left: auto;
    font-size: 14px;
    opacity: 0.8;
  }

  #lobby-panel.lobby-collapsed .lobby-header::after,
  #lobby-panel.participants-collapsed .participants-header::after {
    content: "▸";
  }

  /* Cuando el panel de lobby está visible, reserva espacio para que no tape videos */
  .content-wrapper:has(#lobby-panel.side-panel:not(.hidden)) #grid-container {
    padding-bottom: calc(var(--controls-height) + 140px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Si es Admin, no reservar espacio extra para un panel flotante
     porque ya no se superpone sobre el video. */
  body.is-host .content-wrapper:has(#lobby-panel.side-panel:not(.hidden)) #grid-container {
    padding-bottom: 14px !important;
  }

  /* =========================================================
     Grilla móvil: tarjetas más naturales (sin imagen "anchada")
     ========================================================= */
  #grid:not(.screen-share-mode) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    justify-items: center !important;
    align-content: start !important;
  }

  #grid:not(.screen-share-mode)[data-tile-count="1"] {
    grid-template-columns: 1fr !important;
  }

  #grid:not(.screen-share-mode) .tile {
    width: 100% !important;
    max-width: none !important;
    /* Uniforme para local y remotos en movil */
    aspect-ratio: 3 / 4 !important;
    max-height: none !important;
  }

  #grid:not(.screen-share-mode) .tile video {
    object-fit: cover !important;
    background: transparent;
  }
}

/* =========================================================
   SCREEN SHARE FOCUS MODE
   Mantiene la pantalla compartida siempre visible en grande
   ========================================================= */
#grid.screen-share-mode {
  max-width: none;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 0;
  height: calc(100dvh - var(--header-height) - var(--controls-height) - 26px);
  max-height: calc(100dvh - var(--header-height) - var(--controls-height) - 26px);
  overflow: hidden;
}

#grid.screen-share-mode .tile.pinned {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  border-color: rgba(88, 101, 242, 0.75);
}

#grid.screen-share-mode .tile.pinned video {
  object-fit: contain;
  background: #000;
  cursor: grab;
  user-select: none;
}

#grid.screen-share-mode .tile:not(.pinned) {
  grid-row: 1;
  min-width: 0;
  aspect-ratio: 16 / 9;
  max-height: 110px;
}

body.screen-share-active #grid-container {
  overflow: hidden;
}

/* ===============================
   Lobby/Participants: filtros + scroll interno estable
   =============================== */
#lobby-panel.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#lobby-panel .lobby-list,
#lobby-panel .participants-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#participants-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-filter-wrap {
  padding: 8px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(8, 10, 20, 0.45);
}

.panel-filter-input {
  width: 100%;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: #f3f6ff;
  outline: none;
  padding: 0 11px;
  font-size: 13px;
}

.panel-filter-input::placeholder {
  color: rgba(230, 235, 255, 0.55);
}

.panel-filter-input:focus {
  border-color: rgba(87, 198, 255, 0.65);
  box-shadow: 0 0 0 2px rgba(87, 198, 255, 0.16);
}

#lobby-panel .lobby-body,
#lobby-panel .participants-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#lobby-panel .lobby-body {
  flex: 0 0 auto;
}

#lobby-panel .participants-body {
  flex: 1 1 auto;
}

#lobby-panel .lobby-list {
  /* Espacio para ~3 invitados visibles; el resto por scroll */
  max-height: 290px;
}

#lobby-panel.lobby-collapsed .lobby-body,
#lobby-panel.participants-collapsed .participants-body {
  display: none;
}

body.screen-share-active.screen-share-panning #grid.screen-share-mode .tile.pinned video {
  cursor: grabbing;
}

@media (min-width: 901px) {
  #grid.screen-share-mode .tile:not(.pinned) {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  body.screen-share-active #grid-container,
  #grid-container:has(#grid.screen-share-mode) {
    overflow: hidden;
    padding-bottom: 8px !important;
  }

  #grid.screen-share-mode {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    height: calc(100dvh - var(--controls-height) - 24px);
    max-height: calc(100dvh - var(--controls-height) - 24px);
  }

  #grid.screen-share-mode .tile:not(.pinned) {
    grid-column: span 2;
    max-height: 84px;
  }

  #grid.screen-share-mode .tile.pinned {
    height: 100%;
    min-height: 0;
    max-height: 100%;
  }
}

/* Controles de zoom/fullscreen para pantalla compartida */
.screen-share-toolbar {
  position: absolute;
  top: 10px;
  right: 14px;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(9, 11, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
}

.screen-share-toolbar .ss-btn {
  min-width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
}

.screen-share-toolbar .ss-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* Cuando hay zoom, permitimos desplazar el contenido dentro del tile principal */
#grid.screen-share-mode .tile.pinned {
  overflow: auto;
}

#grid.screen-share-mode .tile.pinned video {
  touch-action: pinch-zoom;
}

@media (max-width: 900px) {
  .screen-share-toolbar {
    top: 8px;
    right: 8px;
    gap: 4px;
    padding: 4px;
  }

  .screen-share-toolbar .ss-btn {
    min-width: 30px;
    height: 30px;
    font-size: 12px;
  }
}

/* =========================================================
   FIX MOBILE GUEST PRE-JOIN
   Asegura que input + boton "Join the meeting" siempre se vean
   ========================================================= */
@media (max-width: 900px) {
  body:not(.is-host):not(.in-meeting) #main-app-container {
    height: 100dvh !important;
  }

  body:not(.is-host):not(.in-meeting) #setup-panel {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    min-height: auto !important;
    height: auto !important;
    display: block !important;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 12px 12px !important;
    overflow: visible !important;
    z-index: 30 !important;
  }

  body:not(.is-host):not(.in-meeting) #guest-controls {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  body:not(.is-host):not(.in-meeting) #guest-controls input,
  body:not(.is-host):not(.in-meeting) #guest-controls button {
    width: 100% !important;
    min-width: 0 !important;
  }

  body:not(.is-host):not(.in-meeting) .logo-text {
    margin: 0 0 10px 0 !important;
    font-size: 1.15rem !important;
  }
}

/* =========================================================
   UI POLISH V2 (solo visual, sin lógica)
   ========================================================= */
:root {
  --ux-bg-0: #0a0d14;
  --ux-bg-1: #0f1420;
  --ux-bg-2: #161c29;
  --ux-glass: rgba(255, 255, 255, 0.05);
  --ux-glass-2: rgba(255, 255, 255, 0.08);
  --ux-border: rgba(160, 174, 209, 0.24);
  --ux-border-soft: rgba(160, 174, 209, 0.14);
  --ux-text: #f4f7ff;
  --ux-muted: #9eabc6;
  --ux-accent: #5f76ff;
  --ux-accent-2: #62d6ff;
  --ux-success: #27c28a;
  --ux-danger: #ef5a67;
}

html, body {
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(95, 118, 255, 0.16), transparent 60%),
    linear-gradient(180deg, var(--ux-bg-1), var(--ux-bg-0));
}

#setup-panel {
  background: linear-gradient(180deg, rgba(18, 24, 38, 0.96), rgba(13, 18, 29, 0.96));
  border-bottom: 1px solid var(--ux-border-soft);
  backdrop-filter: blur(8px);
}

.logo-text {
  letter-spacing: 0.2px;
  color: var(--ux-text);
}

.controls-bar {
  background: linear-gradient(180deg, rgba(17, 23, 36, 0.95), rgba(13, 18, 29, 0.95));
  border-top: 1px solid var(--ux-border-soft);
  backdrop-filter: blur(8px);
}

.media-controls {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--ux-border-soft);
  padding: 5px;
}

.media-btn,
.control-btn,
.mod-btn {
  border: 1px solid transparent;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.media-btn {
  background: rgba(255, 255, 255, 0.08);
}
.media-btn:hover,
.control-btn:hover,
.mod-btn:hover {
  transform: translateY(-1px);
  border-color: var(--ux-border);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
}

.media-btn.off {
  background: rgba(239, 90, 103, 0.2);
  border-color: rgba(239, 90, 103, 0.45);
}

.btn-leave {
  background: linear-gradient(135deg, #d8513d, #b33e2f);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

#grid-container {
  background:
    radial-gradient(900px 380px at 50% -30%, rgba(98, 214, 255, 0.08), transparent 60%),
    linear-gradient(180deg, #0a0e16, #090c13);
}

.tile {
  border-radius: 14px;
  border: 1px solid rgba(117, 133, 170, 0.35);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.tile.me {
  border-color: rgba(98, 214, 255, 0.72);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(98, 214, 255, 0.2) inset;
}

.namepill {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(6, 10, 18, 0.72);
  border-radius: 999px;
  padding: 4px 10px;
}

#lobby-panel.side-panel,
#chat-panel.side-panel {
  border-left: 1px solid var(--ux-border-soft);
}

#lobby-panel.side-panel {
  background:
    linear-gradient(180deg, rgba(17, 23, 36, 0.97), rgba(12, 17, 28, 0.97));
}

#lobby-panel .lobby-header,
#lobby-panel .participants-header {
  background:
    linear-gradient(180deg, rgba(95, 118, 255, 0.14), rgba(95, 118, 255, 0.02));
  border-bottom: 1px solid var(--ux-border-soft);
}

#lobby-panel .lobby-title,
#lobby-panel .participants-header h3 {
  color: var(--ux-text);
  letter-spacing: 0.2px;
}

#lobby-panel .lobby-title::before,
#lobby-panel .participants-header h3::before {
  filter: saturate(1.15);
}

.panel-filter-wrap {
  background: rgba(12, 18, 30, 0.66);
  border-top: 1px solid var(--ux-border-soft);
  border-bottom: 1px solid var(--ux-border-soft);
}

.panel-filter-input {
  border: 1px solid var(--ux-border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ux-text);
}

.panel-filter-input::placeholder {
  color: var(--ux-muted);
}

.panel-filter-input:focus {
  border-color: rgba(98, 214, 255, 0.62);
  box-shadow: 0 0 0 3px rgba(98, 214, 255, 0.14);
}

#lobby-panel .lobby-item,
#lobby-panel .participants-item {
  border-radius: 14px;
  border: 1px solid var(--ux-border-soft);
  background:
    radial-gradient(110% 140% at 0% 0%, rgba(95, 118, 255, 0.13), transparent 44%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
}

#lobby-panel .lobby-meta .name,
#lobby-panel .participants-meta .name {
  color: var(--ux-text) !important;
}

#lobby-panel .lobby-meta .sub,
#lobby-panel .participants-meta .sub {
  color: var(--ux-muted) !important;
}

#lobby-panel .lobby-admit-all {
  background: rgba(39, 194, 138, 0.15);
  border-color: rgba(39, 194, 138, 0.36);
}

#lobby-panel .lobby-btn.accept {
  background: rgba(39, 194, 138, 0.18);
  border-color: rgba(39, 194, 138, 0.4);
}

#lobby-panel .lobby-btn.reject,
#lobby-panel .participants-btn.danger,
#lobby-panel .participants-btn.off {
  background: rgba(239, 90, 103, 0.18);
  border-color: rgba(239, 90, 103, 0.4);
}

#lobby-panel .participants-btn.on {
  background: rgba(39, 194, 138, 0.16);
  border-color: rgba(39, 194, 138, 0.38);
}

#lobby-panel .participants-you {
  background: linear-gradient(135deg, rgba(95, 118, 255, 0.32), rgba(98, 214, 255, 0.2));
  border-color: rgba(98, 214, 255, 0.46);
}

#chat-panel .panel-header {
  background: linear-gradient(180deg, rgba(95, 118, 255, 0.14), rgba(0, 0, 0, 0));
}

#chat-messages {
  background:
    radial-gradient(1000px 260px at 50% 0%, rgba(95, 118, 255, 0.11), transparent 60%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.14), transparent 42%);
}

#chat-form {
  background: rgba(20, 27, 41, 0.92);
  border-top: 1px solid var(--ux-border-soft);
}

#chat-input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--ux-border-soft);
}

#chat-input:focus {
  border-color: rgba(98, 214, 255, 0.62);
  box-shadow: 0 0 0 3px rgba(98, 214, 255, 0.14);
}

.media-settings-modal {
  max-width: 520px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.settings-group label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.settings-group select {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.06);
  color: #fff;
  padding: 0 10px;
}

.settings-group input[type="file"] {
  width: 100%;
  border-radius: 10px;
  border: 1px dashed rgba(255,255,255,0.24);
  padding: 10px;
  background: rgba(255,255,255,0.03);
  color: #dbe5ff;
}

.settings-group.toggles {
  gap: 10px;
}

.settings-group.toggles label {
  color: #e5e7eb;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-group.toggles input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #5f76ff;
}

.preview-filter-blur video,
.preview-filter-dark video {
  filter: blur(2px) saturate(0.95);
}

.preview-filter-dark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 24, 0.38);
  pointer-events: none;
}

/* =========================================================
   PANEL PREMIUM BOOST (solo visual)
   ========================================================= */
#lobby-panel.side-panel {
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(97, 118, 255, 0.15), transparent 42%),
    radial-gradient(120% 80% at 0% 100%, rgba(98, 214, 255, 0.1), transparent 45%),
    linear-gradient(180deg, #121824 0%, #0d121d 100%);
  box-shadow:
    -12px 0 28px rgba(0, 0, 0, 0.35),
    inset 1px 0 0 rgba(255, 255, 255, 0.04);
}

#lobby-panel .lobby-header,
#lobby-panel .participants-header {
  position: relative;
  padding: 14px 16px;
  background:
    linear-gradient(180deg, rgba(98, 214, 255, 0.1), rgba(95, 118, 255, 0.04)),
    rgba(255, 255, 255, 0.01);
  border-bottom: 1px solid rgba(160, 174, 209, 0.22);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.04);
}

#lobby-panel .lobby-header::before,
#lobby-panel .participants-header::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, #62d6ff, #5f76ff);
  opacity: 0.9;
}

#lobby-panel .lobby-title,
#lobby-panel .participants-header h3 {
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

#lobby-panel .lobby-title::before {
  font-size: 1rem;
}

#lobby-panel .participants-header h3::before {
  font-size: 1rem;
  margin-right: 3px;
}

#lobby-panel .lobby-admit-all {
  background:
    linear-gradient(135deg, rgba(39, 194, 138, 0.3), rgba(39, 194, 138, 0.12));
  border: 1px solid rgba(111, 240, 188, 0.42);
  color: #e8fff5;
  box-shadow:
    0 6px 14px rgba(12, 80, 55, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

#lobby-panel .lobby-admit-all:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

#lobby-panel .panel-filter-wrap {
  padding: 10px 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  border-top: 1px solid rgba(160, 174, 209, 0.12);
  border-bottom: 1px solid rgba(160, 174, 209, 0.12);
}

#lobby-panel .panel-filter-input {
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(160, 174, 209, 0.28);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.025));
  padding: 0 13px;
  font-size: 0.96rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

#lobby-panel .panel-filter-input::placeholder {
  color: rgba(198, 208, 232, 0.78);
}

#lobby-panel .lobby-list,
#lobby-panel .participants-list {
  padding: 12px;
  background: transparent;
}

#lobby-panel .lobby-item,
#lobby-panel .participants-item {
  position: relative;
  border-radius: 17px;
  border: 1px solid rgba(155, 170, 205, 0.28);
  background:
    radial-gradient(120% 130% at -8% -16%, rgba(95, 118, 255, 0.2), transparent 52%),
    linear-gradient(165deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.03));
  box-shadow:
    0 14px 30px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#lobby-panel .lobby-item::after,
#lobby-panel .participants-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

#lobby-panel .lobby-item:hover,
#lobby-panel .participants-item:hover {
  transform: translateY(-2px);
  border-color: rgba(130, 151, 255, 0.52);
  box-shadow:
    0 18px 34px rgba(0, 0, 0, 0.36),
    0 0 0 1px rgba(98, 214, 255, 0.15) inset;
}

#lobby-panel .lobby-avatar,
#lobby-panel .participants-avatar {
  width: 46px;
  height: 46px;
  box-shadow:
    0 0 0 4px rgba(98, 214, 255, 0.1),
    0 10px 18px rgba(27, 41, 88, 0.4);
}

#lobby-panel .lobby-meta .name,
#lobby-panel .participants-meta .name {
  font-size: 1.02rem;
  font-weight: 800;
}

#lobby-panel .lobby-meta .sub,
#lobby-panel .participants-meta .sub {
  font-size: 0.9rem;
}

#lobby-panel .lobby-btn,
#lobby-panel .participants-btn.icon-btn {
  border-radius: 12px;
  border: 1px solid rgba(176, 191, 227, 0.3);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.04));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

#lobby-panel .lobby-btn.accept {
  background: linear-gradient(135deg, rgba(39, 194, 138, 0.34), rgba(39, 194, 138, 0.14));
  border-color: rgba(111, 240, 188, 0.45);
}

#lobby-panel .lobby-btn.reject {
  background: linear-gradient(135deg, rgba(239, 90, 103, 0.34), rgba(239, 90, 103, 0.14));
  border-color: rgba(255, 157, 166, 0.45);
}

#lobby-panel .participants-you {
  padding: 9px 14px;
  background:
    linear-gradient(135deg, rgba(95, 118, 255, 0.42), rgba(98, 214, 255, 0.18));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

/* =========================================================
   MOBILE: controles abajo + switch de camara en tile local
   ========================================================= */
.cam-switch-btn {
  display: none;
}

.cam-zoom-wrap {
  position: absolute;
  left: 10px;
  right: auto;
  width: auto;
  bottom: 10px;
  min-height: 38px;
  padding: 6px;
  border: 1px solid rgba(178, 198, 236, 0.28);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(11, 15, 26, 0.86), rgba(8, 12, 20, 0.86));
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  z-index: 6;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.cam-zoom-wrap.hidden {
  display: none !important;
}

.cam-zoom-btn {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 1px solid rgba(176, 191, 227, 0.34);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.05));
  color: #fff;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, background .12s ease, border-color .12s ease;
}

.cam-zoom-btn i {
  pointer-events: none;
}

.cam-zoom-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
  border-color: rgba(143, 176, 245, 0.52);
}

.cam-zoom-btn:active:not(:disabled) {
  transform: translateY(0);
  filter: brightness(0.98);
}

.cam-zoom-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .controls-bar {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto !important;
    z-index: 90;
    border-top: 1px solid var(--border-subtle);
    border-bottom: none !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  #grid-container {
    padding-bottom: calc(var(--controls-height) + env(safe-area-inset-bottom, 0px) + 14px) !important;
  }

  .tile.me .cam-switch-btn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 999px;
    background: rgba(7, 10, 18, 0.72);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 6;
    backdrop-filter: blur(6px);
    -webkit-tap-highlight-color: transparent;
  }

  .tile.me .cam-switch-btn i {
    font-size: 14px;
    pointer-events: none;
  }

  .tile.me .cam-zoom-wrap {
    right: auto;
    bottom: 10px;
    min-height: 34px;
    padding: 5px;
    gap: 6px;
  }

  .tile.me .cam-zoom-btn {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    font-size: 12px;
  }

}

/* =========================================================
   ADMIN: barra de controles arriba (desktop + movil)
   ========================================================= */
body.is-host .controls-bar {
  position: sticky !important;
  top: 0 !important;
  bottom: auto !important;
  z-index: 1000 !important;
  border-top: none !important;
  border-bottom: 1px solid var(--border-subtle);
}

body.is-host #grid-container {
  padding-top: calc(var(--controls-height) + 12px) !important;
}

@supports (padding: max(0px)) {
  body.is-host #grid-container {
    padding-top: calc(var(--controls-height) + env(safe-area-inset-top) + 12px) !important;
  }
}

@media (max-width: 900px) {
  body.is-host .controls-bar {
    position: fixed !important;
    left: 0;
    right: 0;
    top: 0 !important;
    bottom: auto !important;
    border-bottom: 1px solid var(--border-subtle) !important;
    border-top: none !important;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-bottom: 8px;
  }

  body.is-host #grid-container {
    padding-top: calc(var(--controls-height) + env(safe-area-inset-top, 0px) + 14px) !important;
    padding-bottom: 14px !important;
  }
}

/* =========================================================
   CHAT PRO UI (solo mensajes enviados por usuarios)
   ========================================================= */
#chat-panel.side-panel {
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(88, 101, 242, 0.12), transparent 45%),
    #111827;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

#chat-panel .panel-header {
  background: rgba(17, 24, 39, 0.88);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
}

#chat-panel .panel-header h3 {
  color: #e5e7eb;
  letter-spacing: 0.2px;
}

#chat-messages {
  padding: 14px 12px;
  gap: 10px;
}

.chat-message-wrapper {
  width: 100%;
  display: flex;
}

.chat-message {
  max-width: 86%;
  background: rgba(31, 41, 55, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 9px 11px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.26);
}

.chat-message-wrapper .sender {
  font-size: 0.72rem;
  font-weight: 700;
  color: #93c5fd;
  margin-bottom: 4px;
}

.chat-message .content {
  color: #f3f4f6;
  line-height: 1.4;
}

.chat-message .timestamp {
  display: block;
  margin-top: 6px;
  font-size: 0.68rem;
  color: #9ca3af;
  text-align: right;
}

.chat-message-wrapper.me {
  justify-content: flex-end;
}

.chat-message-wrapper.me .chat-message {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: rgba(191, 219, 254, 0.35);
}

.chat-message-wrapper.me .chat-message .content,
.chat-message-wrapper.me .chat-message .timestamp {
  color: #ffffff;
}

#chat-form {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(17, 24, 39, 0.92);
  padding: 10px 10px 12px;
}

#chat-input {
  background: rgba(3, 7, 18, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f9fafb;
  border-radius: 14px;
  padding: 10px 12px;
}

#chat-input::placeholder {
  color: #9ca3af;
}

#btn-send-chat {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* =========================================================
   CHAT FILES (estilo tipo WhatsApp)
   ========================================================= */
.chat-image-preview {
  width: 100%;
  max-width: 260px;
  max-height: 300px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  margin-top: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.download-link {
  margin-top: 6px;
  font-size: 0.78rem;
  line-height: 1.1;
}

.chat-download-link {
  color: #8fd3ff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.1px;
}

.chat-download-link:hover {
  color: #b9e6ff;
  text-decoration: underline;
}

.file-info.is-image-file {
  display: none;
}

#btnToggleChat {
  position: relative;
}

.chat-unread-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* =========================================================
   GUEST LAYOUT LOCK
   Barra fija + scroll solo en videos (siempre debajo de la barra)
   ========================================================= */
body.is-guest .controls-bar {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  z-index: 1200 !important;
  border-top: 1px solid var(--border-subtle) !important;
  border-bottom: none !important;
}

body.is-guest .content-wrapper {
  min-height: 0 !important;
  height: 100% !important;
  overflow: hidden !important;
}

body.is-guest #grid-container {
  min-height: 0 !important;
  height: 100% !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  padding-bottom: calc(var(--controls-height) + 16px) !important;
}

@media (max-width: 900px) {
  body.is-guest .controls-bar {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.is-guest #grid-container {
    padding-bottom: calc(var(--controls-height) + env(safe-area-inset-bottom, 0px) + 16px) !important;
  }
}

/* =========================================================
   MOBILE PRE-JOIN HOST/GUEST BAR FIX
   Asegura visibilidad de "nombre + iniciar sala/unirse"
   ========================================================= */
@media (max-width: 900px) {
  /* Antes de entrar: ocultar barra de controles para liberar espacio */
  body:not(.in-meeting) .controls-bar {
    display: none !important;
  }

  body:not(.in-meeting) #setup-panel {
    display: flex !important;
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    min-height: auto !important;
    height: auto !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 12px !important;
    overflow: visible !important;
    z-index: 40 !important;
  }

  body:not(.in-meeting) .logo-text {
    margin: 0 0 6px 0 !important;
    font-size: 1.15rem !important;
  }

  body:not(.in-meeting) #guest-controls,
  body:not(.in-meeting) #host-controls {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    gap: 10px !important;
    justify-content: stretch !important;
  }

  body:not(.in-meeting) #guest-controls input,
  body:not(.in-meeting) #guest-controls button,
  body:not(.in-meeting) #host-controls button {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Respetar estado real del rol: no mostrar el bloque oculto */
  body:not(.in-meeting) #guest-controls.hidden,
  body:not(.in-meeting) #host-controls.hidden {
    display: none !important;
  }

  /* Host pre-join: panel legible y completo en móvil */
  body.is-host:not(.in-meeting) #main-app-container {
    height: 100dvh !important;
  }

  body.is-host:not(.in-meeting) #setup-panel {
    padding-top: calc(14px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: 14px !important;
  }

  body.is-host:not(.in-meeting) #host-controls {
    max-width: 640px !important;
    margin: 0 auto !important;
    gap: 10px !important;
  }

  body.is-host:not(.in-meeting) #host-controls .btn-action,
  body.is-host:not(.in-meeting) #host-controls .btn-ghost,
  body.is-host:not(.in-meeting) #host-controls .btn-danger-ghost {
    min-height: 46px !important;
    font-size: 1rem !important;
  }
}
