/* mobile.css — phones and small tablets (≤ 760 px wide). Linked last, so these rules
   adjust the desktop layout without changing it on wider screens.
   Goals: keep the map visible, nothing hidden behind something else, comfortable
   tap targets (about 40 px), and no iOS zoom-in when typing (inputs at 16 px). */

/* The fold arrow in the left panel's title only shows on phones. */
.panel-toggle { display: none; }

@media (max-width: 760px), (max-height: 500px) and (orientation: landscape) {
  /* ---------- Typing: iOS zooms the page when a field's text is under 16 px ---------- */
  input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="tel"],
  input[type="number"], input:not([type]), select, textarea { font-size: 16px; }

  /* ---------- Map controls: pinch to zoom, so the +/− buttons go ---------- */
  .leaflet-control-zoom { display: none; }

  /* ---------- Right toolbar: sits above the panels, starts below the mode tabs ---------- */
  .map-toolbar { z-index: 1050; right: 8px; top: calc(68px + env(safe-area-inset-top, 0px)); gap: 5px; }
  .tb-btn { width: 50px; height: 46px; }
  /* Log in button: top right, beside the mode tabs */
  /* Top bar: the four tabs fill it, the account button is round (icon only) */
  :root { --bar-h: 60px; --topbar-h: 60px; }
  .topbar { display: flex; padding: env(safe-area-inset-top, 0px) 8px 0; gap: 8px; }
  .tb-brand { display: none; }
  .topbar .mode-tabs { flex: 1; min-width: 0; }
  .topbar .acct-btn { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 22px; }
  .topbar .acct-btn span { display: none; }
  .dep-picker { top: calc(68px + env(safe-area-inset-top, 0px)) !important; max-height: calc(100dvh - 90px) !important; }
  .acct-pop { position: fixed; left: 8px; right: 8px; width: auto; top: calc(68px + env(safe-area-inset-top, 0px)); z-index: 1060; }
  .login-dlg { width: calc(100vw - 16px); }
  /* Toolbar menus (Prefs, Charts) open as wide sheets beside the toolbar */
  .tb-pop, .prefs-pop {
    position: fixed; left: 8px; right: 66px; top: calc(68px + env(safe-area-inset-top, 0px)); width: auto;
    max-height: calc(100dvh - 200px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .pref-row { min-height: 44px; }
  .prefs-pop .seg button { min-height: 38px; }
  #ov-chart-list button { min-height: 40px; }

  /* ---------- Left panel: below the mode tabs, beside the toolbar, folds to its title ---------- */
  #controls, .trips-panel {
    left: 8px; right: 66px; width: auto; box-sizing: border-box;
    top: calc(68px + env(safe-area-inset-top, 0px)); padding: 10px 12px;
    max-height: calc(100dvh - 200px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  #controls h1 { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; font-size: 16px; }
  .panel-toggle {
    display: grid; place-items: center; width: 40px; height: 36px; margin: -6px -8px -6px 8px; padding: 0;
    background: transparent; border: 0; border-radius: 8px;
  }
  .panel-toggle svg { width: 20px; height: 20px; fill: var(--muted); transform: rotate(180deg); transition: transform 0.2s; }
  #controls.folded { padding-top: 8px; padding-bottom: 8px; overflow: hidden; }
  #controls.folded h1 { margin: 0; }
  #controls.folded .panel-toggle svg { transform: none; }
  #controls.folded > :not(h1) { display: none !important; }

  /* Bigger tap targets inside the panel */
  .zip-row input, .zip-row button, .locate-btn { min-height: 42px; }
  .flights > summary { min-height: 40px; }
  .seg button { min-height: 38px; }
  .clear-x { width: 34px; height: 34px; right: 2px; }
  .clearable .text-in { padding-right: 38px; }
  .factions button, .adb-actions button, .pin-acts button { min-height: 40px; }

  /* ---------- Mode tabs (Explore / My flights / On board) ---------- */
  .topbar .mode-tabs button { flex: 1; min-height: 38px; padding: 6px 4px; font-size: 12.5px; }

  /* ---------- Bottom: aircraft count and altitude legend, compact ---------- */
  #stats { left: 8px; width: auto; right: 8px; max-width: 320px; padding: 7px 10px; font-size: 11.5px;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  #stats .count { font-size: 13.5px; }
  .credit { margin-top: 3px; font-size: 10.5px; }
  #alt-legend { width: calc(100vw - 16px); padding: 6px 10px 2px; gap: 8px; }
  /* Only 0 / 10,000 / 20,000 / 30,000 / 40,000+ under the colour bar, so labels don't collide */
  .tick b { display: none; }
  .tick[data-ft="0"] b, .tick[data-ft="10000"] b, .tick[data-ft="20000"] b, .tick[data-ft="30000"] b, .tick[data-ft="40000"] b { display: block; }
  .leaflet-bottom { bottom: calc(50px + env(safe-area-inset-bottom, 0px)); }
  .leaflet-control-attribution { font-size: 9.5px; }

  /* ---------- Plane popup ---------- */
  .ac-popup .leaflet-popup-content { margin: 12px 14px; }
  .pop-btns button { min-height: 42px; }
  .leaflet-popup-close-button { width: 36px !important; height: 36px !important; font-size: 22px !important; line-height: 34px !important; }

  /* ---------- NOTAMs panel: full width under the tabs, beside the toolbar ---------- */
  .notam-panel { left: 8px; right: 66px; width: auto; top: calc(68px + env(safe-area-inset-top, 0px));
    max-height: calc(100dvh - 200px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
  .notam-tools .toggle { min-height: 36px; }

  /* ---------- Weather radar bar: above the count box ---------- */
  .wx-bar { left: 8px; right: 8px; width: auto; transform: none; bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
  .wx-bar button { min-width: 40px; min-height: 40px; }

  /* ---------- Small text links (Show on map, Mark, Wiki…) get a taller tap area ---------- */
  .linkish { min-height: 32px; padding-top: 6px; padding-bottom: 6px; }
  .wv-seat { min-height: 34px; }
  #ob-others { width: 20px; height: 20px; }

  /* ---------- Window and cockpit views ---------- */
  .wv-views button, .wv-acts button { min-height: 38px; }
  .wv-level { min-height: 34px; }
  /* Cesium / Google credits must stay readable: under the title box, never under the controls */
  .wv-credits { max-width: calc(100vw - 90px); left: 12px; bottom: auto; top: calc(116px + env(safe-area-inset-top, 0px)); z-index: 6; }
  .wv-credits .cesium-widget-credits { position: static; }
  /* No floating title box over the view on phones: its facts are one line in the controls bar */
  .winview .wv-hud { display: none; }
  .wv-line { display: block; flex: 1 0 100%; text-align: center; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -4px; }
  .wv-line .wv-msg { color: var(--warn); }
  .wv-credits { top: calc(12px + env(safe-area-inset-top, 0px)); }
  .winview.deck3d .wv-credits { top: auto !important; bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important; left: 10px !important; right: auto !important; text-align: left; }
  .winview[data-frame="deck"] .wv-attrib { top: calc(170px + env(safe-area-inset-top, 0px)); left: 12px; right: auto; }
  .winview[data-frame="deck"] .wv-credits { top: calc(170px + env(safe-area-inset-top, 0px)); left: 12px; right: auto; text-align: left; }
  .winview[data-frame="deck"] .wv-look { top: calc(250px + env(safe-area-inset-top, 0px)); }

  /* ---------- Share dialog ---------- */
  #share-dlg { width: calc(100vw - 16px); max-width: none; margin: auto; box-sizing: border-box; }
  .share-actions button { min-height: 42px; }
}

/* ---------- Phone turned sideways (short screen): panel and tabs keep a fixed width on the left,
   the toolbar runs from the top, and the count box and legend move right of the panel ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar .mode-tabs { flex: 0 1 420px; }
  .topbar { justify-content: space-between; }
  #controls, .trips-panel, .tb-pop, .prefs-pop, .notam-panel { right: auto; width: 340px;
    max-height: calc(100dvh - 76px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
  .map-toolbar { top: calc(66px + env(safe-area-inset-top, 0px)); gap: 4px; }
  :root { --bar-h: 56px; --topbar-h: 56px; }
  .topbar .acct-btn { width: 42px; height: 42px; }
  .tb-btn { width: 50px; height: 40px; }
  #alt-legend { left: 356px; right: 66px; width: auto; transform: none; }
  #stats { left: 356px; right: 66px; max-width: 300px; }
  .wx-bar { left: 356px; right: 66px; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  /* The legend is narrower here: label only 0, 20,000 and 40,000+ */
  .tick[data-ft="10000"] b, .tick[data-ft="30000"] b { display: none; }
  /* Window views: the controls bar stops short of the Up/Down slider on the right.
     Cockpit: bar on top (two rows), title and credits below it. Windows: bar at the bottom. */
  .wv-bar, .winview[data-frame="deck"] .wv-bar { left: 12px; transform: none; width: calc(100vw - 100px); }
  .wv-bar { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .wv-look input { height: 110px; }
  .wv-credits { top: calc(86px + env(safe-area-inset-top, 0px)); }
  .winview[data-frame="deck"] .wv-credits { top: calc(200px + env(safe-area-inset-top, 0px)); }
  .winview[data-frame="deck"] .wv-look { top: calc(14px + env(safe-area-inset-top, 0px)); }
}
}

/* Very small phones (e.g. iPhone SE): a little tighter */
@media (max-width: 380px) {
  .topbar .mode-tabs button { font-size: 11.5px; }
  .tb-btn { width: 46px; height: 42px; }
  .tb-btn span { font-size: 8.5px; }
  #controls, .trips-panel, .tb-pop, .prefs-pop, .notam-panel { right: 60px; }
}
/* ---------- Phone menu (js/core/mobile-nav.js): a bar along the bottom instead of the section tabs ---------- */
.mnav, .mnav-sheet { display: none; }
/* inside the iPhone app the tab bar is native: no site bar and no room kept for it */
html.in-app .mnav, html.in-app .mnav-sheet { display: none !important; }
html.in-app body { padding-bottom: 0 !important; }
html.in-app .topbar .mode-tabs { display: none !important; }   /* the app's tab bar has the sections, in any orientation */
html.in-app .topbar { justify-content: space-between; padding-left: 12px; }
/* phones: the page itself never slides sideways (wide pieces scroll inside their own box, or are cut off) */
@media (max-width: 760px), (max-height: 500px) and (orientation: landscape) and (pointer: coarse) { html, body { overflow-x: clip; overscroll-behavior-x: none; } }
html.in-app, html.in-app body { overflow-x: clip; overscroll-behavior-x: none; }
/* inside the iPhone app the top bar is native too (js/core/app-bridge.js): no site top bar, nothing kept free for it */
html.in-app-bar { --bar-h: 0px; --topbar-h: 0px; }
html.in-app-bar .topbar { display: none !important; }
html.in-app-bar .acct-pop { top: 8px; }
/* the bell and Inbox panels fill the screen (Inbox gets Done at the top right; the bell's panel has its own ✕) */
html.in-app-bar .bell-pop { inset: 0; top: 0; left: 0; right: 0; bottom: 0; width: auto; max-height: none; border-radius: 0; border: 0; box-shadow: none; animation: none; }
html.in-app-bar .ib-pop { padding: 52px 18px 18px; }
#app-pop-done { display: none; }
html.in-app-bar #app-pop-done:not([hidden]) { display: block; position: fixed; top: 6px; right: 10px; z-index: 1070; border: 0; background: none; color: var(--accent);
  font: 600 17px/32px -apple-system, BlinkMacSystemFont, system-ui, sans-serif; padding: 0 8px; box-shadow: none; }
@media (max-width: 760px), (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  body.has-mnav { --mnav-h: calc(62px + env(safe-area-inset-bottom, 0px)); padding-bottom: var(--mnav-h); }
  /* from the first paint (not waiting for the script): no section tabs in the top bar on phones */
  .topbar .mode-tabs { display: none !important; }
  .topbar { justify-content: space-between; padding-left: 12px; }
  .topbar .tb-brand { display: flex; flex: 1; min-width: 0; color: var(--text); text-decoration: none; }
  .topbar .theme-sw { display: none; }
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }
  body.has-mnav .mnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--mnav-h);
    padding: 4px 4px env(safe-area-inset-bottom, 0px); box-sizing: border-box;
    background: var(--pop-bg, var(--night)); border-top: 1px solid var(--edge); box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  }
  .mnav button {
    flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 10.5px; padding: 4px 0; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mnav button[hidden] { display: none; }
  .mnav .mnav-ic { display: block; width: 50px; height: 30px; border-radius: 15px; font-style: normal; font-size: 21px; line-height: 30px; text-align: center; transition: background 0.15s; }
  .mnav [data-k="more"] .mnav-ic { font-size: 20px; color: var(--text); }
  .mnav button.on { color: var(--accent); font-weight: 700; }
  .mnav button.on .mnav-ic { background: color-mix(in srgb, var(--accent) 16%, transparent); }
  .mnav-n { position: absolute; top: 1px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box; border-radius: 8px;
    background: var(--accent); color: #fff; font: 700 9.5px/16px var(--font); font-style: normal; text-align: center; }
  .mnav-n[hidden] { display: none; }
  /* the More sheet */
  body.has-mnav .mnav-sheet:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 2590; }
  body.has-mnav .mnav { z-index: 2595; }
  body.has-mnav .tb-brand { color: var(--text); text-decoration: none; }
  /* the trip's Details sheet stops at the bar */
  body.has-mnav.has-sel .tp-side { bottom: var(--mnav-h); max-height: calc(78dvh - var(--mnav-h)); }
  html.in-app body.has-sel .tp-side { bottom: 0; max-height: 82dvh; }   /* the app has its own tab bar: sit on the bottom edge */
  .mnav-dim { position: absolute; inset: 0; background: rgba(8, 16, 32, 0.38); opacity: 0; transition: opacity 0.2s; }
  .mnav-panel { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 14px calc(var(--mnav-h) + 6px); background: var(--pop-bg, var(--night));
    border-radius: 20px 20px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2); transform: translateY(100%); transition: transform 0.22s ease;
    max-height: 80dvh; overflow-y: auto; box-sizing: border-box; }
  .mnav-sheet.open .mnav-dim { opacity: 1; } .mnav-sheet.open .mnav-panel { transform: none; }
  .mnav-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--edge); margin: 0 auto 8px; }
  .mnav-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 50px; padding: 0 6px; border: 0; background: transparent;
    color: var(--text); font: inherit; font-size: 15px; text-align: left; cursor: pointer; border-radius: 10px; box-sizing: border-box; }
  .mnav-item > .mnav-ic { width: 28px; flex: none; font-style: normal; font-size: 21px; text-align: center; }
  .mnav-item[aria-current="page"] { color: var(--accent); font-weight: 700; }
  .mnav-item[data-out] { color: var(--bad); }
  .mnav-theme > span:first-of-type { flex: 1; }
  .mnav-seg { display: inline-flex; border: 1px solid var(--edge); border-radius: 10px; overflow: hidden; }
  .mnav-seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 8px 12px; min-height: 36px; }
  .mnav-seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 700; }
  .mnav-sep { height: 1px; background: var(--edge); margin: 6px 0; }
  /* hide the bar where something covers the whole screen */
  body.has-mnav.wv-open .mnav, body.has-mnav.meet-mode .mnav, body.has-mnav.dv-open .mnav, body.has-mnav.gal-open .mnav { display: none; }
  /* the map page: its bottom pieces sit above the bar */
  body.has-mnav #alt-legend { bottom: calc(var(--mnav-h) + 6px); }
  body.has-mnav #stats { bottom: calc(var(--mnav-h) + 60px); }
  body.has-mnav .leaflet-bottom { bottom: calc(var(--mnav-h) + 50px); }
  body.has-mnav .wx-bar { bottom: calc(var(--mnav-h) + 150px); }
  body.has-mnav #controls, body.has-mnav .trips-panel, body.has-mnav .notam-panel, body.has-mnav .tb-pop, body.has-mnav .prefs-pop {
    max-height: calc(100dvh - 200px - var(--mnav-h) - env(safe-area-inset-top, 0px)); }
}
/* Phones: the section tabs scroll sideways when they don't all fit (never under the bell) */
@media (max-width: 760px) {
  .topbar .mode-tabs { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .topbar .mode-tabs::-webkit-scrollbar { display: none; }
  .topbar nav.mode-tabs a, .topbar nav.mode-tabs button { flex: 0 0 auto; padding-left: 10px; padding-right: 10px; white-space: nowrap; }
}
/* Country card: two tiles across on a phone held upright */
@media (max-width: 760px) { .cc-card .cc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }   /* beats trips-page.css, loaded later */
