:root {
    --primary: #4bc2c5;
    --primary-dark: #1B7B84;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-main: #333333;
    --text-light: #777777;
    --border-radius: 12px;
    --shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-main: #e0e0e0;
    --text-light: #aaaaaa;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

body { background-color: var(--bg-color); color: var(--text-main); transition: background 0.3s; }

/* Login Styles */
.login-body { display: flex; justify-content: center; align-items: center; height: 100vh; }
.login-container { background: var(--card-bg); padding: 2rem; border-radius: var(--border-radius); box-shadow: var(--shadow); width: 100%; max-width: 400px; text-align: center; }
.login-header h1 { color: var(--primary-dark); margin-bottom: 0.5rem; }

.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label { display: block; margin-bottom: 0.5rem; color: var(--text-light); }
.form-group input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: var(--border-radius); background: var(--bg-color); color: var(--text-main); }
.error-msg { color: #e74c3c; font-size: 0.8rem; display: none; }

.btn-primary { background: var(--primary-dark); color: white; border: none; padding: 12px; width: 100%; border-radius: var(--border-radius); cursor: pointer; font-size: 1rem; transition: background 0.2s; }
.btn-primary:hover { background: var(--primary); }

.forgot-password-link {
    color: var(--primary-dark);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}
.forgot-password-link:hover { color: var(--primary); text-decoration: underline; }

.alert-error { background: #ffebee; color: #c62828; padding: 10px; border-radius: var(--border-radius); margin-bottom: 1rem; }

/* Dashboard Header */
.main-header { background: var(--card-bg); box-shadow: var(--shadow); width: 100%; }
.header-content { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }

.logo-area { display: flex; align-items: center; gap: 10px; font-weight: bold; color: var(--primary-dark); }
.logo-circle { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; display: block; }

/* Container General */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; width: 100%; box-sizing: border-box; }

/* Navegación */
.main-nav a { text-decoration: none; color: var(--text-light); margin: 0 15px; font-weight: 500; }
.main-nav a.active { color: var(--primary-dark); border-bottom: 2px solid var(--primary); }

.user-area { display: flex; align-items: center; gap: 15px; }
.user-photo { width: 35px; height: 35px; border-radius: 50%; }
.btn-logout { text-decoration: none; color: #e74c3c; font-size: 0.9rem; }

/* Dashboard Content */
.dashboard-content { padding: 2rem 0; }
.dashboard-content h2 { margin-bottom: 1.5rem; color: var(--primary-dark); }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 2rem; }

.card { background: var(--card-bg); padding: 1.5rem; border-radius: var(--border-radius); box-shadow: var(--shadow); border-left: 5px solid var(--primary); transition: transform 0.3s ease, box-shadow 0.3s ease; }
.card:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.15); }

.card.status-critical { border-left-color: #e74c3c; }
.card.status-low { border-left-color: #f1c40f; }

.card-header h3 { font-size: 1.1rem; color: var(--text-light); margin-bottom: 1rem; }
.metric .number { font-size: 2.5rem; font-weight: bold; color: var(--primary-dark); display: block; }
.metric .label { font-size: 0.9rem; color: var(--text-light); }

.card-footer { margin-top: 1rem; text-align: right; }
.btn-small { background: transparent; border: 1px solid var(--primary); color: var(--primary-dark); padding: 5px 10px; border-radius: var(--border-radius); cursor: pointer; }

.map-placeholder { background: #e0e0e0; height: 300px; border-radius: var(--border-radius); display: flex; align-items: center; justify-content: center; color: #666; }

.main-footer { text-align: center; padding: 2rem; color: var(--text-light); font-size: 0.9rem; }

/* Estilos para Lista de Zonas en Dashboard */
.zones-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.zone-card {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    border-left: 5px solid var(--primary); /* Color por defecto */
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Utilities */
.btn-text { background: none; border: none; cursor: pointer; color: var(--text-light); }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1.2rem; }

@media (max-width: 768px) {
    .header-content { flex-direction: column; gap: 15px; }
    .main-nav { display: flex; gap: 15px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
    .split-section { flex-direction: column; }
    .sensor-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Estilos para la leyenda */
.legend-content {
  display: flex;
  justify-content: center;
  gap: 30px;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* Sección dividida (2 tarjetas) */
.split-section {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}
.split-card {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  padding: 20px;
}
.inner-card-bg {
  background-color: #f4f6f9;
  border-radius: 10px;
  padding: 15px;
  margin: 10px 0;
}
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
.sensor-square {
  aspect-ratio: 1;
  border-radius: 8px;
  position: relative; /* Necesario para posicionar el tooltip */
  display: flex;
  background-color: #999; /* Color de respaldo si falla el dato */
  min-height: 60px; /* Evita que colapse si no hay contenido */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4); /* Asegura lectura sobre colores claros */
  font-weight: bold;
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.2;
}

/* Animación suave de actualización */
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.fade-in {
  animation: fadeIn 0.5s ease-out forwards;
}

/* Badge de estado de conexión */
.offline-badge {
  background-color: #dc3545; color: white; padding: 4px 8px; border-radius: 4px;
  font-size: 0.75rem; font-weight: bold; display: none; margin-left: 10px;
}

/* Tooltip Personalizado CSS */
.sensor-square[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  margin-bottom: 8px;
  opacity: 0;
  animation: fadeIn 0.2s forwards;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
