/* V20 - layout mobile consolidado
   Mantem o navegador/mobile web compacto e legivel.
   O bloco standalone ao final aumenta a escala apenas no PWA instalado. */

@media (max-width: 720px) {
  .app {
    grid-template-rows: 152px minmax(0, 1fr) calc(76px + env(safe-area-inset-bottom)) !important;
  }

  .topbar.halloween-topbar {
    height: 152px !important;
    min-height: 152px !important;
    padding: max(8px, env(safe-area-inset-top)) 8px 6px !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-areas:
      "brand actions"
      "headline headline" !important;
    grid-template-rows: 82px 54px !important;
    gap: 6px 8px !important;
    align-items: center !important;
    overflow: hidden !important;
  }

  .halloween-wordmark {
    grid-area: brand !important;
    min-width: 0 !important;
    height: 82px !important;
  }

  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img {
    width: min(270px, 76vw) !important;
    height: 78px !important;
    max-width: 100% !important;
    object-fit: contain !important;
    object-position: left center !important;
    padding-left: 0 !important;
  }

  .headline-zone {
    grid-area: headline !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 54px !important;
    display: block !important;
    position: relative !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  #screenTitle {
    display: none !important;
  }

  .map-header-metrics {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    width: 100% !important;
    height: 54px !important;
    min-height: 54px !important;
    overflow: hidden !important;
    border-radius: 12px !important;
    background: rgba(7, 17, 31, .96) !important;
    border: 1px solid rgba(255, 255, 255, .13) !important;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .22) !important;
  }

  .map-header-metrics > div {
    min-width: 0 !important;
    width: auto !important;
    padding: 6px 3px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    border-right: 1px solid rgba(255, 255, 255, .12) !important;
  }

  .map-header-metrics > div:last-child { border-right: 0 !important; }

  .map-header-metrics .metric-icon {
    flex: 0 0 auto !important;
    width: 24px !important;
    height: 24px !important;
    border-radius: 7px !important;
    font-size: .88rem !important;
  }

  .map-header-metrics .metric-check {
    width: 24px !important;
    height: 24px !important;
    font-size: .78rem !important;
  }

  .map-header-metrics b {
    flex: 0 0 auto !important;
    font-size: .9rem !important;
    line-height: 1 !important;
  }

  .map-header-metrics small {
    display: none !important;
  }

  .top-actions {
    grid-area: actions !important;
    gap: 8px !important;
    justify-content: flex-end !important;
    height: 82px !important;
    padding-left: 0 !important;
    border-left: 0 !important;
  }

  .install-action,
  .refresh-action {
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    min-height: 60px !important;
    border-radius: 16px !important;
  }

  .install-action b,
  .header-profile,
  #modeBadge {
    display: none !important;
  }

  #screen-map.active {
    grid-template-rows: minmax(0, 1fr) 38px !important;
  }

  #screen-map .map-wrap {
    height: auto !important;
    min-height: 0 !important;
  }

  #screen-map #map {
    top: 58px !important;
  }

  .map-toolbar {
    position: absolute !important;
    z-index: 700 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 58px !important;
    padding: 7px 8px !important;
    display: flex !important;
    gap: 8px !important;
    align-items: center !important;
    overflow: hidden !important;
    pointer-events: auto !important;
  }

  .map-filter-bar {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: flex !important;
    gap: 7px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 0 !important;
    scroll-snap-type: x proximity !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .map-filter-bar::-webkit-scrollbar,
  .map-style-switch::-webkit-scrollbar,
  .map-legend-strip::-webkit-scrollbar { display: none !important; }

  .map-filter-bar button,
  .map-style-switch button {
    flex: 0 0 auto !important;
    min-height: 42px !important;
    height: 42px !important;
    padding: 0 13px !important;
    border-radius: 22px !important;
    white-space: nowrap !important;
    font-size: .76rem !important;
    line-height: 1 !important;
    scroll-snap-align: start !important;
  }

  .map-style-switch {
    flex: 0 0 auto !important;
    max-width: 44vw !important;
    display: flex !important;
    gap: 4px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 2px !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .map-wallet-hud {
    top: 66px !important;
    left: 8px !important;
    right: 8px !important;
    display: flex !important;
    gap: 7px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }

  .map-wallet-hud::-webkit-scrollbar { display: none !important; }

  .wallet-chip {
    min-height: 38px !important;
    padding: 4px 8px 4px 5px !important;
  }

  .wallet-chip img { width: 28px !important; height: 28px !important; }
  .wallet-chip b { font-size: .82rem !important; }
  .wallet-chip small { font-size: .48rem !important; }

  .map-float.bottom {
    bottom: 8px !important;
    left: 8px !important;
    right: 8px !important;
    transform: none !important;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
    max-width: none !important;
    padding: 5px !important;
  }

  .map-float.bottom .btn {
    min-width: 0 !important;
    min-height: 44px !important;
    height: 44px !important;
    padding: 0 8px !important;
    font-size: .75rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .leaflet-control-zoom a {
    width: 40px !important;
    height: 40px !important;
    line-height: 38px !important;
    font-size: 1.18rem !important;
  }

  .leaflet-bottom.leaflet-right {
    right: 7px !important;
    bottom: 64px !important;
  }

  .map-legend-strip {
    height: 38px !important;
    min-height: 38px !important;
    padding: 4px 8px !important;
    gap: 16px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
    font-size: .58rem !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    justify-content: flex-start !important;
  }

  .map-legend-strip > div { font-size: .58rem !important; flex: 0 0 auto !important; }
  .map-legend-strip img { width: 21px !important; height: 21px !important; }

  .bottom-nav {
    height: calc(76px + env(safe-area-inset-bottom)) !important;
    min-height: calc(76px + env(safe-area-inset-bottom)) !important;
    padding: 0 0 env(safe-area-inset-bottom) !important;
  }

  .bottom-nav button {
    min-height: 76px !important;
    gap: 4px !important;
  }

  .nav-icon { width: 29px !important; height: 29px !important; }
  .nav-icon svg { width: 29px !important; height: 29px !important; }
  .bottom-nav button b { font-size: .68rem !important; }

  .marker-house { font-size: 34px !important; }
  .marker-child { font-size: 35px !important; }
  .map-score-badge { height: 23px !important; min-width: 38px !important; font-size: .61rem !important; }
  .map-score-badge img { width: 18px !important; height: 18px !important; }
  .candy-status-badge { font-size: 17px !important; }
  .candy-low { font-size: 15px !important; }

  .app:not(.map-screen-active) {
    grid-template-rows: 72px minmax(0, 1fr) calc(72px + env(safe-area-inset-bottom)) !important;
  }

  .app:not(.map-screen-active) .topbar.halloween-topbar {
    height: 72px !important;
    min-height: 72px !important;
    display: grid !important;
    grid-template-columns: 132px minmax(0, 1fr) auto !important;
    grid-template-areas: "brand headline actions" !important;
    grid-template-rows: 1fr !important;
    padding: 3px 7px 3px 0 !important;
    gap: 5px !important;
  }

  .app:not(.map-screen-active) .halloween-wordmark {
    grid-area: brand !important;
    height: 68px !important;
  }

  .app:not(.map-screen-active) .halloween-wordmark-img {
    width: 132px !important;
    height: 64px !important;
  }

  .app:not(.map-screen-active) .headline-zone {
    grid-area: headline !important;
    height: auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
  }

  .app:not(.map-screen-active) .headline-zone #screenTitle {
    display: block !important;
    width: 100% !important;
    color: #ffab31 !important;
    text-align: center !important;
    font-size: .92rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .app:not(.map-screen-active) .map-header-metrics { display: none !important; }
  .app:not(.map-screen-active) .top-actions { grid-area: actions !important; height: 66px !important; }
  .app:not(.map-screen-active) .bottom-nav { height: calc(72px + env(safe-area-inset-bottom)) !important; min-height: calc(72px + env(safe-area-inset-bottom)) !important; }
  .app:not(.map-screen-active) .bottom-nav button { min-height: 72px !important; }

  .screen:not(#screen-map) {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

@media (max-width: 390px) {
  .topbar.halloween-topbar { grid-template-rows: 78px 50px !important; height: 142px !important; min-height: 142px !important; }
  .app { grid-template-rows: 142px minmax(0, 1fr) calc(72px + env(safe-area-inset-bottom)) !important; }
  .halloween-wordmark { height: 78px !important; }
  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img { width: min(235px, 68vw) !important; height: 74px !important; }
  .top-actions { height: 78px !important; }
  .install-action,
  .refresh-action { width: 54px !important; height: 54px !important; min-width: 54px !important; min-height: 54px !important; }
  .headline-zone { height: 50px !important; }
  .map-header-metrics { height: 50px !important; min-height: 50px !important; }
  .map-filter-bar button,
  .map-style-switch button { min-height: 40px !important; height: 40px !important; padding: 0 11px !important; font-size: .72rem !important; }
  .map-float.bottom .btn { font-size: .68rem !important; padding: 0 5px !important; }
}

/* PWA instalado: interface propositalmente maior.
   No modo standalone existe mais altura útil porque a barra do navegador desaparece. */
@media (display-mode: standalone) and (max-width: 720px) {
  .app {
    grid-template-rows: 176px minmax(0, 1fr) calc(92px + env(safe-area-inset-bottom)) !important;
  }

  .topbar.halloween-topbar {
    height: 176px !important;
    min-height: 176px !important;
    grid-template-rows: 88px 72px !important;
    padding: max(9px, env(safe-area-inset-top)) 10px 7px !important;
    gap: 8px 10px !important;
  }

  .halloween-wordmark { height: 88px !important; }
  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img {
    width: min(300px, 76vw) !important;
    height: 84px !important;
  }

  .top-actions { height: 88px !important; }
  .install-action,
  .refresh-action {
    width: 66px !important;
    height: 66px !important;
    min-width: 66px !important;
    min-height: 66px !important;
    border-radius: 18px !important;
  }
  .refresh-action svg { width: 28px !important; height: 28px !important; }

  .headline-zone { height: 72px !important; }
  #screenTitle {
    display: block !important;
    height: 22px !important;
    margin: 0 0 5px !important;
    color: #ffab31 !important;
    text-align: left !important;
    font-size: .96rem !important;
    line-height: 22px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .map-header-metrics {
    height: 45px !important;
    min-height: 45px !important;
    border-radius: 13px !important;
  }

  .map-header-metrics > div {
    padding: 5px 4px !important;
    gap: 6px !important;
  }

  .map-header-metrics .metric-icon {
    width: 28px !important;
    height: 28px !important;
    font-size: 1rem !important;
  }

  .map-header-metrics .metric-check {
    width: 28px !important;
    height: 28px !important;
    font-size: .88rem !important;
  }

  .map-header-metrics b { font-size: 1rem !important; }
  .map-header-metrics small {
    display: block !important;
    font-size: .46rem !important;
    line-height: 1 !important;
    letter-spacing: 0 !important;
  }

  #screen-map.active { grid-template-rows: minmax(0, 1fr) 48px !important; }
  #screen-map #map { top: 106px !important; }

  .map-toolbar {
    height: 106px !important;
    padding: 8px 9px !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: 50px 40px !important;
    gap: 7px !important;
    align-content: center !important;
  }

  .map-filter-bar {
    width: 100% !important;
    gap: 8px !important;
  }

  .map-filter-bar button {
    min-height: 48px !important;
    height: 48px !important;
    padding: 0 16px !important;
    border-radius: 25px !important;
    font-size: .88rem !important;
  }

  .map-style-switch {
    width: max-content !important;
    max-width: none !important;
    justify-self: end !important;
    gap: 5px !important;
  }

  .map-style-switch button {
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 16px !important;
    font-size: .82rem !important;
  }

  .map-wallet-hud {
    top: 116px !important;
    gap: 8px !important;
  }

  .wallet-chip {
    min-height: 46px !important;
    padding: 5px 10px 5px 6px !important;
    border-radius: 11px !important;
  }

  .wallet-chip img { width: 34px !important; height: 34px !important; }
  .wallet-chip b { font-size: .96rem !important; }
  .wallet-chip small { display: block !important; font-size: .52rem !important; }

  .map-float.bottom {
    bottom: 10px !important;
    gap: 7px !important;
    padding: 6px !important;
  }

  .map-float.bottom .btn {
    min-height: 54px !important;
    height: 54px !important;
    padding: 0 9px !important;
    font-size: .86rem !important;
    border-radius: 11px !important;
  }

  .leaflet-control-zoom a {
    width: 46px !important;
    height: 46px !important;
    line-height: 44px !important;
    font-size: 1.4rem !important;
  }

  .leaflet-bottom.leaflet-right {
    right: 8px !important;
    bottom: 76px !important;
  }

  .marker-house { font-size: 42px !important; }
  .marker-child { font-size: 43px !important; }
  .map-score-badge {
    height: 28px !important;
    min-width: 44px !important;
    padding: 2px 6px !important;
    font-size: .72rem !important;
  }
  .map-score-badge img { width: 22px !important; height: 22px !important; }
  .candy-status-badge { font-size: 21px !important; }
  .candy-low { font-size: 18px !important; }
  .visit-mini-badge { min-width: 25px !important; height: 25px !important; font-size: .62rem !important; }
  .soldout-stamp { font-size: .58rem !important; padding: 3px 6px !important; }

  .map-legend-strip {
    height: 48px !important;
    min-height: 48px !important;
    padding: 6px 10px !important;
    gap: 20px !important;
  }
  .map-legend-strip > div { font-size: .68rem !important; gap: 6px !important; }
  .map-legend-strip img { width: 25px !important; height: 25px !important; }
  .legend-candy { font-size: 1.15rem !important; }
  .legend-sold { font-size: .54rem !important; padding: 3px 6px !important; }

  .bottom-nav {
    height: calc(92px + env(safe-area-inset-bottom)) !important;
    min-height: calc(92px + env(safe-area-inset-bottom)) !important;
  }
  .bottom-nav button {
    min-height: 92px !important;
    gap: 6px !important;
  }
  .bottom-nav button:before { height: 4px !important; }
  .nav-icon { width: 36px !important; height: 36px !important; }
  .nav-icon svg { width: 35px !important; height: 35px !important; }
  .bottom-nav button b { font-size: .76rem !important; }

  .app:not(.map-screen-active) {
    grid-template-rows: 86px minmax(0, 1fr) calc(86px + env(safe-area-inset-bottom)) !important;
  }
  .app:not(.map-screen-active) .topbar.halloween-topbar {
    height: 86px !important;
    min-height: 86px !important;
    grid-template-columns: 150px minmax(0, 1fr) auto !important;
  }
  .app:not(.map-screen-active) .halloween-wordmark,
  .app:not(.map-screen-active) .halloween-wordmark-img {
    height: 80px !important;
  }
  .app:not(.map-screen-active) .halloween-wordmark-img { width: 150px !important; }
  .app:not(.map-screen-active) .headline-zone #screenTitle {
    font-size: 1.08rem !important;
  }
  .app:not(.map-screen-active) .top-actions { height: 80px !important; }
  .app:not(.map-screen-active) .bottom-nav {
    height: calc(86px + env(safe-area-inset-bottom)) !important;
    min-height: calc(86px + env(safe-area-inset-bottom)) !important;
  }
  .app:not(.map-screen-active) .bottom-nav button { min-height: 86px !important; }
}

@media (display-mode: standalone) and (max-width: 390px) {
  .app { grid-template-rows: 166px minmax(0, 1fr) calc(88px + env(safe-area-inset-bottom)) !important; }
  .topbar.halloween-topbar {
    height: 166px !important;
    min-height: 166px !important;
    grid-template-rows: 82px 70px !important;
  }
  .halloween-wordmark { height: 82px !important; }
  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img { width: min(255px, 70vw) !important; height: 78px !important; }
  .top-actions { height: 82px !important; }
  .install-action,
  .refresh-action { width: 60px !important; height: 60px !important; min-width: 60px !important; min-height: 60px !important; }
  .headline-zone { height: 70px !important; }
  #screenTitle { font-size: .88rem !important; }
  .map-header-metrics small { display: none !important; }
  .map-filter-bar button { padding: 0 14px !important; font-size: .82rem !important; }
  .map-float.bottom .btn { font-size: .78rem !important; padding: 0 6px !important; }
  .bottom-nav { height: calc(88px + env(safe-area-inset-bottom)) !important; min-height: calc(88px + env(safe-area-inset-bottom)) !important; }
  .bottom-nav button { min-height: 88px !important; }
  .nav-icon { width: 33px !important; height: 33px !important; }
  .nav-icon svg { width: 32px !important; height: 32px !important; }
  .bottom-nav button b { font-size: .72rem !important; }
}
