/* PWA standalone compacto — foco no mapa.
   Aplicado somente quando o app esta instalado/aberto como PWA. */

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

  .topbar.halloween-topbar {
    height: 118px !important;
    min-height: 118px !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-areas:
      "brand actions"
      "headline headline" !important;
    grid-template-rows: 66px 46px !important;
    gap: 3px 6px !important;
    padding: max(4px, env(safe-area-inset-top)) 7px 3px 0 !important;
    overflow: hidden !important;
  }

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

  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img {
    width: min(225px, 70vw) !important;
    height: 64px !important;
    max-width: 100% !important;
    object-fit: contain !important;
    object-position: left center !important;
    padding-left: 3px !important;
  }

  .top-actions {
    grid-area: actions !important;
    height: 66px !important;
    gap: 5px !important;
    padding-left: 4px !important;
    border-left: 0 !important;
  }

  .install-action {
    display: none !important;
  }

  .refresh-action {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    border-radius: 13px !important;
  }

  .refresh-action svg {
    width: 23px !important;
    height: 23px !important;
  }

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

  .headline-zone {
    grid-area: headline !important;
    height: 46px !important;
    width: 100% !important;
    display: block !important;
    padding: 0 7px 2px 9px !important;
    overflow: hidden !important;
  }

  .headline-zone #screenTitle {
    display: none !important;
  }

  .map-header-metrics {
    width: 100% !important;
    height: 44px !important;
    min-height: 44px !important;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    border-radius: 11px !important;
    overflow: hidden !important;
  }

  .map-header-metrics > div {
    min-width: 0 !important;
    width: 100% !important;
    padding: 3px 2px !important;
    display: grid !important;
    grid-template-columns: 23px auto !important;
    grid-template-rows: auto auto !important;
    column-gap: 4px !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .map-header-metrics .metric-icon {
    grid-column: 1 !important;
    grid-row: 1 / 3 !important;
    width: 22px !important;
    height: 22px !important;
    border-radius: 7px !important;
    font-size: .78rem !important;
  }

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

  .map-header-metrics b {
    grid-column: 2 !important;
    grid-row: 1 !important;
    font-size: .78rem !important;
    line-height: 1 !important;
    text-align: left !important;
  }

  .map-header-metrics small {
    display: block !important;
    grid-column: 2 !important;
    grid-row: 2 !important;
    margin: 1px 0 0 !important;
    font-size: .36rem !important;
    line-height: 1 !important;
    letter-spacing: 0 !important;
    text-align: left !important;
  }

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

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

  .map-toolbar {
    height: 52px !important;
    padding: 5px 6px !important;
    display: flex !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    align-items: center !important;
    gap: 5px !important;
    overflow: hidden !important;
  }

  .map-filter-bar {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    gap: 5px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 0 !important;
  }

  .map-filter-bar button {
    min-height: 38px !important;
    height: 38px !important;
    padding: 0 11px !important;
    border-radius: 20px !important;
    font-size: .69rem !important;
  }

  .map-style-switch {
    flex: 0 0 auto !important;
    width: auto !important;
    max-width: 46vw !important;
    justify-self: auto !important;
    gap: 2px !important;
    padding: 2px !important;
    overflow-x: auto !important;
  }

  .map-style-switch button {
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 10px !important;
    border-radius: 19px !important;
    font-size: .66rem !important;
  }

  .map-wallet-hud {
    top: 59px !important;
    left: 6px !important;
    right: auto !important;
    gap: 5px !important;
  }

  .wallet-chip {
    min-height: 34px !important;
    padding: 3px 7px 3px 4px !important;
    border-radius: 9px !important;
  }

  .wallet-chip img {
    width: 25px !important;
    height: 25px !important;
  }

  .wallet-chip b {
    font-size: .75rem !important;
  }

  .wallet-chip small {
    display: block !important;
    font-size: .39rem !important;
  }

  .map-float.bottom {
    left: 7px !important;
    right: 7px !important;
    bottom: 6px !important;
    gap: 5px !important;
    padding: 4px !important;
    display: grid !important;
    grid-template-columns: .9fr 1.1fr 1.3fr !important;
    transform: none !important;
  }

  .map-float.bottom .btn {
    min-width: 0 !important;
    min-height: 42px !important;
    height: 42px !important;
    padding: 0 6px !important;
    font-size: .69rem !important;
    border-radius: 9px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

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

  .leaflet-bottom.leaflet-right {
    right: 6px !important;
    bottom: 57px !important;
  }

  .marker-house {
    font-size: 31px !important;
  }

  .marker-child {
    font-size: 32px !important;
  }

  .map-score-badge {
    height: 21px !important;
    min-width: 35px !important;
    font-size: .55rem !important;
  }

  .map-score-badge img {
    width: 16px !important;
    height: 16px !important;
  }

  .candy-status-badge {
    font-size: 15px !important;
  }

  .candy-low {
    font-size: 13px !important;
  }

  .map-legend-strip {
    height: 32px !important;
    min-height: 32px !important;
    padding: 2px 7px !important;
    gap: 12px !important;
    justify-content: flex-start !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    white-space: nowrap !important;
  }

  .map-legend-strip > div {
    flex: 0 0 auto !important;
    font-size: .46rem !important;
    gap: 4px !important;
  }

  .map-legend-strip img {
    width: 18px !important;
    height: 18px !important;
  }

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

  .bottom-nav button {
    min-height: 68px !important;
    padding: 5px 2px 3px !important;
    gap: 3px !important;
  }

  .nav-icon {
    width: 25px !important;
    height: 25px !important;
  }

  .nav-icon svg {
    width: 25px !important;
    height: 25px !important;
  }

  .bottom-nav button b {
    font-size: .61rem !important;
  }

  /* Telas internas: compactas no topo, com o conteudo podendo rolar. */
  .app:not(.map-screen-active) {
    grid-template-rows: 64px minmax(0, 1fr) calc(68px + env(safe-area-inset-bottom)) !important;
  }

  .app:not(.map-screen-active) .topbar.halloween-topbar {
    height: 64px !important;
    min-height: 64px !important;
    grid-template-columns: 118px minmax(0, 1fr) auto !important;
    grid-template-areas: "brand headline actions" !important;
    grid-template-rows: 1fr !important;
    padding: 2px 6px 2px 0 !important;
    gap: 4px !important;
  }

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

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

  .app:not(.map-screen-active) .headline-zone {
    grid-area: headline !important;
    height: 60px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .app:not(.map-screen-active) .headline-zone #screenTitle {
    display: block !important;
    width: 100% !important;
    margin: 0 !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 {
    height: 60px !important;
  }

  .app:not(.map-screen-active) .refresh-action {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }
}

@media (display-mode: standalone) and (max-width: 390px) {
  .app {
    grid-template-rows: 112px minmax(0, 1fr) calc(64px + env(safe-area-inset-bottom)) !important;
  }

  .topbar.halloween-topbar {
    height: 112px !important;
    min-height: 112px !important;
    grid-template-rows: 63px 43px !important;
  }

  .halloween-wordmark,
  .top-actions {
    height: 63px !important;
  }

  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img {
    width: min(205px, 68vw) !important;
    height: 60px !important;
  }

  .refresh-action {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  .headline-zone,
  .map-header-metrics {
    height: 42px !important;
    min-height: 42px !important;
  }

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

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

  .map-toolbar {
    height: 48px !important;
  }

  .map-filter-bar button {
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 9px !important;
    font-size: .64rem !important;
  }

  .map-style-switch button {
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 8px !important;
    font-size: .62rem !important;
  }

  .map-wallet-hud {
    top: 55px !important;
  }

  .map-float.bottom .btn {
    min-height: 40px !important;
    height: 40px !important;
    font-size: .64rem !important;
  }

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

  .bottom-nav button {
    min-height: 64px !important;
  }
}

@media (display-mode: standalone) and (max-width: 720px) and (max-height: 720px) {
  .app {
    grid-template-rows: 104px minmax(0, 1fr) calc(60px + env(safe-area-inset-bottom)) !important;
  }

  .topbar.halloween-topbar {
    height: 104px !important;
    min-height: 104px !important;
    grid-template-rows: 58px 42px !important;
  }

  .halloween-wordmark,
  .top-actions {
    height: 58px !important;
  }

  .halloween-wordmark-img,
  .topbar .halloween-wordmark-img {
    height: 55px !important;
    width: min(195px, 64vw) !important;
  }

  .headline-zone,
  .map-header-metrics {
    height: 40px !important;
    min-height: 40px !important;
  }

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

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

  .bottom-nav button {
    min-height: 60px !important;
  }
}
