:root {
  --bg: #0b1120;
  --bg-panel: #111827;
  --bg-panel-soft: #1f2937;
  --border-soft: #374151;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --danger: #ef4444;
  --success: #22c55e;

  /* Chat específicos */
  --bg-chat: #020617;
  --bg-chat-input: #020617;
}

[data-theme="light"] {
  --bg: #f3f4f6;
  --bg-panel: #ffffff;
  --bg-panel-soft: #e5e7eb;
  --border-soft: #d1d5db;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --text: #111827;
  --text-muted: #6b7280;

  /* Chat en modo claro: fondo blanco, texto oscuro */
  --bg-chat: #ffffff;
  --bg-chat-input: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* LOGIN */

#login-screen {
  height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1f2937 0, #020617 55%);
}

#login-screen .login-card {
  background: var(--bg-panel);
  padding: 2rem 2.5rem;
  border-radius: 1rem;
  border: 1px solid var(--border-soft);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  max-width: 360px;
  width: 100%;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-group input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border-soft);
  background: #020617;
  color: var(--text);
  outline: none;
}

[data-theme="light"] .form-group input {
  background: #ffffff;
  color: #111827;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.btn {
  border-radius: 999px;
  border: none;
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--accent);
  color: white;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-sm {
  padding: 0.3rem 0.8rem;
  font-size: 0.75rem;
}

/* APP PRINCIPAL */

#main-app {
  display: none;
  height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: row;
  height: 100%;
  width: 100%;
}

/* SIDEBAR IZQUIERDA */

.sidebar {
  width: 280px;
  min-width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
}

/* CABECERA SIDEBAR */

.sidebar-header {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.app-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.current-user-pill {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sidebar-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* SECCIONES DE LA SIDEBAR */

.sidebar-section {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-soft);
}

.section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

/* LISTAS (USUARIOS / SALAS) */

#rooms-list,
#users-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 8rem;
  overflow-y: auto;
  scrollbar-width: thin;
}

#rooms-list li,
#users-list li {
  padding: 0.35rem 0.45rem;
  border-radius: 0.45rem;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  cursor: pointer;
}

#rooms-list li:hover,
#users-list li:hover {
  background: var(--bg-panel-soft);
}

#rooms-list li.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.user-item {
  cursor: default;
}

.user-status {
  margin-right: 0.2rem;
}

.user-name {
  flex: 1;
}

.call-btn {
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: transparent;
  color: var(--accent);
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
}

.call-btn.selected-call {
  background: var(--accent);
  color: white;
}

/* UBICACIÓN */

.location-controls {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.location-controls .btn {
  font-size: 0.75rem;
  padding: 0.3rem 0.7rem;
}

/* PREFERENCIAS TEMA */

.theme-toggle {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.theme-toggle button {
  font-size: 0.7rem;
}

/* CHAT ABAJO */

.chat-panel {
  margin-top: auto;
  padding: 0.7rem 1rem 0.9rem;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-panel-soft);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#current-room-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

/* Chat compatible con modo claro/oscuro + burbujas */

#chat-messages {
  background: var(--bg-chat);
  color: var(--text);
  border-radius: 0.5rem;
  border: 1px solid var(--border-soft);
  padding: 0.45rem 0.5rem;
  height: 150px;
  overflow-y: auto;
  font-size: 0.8rem;

  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  word-wrap: break-word;
}

.chat-message {
  max-width: 90%;
  display: flex;
  flex-direction: column;
}

.chat-own {
  align-self: flex-end;
  text-align: right;
}

.chat-other {
  align-self: flex-start;
  text-align: left;
}

.chat-header {
  font-size: 0.7rem;
  margin-bottom: 0.1rem;
  opacity: 0.85;
}

.chat-bubble {
  border-radius: 0.75rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg-panel-soft);
}

.chat-own .chat-bubble {
  background: var(--accent);
  color: #ffffff;
}

.chat-image-preview {
  max-width: 100%;
  max-height: 120px;
  border-radius: 0.35rem;
  margin-top: 0.15rem;
}

.chat-input-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

#chat-text {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  background: var(--bg-chat-input);
  color: var(--text);
}

.chat-file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.15rem;
}

.chat-file-row input[type="file"] {
  font-size: 0.7rem;
  color: var(--text);
}

/* Estilo cuando se arrastra archivo al chat */

.chat-drop-active {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* MAPA Y VIDEO */

.map-container {
  flex: 1;
  position: relative;
  min-width: 0;
  background: #020617;
}

/* El mapa ocupa todo el espacio de la derecha */
#map {
  position: absolute;
  inset: 0;
}

/* Panel de vídeo flotante dentro del mapa */

.video-panel {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  width: 260px;
  background: rgba(15, 23, 42, 0.92);
  border-radius: 0.75rem;
  border: 1px solid var(--border-soft);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 1000;
}

.video-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.video-panel-body {
  position: relative;
  overflow: hidden;
  border-radius: 0.5rem;
  background: #000;
  height: 160px;
}

#remote-video,
#local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#local-video {
  position: absolute;
  width: 35%;
  height: 35%;
  right: 0.35rem;
  bottom: 0.35rem;
  border-radius: 0.5rem;
  border: 2px solid white;
}

.video-panel-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.3rem;
}

.video-panel-footer .btn {
  flex: 1;
  font-size: 0.7rem;
  padding: 0.3rem 0.4rem;
}

.btn-danger {
  background: var(--danger);
}

/* Leaflet */

.leaflet-control-layers {
  font-size: 0.8rem;
}

/* Generales */

.hidden {
  display: none !important;
}

a {
  color: var(--accent);
}

/* ====================== */
/*   RESPONSIVE LAYOUT    */
/* ====================== */

@media (max-width: 960px) {
  #login-screen .login-card {
    margin: 0 1rem;
    max-width: 100%;
  }

  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
    max-height: 60vh;
  }

  #rooms-list,
  #users-list {
    max-height: 6rem;
  }

  #chat-messages {
    height: 120px;
  }

  .map-container {
    flex: 1;
    min-height: 40vh;
  }
}

@media (max-width: 640px) {
  .sidebar-header {
    padding: 0.7rem 0.8rem;
  }

  .sidebar-section {
    padding: 0.6rem 0.8rem;
  }

  .chat-panel {
    padding: 0.6rem 0.8rem 0.7rem;
  }

  .video-panel {
    width: 200px;
    right: 0.6rem;
    bottom: 0.6rem;
  }

  .video-panel-body {
    height: 130px;
  }

  #chat-messages {
    height: 110px;
  }

  .app-title {
    font-size: 0.95rem;
  }

  .current-user-pill {
    font-size: 0.75rem;
  }

  .btn,
  .btn-sm {
    font-size: 0.75rem;
  }
}
