/*
 * chart_envios_plus.css
 *
 * Mejoras visuales para la grilla hora×pozo del módulo DGA. Se usa tanto en
 * /dga/chart-envios/ (real) como en /demo/dga/chart-envios/ (demo) para mantener
 * consistencia visual entre ambos entornos.
 *
 * Funcionalidades que cubre:
 *   1. Tooltip flotante al hover sobre cada celda (sin requerir click).
 *   2. Heatmap por intensidad de éxito por pozo y por hora.
 *   3. Fila de totales por pozo (footer sticky de la grilla).
 *   4. Columna de totales por hora (extremo derecho).
 *   5. Popup/modal de detalle con encabezado en gradiente según estado.
 *   6. Filtros rápidos: solo fallidos / solo sin envío.
 */

/* ---------------------------------------------------------------- */
/* 1. Tooltip flotante                                                */
/* ---------------------------------------------------------------- */
.chart-tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -112%) scale(0.96);
  transition: opacity 0.12s ease, transform 0.12s ease;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.96));
  color: #f8fafc;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  max-width: 260px;
  min-width: 180px;
}

.chart-tooltip.visible {
  opacity: 1;
  transform: translate(-50%, -115%) scale(1);
}

.chart-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid rgba(30, 41, 59, 0.96);
}

.chart-tooltip .tip-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}

.chart-tooltip .tip-row:last-child {
  margin-bottom: 0;
}

.chart-tooltip .tip-label {
  color: #94a3b8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.62rem;
}

.chart-tooltip .tip-value {
  color: #f8fafc;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.chart-tooltip .tip-title {
  font-weight: 700;
  margin-bottom: 0.35rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.76rem;
}

.chart-tooltip .tip-badge {
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.62rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.chart-tooltip .tip-badge.exitoso { background: #059669; color: #fff; }
.chart-tooltip .tip-badge.fallido { background: #dc2626; color: #fff; }
.chart-tooltip .tip-badge.sin-envio { background: #64748b; color: #fff; }

/* ---------------------------------------------------------------- */
/* 2. Heatmap de intensidad por pozo (header) y por hora (label)     */
/* ---------------------------------------------------------------- */
.chart-header-pozo {
  position: relative;
}

.chart-header-pozo .heatmap-bar {
  display: block;
  margin-top: 6px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.chart-header-pozo .heatmap-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444 0%, #f59e0b 50%, #10b981 100%);
  transition: width 0.35s ease;
  border-radius: 2px;
}

.chart-header-pozo .heatmap-pct {
  display: block;
  font-size: 0.64rem;
  font-weight: 600;
  opacity: 0.85;
  margin-top: 2px;
}

.chart-hora-label .hora-pct {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.08rem 0.3rem;
  margin-top: 0.15rem;
  border-radius: 6px;
}

.chart-hora-label .hora-pct.ok {
  background: rgba(16, 185, 129, 0.18);
  color: #047857;
}
.chart-hora-label .hora-pct.ko {
  background: rgba(220, 38, 38, 0.18);
  color: #991b1b;
}
.chart-hora-label .hora-pct.empty {
  background: rgba(148, 163, 184, 0.2);
  color: #475569;
}

[data-theme="dark"] .chart-hora-label .hora-pct.ok { color: #6ee7b7; }
[data-theme="dark"] .chart-hora-label .hora-pct.ko { color: #fca5a5; }
[data-theme="dark"] .chart-hora-label .hora-pct.empty { color: #cbd5e1; }

/* ---------------------------------------------------------------- */
/* 3. Fila de totales por pozo (footer sticky-bottom)                 */
/* ---------------------------------------------------------------- */
.chart-footer-hora,
.chart-footer-pozo {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  color: #f8fafc;
  padding: 10px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  position: sticky;
  bottom: 0;
  z-index: 7;
  border-radius: 0 0 4px 4px;
}

.chart-footer-hora {
  grid-column: 1;
  left: 0;
  z-index: 13;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 0 0 0 6px;
}

.chart-footer-pozo .stat-ok {
  color: #6ee7b7;
}
.chart-footer-pozo .stat-ko {
  color: #fca5a5;
}
.chart-footer-pozo .stat-pct {
  font-weight: 800;
  font-size: 0.72rem;
}
.chart-footer-pozo .stat-muted {
  color: rgba(255, 255, 255, 0.5);
  font-weight: 500;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---------------------------------------------------------------- */
/* 4. Columna de totales por hora (lado derecho de cada fila)         */
/* ---------------------------------------------------------------- */
.chart-cell.cell-totales {
  background: #f1f5f9;
  border-left: 2px solid #cbd5e1;
  font-size: 0.7rem;
  font-weight: 700;
  color: #334155;
  cursor: default;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 4px 6px;
  flex-direction: column;
  gap: 0;
}

.chart-cell.cell-totales:hover {
  background: #e2e8f0;
  transform: none;
  box-shadow: none;
}

.chart-cell.cell-totales .tot-ok { color: #047857; font-size: 0.75rem; }
.chart-cell.cell-totales .tot-ko { color: #b91c1c; font-size: 0.75rem; }

[data-theme="dark"] .chart-cell.cell-totales {
  background: #1e293b;
  border-left-color: rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
}
[data-theme="dark"] .chart-cell.cell-totales .tot-ok { color: #6ee7b7; }
[data-theme="dark"] .chart-cell.cell-totales .tot-ko { color: #fca5a5; }

/* Header de la columna de totales */
.chart-header-pozo.head-totales {
  background: linear-gradient(180deg, #475569 0%, #1e293b 100%);
  border-radius: 0 6px 0 0;
}

/* ---------------------------------------------------------------- */
/* 5. Filtros rápidos                                                 */
/* ---------------------------------------------------------------- */
.chart-quick-filters {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  background: rgba(15, 23, 42, 0.04);
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.chart-quick-filters .qf-btn {
  border: none;
  background: transparent;
  color: #475569;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chart-quick-filters .qf-btn i { font-size: 0.7rem; }

.chart-quick-filters .qf-btn:hover {
  background: rgba(15, 23, 42, 0.08);
  color: #0f172a;
}

.chart-quick-filters .qf-btn.active {
  background: #0f172a;
  color: #fff;
}

[data-theme="dark"] .chart-quick-filters {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.2);
}
[data-theme="dark"] .chart-quick-filters .qf-btn {
  color: #cbd5e1;
}
[data-theme="dark"] .chart-quick-filters .qf-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
}
[data-theme="dark"] .chart-quick-filters .qf-btn.active {
  background: #38bdf8;
  color: #0f172a;
}

/* Cuando hay un filtro activo, atenuamos celdas que no coinciden */
.chart-grid[data-filter="fallidos"] .chart-cell:not([data-estado="fallido"]) .chart-point {
  opacity: 0.18;
  filter: grayscale(0.8);
}
.chart-grid[data-filter="sin-envio"] .chart-cell[data-estado] .chart-point {
  opacity: 0.18;
  filter: grayscale(0.8);
}
.chart-grid[data-filter="exitosos"] .chart-cell:not([data-estado="exitoso"]) .chart-point {
  opacity: 0.18;
  filter: grayscale(0.8);
}

/* ---------------------------------------------------------------- */
/* 6. Popup/modal de detalle con encabezado en gradiente              */
/* ---------------------------------------------------------------- */
#detalleModal .modal-content,
.dga-chart-detalle .modal-content {
  border-radius: 14px;
  overflow: hidden;
  border: 0;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.dga-chart-detalle-header {
  color: #fff;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 0;
}

.dga-chart-detalle-header.estado-exitoso {
  background: linear-gradient(135deg, #065f46 0%, #10b981 100%);
}
.dga-chart-detalle-header.estado-fallido {
  background: linear-gradient(135deg, #991b1b 0%, #ef4444 100%);
}
.dga-chart-detalle-header.estado-sin-envio {
  background: linear-gradient(135deg, #334155 0%, #64748b 100%);
}

.dga-chart-detalle-header .dch-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.dga-chart-detalle-header .dch-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.dga-chart-detalle-header .dch-subtitle {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
  font-weight: 600;
}

.dga-chart-detalle-body {
  padding: 1.1rem 1.25rem 1rem;
}

.dga-chart-detalle-body .meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.dga-chart-detalle-body .meta-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
}

.dga-chart-detalle-body .meta-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.1rem;
}

.dga-chart-detalle-body .meta-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: #0f172a;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  word-break: break-word;
}

[data-theme="dark"] .dga-chart-detalle-body .meta-item {
  background: #1e293b;
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .dga-chart-detalle-body .meta-label { color: #94a3b8; }
[data-theme="dark"] .dga-chart-detalle-body .meta-value { color: #e2e8f0; }

.dga-chart-detalle-body .respuesta-bloque {
  margin-top: 0.8rem;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid #e2e8f0;
  color: #334155;
}

[data-theme="dark"] .dga-chart-detalle-body .respuesta-bloque {
  background: #0f172a;
  border-color: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
}

/* ---------------------------------------------------------------- */
/* Grid override: dejamos espacio para la columna de totales          */
/* ---------------------------------------------------------------- */
.chart-grid.has-totales {
  grid-template-columns:
    152px
    repeat(var(--pozos-count, 1), minmax(88px, 1fr))
    minmax(84px, 96px);
}

.chart-grid.has-totales-row {
  grid-auto-rows: minmax(34px, auto);
}

/* ---------------------------------------------------------------- */
/* Chart modal: tabs + JSON (detalle envío SMA / DGA)               */
/* ---------------------------------------------------------------- */
.dga-tl-cell:focus {
  outline: none;
}
.dga-tl-cell:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.85);
  outline-offset: 2px;
  z-index: 5;
  position: relative;
}

[data-theme="dark"] .dga-tl-cell:focus-visible {
  outline-color: rgba(56, 189, 248, 0.9);
}

.chart-modal-summary.chart-modal-summary {
  border-radius: 12px;
}
[data-theme="dark"] .chart-modal-summary {
  background: #1e293b !important;
}

.chart-modal-kv-l {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}
.chart-modal-kv-v {
  font-size: 0.88rem;
  font-weight: 600;
  color: #0f172a;
  word-break: break-word;
}
[data-theme="dark"] .chart-modal-kv-v {
  color: #e2e8f0;
}
[data-theme="dark"] .chart-modal-kv-l {
  color: #94a3b8;
}

.chart-modal-nav {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}
.chart-modal-nav .chart-modal-nav-link {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  border-radius: 10px 10px 0 0;
}
.chart-modal-tab-content {
  background: var(--bs-body-bg, #fff);
  max-height: min(58vh, 520px);
  overflow: auto;
}
[data-theme="dark"] .chart-modal-tab-content {
  background: #151b24;
}
.chart-modal-toolbar {
  display: flex;
  align-items: center;
  margin-bottom: 0.65rem;
}

.chart-modal-json-wrap {
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  overflow: auto;
  max-height: min(46vh, 420px);
}
[data-theme="dark"] .chart-modal-json-wrap {
  border-color: rgba(255, 255, 255, 0.1);
  background: #0f172a;
}

.chart-modal-json-pre {
  margin: 0;
  padding: 0.75rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  color: #334155;
  white-space: pre;
  overflow-x: auto;
}
.chart-modal-json-pre code {
  font-size: inherit;
  color: inherit;
  white-space: pre;
  word-break: normal;
}
[data-theme="dark"] .chart-modal-json-pre {
  color: #cbd5e1;
}

.dga-chart-detalle .modal-dialog.chart-modal-xl {
  max-width: min(960px, 96vw);
}
@media (min-width: 1200px) {
  .dga-chart-detalle .modal-dialog.chart-modal-xl {
    max-width: 1040px;
  }
}

/*
 * base.html fuerza .modal-dialog { margin: 0.5rem; } sin auto → el diálogo queda
 * descentrado. Restaurar centrado horizontal (y margen vertical razonable).
 */
.modal.dga-chart-detalle .modal-dialog.modal-dialog-centered.chart-modal-xl {
  margin-left: auto;
  margin-right: auto;
  margin-top: 1rem;
  margin-bottom: 1rem;
}
