/* Phone portrait and short touch landscapes share one interaction model.
   Keep this query aligned with MOBILE_PANEL_QUERY in geoportal.js. */
:root { --keyboard-inset: 0px; }
.mobile-navigation, .map-toolbar .mobile-map-options { display: none; }
.map-options { display: contents; }

@media (max-width: 680px), (max-width: 1000px) and (max-height: 500px) and (pointer: coarse) {
  :root { --header-height: calc(52px + var(--safe-top)); --mobile-nav-height: calc(58px + var(--safe-bottom)); --mobile-bottom: calc(var(--mobile-nav-height) + var(--keyboard-inset)); }
  .topbar { height: var(--header-height); min-height: var(--header-height); padding: var(--safe-top) max(8px, var(--safe-right)) 0 max(8px, var(--safe-left)); gap: 8px; }
  .brand-block { min-width: 0; gap: 8px; }
  .brand-block h1 { display: block; font-size: 14px; line-height: 1.25; white-space: nowrap; }
  .brand-block > div { display: block; }
  .brand-mark { width: 30px; height: 30px; flex: 0 0 30px; }
  .topbar-actions { margin-left: auto; gap: 2px; flex-shrink: 0; }
  .topbar-action { min-width: 44px; min-height: 44px; width: 44px; padding: 10px; }
  .topbar-action > span:last-child:not([data-icon]),
  #catalogueToggle, .topbar-panel-controls, #fullscreenToggle { display: none; }
  .panel-rail { display: none !important; }
  .map-logo-watermark { top: calc(var(--header-height) + 10px); right: 12px; }
  .mobile-navigation { position: fixed; z-index: 45; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); bottom: var(--keyboard-inset); left: 0; right: 0; height: var(--mobile-nav-height); padding: 3px var(--safe-right) var(--safe-bottom) var(--safe-left); border-top: 1px solid var(--line); background: var(--surface-strong); }
  .mobile-navigation button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; min-height: 48px; padding: 3px; border: 0; border-radius: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: 11px; cursor: pointer; }
  .mobile-navigation .icon { width: 19px; height: 19px; }
  .mobile-navigation [aria-current="page"] { color: var(--brand-strong); background: var(--selected-bg); font-weight: 700; }
  .mobile-navigation :focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -3px; }
  body.has-modal .mobile-navigation { visibility: hidden; }
  .catalogue-panel, .info-panel, .upload-panel { z-index: 50; }

  .sidebar, .right-panel { z-index: 40; display: flex; flex-direction: column; position: fixed; top: auto; bottom: var(--mobile-bottom); left: max(8px, var(--safe-left)); right: max(8px, var(--safe-right)); width: auto; height: min(65dvh, 560px); max-height: calc(100dvh - var(--header-height) - var(--mobile-bottom) - 48px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; background: var(--surface-strong); box-shadow: 0 -8px 24px rgb(15 45 38 / 10%); transition: transform 180ms ease-out, opacity 180ms ease-out; }
  body.sidebar-collapsed .sidebar, body.right-panel-collapsed .right-panel { transform: translateY(calc(100% + var(--mobile-bottom))); opacity: 0; pointer-events: none; }
  body:not(.sidebar-collapsed) .right-panel { display: flex; }
  .preset-panel { width: 100%; min-height: 0; padding: 0 12px 16px; overflow-y: auto; overscroll-behavior: contain; }
  .preset-panel .panel-header, .right-panel-header { position: sticky; top: 0; z-index: 2; flex: 0 0 auto; margin: 0; min-height: 54px; padding: 5px 0; gap: 8px; background: var(--surface-strong); border-bottom: 1px solid var(--line-soft); }
  .right-panel-header { padding-inline: 12px; }
  .preset-panel .panel-header h2, .right-panel-header h2 { font-size: 15px; }
  .preset-panel .panel-header p { display: none; }
  .panel-action--icon { min-height: 44px; height: 44px; min-width: 44px; padding-inline: 6px; }
  .panel-action-label { display: inline; font-size: 11px; }
  .preset-intro { margin-block: 12px; font-size: 12px; }
  .preset-list { gap: 8px; }
  .preset-choice, .preset-apply { min-height: 44px; }
  .preset-composition > summary, .discovery-reset { min-height: 44px; display: flex; align-items: center; }
  .right-panel-body, .right-panel-body.is-resizable { display: block; overflow-y: auto; overscroll-behavior: contain; }
  .right-panel-body .layer-stack-panel--right, .right-panel-body.is-resizable .layer-stack-panel--right { height: auto; max-height: none; padding: 8px 12px; overflow: visible; }
  .layer-stack-list { max-height: none; overflow: visible; }
  .layer-stack-header { padding-block: 2px; }
  .layer-stack-header h2 { font-size: 12px; }
  .layer-stack-actions { padding-block: 2px; }
  #rightPanelSplitter { display: none; }
  .right-tabs-panel { overflow: visible; padding: 8px 12px 16px; }
  .right-tab-panel { overflow: visible; flex: none; }
  .layer-stack-panel--right .layer-stack-item { grid-template-columns: 28px minmax(0, 1fr) 44px 44px; gap: 2px; min-height: 44px; padding: 0; }
  .layer-stack-panel--right .stack-grip { width: 28px; min-height: 44px; }
  .layer-stack-panel--right .stack-visibility, .layer-stack-panel--right .stack-remove { width: 44px; height: 44px; min-width: 44px; }
  .layer-stack-panel--right .stack-layer-text strong { font-size: 12px; }
  .selected-layer-controls .stack-opacity { width: 100%; gap: 8px; grid-template-columns: auto minmax(90px, 1fr) auto; }
  .stack-opacity input { min-height: 44px; height: 44px; touch-action: pan-y; }
  .aggregation-control--details .aggregation-pill, .right-tabs-panel .value-field-trigger, .right-tab { min-height: 44px; }
  .right-tab { padding-inline: 6px; font-size: 11px; white-space: nowrap; }
  .legend-category { min-height: 36px; }

  .map-toolbar, body.sidebar-collapsed .map-toolbar, body.right-panel-collapsed .map-toolbar { position: fixed; left: auto; right: max(8px, var(--safe-right)); bottom: calc(var(--mobile-bottom) + 8px); width: auto; max-width: calc(100vw - 16px - var(--safe-left) - var(--safe-right)); min-height: 48px; padding: 2px; gap: 2px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-strong); }
  .map-toolbar .control-group { gap: 0; padding: 0; }
  .map-toolbar button { min-width: 44px; min-height: 44px; padding: 6px; }
  .map-toolbar .mobile-map-options { display: inline-flex; gap: 5px; font-size: 12px; }
  .map-toolbar button.mobile-map-options > span:last-child:not([data-icon]) { display: inline; }
  .map-options { display: none; position: absolute; right: 0; bottom: calc(100% + 8px); width: min(340px, calc(100vw - 16px - var(--safe-right) - var(--safe-left))); max-height: calc(100dvh - var(--header-height) - var(--mobile-bottom) - 76px); padding: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-strong); box-shadow: var(--shadow-md); }
  body.mobile-tools-open .map-options { display: grid; }
  .map-options > .control-group { display: contents; }
  .map-options button { justify-content: flex-start; white-space: normal; font-size: 12px; }
  .map-options button > span:last-child:not([data-icon]) { display: inline; }
  .map-options .basemap-control { display: grid; grid-template-columns: auto 1fr; grid-column: 1 / -1; width: 100%; gap: 8px; }
  .map-options .basemap-control > span { display: block; font-size: 12px; }
  .map-options select { width: 100%; max-width: none; min-width: 0; font-size: 16px; }
  .map-readout { display: none !important; }
  .maplibregl-ctrl-bottom-left { left: max(8px, var(--safe-left)); bottom: calc(var(--mobile-bottom) + 66px); }
  .maplibregl-ctrl-bottom-right { right: max(8px, var(--safe-right)); bottom: calc(var(--mobile-bottom) + 66px); }
  .cell-hover[data-docked="true"] { z-index: 35; border-radius: 10px 10px 4px 4px; }
  .cell-hover[data-docked="true"] h4 { font-size: 13px; }
  .cell-hover[data-docked="true"] .cell-hover-primary { font-size: 13px; }
  .cell-hover[data-docked="true"] .cell-hover-native, .cell-hover[data-docked="true"] .cell-hover-note, .cell-hover[data-docked="true"] dl { font-size: 12px; }
  .cell-hover[data-docked="true"] > header button { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  .cell-hover[data-docked="true"] summary { display: flex; align-items: center; min-height: 44px; padding-block: 4px; font-size: 12px; }
  .cell-hover[data-docked="true"] .cell-hover-layer { padding-block: 10px; }
  body.has-cell-reading .map-toolbar { display: none; }
  @media (orientation: landscape) {
    .sidebar, .right-panel { top: calc(var(--header-height) + 4px); bottom: var(--mobile-bottom); left: auto; width: min(400px, 52vw); height: auto; max-height: none; }
    .cell-hover[data-docked="true"] { border-radius: 6px; }
  }
  @media (prefers-reduced-motion: reduce) { .sidebar, .right-panel { transition: none; } }
}
