:root {
  --bg: #07131b;
  --panel: #0d1e28;
  --panel-2: #102732;
  --border: rgba(255,255,255,.09);
  --text: #eef7fa;
  --muted: #93aab5;
  --accent: #4bd1a0;
  --accent-2: #53a7ff;
  --warn: #ffc857;
  --danger: #ff6b6b;
  --shadow: 0 20px 45px rgba(0,0,0,.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(
      circle at top right,
      rgba(37,102,122,.22),
      transparent 28rem
    ),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body {
  min-width: 320px;
}

.topbar {
  min-height: 86px;
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(7,19,27,.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  background:
    linear-gradient(
      135deg,
      var(--accent),
      var(--accent-2)
    );
  color: #041014;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: .08em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.source-status {
  display: flex;
  gap: 14px;
  align-items: center;
}

.status-badge {
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(75,209,160,.12);
  border: 1px solid rgba(75,209,160,.35);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.source-version {
  color: var(--muted);
  font-size: 12px;
}

.source-version strong {
  color: var(--text);
}

main {
  width: min(1500px, calc(100% - 40px));
  margin: 24px auto 48px;
}

.filter-panel {
  display: grid;
  grid-template-columns:
    repeat(5, minmax(145px, 1fr));
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(13,30,40,.82);
  box-shadow: var(--shadow);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.filter-group label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

select {
  width: 100%;
  min-height: 43px;
  padding: 0 12px;
  background: #091820;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  font: inherit;
  outline: none;
}

select:focus {
  border-color: rgba(75,209,160,.55);
}

.scope-line {
  display: flex;
  align-items: end;
  justify-content: space-between;
  padding: 22px 4px 10px;
}

.scope-line strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

#coverageText {
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
}

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

.kpi-card {
  min-height: 140px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background:
    linear-gradient(
      180deg,
      rgba(16,39,50,.96),
      rgba(10,25,34,.96)
    );
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.kpi-value {
  margin-top: 16px;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1;
}

.kpi-site {
  margin-top: auto;
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-grid {
  display: grid;
  grid-template-columns:
    minmax(0, 2fr)
    minmax(330px, .9fr);
  gap: 14px;
  margin-top: 14px;
}

.secondary-grid {
  display: grid;
  grid-template-columns:
    1.35fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(13,30,40,.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  padding: 17px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 4px 0 0;
  font-size: 17px;
}

.map-wrap {
  min-height: 500px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(
      circle at center,
      #11323d,
      #091820
    );
}

#weatherMap {
  display: block;
  width: 100%;
  height: 500px;
}

.map-boundary {
  fill: rgba(75,209,160,.055);
  stroke: rgba(150,200,205,.7);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.map-point {
  cursor: pointer;
  stroke: rgba(255,255,255,.82);
  stroke-width: .7;
  vector-effect: non-scaling-stroke;
  transition:
    r .12s ease,
    opacity .12s ease;
}

.map-point:hover {
  opacity: 1;
}

.map-footnote {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

.map-legend {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.map-tooltip {
  position: absolute;
  pointer-events: none;
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(4,15,21,.96);
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  font-size: 12px;
  z-index: 4;
}

.map-tooltip strong {
  display: block;
  margin-bottom: 5px;
}

.hidden {
  display: none !important;
}

.table-wrap {
  overflow: auto;
  max-height: 500px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--panel);
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: rgba(255,255,255,.035);
}

td:last-child,
th:last-child {
  text-align: right;
}

.mini-stat-grid {
  padding: 18px;
  display: grid;
  grid-template-columns:
    repeat(4, 1fr);
  gap: 12px;
}

.mini-stat {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.025);
}

.mini-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.mini-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

.quality-panel {
  min-height: 170px;
}

#qualityContent {
  padding: 18px;
  display: grid;
  gap: 10px;
}

.quality-row {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.025);
  color: var(--muted);
  font-size: 12px;
}

.quality-row strong {
  color: var(--text);
}

.quality-warning {
  border-left: 3px solid var(--warn);
}

.site-detail {
  margin-top: 14px;
}

.site-detail-body {
  padding: 18px;
}

.site-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.site-meta span {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-size: 11px;
}

.site-day-grid {
  display: grid;
  grid-template-columns:
    repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.site-day {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.025);
}

.site-day h3 {
  margin: 0 0 12px;
  font-size: 14px;
}

.site-day dl {
  margin: 0;
  display: grid;
  grid-template-columns:
    1fr auto;
  gap: 7px 12px;
  font-size: 12px;
}

.site-day dt {
  color: var(--muted);
}

.site-day dd {
  margin: 0;
}

.close-button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor: pointer;
}

footer {
  min-height: 68px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 1050px) {
  .filter-panel {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .content-grid,
  .secondary-grid {
    grid-template-columns: 1fr;
  }

  .site-day-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 650px) {
  .topbar {
    padding: 14px 16px;
    align-items: flex-start;
    gap: 14px;
  }

  .source-status {
    flex-direction: column;
    align-items: end;
    gap: 5px;
  }

  main {
    width: min(100% - 20px, 1500px);
  }

  .filter-panel,
  .kpi-grid,
  .mini-stat-grid {
    grid-template-columns: 1fr;
  }

  .scope-line {
    align-items: flex-start;
    gap: 8px;
    flex-direction: column;
  }

  .map-wrap,
  #weatherMap {
    height: 400px;
    min-height: 400px;
  }
}


/* ==========================================================
   KC METEO — LEAFLET
   ========================================================== */

#weatherMap {
  width: 100%;
  height: 500px;
  min-height: 500px;
  background: #091820;
  z-index: 1;
}

.leaflet-container {
  font-family:
    Inter,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  background: #091820;
}

.leaflet-control-zoom a {
  background: rgba(8, 24, 32, .94) !important;
  color: #eef7fa !important;
  border-color: rgba(255,255,255,.12) !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(75,209,160,.18) !important;
}

.leaflet-control-attribution {
  background: rgba(4,15,21,.78) !important;
  color: #93aab5 !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a {
  color: #6fd9b1 !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #0d1e28;
  color: #eef7fa;
}

.leaflet-popup-content {
  margin: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
}

.leaflet-tooltip {
  background: rgba(4,15,21,.96);
  color: #eef7fa;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,.28);
}

.leaflet-tooltip-top:before {
  border-top-color: rgba(4,15,21,.96);
}



/* ================================================================
   KC METEO — T4B2 SINGLE SCREEN
   Dashboard operacional de escritorio
   ================================================================ */

@media (min-width: 1051px) {

  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden !important;
  }

  body {
    display: grid;
    grid-template-rows: 58px minmax(0, 1fr);
  }

  /* CABECERA */

  .topbar {
    position: relative;
    top: auto;

    height: 58px;
    min-height: 58px;

    padding: 7px 22px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    font-size: 14px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    margin-top: 1px;
    font-size: 10px;
  }

  .source-status {
    gap: 10px;
  }

  .status-badge {
    padding: 5px 9px;
    font-size: 10px;
  }

  .source-version {
    font-size: 10px;
  }


  /* CONTENEDOR PRINCIPAL */

  main {
    width: min(1500px, calc(100% - 24px));
    height: 100%;
    min-height: 0;

    margin: 0 auto;
    padding: 7px 0;

    display: grid;

    grid-template-rows:
      51px
      25px
      80px
      minmax(0, 1fr)
      84px;

    gap: 6px;

    overflow: hidden;
  }


  /* FILTROS */

  .filter-panel {
    height: 51px;
    min-height: 0;

    padding: 5px 8px;

    grid-template-columns:
      repeat(5, minmax(120px, 1fr));

    gap: 7px;

    border-radius: 10px;
    box-shadow: none;
  }

  .filter-group {
    min-width: 0;
    gap: 2px;
  }

  .filter-group label {
    font-size: 8px;
  }

  select {
    height: 30px;
    min-height: 30px;

    padding: 0 8px;

    border-radius: 6px;

    font-size: 11px;
  }


  /* CONTEXTO ACTUAL */

  .scope-line {
    height: 25px;
    min-height: 0;

    padding: 0 4px;

    align-items: center;
  }

  .scope-line .eyebrow {
    display: none;
  }

  .scope-line strong {
    margin: 0;
    font-size: 15px;
  }

  #coverageText {
    font-size: 9px;
  }


  /* KPI */

  .kpi-grid {
    height: 80px;
    min-height: 0;

    gap: 6px;
  }

  .kpi-card {
    height: 80px;
    min-height: 0;

    padding: 8px 11px;

    border-radius: 10px;
    box-shadow: none;
  }

  .kpi-label {
    font-size: 8px;
  }

  .kpi-value {
    margin-top: 5px;

    font-size: clamp(
      22px,
      1.8vw,
      29px
    );

    line-height: 1;
  }

  .kpi-site {
    padding-top: 4px;
    font-size: 9px;
  }


  /* MAPA + RANKING */

  .content-grid {
    min-height: 0;
    height: 100%;

    margin: 0;

    display: grid;

    grid-template-columns:
      minmax(0, 2.35fr)
      minmax(300px, .95fr);

    gap: 6px;

    overflow: hidden;
  }

  .content-grid > .panel {
    min-height: 0;
    height: 100%;

    border-radius: 10px;

    box-shadow: none;
    overflow: hidden;
  }


  /* MAPA */

  .map-panel {
    display: grid;

    grid-template-rows:
      42px
      minmax(0, 1fr)
      18px;
  }

  .map-panel .panel-header {
    height: 42px;

    padding: 5px 11px;
  }

  .map-panel .panel-header h2 {
    margin-top: 1px;
    font-size: 13px;
  }

  .eyebrow {
    font-size: 7px;
  }

  .map-legend {
    font-size: 8px;
  }

  .map-wrap {
    width: 100%;
    height: 100%;
    min-height: 0 !important;

    overflow: hidden;
  }

  #weatherMap {
    width: 100%;
    height: 100% !important;
    min-height: 0 !important;
  }

  .map-footnote {
    height: 18px;

    padding: 3px 9px;

    font-size: 7px;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }


  /* RANKING */

  .ranking-panel {
    display: grid;

    grid-template-rows:
      42px
      minmax(0, 1fr);
  }

  .ranking-panel .panel-header {
    height: 42px;

    padding: 5px 11px;
  }

  .ranking-panel .panel-header h2 {
    margin-top: 1px;
    font-size: 13px;
  }

  .table-wrap {
    width: 100%;
    height: 100%;
    max-height: none;

    overflow-y: auto;
    overflow-x: hidden;
  }

  table {
    font-size: 9px;
  }

  th,
  td {
    padding: 6px 8px;
  }


  /* BANDA INFERIOR */

  .secondary-grid {
    height: 84px;
    min-height: 0;

    margin: 0;

    grid-template-columns:
      1.25fr
      1fr;

    gap: 6px;
  }

  .secondary-grid > .panel {
    height: 84px;
    min-height: 0;

    display: grid;

    grid-template-rows:
      26px
      minmax(0, 1fr);

    border-radius: 10px;

    box-shadow: none;
    overflow: hidden;
  }

  .secondary-grid .panel-header {
    height: 26px;

    padding: 3px 9px;
  }

  .secondary-grid .panel-header .eyebrow {
    display: none;
  }

  .secondary-grid .panel-header h2 {
    margin: 0;
    font-size: 11px;
  }


  /* ESTADÍSTICAS */

  .mini-stat-grid {
    height: 100%;

    padding: 4px 6px;

    grid-template-columns:
      repeat(4, 1fr);

    gap: 4px;
  }

  .mini-stat {
    min-height: 0;

    padding: 4px 7px;

    border-radius: 6px;
  }

  .mini-stat span {
    font-size: 7px;
  }

  .mini-stat strong {
    margin-top: 2px;

    font-size: 14px;
  }


  /* CALIDAD */

  #qualityContent {
    height: 100%;

    padding: 4px 6px;

    display: grid;

    grid-template-columns:
      repeat(2, minmax(0, 1fr));

    grid-template-rows:
      repeat(2, minmax(0, 1fr));

    gap: 3px;

    overflow: hidden;
  }

  .quality-row {
    min-width: 0;
    min-height: 0;

    padding: 3px 6px;

    border-radius: 5px;

    font-size: 7px;
    line-height: 1.2;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }


  /* DETALLE DE SITIO COMO MODAL */

  .site-detail:not(.hidden) {
    position: fixed;

    inset:
      70px
      28px
      24px
      28px;

    margin: 0;

    z-index: 10000;

    overflow-y: auto;

    background:
      rgba(13,30,40,.99);

    box-shadow:
      0 30px 90px rgba(0,0,0,.7);
  }


  /* FOOTER NO CONSUME ALTURA */

  footer {
    display: none !important;
  }

}


/* TABLET / MÓVIL conserva scroll */
@media (max-width: 1050px) {

  html,
  body {
    height: auto;
    overflow: auto;
  }

}
