/* ===========================
   NEXUS DASHBOARD — STYLE.CSS
   =========================== */

/* ---- VARIABLES ---- */
:root {
  --bg-primary:   #0f172a;
  --bg-secondary: #1e293b;
  --bg-card:      #1e2a3a;
  --border:       #2d3f55;
  --text-primary: #e0eaf5;
  --text-muted:   #94a3b8;
  --text-dim:     #64748b;
  --accent:       #38bdf8;
  --success:      #34d399;
  --warning:      #facc15;
  --error:        #f87171;
  --chart-bg:     #1e293b;
  --grid-color:   #334155;
}

body.light {
  --bg-primary:   #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card:      #f8fafc;
  --border:       #cbd5e1;
  --text-primary: #0f172a;
  --text-muted:   #475569;
  --text-dim:     #94a3b8;
  --chart-bg:     #ffffff;
  --grid-color:   #e2e8f0;
}

/* ---- RESET ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 20px;
  transition: background 0.3s, color 0.3s;
}

/* ---- HEADER ---- */
header {
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(20px);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  padding: 20px 32px;
  margin-bottom: 16px;
  text-align: center;
  position: relative;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 800;
  color: #00d4ff;
  letter-spacing: 4px;
  text-shadow: 0 2px 8px rgba(0,212,255,0.3);
}

header p { color: var(--text-dim); margin-top: 4px; }

.theme-toggle {
  position: absolute;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}
.theme-toggle:hover { background: var(--bg-card); color: var(--text-primary); }

/* ---- STATUS BAR ---- */
.status-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
  margin-bottom: 20px;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.status-bar span strong { color: var(--text-muted); }
.countdown { color: #38bdf8; font-weight: bold; font-size: 0.95rem; }

/* ---- LAYOUT 2 COLUMNAS ---- */
.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 20px;
  height: fit-content;
}

/* ---- SIDEBAR ---- */
.sidebar-panel {
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 16px !important;
}

.sidebar-panel h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-filtro {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-filtro label { font-size: 0.82rem; color: var(--text-dim); }

.sidebar-filtro input[type="date"] {
  width: 100%;
  height: 32px !important;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 0.85rem !important;
}

.sidebar-filtro button {
  width: 100%;
  height: 36px !important;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.85rem !important;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

/* ---- KPI CARDS ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.card {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
  border: 1px solid var(--border);
  height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 12px 32px rgba(0,0,0,0.2); }

.card .label { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.card .value { font-size: 2.6rem; font-weight: 800; margin: 10px 0 4px; line-height: 1; }
.card .unit  { font-size: 0.9rem; color: var(--text-muted); }
.card .alert-badge { font-size: 0.68rem; margin-top: 4px; color: var(--error); min-height: 14px; }

.temp { color: #f87171; }
.hum  { color: #34d399; }
.pres { color: #818cf8; }

.card.warn  { border-color: #facc15; box-shadow: 0 0 12px #facc1530; }
.card.alert { border-color: #f87171; box-shadow: 0 0 12px #f8717130; }
.card.warn  .value { color: #facc15; }
.card.alert .value { color: #f87171; }

/* ---- CHARTS ---- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 12px;
}

.chart-box {
  height: 400px !important;
  padding: 28px !important;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.chart-box h3 {
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---- STATS BAR ---- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-size: 1.15rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-unit  { font-size: 0.68rem; color: var(--text-dim); }

/* ---- UMBRALES ---- */
/* ---- UMBRALES ---- */
.umbrales {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-primary);
}

.umbrales-header {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background 0.2s;
}

.umbrales-header:hover {
  background: var(--bg-card);
  color: var(--text-muted);
}

.umbrales-body {
  display: none;
  padding: 14px;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.umbrales-body.open {
  display: flex;
}

.umbral-row {
  display: grid;
  grid-template-columns: 1fr 28px 54px 28px 54px;
  grid-template-areas:
    "label label label label label"
    ". minLabel minInput maxLabel maxInput";
  gap: 6px 6px;
  padding: 10px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.umbral-label {
  grid-area: label;
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--text-muted);
  font-weight: 600;
}

.umbral-row label:nth-of-type(1) { grid-area: minLabel; }
.umbral-row label:nth-of-type(2) { grid-area: maxLabel; }
.umbral-row input:nth-of-type(1) { grid-area: minInput; }
.umbral-row input:nth-of-type(2) { grid-area: maxInput; }

.umbral-row label {
  font-size: 0.67rem;
  color: var(--text-dim);
  text-align: center;
  align-self: center;
}

.umbral-row input {
  width: 100%;
  height: 28px;
  padding: 4px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.78rem;
  text-align: center;
}

.umbral-row input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px #3b82f620;
}

.umbrales-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.umbrales-actions button,
.umbrales-actions .btn-secondary {
  width: 100%;
  font-size: 0.8rem;
  padding: 8px 10px;
  border-radius: 8px;
}

.umbrales-actions button:first-child {
  background: #1e3a5f;
  border: 1px solid #3b82f6;
  color: #93c5fd;
  cursor: pointer;
  transition: all 0.2s;
}

.umbrales-actions button:first-child:hover {
  background: #3b82f6;
  color: #fff;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--bg-card);
  color: var(--text-muted);
}

/* ---- ALERTAS PRO ---- */
.alerts-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 20px;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.alerts-section::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--success), var(--warning));
}

.alerts-section h3 {
  margin-bottom: 18px;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Cada alerta individual como card */
.alert-item {
  display: flex;
  gap: 12px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  transition: all 0.2s;
  position: relative;
}

.alert-item:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
  transform: translateX(4px);
}

.alert-item:last-child { margin-bottom: 0; }

/* Icono de severidad */
.alert-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: bold;
  flex-shrink: 0;
}

.alert-high    { background: #fef2f2; color: #dc2626; border: 1px solid #fca5a5; }
.alert-medium  { background: #fefce8; color: #d97706; border: 1px solid #fcd34d; }
.alert-low     { background: #f0fdf4; color: #059669; border: 1px solid #6ee7b7; }

/* Contenido de alerta */
.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-message {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.3;
}

.alert-meta {
  display: flex;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.alert-time {
  font-family: 'SF Mono', 'Roboto Mono', monospace;
  font-weight: 500;
}

.alert-value {
  background: rgba(255,255,255,0.1);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

/* Sin alertas */
.no-alerts {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.no-alerts::before {
  content: "🔔";
  display: block;
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

#alerts-container {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}

#alerts-container::-webkit-scrollbar {
  width: 6px;
}

#alerts-container::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
}

#alerts-container::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 1200px) {
  .dashboard-layout { grid-template-columns: 1fr; }
  .dashboard-sidebar { position: static; }
}

@media (max-width: 1200px) {
  body { padding: 12px; }
  .cards { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .umbral-row { grid-template-columns: 1fr 36px 60px 36px 60px; gap: 6px; }
}