/* Genova mApp - Fase 3: pannelli e comandi, mobile 2026-10-18.
   Progressive sizing only; no changes to app font-size preferences or theme. */
@media (max-width: 480px) {
  /* Modal panels: keep content reachable when device text is enlarged. */
  #settings-modal-overlay { padding: max(8px, env(safe-area-inset-top, 0px)) 8px max(8px, env(safe-area-inset-bottom, 0px)); }
  #settings-modal-overlay > #settings-dropdown {
    width:100% !important;
    max-height:calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    overscroll-behavior:contain;
  }
  #settings-modal-overlay #settings-dropdown .settings-row { min-width:0; overflow-wrap:anywhere; }
  .auth-account-dialog, .auth-account-dialog.is-authenticated {
    box-sizing:border-box;
    max-width:calc(100vw - 16px);
    max-height:calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  .auth-account-dialog :is(button, input, select),
  #settings-modal-overlay :is(button, input, select) { max-width:100%; }
  .auth-dashboard-grid > *, .auth-account-dashboard > * { min-width:0; overflow-wrap:anywhere; }
  /* Abbonamento: stay within the viewport, scrolling content rather than the page. */
  .sub-modal { padding:8px; box-sizing:border-box; }
  .sub-modal-inner { box-sizing:border-box; width:min(420px,100%); max-width:100%; max-height:calc(100dvh - 16px); overflow-y:auto; overscroll-behavior:contain; }
  .sub-modal-header > * { min-width:0; }
  .sub-modal-body, .sub-modal-body * { overflow-wrap:anywhere; }
  .sub-v2-tier-grid, .sub-v2-promo-row { min-width:0; max-width:100%; }
  .sub-v2-promo-input { min-width:0; max-width:100%; box-sizing:border-box; }
  /* Favorites panel used as an auxiliary map menu. */
  #fav-menu { box-sizing:border-box; max-width:calc(100vw - 16px); max-height:min(65dvh,520px); overflow-x:hidden; overflow-y:auto; }
  #fav-menu .fav-item, #fav-menu .fav-acc-head { min-width:0; }
  #fav-menu .fav-name { min-width:0; overflow-wrap:anywhere; }
  /* New Home: allow long translations and large device text to wrap. */
  .gm-new-home-topbar > *, .gm-new-home-heading { min-width:0; }
  .gm-new-home-card, .gm-new-home-card *, .gm-new-home-events-panel, .gm-new-home-events-panel * { min-width:0; }
  .gm-new-home-card :is(h2,h3,p,strong), .gm-new-home-events-panel :is(h2,h3,p,strong) { overflow-wrap:anywhere; }
  .gm-new-home-scroll { overscroll-behavior:contain; }
}
@media (max-width: 380px) {
  /* Notebook keeps full-height layout but wastes less space at the sides. */
  #fav-notes-panel { padding:max(40px,env(safe-area-inset-top,0px)) 9px max(10px,env(safe-area-inset-bottom,0px)) !important; }
  #fav-notes-panel .taccuino-cover-head { padding-right:9px; }
  #fav-notes-panel .taccuino-tabs { padding-left:14px; padding-right:7px; }
  #fav-notes-panel .taccuino-tabs button { white-space:normal; overflow-wrap:anywhere; height:auto; min-height:40px; }
  #fav-notes-panel .taccuino-page-head { padding-left:23px; }
  #fav-notes-panel .taccuino-page-body { padding-left:23px; }
  #fav-notes-panel .taccuino-page-actions { min-width:0; flex-wrap:wrap; }
  .gm-new-home-overlay { padding-inline:4px; }
  .gm-new-home-topbar { gap:4px; padding-inline:5px; }
  .gm-new-home-heading { max-width:none; }
  .gm-new-home-scroll { padding:9px; }
  .gm-new-home-game-card { grid-template-columns:56px minmax(0,1fr); }
  .gm-new-home-game-icon { width:56px; height:56px; }
  #settings-modal-overlay #settings-dropdown .settings-row { padding:10px 8px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #settings-modal-overlay > #settings-dropdown, .auth-account-dialog, .sub-modal-inner { max-height:calc(100dvh - 14px) !important; overflow-y:auto; }
}

/* Only the separate popup pane sits above side/bottom map controls.
   Map tiles and markers keep their usual layer and never hide controls. */
#map.leaflet-container > .gm-popup-front-pane {
  z-index: 11000 !important;
}

/* Fase 4 - UI compatta sui telefoni stretti (<=360px).
   Ridimensiona i soli controlli visivi, senza trasformare le colonne
   e senza alterare il popup pane separato. */
@media (max-width: 360px) {
  /* Il pulsante resta accessibile con il suo aria-label originale. */
  .gm-new-home-topbar { grid-template-columns: 38px minmax(0,1fr) 38px; }
  #gm-new-home-close { width:38px; min-width:38px; height:38px; min-height:38px; padding:0; gap:0; border-radius:11px; }
  #gm-new-home-close > span { display:none; }
  #gm-new-home-close svg { width:20px; height:20px; }
  #gm-new-home-back { width:38px; height:38px; }
  .gm-new-home-heading { max-width:100%; }

  /* Categoria Patrimonio: icone, colonne e padding piu equilibrati. */
  .gm-new-home-category.has-map-icon { grid-template-columns:52px minmax(0,1fr); min-height:74px; }
  .gm-new-home-category-map { padding:6px; }
  .gm-new-home-category-map img { width:34px; height:34px; }
  .gm-new-home-category-open { padding:10px 10px; gap:6px; }
  .gm-new-home-category { min-height:74px; padding:10px; gap:8px; }
  .gm-new-home-card .gm-new-home-icon { width:38px; height:38px; top:11px; right:11px; border-radius:11px; }
  .gm-new-home-card .gm-new-home-icon svg { width:23px; height:23px; }
  .gm-new-home-card .gm-new-home-icon img { width:26px; height:26px; }
  .gm-new-home-game-card { grid-template-columns:48px minmax(0,1fr) auto; gap:8px; }
  .gm-new-home-game-icon { width:48px; height:48px; border-radius:12px; }

  /* Colonna destra: dimensioni reali (non transform:scale). */
  #quick-toggles {
    box-sizing:content-box; width:36px !important;
    right:max(10px, env(safe-area-inset-right, 0px)) !important;
    padding:0 !important; gap:5px !important;
  }
  /* Main column buttons use .qt-pill, not .qt-btn (which belongs to flyout menus). */
  #quick-toggles > .qt-item.qt-cat.qt-pill {
    box-sizing:border-box; width:36px !important; height:36px !important;
    min-width:36px !important; min-height:36px !important;
    padding:0 !important; flex:0 0 36px;
  }
  #quick-toggles > .qt-pill .qt-icon,
  #quick-toggles > .qt-pill .qt-icon img,
  #quick-toggles > .qt-pill .qt-icon svg {
    width:23px !important; height:23px !important;
    max-width:23px !important; max-height:23px !important;
  }
  #quick-toggles > #qt-cat-food-btn .qt-icon svg {width:25px !important;height:25px !important;}
  /* Routes submenu should open alongside the new 36px column. */
  #quick-toggles #qt-cat-routes {right:calc(36px + 8px) !important;}
  #quick-toggles .qt-btn,
  #quick-toggles .qt-pill-favorites,
  #quick-toggles .qt-pill-qr {
    width:36px !important; height:36px !important;
    min-width:36px !important; min-height:36px !important;
  }
  #quick-toggles .qt-btn svg { width:19px !important; height:19px !important; }
  #quick-toggles .qt-pill-favorites .qt-icon,
  #quick-toggles .qt-pill-favorites svg { width:21px !important; height:21px !important; }
  #quick-toggles .qt-btn .qt-icon img,
  #quick-toggles .qt-pill-qr img { max-width:26px; max-height:26px; }

  /* Colonna sinistra compatta: stessi ingombri visivi dei controlli destri.
     Il Taccuino resta una linguetta laterale, non un pulsante circolare. */
  #gmec-map-toggle {
    box-sizing:border-box; width:36px !important; height:36px !important;
    min-width:36px !important; min-height:36px !important;
  }
  #map > #ui-taccuino-button.ui-taccuino-edge {
    width:38px !important; height:46px !important;
    min-width:38px !important; min-height:46px !important;
    padding:3px 3px 3px 2px !important;
    border-radius:0 11px 11px 0 !important;
  }
  #map > #ui-taccuino-button.ui-taccuino-edge img.taccuino-toolbar-icon {
    width:33px !important; height:33px !important;
  }
  #gm-griff-mini {
    box-sizing:border-box; width:36px !important; height:36px !important;
    min-width:36px !important; min-height:36px !important;
  }
}
