/* ==========================================================
   KC METEO — MOBILE RESPONSIVE v1
   Cargado al final para no alterar escritorio.
   ========================================================== */

@media (max-width: 720px) {

  html,
  body {
    width: 100% !important;
    max-width: 100% !important;

    min-width: 0 !important;

    height: auto !important;

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


  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }


  img,
  svg,
  canvas {
    max-width: 100%;
  }


  /* --------------------------------------------------------
     CABECERA
     -------------------------------------------------------- */

  .topbar,
  .console-topbar {
    width: 100% !important;

    height: auto !important;
    min-height: 0 !important;

    padding: 8px 10px !important;

    gap: 8px !important;

    flex-wrap: wrap !important;

    overflow: visible !important;
  }


  .brand {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }


  .brand h1 {
    font-size: 15px !important;
    line-height: 1.15 !important;
  }


  .brand p {
    font-size: 9px !important;
    line-height: 1.2 !important;
  }


  .source-status {
    max-width: 100% !important;

    align-items: flex-end !important;

    font-size: 9px !important;
  }


  .source-version {
    display: none !important;
  }


  /* --------------------------------------------------------
     CONTENEDOR PRINCIPAL
     -------------------------------------------------------- */

  main,
  .console-shell,
  .console-v2 .console-shell {
    width: 100% !important;
    max-width: 100% !important;

    min-width: 0 !important;

    margin: 0 !important;

    overflow: visible !important;
  }


  body.console-v2 {
    width: 100% !important;

    min-width: 0 !important;

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


  /* --------------------------------------------------------
     FILTROS
     -------------------------------------------------------- */

  .console-toolbar {
    width: 100% !important;

    height: auto !important;

    padding: 8px !important;

    display: block !important;

    overflow: visible !important;
  }


  .primary-filters,
  .filter-panel {
    width: 100% !important;

    grid-template-columns:
      minmax(0, 1fr) !important;

    gap: 6px !important;
  }


  select,
  button,
  input {
    max-width: 100%;
  }


  .primary-filters select,
  .filter-panel select {
    width: 100% !important;
    min-width: 0 !important;
  }


  /* --------------------------------------------------------
     CUERPO OPERACIONAL
     -------------------------------------------------------- */

  .ops-grid {
    width: 100% !important;

    grid-template-columns:
      minmax(0, 1fr) !important;

    overflow: visible !important;
  }


  /* --------------------------------------------------------
     MAPA
     -------------------------------------------------------- */

  .map-console {
    width: 100% !important;

    height:
      clamp(
        480px,
        72svh,
        650px
      )
      !important;

    min-height: 480px !important;

    grid-template-rows:
      40px
      minmax(0, 1fr)
      88px
      !important;

    overflow: hidden !important;
  }


  .map-wrap,
  #weatherMap,
  body.windy-ui #weatherMap {
    width: 100% !important;
    max-width: 100% !important;

    min-width: 0 !important;
  }


  body.windy-ui #weatherMap {
    inset: 0 !important;
  }


  /* --------------------------------------------------------
     KPIs SOBRE EL MAPA
     -------------------------------------------------------- */

  .map-kpis {
    left: 52px !important;
    right: 6px !important;

    width: auto !important;

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

    gap: 4px !important;
  }


  /* --------------------------------------------------------
     HERRAMIENTAS METEOROLÓGICAS
     -------------------------------------------------------- */

  .windy-controls {
    left: 8px !important;
    right: 8px !important;

    width: auto !important;

    max-width:
      calc(
        100vw - 16px
      )
      !important;

    overflow-x: auto !important;
    overflow-y: hidden !important;

    scrollbar-width: thin;
  }


  .windy-control {
    min-width: 112px !important;

    flex: 0 0 auto !important;
  }


  .windy-secondary-tools {
    right: 8px !important;
  }


  .windy-layer-stack {
    right: 8px !important;
    top: 70px !important;
  }


  .wx-tool,
  .windy-tool-secondary {
    width: 44px !important;
    min-width: 44px !important;
  }


  .weather-tools {
    top: 120px !important;
  }


  /* --------------------------------------------------------
     TIMELINE
     -------------------------------------------------------- */

  .windy-timeline {
    left: 8px !important;
    right: 8px !important;

    width: auto !important;

    bottom: 8px !important;

    height: 86px !important;

    max-width:
      calc(
        100vw - 16px
      )
      !important;

    overflow: hidden !important;
  }


  .timeline-content {
    min-width: 0 !important;

    overflow-x: auto !important;
    overflow-y: hidden !important;

    -webkit-overflow-scrolling: touch;
  }


  .timeline-days,
  .timeline-track {
    min-width: max-content;
  }


  /* --------------------------------------------------------
     PICKER / DRAWER
     -------------------------------------------------------- */

  .windy-picker,
  .windy-drawer {
    left: 8px !important;
    right: 8px !important;

    width:
      calc(
        100vw - 16px
      )
      !important;

    max-width:
      calc(
        100vw - 16px
      )
      !important;
  }


  .windy-picker {
    bottom: 108px !important;
  }


  .windy-drawer {
    bottom: 104px !important;

    max-height: 60svh !important;

    overflow-y: auto !important;
  }


  /* --------------------------------------------------------
     LEYENDA
     -------------------------------------------------------- */

  .weather-field-legend,
  .kc-weather-field-legend {
    right: 8px !important;

    width:
      min(
        210px,
        calc(
          100vw - 24px
        )
      )
      !important;

    max-width:
      calc(
        100vw - 24px
      )
      !important;
  }


  /* --------------------------------------------------------
     PANEL ANALÍTICO
     Se mantiene como drawer móvil.
     -------------------------------------------------------- */

  .kc-analytics-panel {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;

    width: 94vw !important;
    max-width: 420px !important;

    height: 100dvh !important;
    max-height: 100dvh !important;

    overflow-y: auto !important;

    transform:
      translateX(101%);
  }


  body.kc-analysis-mobile-open
  .kc-analytics-panel {
    transform:
      translateX(0) !important;
  }


  body:not(.kc-analysis-collapsed)
  .windy-secondary-tools,

  body:not(.kc-analysis-collapsed)
  .windy-layer-stack,

  body:not(.kc-analysis-collapsed)
  .windy-flyout,

  body:not(.kc-analysis-collapsed)
  .windy-picker,

  body:not(.kc-analysis-collapsed)
  .kc-weather-field-legend {
    right: 8px !important;
  }


  /* --------------------------------------------------------
     PANELES BAJO EL MAPA
     -------------------------------------------------------- */

  .side-rail {
    width: 100% !important;

    min-width: 0 !important;
    min-height: 0 !important;

    display: block !important;

    overflow: visible !important;
  }


  .rail-panel {
    width: 100% !important;

    min-width: 0 !important;
    min-height: 0 !important;

    height: auto !important;

    margin-bottom: 8px !important;
  }


  .kpi-grid,
  .secondary-grid,
  .site-day-grid,
  .mini-stat-grid {
    grid-template-columns:
      minmax(0, 1fr) !important;
  }


  /* --------------------------------------------------------
     LEAFLET
     -------------------------------------------------------- */

  .leaflet-control-attribution {
    max-width: 65vw !important;

    white-space: normal !important;

    font-size: 7px !important;
    line-height: 1.15 !important;
  }


  .leaflet-control-scale {
    margin-bottom: 102px !important;
  }


  .leaflet-control-attribution {
    margin-bottom: 96px !important;
  }


  /* --------------------------------------------------------
     FOOTER
     -------------------------------------------------------- */

  footer {
    width: 100% !important;

    min-height: 0 !important;

    padding: 12px !important;

    gap: 8px !important;

    flex-direction: column !important;

    align-items: flex-start !important;
  }
}


/* ==========================================================
   TELÉFONOS MUY ESTRECHOS
   ========================================================== */

@media (max-width: 390px) {

  .map-console {
    height:
      clamp(
        460px,
        70svh,
        590px
      )
      !important;

    min-height: 460px !important;
  }


  .map-kpis {
    left: 48px !important;

    grid-template-columns:
      minmax(0, 1fr)
      !important;
  }


  .windy-control {
    min-width: 104px !important;
  }


  .kc-analytics-panel {
    width: 96vw !important;
  }

}


/* ==========================================================
   KC METEO — MOBILE MAP + METEO TOOLBAR FIX v1
   2026-09-21
   ========================================================== */

@media (max-width: 900px) {

  /*
   * Blindaje del área cartográfica.
   * Evita que reglas de Analytics/Radar colapsen
   * o desplacen el mapa en teléfonos.
   */
  body.windy-ui .windy-main {
    position: relative !important;

    width: 100% !important;

    height:
      clamp(
        500px,
        72svh,
        680px
      )
      !important;

    min-height:
      500px
      !important;

    overflow:
      hidden
      !important;
  }


  body.windy-ui .map-wrap {
    position: absolute !important;

    inset: 0 !important;

    width: 100% !important;
    height: 100% !important;

    min-width: 0 !important;
    min-height: 0 !important;

    display: block !important;
  }


  body.windy-ui #weatherMap,
  body.windy-ui:not(.kc-analysis-collapsed) #weatherMap,
  body.windy-ui.kc-analysis-collapsed #weatherMap {

    position: absolute !important;

    inset: 0 !important;

    width: 100% !important;
    height: 100% !important;

    min-width: 0 !important;
    min-height: 0 !important;

    max-width: none !important;
    max-height: none !important;

    display: block !important;

    visibility: visible !important;
    opacity: 1 !important;

    margin: 0 !important;
  }


  /*
   * Leaflet debe quedar visible debajo de overlays,
   * timelines y controles.
   */
  body.windy-ui #weatherMap .leaflet-map-pane {
    visibility: visible !important;
    opacity: 1 !important;
  }


  body.windy-ui #weatherMap .leaflet-tile-pane {
    visibility: visible !important;
    opacity: 1 !important;
  }


  /*
   * Barra meteorológica móvil.
   *
   * En escritorio continúa vertical.
   * En teléfono pasa a ser horizontal y desplazable.
   */
  body.windy-ui .windy-layer-stack,
  body.windy-ui:not(.kc-analysis-collapsed) .windy-layer-stack,
  body.kc-radar-mode .windy-layer-stack {

    display: flex !important;

    flex-direction: row !important;
    flex-wrap: nowrap !important;

    align-items: center !important;

    gap: 6px !important;

    position: absolute !important;

    left: 8px !important;
    right: 8px !important;

    top: auto !important;
    bottom: 118px !important;

    width: auto !important;
    max-width:
      calc(
        100% - 16px
      )
      !important;

    padding: 5px !important;

    overflow-x: auto !important;
    overflow-y: hidden !important;

    z-index: 1500 !important;

    border-radius: 13px !important;

    background:
      rgba(7, 25, 35, .84)
      !important;

    backdrop-filter:
      blur(8px);

    -webkit-overflow-scrolling:
      touch;

    scrollbar-width:
      none;
  }


  body.windy-ui
  .windy-layer-stack::-webkit-scrollbar {
    display: none;
  }


  body.windy-ui
  .windy-layer-stack
  .wx-tool {

    position: static !important;

    flex:
      0 0 54px
      !important;

    width: 54px !important;
    min-width: 54px !important;

    height: 48px !important;

    margin: 0 !important;

    transform: none !important;
  }


  body.windy-ui
  .windy-layer-stack
  .wx-tool b {

    font-size:
      14px
      !important;
  }


  body.windy-ui
  .windy-layer-stack
  .wx-tool span {

    display: block !important;

    max-width: 48px;

    overflow: hidden;

    font-size:
      7px
      !important;

    text-overflow:
      ellipsis;

    white-space:
      nowrap;
  }


  /*
   * En modo Radar el reloj queda arriba
   * y la toolbar meteorológica abajo.
   */
  body.kc-radar-mode
  .kc-radar-frame-clock {

    left: 10px !important;

    top: 12px !important;

    z-index: 1510 !important;
  }


  /*
   * Timeline Radar: mantenerla debajo de la
   * nueva barra de capas.
   */
  body.kc-radar-mode
  .kc-radar-timeline {

    left: 8px !important;
    right: 8px !important;

    bottom: 8px !important;

    min-height: 98px !important;

    z-index: 1490 !important;
  }


  /*
   * En Radar mantenemos ocultos Fecha/Período:
   * son controles del pronóstico y no del radar.
   *
   * Pero NO ocultamos las capas meteorológicas.
   */
  body.kc-radar-mode
  .windy-controls {

    display: none !important;
  }

}
