/* ==========================================================================
   Demo uniCloud · extras sobre core/base.html
   La sidebar, topbar, tipografía, tema, tablas y cards se heredan tal cual
   de core/base.html (éste reacciona a is_demo). Aquí sólo añadimos:
     - botón flotante para reiniciar el tour,
     - mini-widgets para el dashboard interactivo demo,
     - utilidades para ocultar acciones destructivas.
   ========================================================================== */

/* ==========================================================================
   Popups de Leaflet en el modo demo
   --------------------------------------------------------------------------
   Overrides sobre map_v2.css scopeados a .demo-popup (aplicada vía
   bindPopup({ className: 'demo-popup' })), para que los popups se vean
   modernos, limpios y consistentes con el estilo del dashboard del demo.
   ========================================================================== */

.leaflet-popup.demo-popup .leaflet-popup-content-wrapper {
  min-width: 280px;
  max-width: 340px;
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(15, 23, 42, .18), 0 2px 6px rgba(15, 23, 42, .08);
  border: 1px solid rgba(15, 23, 42, .06);
  background: #fff;
}
.leaflet-popup.demo-popup .leaflet-popup-content {
  margin: 0;
  width: auto !important;
  font-family: inherit;
  color: #0f172a;
}
.leaflet-popup.demo-popup .leaflet-popup-tip {
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .08);
}

/* Botón de cerrar más discreto */
.leaflet-popup.demo-popup .leaflet-popup-close-button {
  color: rgba(255, 255, 255, .85) !important;
  font-size: 18px !important;
  width: 26px;
  height: 26px;
  line-height: 26px !important;
  top: 8px !important;
  right: 8px !important;
  border-radius: 50%;
  background: rgba(0, 0, 0, .18);
  transition: background .15s ease;
}
.leaflet-popup.demo-popup .leaflet-popup-close-button:hover {
  background: rgba(0, 0, 0, .32);
  color: #fff !important;
}

/* --- Header con gradiente moderno ---------------------------------------- */
.leaflet-popup.demo-popup .popup-header {
  padding: 14px 16px;
  gap: 12px;
  border-left: 0;
  animation: none;
  color: #fff;
}
.leaflet-popup.demo-popup .popup-header.concentrador {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
}
.leaflet-popup.demo-popup .popup-header.no-alarm {
  background: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
}
.leaflet-popup.demo-popup .popup-header.alarm-pending {
  background: linear-gradient(135deg, #b45309 0%, #f59e0b 100%);
}
.leaflet-popup.demo-popup .popup-header.alarm-active {
  background: linear-gradient(135deg, #991b1b 0%, #dc2626 100%);
}
.leaflet-popup.demo-popup .popup-header-icon {
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  background: rgba(255, 255, 255, .18);
  border-radius: 10px;
  flex-shrink: 0;
}
.leaflet-popup.demo-popup .popup-header-title {
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .2px;
}
.leaflet-popup.demo-popup .popup-header-mac {
  font-family: inherit;
  font-size: .72rem;
  opacity: .85;
  margin-top: 2px;
}

/* --- Body --------------------------------------------------------------- */
.leaflet-popup.demo-popup .popup-body {
  padding: 14px 16px;
  background: #fff;
  max-height: none;
}

/* Info-grid como mini-cards limpios */
.leaflet-popup.demo-popup .popup-info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 0;
}
.leaflet-popup.demo-popup .popup-info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #eef2f7;
  border-radius: 10px;
}
.leaflet-popup.demo-popup .popup-info-label {
  font-size: .72rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .4px;
  margin: 0;
}
.leaflet-popup.demo-popup .popup-info-value {
  font-size: .85rem;
  font-weight: 600;
  color: #0f172a;
  text-align: right;
  margin: 0;
}

/* --- Footer ------------------------------------------------------------- */
.leaflet-popup.demo-popup .popup-footer {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  background: #fff;
  border-top: 1px solid #f1f5f9;
}
.leaflet-popup.demo-popup .popup-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .75rem;
  border-radius: 10px;
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.leaflet-popup.demo-popup .popup-btn-primary {
  background: #2563eb;
  color: #fff;
}
.leaflet-popup.demo-popup .popup-btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(37, 99, 235, .28);
}
.leaflet-popup.demo-popup .popup-btn-secondary {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #e2e8f0;
}
.leaflet-popup.demo-popup .popup-btn-secondary:hover {
  background: #e2e8f0;
}

/* ---- Pista "haz click para activar zoom" sobre mapas demo -------------- */
/*  Se muestra mientras el zoom-wheel está bloqueado (scroll-lock activo).  */
.demo-map-hint {
  position: absolute;
  inset: auto 12px 12px auto;
  z-index: 500;
  background: rgba(15, 23, 42, .8);
  color: #fff;
  padding: .45rem .75rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  pointer-events: none;
  opacity: 1;
  transition: opacity .25s ease;
}
.demo-map-hint i { color: #facc15; }
.demo-map-active .demo-map-hint { opacity: 0; }

/* ---- Botón flotante "Iniciar tour" ------------------------------------- */
.demo-tour-fab {
  position: fixed;
  right: 22px;
  bottom: 84px;                 /* por encima del floating-help-btn de core */
  z-index: 1045;
  border-radius: 999px;
  padding: .55rem 1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  box-shadow: 0 6px 18px rgba(245,158,11,.35);
}
.demo-tour-fab:hover { transform: translateY(-1px); }
@media (max-width: 576px) {
  .demo-tour-fab { right: 16px; bottom: 78px; padding: .5rem .7rem; }
}

/* ---- Badges estado (usados en tablas demo) ------------------------------ */
.demo-badge {
  display: inline-block;
  padding: .3rem .65rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .3px;
}
.demo-badge--online { background: rgba(22,163,74,.12); color: #15803d; }
.demo-badge--offline { background: rgba(239,68,68,.12); color: #b91c1c; }
.demo-badge--warn { background: rgba(245,158,11,.15); color: #b45309; }
.demo-badge--info { background: rgba(67,97,238,.12); color: #4361ee; }
.demo-badge--muted { background: rgba(107,114,128,.12); color: #4b5563; }

/* ---- KPI cards (reutilizables en dashboard concentradores/DGA/SMA) ----- */
.demo-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.demo-kpi {
  background: #fff;
  border-radius: 14px;
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,.06);
  position: relative;
  overflow: hidden;
  border: 1px solid #eef1f5;
}
[data-theme="dark"] .demo-kpi {
  background: var(--surface);
  border-color: rgba(255,255,255,.08);
}
.demo-kpi-label {
  color: #6b7280;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}
.demo-kpi-value {
  font-size: 1.7rem;
  font-weight: 700;
  margin-top: .25rem;
  color: #0f172a;
}
[data-theme="dark"] .demo-kpi-value { color: var(--ink); }
.demo-kpi-icon {
  position: absolute;
  top: 50%;
  right: 1rem;
  transform: translateY(-50%);
  font-size: 2rem;
  opacity: .14;
  color: #4361ee;
}
.demo-kpi--ok .demo-kpi-icon { color: #16a34a; }
.demo-kpi--warn .demo-kpi-icon { color: #f59e0b; }
.demo-kpi--danger .demo-kpi-icon { color: #ef4444; }

/* ---- Mapa Leaflet ------------------------------------------------------- */
.demo-map {
  height: 380px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,.06);
}

/* ---- Chart wrappers genéricos ------------------------------------------ */
.demo-chart-box {
  position: relative;
  height: 280px;
  padding: .5rem;
}

/* ---- Acciones deshabilitadas ------------------------------------------- */
.demo-disabled {
  opacity: .5;
  pointer-events: none;
}
[data-destructive] {
  display: none !important;
}

/* ---- Mini-widgets para el dashboard interactivo demo ------------------- */
/* Grid simple (sin gridstack) que respeta el data-gs-w/h por columnas */
.demo-widget-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.demo-widget {
  grid-column: span var(--gs-w, 4);
  background: #fff;
  border-radius: 12px;
  border: 1px solid #eef1f5;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(var(--gs-h, 3) * 95px);
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
  overflow: hidden;
}
[data-theme="dark"] .demo-widget {
  background: var(--surface);
  border-color: rgba(255,255,255,.08);
}
.demo-widget-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: .75rem 1rem .35rem;
  border-bottom: 1px solid #f1f5f9;
}
.demo-widget-head h4 {
  margin: 0;
  font-size: .95rem;
  font-weight: 600;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: .4rem;
}
[data-theme="dark"] .demo-widget-head h4 { color: var(--ink); }
.demo-widget-head small {
  color: #64748b;
  font-size: .72rem;
  font-weight: 500;
}
.demo-widget-body {
  padding: .75rem 1rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}
.demo-widget-kpi-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: #0f172a;
  font-family: "Handjet", system-ui, monospace;
  line-height: 1;
}
[data-theme="dark"] .demo-widget-kpi-value { color: var(--ink); }
.demo-widget-kpi-unit {
  font-size: 1rem;
  color: #64748b;
  margin-left: .25rem;
  font-family: inherit;
}
.demo-widget-kpi-trend {
  margin-top: .5rem;
  font-size: .8rem;
  font-weight: 600;
}
.demo-widget-kpi-trend.up   { color: #16a34a; }
.demo-widget-kpi-trend.down { color: #ef4444; }
.demo-widget-chart {
  width: 100%;
  height: 100%;
  min-height: 180px;
}
.demo-widget-progress {
  width: 100%;
  background: #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  height: 28px;
  position: relative;
}
.demo-widget-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #4361ee, #4cc9f0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  transition: width .8s ease;
}

@media (max-width: 992px) {
  .demo-widget { grid-column: span 6; }
}
@media (max-width: 576px) {
  .demo-widget { grid-column: span 12; }
}

/* ---- Tour Shepherd ajustes menores ------------------------------------- */
.shepherd-button.demo-tour-btn {
  background: #4361ee;
  color: #fff;
}
.shepherd-button.demo-tour-btn:hover { background: #3f37c9; }
