/**
 * AlertaVecino — Consola Web de Portería / Monitoreo Comunitario
 * Tema Oscuro de Alta Visibilidad, Glassmorphism y Responsive Design
 */

:root {
  --bg-main: #0B0F19;
  --bg-card: #131B2E;
  --bg-card-hover: #1C2742;
  --border-color: rgba(255, 255, 255, 0.08);
  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --accent-red: #EF4444;
  --accent-red-glow: rgba(239, 68, 68, 0.4);
  --accent-green: #10B981;
  --accent-amber: #F59E0B;
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --radius-lg: 16px;
  --radius-md: 10px;
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea, select {
  user-select: text;
  -webkit-user-select: text;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ─── Header & Barra Superior ───────────────────────────────────────────── */
.app-header {
  background: rgba(19, 27, 46, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #EF4444, #B91C1C);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-porteria {
  background: rgba(59, 130, 246, 0.2);
  color: #60A5FA;
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34D399;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.84rem;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 10px #10B981;
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.user-tag {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-header {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-logout {
  color: #F87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ─── Navegación de Pestañas ────────────────────────────────────────────── */
.nav-tabs {
  display: flex;
  background: #111827;
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  gap: 8px;
}

.nav-tab {
  padding: 14px 20px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.nav-tab:hover {
  color: var(--text-main);
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ─── Contenedor Principal ──────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* ─── Banner de Sirena de Audio Web ─────────────────────────────────────── */
.sound-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(217, 119, 6, 0.05));
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sound-banner-text {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #FCD34D;
  font-size: 0.9rem;
}

.btn-sound-activate {
  background: #F59E0B;
  color: #000;
  border: none;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.btn-sound-activate:hover {
  transform: scale(1.03);
}

/* ─── Tarjeta de Alerta en Vivo (Crítica) ────────────────────────────────── */
.active-emergencies-container {
  margin-bottom: 24px;
}

.alert-card-live {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.18), rgba(185, 28, 28, 0.08));
  border: 2px solid #EF4444;
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 0 30px var(--accent-red-glow);
  animation: alert-pulse 1.8s infinite;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

@keyframes alert-pulse {
  0% { box-shadow: 0 0 15px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 35px rgba(239, 68, 68, 0.8); }
  100% { box-shadow: 0 0 15px rgba(239, 68, 68, 0.4); }
}

.alert-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 1px solid rgba(239, 68, 68, 0.3);
  padding-bottom: 14px;
}

.alert-type-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 800;
  color: #F87171;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.alert-time {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.alert-body-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.alert-info-box {
  background: rgba(11, 15, 25, 0.6);
  border: 1px solid var(--border-color);
  padding: 14px;
  border-radius: var(--radius-md);
}

.alert-info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.alert-info-value {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-word;
}

.alert-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn-resolve {
  background: #10B981;
  color: #fff;
  border: none;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
  transition: all 0.2s;
}

.btn-resolve:hover {
  background: #059669;
  transform: translateY(-1px);
}

.btn-whatsapp {
  background: #25D366;
  color: #fff;
  border: none;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn-whatsapp:hover {
  background: #1EBE5D;
}

/* ─── Tarjetas de Resumen Dashboard ─────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-content h3 {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat-content p {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ─── Formularios de Difusión Push ──────────────────────────────────────── */
.card-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: rgba(11, 15, 25, 0.7);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

.radio-group {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  cursor: pointer;
  color: var(--text-main);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  transition: all 0.2s;
}

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

/* ─── Tablas de Datos (Residentes e Historial) ───────────────────────────── */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  background: rgba(255, 255, 255, 0.04);
  padding: 12px 16px;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* ─── Pantalla de Login ─────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(circle at top, #172554, #0B0F19);
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 36px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-top: 12px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 4px;
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #F87171;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

/* ─── Responsive Móvil ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .header-status {
    width: 100%;
    justify-content: space-between;
  }
  .nav-tabs {
    overflow-x: auto;
  }
}
