/* Pillan360 · panel meteorológico compacto y reactivación estable */
html,
body {
  width: 100%;
  height: 100%;
}

body {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}

#main-header {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
}

#app-shell {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow: hidden;
}

#app-sidebar {
  flex: 0 0 min(290px, 24vw);
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 0.25rem;
}

#app-main {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

#main-tabs {
  position: relative;
  z-index: 30;
  flex: 0 0 auto;
  margin-bottom: 0.75rem;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  box-shadow: 0 0.45rem 1.2rem rgb(2 6 23 / 0.16);
}

#app-main > section[role="tabpanel"] {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  align-content: start;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgb(15 23 42 / 0.08);
}

#app-main > section[role="tabpanel"].hide {
  display: none !important;
}

#tab-monitoreo,
#tab-tactical,
#tab-maps {
  height: auto !important;
  min-height: 0 !important;
}

#app-sidebar,
#app-main > section[role="tabpanel"] {
  scrollbar-color: rgb(71 85 105 / 0.85) transparent;
  scrollbar-width: thin;
}

#app-sidebar::-webkit-scrollbar,
#app-main > section[role="tabpanel"]::-webkit-scrollbar {
  width: 0.55rem;
}

#app-sidebar::-webkit-scrollbar-thumb,
#app-main > section[role="tabpanel"]::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgb(71 85 105 / 0.85);
  background-clip: padding-box;
}

#tab-now {
  container-name: realtime-tab;
  container-type: inline-size;
}

/* Las filas conservan la altura de su contenido y el excedente usa el scroll. */
#tab-now,
#tab-risk {
  grid-auto-flow: row;
  grid-auto-rows: max-content;
  align-content: start;
  align-items: start;
}

#tab-now > *,
#tab-risk > * {
  min-height: max-content;
  height: auto;
  align-self: start;
}

#current-weather-overview {
  min-height: 18rem !important;
  isolation: isolate;
}

/* Desde el ancho de escritorio el resumen ocupa exactamente 220 px. Los
   elementos centrales se compactan también en portátiles de 1024 px. */
@media (min-width: 1024px) {
  #current-weather-overview {
    height: 220px !important;
    min-height: 220px !important;
    padding: 1rem !important;
  }

  #current-weather-overview > .flex {
    height: 100%;
    gap: 1rem;
  }

  #current-weather-overview > .flex > div:first-child > .gap-2 {
    gap: 0.375rem;
  }

  #current-weather-overview > .flex > div:first-child > .gap-2 > div {
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
  }

  #current-weather-overview #now-icon {
    width: 5.75rem;
    height: 5.75rem;
    margin-bottom: 0;
  }

  #current-weather-overview #moon-phase-display {
    margin-top: 0.375rem;
  }

  #current-weather-overview > .flex > div:nth-child(2) > .flex:first-child {
    width: 100%;
    justify-content: center;
    min-width: 0;
  }

  #current-weather-overview #now-time {
    max-width: 100%;
    margin-bottom: 0.5rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #current-weather-overview #now-temp {
    font-size: 3.25rem;
    line-height: 1;
  }

  #current-weather-overview #now-desc {
    display: block;
    min-width: 0;
    max-width: 9rem;
    overflow: hidden;
    font-size: 0.85rem;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

#conaf-fire-context {
  min-height: 11rem !important;
  isolation: isolate;
}

#territorial-assessment-card {
  min-height: 14rem !important;
  isolation: isolate;
}

#realtime-trend-panel {
  container-name: realtime-trend-panel;
  container-type: inline-size;
}

#sinca-air-quality {
  container-name: sinca-panel;
  container-type: inline-size;
}

#tab-now #realtime-trend-panel,
#tab-now #sinca-air-quality,
#tab-now #institutional-comparison,
#tab-now .realtime-services-panel {
  align-self: start;
  position: relative;
  height: auto !important;
  min-height: max-content;
}

#realtime-trend-panel .realtime-chart-shell {
  height: 10.75rem;
  min-height: 10.75rem;
}

#realtime-trend-panel #realtime-trend-chart {
  height: 100%;
  min-height: 100%;
}

/* Los paneles de cada columna responden a su propio ancho, no al viewport. */
@container realtime-trend-panel (max-width: 34rem) {
  #realtime-trend-panel > div:first-child {
    flex-direction: column;
    align-items: stretch;
  }

  #realtime-trend-panel .realtime-trend-toolbar {
    width: 100%;
    align-items: stretch;
  }

  #realtime-trend-panel .realtime-trend-select {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  #realtime-trend-panel .realtime-trend-quality,
  #realtime-trend-panel .realtime-trend-direction {
    flex: 1 1 auto;
    justify-content: center;
  }

  #realtime-trend-panel .realtime-trend-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #realtime-trend-panel .realtime-trend-stat:last-child {
    grid-column: 1 / -1;
  }

  #realtime-trend-panel .realtime-trend-footer {
    flex-direction: column;
    gap: 0.25rem;
  }

  #realtime-trend-panel .realtime-trend-footer span:first-child {
    max-width: 100%;
  }
}

@container sinca-panel (max-width: 34rem) {
  #sinca-air-quality .official-context-header,
  #sinca-air-quality .official-context-strip {
    align-items: stretch;
    flex-direction: column;
  }

  #sinca-air-quality .official-context-action {
    width: 100%;
  }

  #sinca-air-quality .official-gas-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container sinca-panel (max-width: 20rem) {
  #sinca-air-quality .official-measure-grid,
  #sinca-air-quality .official-measure-pair,
  #sinca-air-quality .official-gas-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Riesgo debe responder al espacio real del panel después de descontar la barra lateral. */
#tab-risk {
  container-name: risk-tab;
  container-type: inline-size;
}

#tab-risk .risk-threats-grid,
#tab-risk .risk-exposure-pair {
  grid-template-columns: minmax(0, 1fr);
}

#tab-risk .territorial-metric-grid,
#tab-risk .risk-capacity-metric-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#tab-risk .risk-critical-status-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@container risk-tab (min-width: 34rem) {
  #tab-risk .risk-threats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container risk-tab (min-width: 56rem) {
  #tab-risk .territorial-metric-grid,
  #tab-risk .risk-capacity-metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #tab-risk .risk-critical-status-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@container risk-tab (min-width: 68rem) {
  #tab-risk .risk-threats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #tab-risk .risk-exposure-pair {
    grid-template-columns: minmax(0, 2fr) minmax(18rem, 1fr);
  }
}

@media (max-width: 1023px) {
  #app-shell {
    flex-direction: column;
  }

  #app-sidebar {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    max-height: min(28dvh, 15rem);
    padding-right: 0.2rem;
  }

  #app-main {
    width: 100%;
  }
}

@media (max-width: 767px) {
  #app-shell {
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }

  #app-sidebar {
    max-height: min(22dvh, 11rem);
  }

  #main-tabs {
    margin-bottom: 0.5rem;
  }

  #app-main > section[role="tabpanel"] {
    padding: 0.45rem;
    border-radius: 0.8rem;
  }

  #realtime-trend-panel .realtime-chart-shell {
    height: 9.75rem;
    min-height: 9.75rem;
  }
}

@media (max-height: 700px) {
  #app-shell {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
  }

  #app-sidebar {
    max-height: min(20dvh, 8.5rem);
  }
}

.light-mode #main-tabs {
  background: rgb(248 250 252 / 0.94);
}

.light-mode #app-main > section[role="tabpanel"] {
  background: rgb(248 250 252 / 0.3);
}
