/* =====================================================
   CUIDA VÍNCULO - DASHBOARD
   Se carga después de apple.css.
   Marcas finas, grid recesivo, una cifra principal,
   colores de estado siempre con icono + texto.
===================================================== */

.dash {
  --surface: #ffffff;

  --ink-1: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #86868b;

  --grid: #ececf0;
  --axis: #d2d2d7;

  --series-1: #0071e3;   /* Registradas */
  --series-2: #eb6834;   /* Atendidas */
  --gap-wash: rgba(0, 113, 227, .08);
  --spark: #c7c7cc;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-text: #1d7a1d;
  --bad-text: #c4262e;

  max-width: 1280px;

  padding-top: 30px !important;
}


/* =====================================================
   ENCABEZADO
===================================================== */

.dash-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;

  margin-bottom: 22px;
}

.dash-date {
  display: block;

  margin-bottom: 4px;

  color: var(--ink-2);

  font-size: 13px;
  font-weight: 600;
}

.dash-head h1 {
  color: var(--ink-1);

  font-size: 34px;
  line-height: 1.1;
}

.dash-head p {
  margin-top: 6px;

  color: var(--ink-2);

  font-size: 15px;
}

.dash-head-actions {
  display: flex;
  gap: 10px;

  flex-shrink: 0;
}

.dash-primary,
.dash-secondary {
  height: 36px;

  display: inline-flex;
  align-items: center;
  gap: 7px;

  padding: 0 16px;

  font-size: 13.5px !important;

  cursor: pointer;
}

.dash-primary i,
.dash-secondary i {
  font-size: 12px;
}


/* =====================================================
   FILTRO DE PERIODO
===================================================== */

.dash-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;

  margin-bottom: 20px;
}

.dash-scope {
  color: var(--ink-2);
  font-size: 13px;
}


/* Control segmentado estilo Apple */

.segmented {
  display: inline-flex;

  padding: 2px;

  border-radius: 9px;

  background: rgba(118, 118, 128, .12);
}

.segmented button {
  height: 28px;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 0 14px;

  border-radius: 7px;

  color: var(--ink-1);
  background: transparent;

  font-size: 13px;
  font-weight: 500;

  cursor: pointer;
}

.segmented button:hover:not([aria-pressed="true"]) {
  background: rgba(0, 0, 0, .04);
}

.segmented button[aria-pressed="true"] {
  background: white;

  box-shadow:
    0 3px 8px rgba(0, 0, 0, .12),
    0 3px 1px rgba(0, 0, 0, .04);

  font-weight: 600;
}

.segmented.small button {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
}

.segmented.small i {
  font-size: 11px;
  color: var(--ink-2);
}


/* =====================================================
   TARJETAS
===================================================== */

.dash-card {
  position: relative;

  padding: 20px 22px;

  border: 1px solid rgba(0, 0, 0, .06);
  border-radius: 18px;

  background: var(--surface);
}

.main .dash-card:hover {
  box-shadow: var(--shadow-sm) !important;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;

  margin-bottom: 14px;
}

.card-top h2 {
  color: var(--ink-1);
  font-size: 17px;
  line-height: 1.25;
}

.card-top p {
  margin-top: 3px;

  color: var(--ink-2);
  font-size: 13px;
}


/* =====================================================
   FILA SUPERIOR
===================================================== */

.dash-top {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 2fr;
  gap: 16px;

  margin-bottom: 16px;
}

.tile-label {
  color: var(--ink-2);

  font-size: 13px;
  font-weight: 500;
}


/* Cifra principal */

.hero-tile {
  display: flex;
  flex-direction: column;

  padding: 22px 24px;
}

.hero-value-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;

  margin-top: 6px;
}

.hero-value {
  color: var(--ink-1);

  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.035em;
}

.meter {
  position: relative;

  height: 8px;

  margin: 20px 0 10px;

  border-radius: 999px;

  background: rgba(0, 113, 227, .14);
}

.meter-fill {
  height: 100%;

  border-radius: 999px;

  background: var(--series-1);

  transition: width .6s cubic-bezier(.25, .1, .25, 1);
}

.meter-goal {
  position: absolute;
  top: -4px;

  width: 2px;
  height: 16px;

  border-radius: 1px;

  background: var(--ink-1);
}

.meter-goal span {
  position: absolute;
  top: 20px;
  left: 50%;

  transform: translateX(-50%);

  color: var(--ink-2);

  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.hero-caption {
  margin-top: 26px;

  color: var(--ink-2);

  font-size: 13px;
  line-height: 1.45;
}

.hero-caption strong {
  color: var(--ink-1);
  font-weight: 600;
}

.hero-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;

  margin-top: auto;
  padding-top: 18px;

  border-top: 1px solid var(--grid);
}

.hero-tile .hero-facts {
  margin-top: 18px;
}

.hero-facts div + div {
  padding-left: 16px;
  border-left: 1px solid var(--grid);
}

.hero-facts strong {
  display: block;

  color: var(--ink-1);

  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.hero-facts span {
  color: var(--ink-2);
  font-size: 12px;
}


/* Delta: dirección × si subir es bueno, siempre con flecha */

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;

  color: var(--ink-2);

  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.delta i {
  font-size: 10px;
}

.delta.good {
  color: var(--good-text);
}

.delta.bad {
  color: var(--bad-text);
}

.delta small {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 500;
}


/* Stat tiles */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.stat-tile {
  display: flex;
  flex-direction: column;

  padding: 18px 20px 14px;
}

.stat-value {
  margin-top: 4px;

  color: var(--ink-1);

  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -.025em;
}

.stat-value small {
  margin-left: 2px;

  color: var(--ink-2);

  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0;
}

.stat-tile .delta {
  margin-top: 4px;
  font-size: 12.5px;
}

.spark {
  display: block;

  width: 100%;
  height: 40px;

  margin-top: 10px;

  overflow: visible;

  cursor: crosshair;
}


/* =====================================================
   GRID DE TARJETAS
===================================================== */

.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr);
  gap: 16px;

  margin-bottom: 16px;
}

.map-row {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
}


/* =====================================================
   TENDENCIA
===================================================== */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;

  margin-bottom: 8px;

  list-style: none;

  color: var(--ink-2);

  font-size: 12.5px;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.key-line {
  width: 14px;
  height: 2px;

  border-radius: 2px;
}

.key-line.s1 {
  background: var(--series-1);
}

.key-line.s2 {
  background: var(--series-2);
}

.key-area {
  width: 14px;
  height: 10px;

  border-radius: 3px;

  background: rgba(0, 113, 227, .16);
}

.trend-chart {
  position: relative;

  height: 300px;
}

.trend-chart.loading {
  opacity: .5;
}

.trend-table {
  max-height: 300px;

  overflow: auto;
}


/* Tablas */

.dash table {
  width: 100%;

  border-collapse: collapse;

  font-size: 13px;
}

.dash th {
  position: sticky;
  top: 0;

  padding: 8px 10px;

  background: var(--surface);

  border-bottom: 1px solid var(--axis);

  text-align: left;
}

.dash td {
  padding: 10px;

  border-bottom: 1px solid var(--grid);

  color: var(--ink-1);

  font-variant-numeric: tabular-nums;
}

.dash tr:last-child td {
  border-bottom: 0;
}

.trend-table th:not(:first-child),
.trend-table td:not(:first-child),
.dash .num {
  text-align: right;
}


/* =====================================================
   BARRAS POR TIPO
===================================================== */

.bar-list {
  display: grid;
  gap: 4px;

  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;

  padding: 9px 8px;

  border-radius: 10px;

  outline: none;
}

.bar-row:hover,
.bar-row:focus-visible {
  background: rgba(0, 0, 0, .035);
}

.bar-row:focus-visible {
  box-shadow: 0 0 0 3px rgba(0, 113, 227, .35);
}

.bar-icon {
  grid-row: span 2;

  width: 30px;
  height: 30px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 8px;

  color: var(--ink-2);
  background: rgba(118, 118, 128, .1);

  font-size: 13px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;

  color: var(--ink-1);

  font-size: 13px;
  font-weight: 500;
}

.bar-label span {
  color: var(--ink-2);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  position: relative;

  height: 10px;

  margin-top: 7px;

  border-left: 1px solid var(--axis);
}

.bar-fill {
  height: 100%;

  border-radius: 0 4px 4px 0;

  background: var(--series-1);

  transition: width .5s cubic-bezier(.25, .1, .25, 1), filter .15s;
}

.bar-row:hover .bar-fill,
.bar-row:focus-visible .bar-fill {
  filter: brightness(1.12);
}


/* =====================================================
   MAPA
===================================================== */

.dash .map-card {
  min-height: 0;
}

.dash .care-map {
  width: 100%;
  height: 340px;

  margin: 0;

  border: 1px solid rgba(0, 0, 0, .06);
  border-radius: 14px !important;

  background: #f2f2f4;
  box-shadow: none;
}

.status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;

  margin-top: 14px;

  list-style: none;

  color: var(--ink-2);

  font-size: 12.5px;
}

.status-legend li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.status-dot {
  width: 18px;
  height: 18px;

  flex: 0 0 auto;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  border-radius: 50%;

  color: white;

  font-size: 10px;
}

.status-dot.critical { background: var(--critical); }
.status-dot.warning  { background: var(--warning); color: #1d1d1f; }
.status-dot.good     { background: var(--good); }


/* Popup del mapa */

.dash .leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
}

.dash .leaflet-popup-content {
  margin: 12px 14px;
}

.zone-pop strong {
  display: block;

  color: var(--ink-1);

  font-size: 14px;
  font-weight: 600;
}

.zone-pop .pop-value {
  margin-top: 6px;

  color: var(--ink-1);

  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.zone-pop .pop-meta {
  margin-top: 2px;

  color: var(--ink-2);

  font-size: 12px;
}

.zone-pop .status-pill {
  margin-top: 8px;
}


/* =====================================================
   TABLA DE ALCALDÍAS
===================================================== */

.zones-table tbody tr {
  cursor: pointer;
}

.zones-table tbody tr:focus-visible {
  outline: none;
  background: rgba(0, 113, 227, .06) !important;
}

.zones-table tbody tr.selected {
  background: rgba(0, 113, 227, .06) !important;
}

.zones-table td:first-child {
  font-weight: 500;
}

.mini-meter {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-meter > span:first-child {
  width: 54px;
  height: 6px;

  flex: 0 0 auto;

  overflow: hidden;

  border-radius: 999px;

  background: rgba(118, 118, 128, .14);
}

.mini-meter i {
  display: block;

  height: 100%;

  border-radius: 999px;
}

.mini-meter b {
  min-width: 34px;

  color: var(--ink-1);

  font-weight: 500;
  text-align: right;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;

  color: var(--ink-1);

  font-size: 12.5px;
  white-space: nowrap;
}

.status-pill .status-dot {
  width: 16px;
  height: 16px;

  font-size: 8px;
}


/* =====================================================
   TOOLTIP COMPARTIDO
===================================================== */

.viz-tooltip {
  position: fixed;
  z-index: 10000;

  min-width: 140px;

  padding: 10px 12px;

  border: 1px solid rgba(0, 0, 0, .06);
  border-radius: 12px;

  background: rgba(255, 255, 255, .92);

  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);

  box-shadow:
    0 10px 30px rgba(0, 0, 0, .12),
    0 1px 3px rgba(0, 0, 0, .06);

  font-size: 12px;

  pointer-events: none;

  opacity: 0;

  transform: translateY(4px);

  transition: opacity .12s, transform .12s;
}

.viz-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.tt-title {
  margin-bottom: 6px;

  color: var(--ink-2, #6e6e73);

  font-size: 12px;
  font-weight: 500;
}

.tt-row {
  display: grid;
  grid-template-columns: 12px auto 1fr;
  align-items: center;
  gap: 7px;

  padding: 2px 0;
}

.tt-row i {
  width: 12px;
  height: 2px;

  border-radius: 2px;
}

.tt-row strong {
  color: #1d1d1f;

  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tt-row span {
  color: #6e6e73;
}


/* =====================================================
   RESPONSIVE
===================================================== */

@media (max-width: 1180px) {

  .dash-top,
  .dash-grid,
  .map-row {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 700px) {

  .dash-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .dash-head h1 {
    font-size: 28px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .hero-value {
    font-size: 48px;
  }

  .segmented.small span {
    display: none;
  }

  .dash .care-map {
    height: 280px;
  }

  .zones-table th:nth-child(2),
  .zones-table td:nth-child(2) {
    display: none;
  }

}

@media (prefers-reduced-motion: reduce) {

  .meter-fill,
  .bar-fill,
  .viz-tooltip {
    transition: none;
  }

}


/* Mapa base en tonos suaves: el color lo llevan los marcadores */

.dash .leaflet-tile-pane {
  filter: saturate(.25) brightness(1.05) contrast(.92);
}
.dash .leaflet-control-attribution { font-size: 10px !important; }

.dash [hidden] {
  display: none !important;
}

/* Cambio inmediato, como el control segmentado de macOS */

.main .segmented button {
  transition: none !important;
}


/* =====================================================
   SECCIONES: CONTEXTO REAL / OPERACIÓN
===================================================== */

.dash-section {
  margin-bottom: 36px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;

  margin-bottom: 14px;
}

.section-head h2 {
  color: var(--ink-1);

  font-size: 22px !important;
  line-height: 1.2;
}

.section-head p {
  margin-top: 4px;

  color: var(--ink-2);

  font-size: 13.5px;
}

.operations-head {
  padding-top: 28px;

  border-top: 1px solid rgba(0, 0, 0, .08);
}

.source-chip,
.sample-chip {
  flex: 0 0 auto;

  display: inline-flex;
  align-items: center;
  gap: 7px;

  height: 28px;
  padding: 0 12px;

  border-radius: 999px;

  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.source-chip {
  color: var(--good-text);
  background: rgba(52, 199, 89, .12);
}

.sample-chip {
  color: #8a5a00;
  background: rgba(255, 159, 10, .14);

  cursor: help;
}


/* Tarjetas de contexto */

.context-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;

  margin-bottom: 16px;
}

.context-grid[aria-busy="true"] {
  min-height: 132px;
}

.context-tile {
  padding: 18px 20px;
}

.context-icon {
  width: 30px;
  height: 30px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  margin-bottom: 12px;

  border-radius: 8px;

  color: var(--series-1);
  background: rgba(0, 113, 227, .1);

  font-size: 13px;
}

.context-note {
  margin-top: 4px;

  color: var(--ink-2);

  font-size: 12.5px;
}

.context-error {
  display: flex;
  align-items: center;
  gap: 10px;

  padding: 16px 18px;

  border-radius: 14px;

  color: var(--bad-text);
  background: rgba(255, 59, 48, .08);

  font-size: 13.5px;
  font-weight: 500;
}


/* Leyenda de rampa secuencial */

.ramp-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;

  margin-top: 14px;

  color: var(--ink-2);

  font-size: 12px;
}

.ramp-title {
  font-weight: 500;
}

.ramp-steps {
  display: flex;
  gap: 2px;

  list-style: none;
}

.ramp-steps li {
  display: flex;
  flex-direction: column;
  gap: 4px;

  min-width: 62px;
}

.ramp-steps i {
  height: 10px;
  border-radius: 2px;
}

.ramp-steps li:first-child i {
  border-radius: 4px 2px 2px 4px;
}

.ramp-steps li:last-child i {
  border-radius: 2px 4px 4px 2px;
}

.ramp-steps span {
  color: var(--ink-2);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}


/* Tabla con scroll propio (16 filas) */

.zones-card {
  display: flex;
  flex-direction: column;
}

.zones-scroll {
  flex: 1;

  max-height: 412px;

  overflow: auto;
}

.zones-table .mini-meter > span:first-child {
  width: 64px;
}

.data-source-label {
  display: inline-block;

  margin-left: 6px;

  padding: 1px 8px;

  border-radius: 20px;

  background: rgba(28, 92, 171, .08);

  color: var(--series-1);

  font-size: 11px;
  font-weight: 500;

  vertical-align: middle;
}

.data-source-label:empty {
  display: none;
}

.data-note {
  margin-top: 12px;

  color: var(--ink-3);

  font-size: 12px;
  line-height: 1.5;
}

.data-note a {
  color: var(--series-1);
  font-weight: 500;
}

@media (max-width: 1180px) {

  .context-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .zones-scroll {
    max-height: none;
  }

}

@media (max-width: 700px) {

  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .context-grid {
    grid-template-columns: 1fr;
  }

  .zones-table th:nth-child(2),
  .zones-table td:nth-child(2) {
    display: table-cell;
  }

  .zones-table th:nth-child(3),
  .zones-table td:nth-child(3) {
    display: none;
  }

}

.card-top {
  flex-wrap: wrap;
}

.segmented button,
.dash th {
  white-space: nowrap;
}
