:root {
  --bg-main: #0b0f17;
  --bg-card: #131b29;
  --bg-tile: #161f30;
  --bg-ctrl: #1e293b;
  --border: #263349;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-main);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ================= LOBBY ================= */
.lobby-container {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.lobby-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.auth-box {
  margin-bottom: 18px;
}

.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a2436;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-google:hover {
  border-color: var(--accent);
}

.user-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: underline;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input-with-action {
  display: flex;
  gap: 8px;
}

input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
}

.btn-icon {
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-ctrl);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.field-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.prejoin-toggles {
  display: flex;
  gap: 10px;
}

.toggle-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-main);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--accent);
}

.error-banner {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 0.84rem;
}

.btn-primary {
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #061320;
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ================= SALA ACTIVA ================= */
.room-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.room-header {
  height: 48px;
  padding: 0 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.status-dot.reconnecting {
  background: var(--warn);
}

.room-name-badge {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.count-badge {
  background: var(--bg-ctrl);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.btn-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-ctrl);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-chip:hover {
  background: var(--accent);
  color: #061320;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact-select {
  width: auto;
  padding: 4px 8px;
  font-size: 0.78rem;
  border-radius: 6px;
  background: var(--bg-ctrl);
}

/* Aviso de red lenta */
.network-warning {
  background: #422006;
  border-bottom: 1px solid #854d0e;
  color: #fef08a;
  padding: 7px 14px;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.warning-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-xs {
  padding: 4px 9px;
  border-radius: 5px;
  border: 1px solid #facc15;
  background: #eab308;
  color: #1c1917;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-xs-ghost {
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid transparent;
  background: transparent;
  color: #fde047;
  font-size: 0.75rem;
  cursor: pointer;
}

/* Workspace central */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.media-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
  min-width: 0;
  min-height: 0;
}

/* Cuando hay escenario activo (Screen share o Pin) */
.media-area.has-spotlight {
  flex-direction: row;
}

.spotlight-stage {
  flex: 3.5;
  min-width: 0;
  min-height: 0;
  display: flex;
}

.spotlight-stage .video-tile {
  width: 100%;
  height: 100%;
}

.media-area.has-spotlight .video-grid {
  flex: 1;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  gap: 8px;
}

.media-area.has-spotlight .video-grid .video-tile {
  height: 150px;
  flex-shrink: 0;
}

/* Grilla estándar sin escenario */
.video-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}

/* Tarjeta individual de participante/pantalla (optimizada con contain) */
.video-tile {
  position: relative;
  background: var(--bg-tile);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  contain: layout paint;
  min-height: 160px;
}

.video-tile.speaking {
  border-color: var(--success);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05080d;
}

.video-tile.is-screenshare video,
.spotlight-stage .video-tile video {
  object-fit: contain;
}

.video-tile.is-local-camera video {
  transform: scaleX(-1);
}

.tile-avatar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  user-select: none;
}

.avatar-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-ctrl);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-status {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.tile-overlay {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.tile-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(11, 15, 23, 0.82);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  max-width: 80%;
}

.tile-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quality-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.quality-badge.good { background: #84cc16; }
.quality-badge.poor { background: var(--warn); }
.quality-badge.lost { background: var(--danger); }

.tile-actions {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

.btn-tile-action {
  background: rgba(11, 15, 23, 0.82);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 0.72rem;
  cursor: pointer;
}

.btn-tile-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Panel de Chat */
.chat-panel {
  width: 300px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-header {
  height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
}

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

.chat-messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.83rem;
}

.chat-msg {
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  word-break: break-word;
}

.chat-msg-sender {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.chat-form {
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

.btn-send {
  padding: 0 12px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #061320;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

/* Barra inferior de controles */
.controls-bar {
  height: 64px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 12px;
  flex-shrink: 0;
}

.ctrl-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-ctrl);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn:hover {
  border-color: var(--accent);
}

.ctrl-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent);
  color: var(--accent);
}

.ctrl-btn.off {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.ctrl-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.ctrl-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.unread-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* Responsivo para móviles y pantallas pequeñas */
@media (max-width: 768px) {
  .header-right #screenshare-quality {
    display: none;
  }
  .media-area.has-spotlight {
    flex-direction: column;
  }
  .media-area.has-spotlight .video-grid {
    max-width: 100%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    height: 110px;
    flex: none;
  }
  .media-area.has-spotlight .video-grid .video-tile {
    width: 150px;
    height: 100%;
  }
  .ctrl-label {
    display: none;
  }
  .ctrl-btn {
    padding: 10px 13px;
  }
  .chat-panel {
    position: absolute;
    inset: 48px 0 64px 0;
    width: 100%;
    z-index: 20;
  }
}
