/* CSS Variables and Base Styles */

:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --brand: #0ea5e9;
  --accent: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .06);
}

/* Dark Mode Overrides */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #0f172a;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2a44;
    --shadow: 0 10px 24px rgba(0, 0, 0, .45);
  }
}

/* Global Styles */
* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background:
    radial-gradient(1200px 800px at 10% -10%, rgba(14,165,233,.08), transparent 60%),
    radial-gradient(1000px 600px at 120% 20%, rgba(34,197,94,.06), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
}

/* Layout Components */
.container {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
  margin-left: var(--sidebar-width, 260px);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-left: 8px;
}

.title {
  font-size: clamp(1.4rem, 1.8vw + 1rem, 2.2rem);
  font-weight: 800;
  letter-spacing: .2px;
  margin: 0;
}

/* === Header tipo barra superior BIU === */

.header-tech {
  margin-bottom: 18px;
}

/* Cinta superior institucional */
.header-ribbon {
  width: 100%;
  background: linear-gradient(90deg, var(--brand), rgba(14,165,233,0.35));
  padding: 6px 12px;
  border-radius: 8px;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
}

.ribbon-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Contenido principal del encabezado */
.header-content {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.weather-icon {
  font-size: 1.9rem;
  margin-right: 8px;
  display: inline-block;
  vertical-align: middle;
}

.header-content .title {
  margin: 0;
}

/* Subtítulo bajo el título principal */
.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Responsive para móviles */
@media (max-width: 640px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }

  #status-badge {
    align-self: stretch;
    text-align: center;
  }
}


/* UI Components */
.badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .82rem;
  background: rgba(14,165,233,.12);
  color: var(--brand);
  border: 1px solid rgba(14,165,233,.25);
}

/* Cards Grid */
.cards {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
  margin: 18px 0 22px;
}

/* Individual Card Styles */
.card {
  grid-column: span 4;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  overflow: hidden; /* por defecto, pero lo abrimos para los gauges */
}

/* Card Hover Effect */
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(0,0,0,.10);
  border-color: rgba(14,165,233,.35);
}

/* Card Content Styles */
.card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.card div {
  font-size: clamp(1.25rem, 1.2vw + 1rem, 2rem);
  font-weight: 800;
  letter-spacing: .3px;
}

/* Gauge cards: centrado y overflow visible */
.gauge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: visible; /* permite que el semicírculo no se corte */
}

/* Chart wrapper */
.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.chart-wrap h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 800;
}

#chart {
  display: block;
  width: 100%;
  height: 320px;
}

/* Table Styles */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Table Header */
.table-wrap h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 800;
}

.table-scroller {
  overflow: auto;
  border-radius: calc(var(--radius) - 6px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .94rem;
  min-width: 720px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:hover {
  background: rgba(14,165,233,.06);
}

/* Utility Classes */
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}

.btn:hover {
  border-color: rgba(14,165,233,.45);
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(180deg, rgba(14,165,233,.92), rgba(14,165,233,.75));
  color: #fff;
  border-color: rgba(14,165,233,.6);
}

/* Tag Component */
.tag {
  display:inline-block;
  padding:4px 8px;
  font-size:.78rem;
  border-radius:8px;
  background: rgba(34,197,94,.12);
  color: var(--accent);
  border:1px solid rgba(34,197,94,.25);
}

/* Typography */
h1, h2, h3 { letter-spacing: .2px; }
p { color: var(--text); margin: 0 0 10px; }
.muted { color: var(--muted); }

/* Animations and Responsive Design */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card,
.chart-wrap,
.table-wrap {
  animation: fadeInUp .25s ease both;
}

/* Responsive Adjustments */
@media (max-width: 980px) {
  .card { grid-column: span 6; }
  #chart { height: 280px; }
}

@media (max-width: 640px) {
  .card { grid-column: span 12; }
  .header { flex-direction: column; align-items: flex-start; }
  #chart { height: 240px; }
}

@media print {
  body { background: #fff; color: #111; }
  .card, .chart-wrap, .table-wrap {
    box-shadow: none;
    border-color: #d1d5db;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .btn, .footer { display: none !important; }
}

/* Footer Styles */
.footer {
  background: #f9fafb;
  border-top: 1px solid #e0e0e0;
  padding: 16px 10px;
  color: #444;
  font-size: 0.9rem;
}

/* Footer Content Layout */
.footer-content {
  max-width: 1000px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 20px;
  white-space: nowrap;
}

/* Prevent Overflow of Footer Items */
.footer-content > * { min-width: 0; }

/* Logo Styling */
.biu-logo {
  display: block;
  height: 48px;
  width: auto;
}

/* Footer Text Styling */
.footer-text {
  margin: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer Link Styling */
.footer a {
  color: #0056b3;
  text-decoration: none;
  font-weight: 600;
}
.footer a:hover {
  text-decoration: underline;
  color: #0ea5e9;
}

/* ------------------------------
   Fixes for Chart.js gauges/canvases
   ------------------------------ */

/* Gauges: tamaño y proporción tipo reloj */
.gauge-canvas,
canvas.gauge-fixed {
  width: 100% !important;
  max-width: 260px;
  aspect-ratio: 2 / 1;   /* ancho:alto = 2:1 */
  height: auto !important;
  display: block;
}

/* Ensure main chart has a stable height (you already set #chart, keep it) */
#chart { height: 320px; }

/* Limit table scroller height to avoid page growing indefinitely */
.table-scroller { max-height: 420px; overflow: auto; }

/* Loading overlay (optional element you can include in DOM) */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
}

#loading-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* KPI color classes used by JS for visual semaphore */
.kpi-ok {
  color: var(--accent);
  background: rgba(34,197,94,.08);
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-block;
}
.kpi-normal {
  color: var(--brand);
  background: rgba(14,165,233,.06);
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-block;
}
.kpi-warn {
  color: var(--warn);
  background: rgba(245,158,11,.06);
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-block;
}
.kpi-danger {
  color: var(--danger);
  background: rgba(239,68,68,.06);
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-block;
}

/* Small helper for accessibility (ensures canvas labels aren't overflowing) */
canvas[role="img"] { max-width: 100%; }

/* =========================================
   Layout con sidebar tipo admin
   ========================================= */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Panel lateral */
.sidebar {
  width: 240px;
  background: linear-gradient(180deg, #020617, #020617);
  color: #e5e7eb;
  padding: 16px 14px;
  box-shadow: 6px 0 20px rgba(15,23,42,0.4);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 20;
}

.app-main {
  flex: 1;
  min-width: 0;
}

/* Header del sidebar */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(148,163,184,0.35);
}

.sidebar-logo-circle {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 0%, #38bdf8, #0f172a 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 0 0 1px rgba(15,23,42,0.7), 0 6px 14px rgba(15,23,42,0.8);
}

.sidebar-title-wrap {
  display: flex;
  flex-direction: column;
}

.sidebar-title {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: .02em;
}

.sidebar-subtitle {
  font-size: 0.78rem;
  color: #9ca3af;
}

/* Navegación del sidebar */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: #e5e7eb;
  cursor: pointer;
  font-size: 0.88rem;
  text-align: left;
  transition: background .15s ease, border-color .15s ease, transform .12s ease, color .12s ease;
}

.sidebar-item:hover {
  background: rgba(15,23,42,0.8);
  border-color: rgba(148,163,184,0.4);
  transform: translateY(-1px);
}

.sidebar-item.is-active {
  background: radial-gradient(circle at 0 0, rgba(56,189,248,0.3), rgba(15,23,42,0.95));
  border-color: rgba(56,189,248,0.7);
}

.sidebar-item.is-active .sidebar-icon {
  color: #38bdf8;
}

.sidebar-link {
  text-decoration: none;
}

/* Iconos del sidebar */
.sidebar-icon {
  width: 22px;
  text-align: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

/* Footer del sidebar */
.sidebar-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(15,23,42,0.9);
}

.sidebar-badge {
  display: inline-block;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.5);
  color: #9ca3af;
}

/* Bloques de info para Configuración / About */
.info-block {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 18px 0;
}

/* Iconos KPIs (si aún no estaban) */
.kpi-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  margin-right: 6px;
  font-size: 0.95rem;
  background: rgba(15,23,42,0.04);
  box-shadow: 0 1px 3px rgba(15,23,42,0.12);
}

.kpi-icon-temp {
  background: rgba(248,113,113,0.16);
}

.kpi-icon-hum {
  background: rgba(56,189,248,0.16);
}

.kpi-icon-pres {
  background: rgba(52,211,153,0.16);
}

/* Responsivo: sidebar se convierte en barra superior en pantallas pequeñas */
@media (max-width: 840px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    flex-direction: column;
    box-shadow: 0 4px 14px rgba(15,23,42,0.7);
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .sidebar-item {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}



