/* ============================================================
   Normalización UI - Landings de Estadísticas
   Alcance: solo elementos dentro de .estadisticas-page
   ============================================================ */

/* ============================================================
   BASE UX GLOBAL — Landings de estadísticas
   Regla única: TODOS los títulos iguales, TODOS los botones
   iguales, TODOS los headers iguales. Sin estilos puntuales.
   ============================================================ */

/* --- Título de tarjeta: patrón del dashboard ---
   Usa las clases del tema (stats-small__label / __value) sin
   sobreescribir peso ni fuente: idéntico al dashboard. */
.estadisticas-page .card-header .stats-small__label {
  display: block;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.estadisticas-page .card-header .stats-small__value {
  margin: 0;
  line-height: 1.2;
}

/* Fallback: cualquier título viejo suelto en un header queda
   normalizado al título grande */
.estadisticas-page .card-header p.text-primary,
.estadisticas-page .card-header .card-title {
  font-size: 1.5rem !important;
  font-weight: 500;
  color: #3d5170 !important;
  margin: 0;
  line-height: 1.2;
}

/* --- Header de tarjeta: título a la izquierda, acciones a
   la derecha, alineación vertical centrada siempre --- */
.estadisticas-page .card-header > .row {
  align-items: center;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}

/* La columna de acciones del header no lleva padding extra:
   el botón queda alineado al borde derecho de la tarjeta */
.estadisticas-page .card-header > .row > [class*="col-"]:last-child {
  padding-right: 0;
}

.estadisticas-page .card-header > .row > [class*="col-"]:first-child {
  padding-left: 0;
}

/* --- Botones: un solo tamaño/forma en toda la página --- */
.estadisticas-page .btn {
  font-size: 0.85rem !important;
  font-weight: 500;
  padding: 6px 14px !important;
  border-radius: 6px !important;
  white-space: nowrap;
  margin-bottom: 0 !important;
}

.estadisticas-page .btn i {
  margin-right: 4px;
}

/* Botones dentro de un form-group quedan alineados con los
   inputs (reemplaza margins inline hardcodeados 22px/60px) */
.estadisticas-page .form-group .btn {
  margin-top: 24px !important;
  margin-right: 0 !important;
}

/* En el header los form-group no llevan margen inferior */
.estadisticas-page .card-header .form-group {
  margin-bottom: 0;
}

/* Reporte XLS y acciones del header: misma variante */
.estadisticas-page .card-header .btn {
  padding: 6px 14px !important;
  margin: 0 !important;
}

/* --- Labels de filtros --- */
.estadisticas-page .form-group > label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #818ea3;
  margin-bottom: 4px;
}

/* --- Selects e inputs de filtros --- */
.estadisticas-page .form-group select.form-control,
.estadisticas-page .form-group input.form-control {
  width: 100%;
  max-width: 100%;
  height: 34px;
  padding: 4px 10px;
  font-size: 0.875rem;
  line-height: 1.4;
  border-radius: 6px;
  float: none;
}

/* Corrige selects marcados con clases de columna por error */
.estadisticas-page select.form-control.col-sm-10 {
  width: 100%;
}

/* Los selects múltiples necesitan alto libre */
.estadisticas-page select.form-control[multiple] {
  height: auto;
  min-height: 90px;
}

/* --- Cards: espaciado uniforme en toda la página --- */
.estadisticas-page .card-header {
  padding: 14px 20px 12px;
}

.estadisticas-page .card-body {
  padding: 12px 20px 20px !important;
}

.estadisticas-page .form-group {
  margin-bottom: 10px;
}

/* --- Listas de checkboxes --- */
.estadisticas-page .checkbox-list-container {
  border: 1px solid #e1e5eb !important;
  border-radius: 6px !important;
  background: #fff !important;
  padding: 8px 10px !important;
  max-height: 200px;
  overflow-y: auto;
}

.estadisticas-page .checkbox-list-container .checkbox {
  margin: 6px 0;
}

.estadisticas-page .checkbox-controls label {
  font-size: 0.8rem !important;
  font-weight: 500;
  cursor: pointer;
}

.estadisticas-page .checkbox-list-container .checkbox label,
.estadisticas-page .checkbox-list-container .checkbox-item {
  font-size: 0.85rem;
  font-weight: 400;
}

/* --- Filas de filtros: alineación vertical consistente --- */
.estadisticas-page .card-header .row,
.estadisticas-page .card-body .row {
  align-items: flex-start;
}

/* --- Espaciado interno de cards --- */
.estadisticas-page .card-body {
  padding-top: 12px !important;
}

/* --- Multi-select dropdown (ms-filter) --- */
.estadisticas-page .ms-filter .ms-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  background: #fff;
  height: 34px;
  font-size: 0.875rem;
  color: #495057;
  cursor: pointer;
}

.estadisticas-page .ms-filter .ms-toggle::after {
  content: "";
  border-top: 5px solid #818ea3;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  margin-left: 8px;
}

.estadisticas-page .ms-filter .ms-count {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.estadisticas-page .ms-menu {
  width: 100%;
  min-width: 240px;
  padding: 8px;
  margin-top: 2px;
}

.estadisticas-page .ms-all {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid #e1e5eb;
  cursor: pointer;
}

.estadisticas-page .ms-menu .checkbox-list-container {
  border: none !important;
  padding: 0 4px !important;
  max-height: 180px;
  overflow-y: auto;
}

/* --- Resumen de filtros aplicados + resultados --- */
.estadisticas-page .filtro-resumen {
  font-size: 0.8rem;
  color: #818ea3;
  padding: 6px 0 14px;
  border-bottom: 1px solid #e1e5eb;
  margin-bottom: 18px;
}

.estadisticas-page .informe-resultados {
  margin-top: 4px;
}

/* Métricas del informe (Superficie / Regantes) */
.estadisticas-page .metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #818ea3;
  margin-bottom: 2px;
}

.estadisticas-page .metric-value {
  font-size: 1.75rem;
  font-weight: 600;
  color: #3d5170;
}

.estadisticas-page .metric-sub {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #818ea3;
  margin-bottom: 2px;
}

.estadisticas-page .metric-value-sm {
  font-size: 1.1rem;
  font-weight: 600;
  color: #3d5170;
}

/* Título de sección dentro de una card de resultados */
.estadisticas-page .metric-title-sm {
  font-size: 1.25rem;
  font-weight: 600;
  color: #3d5170;
  margin-bottom: 4px;
}

/* Contenedor de alto fijo para canvas Chart.js:
   evita el loop infinito de resize (responsive + !maintainAspectRatio) */
.estadisticas-page .chart-box {
  position: relative;
  width: 100%;
}

.estadisticas-page .chart-box--xl { height: 480px; }
.estadisticas-page .chart-box--lg { height: 340px; }
.estadisticas-page .chart-box--tomas { height: 400px; }
.estadisticas-page .chart-box--md { height: 200px; }
.estadisticas-page .chart-box--sm { height: 140px; }

/* Lista compacta de tomeros bajo las donas */
.estadisticas-page .tomero-list {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  margin-top: 10px;
  max-height: 168px;
  overflow-y: auto;
}

.estadisticas-page .tl-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f7f8fa;
  border: 1px solid #e9ecef;
  border-radius: 20px;
  padding: 4px 12px 4px 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.estadisticas-page .tl-item:hover,
.estadisticas-page .tl-item--active {
  background: #eef2f7;
  border-color: #3d5170;
}

.estadisticas-page .tl-item--pinned {
  background: #dfe7f2;
  border-color: #3d5170;
  box-shadow: 0 0 0 1px #3d5170;
}

.estadisticas-page .tl-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.estadisticas-page .tl-img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}

.estadisticas-page .tl-name {
  font-weight: 600;
  color: #3d5170;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.estadisticas-page .tl-val {
  color: #5a6169;
  white-space: nowrap;
}

.estadisticas-page .tl-pct {
  font-weight: 700;
  color: #3d5170;
}

/* Columna de deuda alineada al borde derecho (final de la barra) */
.estadisticas-page .informe-metric .col-sm-6 .row .col-sm-6:last-child,
.estadisticas-page .metric-header .col-sm-6 .row .col-sm-6:last-child {
  text-align: right;
}

.estadisticas-page .metric-divider {
  border-color: #e1e5eb;
  margin: 14px 0;
}

/* Mapa Leaflet dentro de card normalizada */
.estadisticas-page #map {
  height: 600px;
  width: 100%;
  border-radius: 6px;
  border: 1px solid #e1e5eb;
}

/* Select de capa alineado al cabezal de la card de mapas */
.estadisticas-page .layer-select {
  display: inline-block;
  width: auto;
  max-width: 280px;
}

/* Botón de descarga XLS: acción secundaria tipo "icon button"
   expandible — círculo quieto que on-hover crece a pill y revela
   el label. Jerarquía baja: no compite con primarios ni KPIs. */
.btn-xls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 8px;
  border-radius: 999px !important;
  border: 1px solid #e1e5eb !important;
  background: #fff !important;
  color: #818ea3 !important;
  font-size: 0.78rem !important;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: none !important;
  vertical-align: middle;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}

.btn-xls i {
  margin-right: 0;
  font-size: 13px;
  line-height: 1;
  color: #4a9e6b;
}

/* Label colapsado por defecto; se expande on-hover */
.btn-xls .xls-label {
  display: inline-block;
  max-width: 0;
  margin-left: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width .18s ease, opacity .18s ease, margin-left .18s ease;
}

.btn-xls:hover {
  color: #3d5170 !important;
  background: #f7f8fa !important;
  border-color: #cbd5e0 !important;
}

.btn-xls:hover .xls-label {
  max-width: 90px;
  margin-left: 6px;
  opacity: 1;
}

/* Dentro de .estadisticas-page la regla global .btn tiene
   !important y más especificidad: fuerzo el pill del btn-xls */
.estadisticas-page .btn-xls {
  padding: 0 8px !important;
  border-radius: 999px !important;
  font-size: 0.78rem !important;
}

.estadisticas-page .btn-xls i {
  margin-right: 0;
}

/* Barra de progreso: % legible siempre */
.estadisticas-page .metric-progress {
  height: 30px;
  margin-top: 10px;
  border-radius: 6px;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
}

.estadisticas-page .metric-progress .progress-bar {
  height: 100%;
  line-height: normal;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  min-width: 46px;
}

/* % "al día" pegado al inicio de la barra */
.estadisticas-page .metric-progress .progress-bar:first-child {
  text-align: left;
  padding-left: 12px;
}

/* % "deuda" ocupa el resto hasta el 100% y va pegado al final */
.estadisticas-page .metric-progress .progress-bar:last-child {
  flex-grow: 1;
  text-align: right;
  padding-right: 12px;
}

/* --- Pills de leyenda (comparación de escenarios) --- */
.estadisticas-page .comp-legend {
  padding-bottom: 4px;
}

.estadisticas-page .comp-legend-pill {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  user-select: none;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  margin-bottom: 4px;
}
