/* mobile-sheet.css — phone layout: bottom tab bar + bottom sheet.
   See the header in mobile-sheet.js. Only applies in the phone layout:
   (max-width: 640px), (pointer: coarse) and (orientation: portrait) and
   (max-width: 1100px) — phones and portrait touch tablets; the sheet and
   tab bar do not exist visually otherwise. */

.msheet, .msheet-tabs { display: none; }

@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  /* the left rail is replaced by the tab bar */
  #leftdock { display: none !important; }

  /* ── tab bar ─────────────────────────────────────────────── */
  .msheet-tabs {
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding: 6px 6px env(safe-area-inset-bottom, 0px);
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: start;
    background: var(--surface2); border-top: 1px solid var(--line);
    font-family: var(--font);
  }
  .msheet-tab {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    min-width: 0; height: 52px; padding: 2px 0 0; border: 0; background: transparent;
    color: var(--fg2); cursor: pointer; -webkit-tap-highlight-color: transparent;
    font: 500 11px/1.2 var(--font);
  }
  .msheet-pill {
    width: 52px; height: 30px; border-radius: 999px; display: grid; place-items: center;
    transition: background-color .2s ease, color .2s ease;
  }
  .msheet-pill svg { width: 20px; height: 20px; display: block; }
  .msheet-lab { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .msheet-tab[aria-selected="true"] { color: var(--fg); font-weight: 600; }
  .msheet-tab[aria-selected="true"] .msheet-pill { background: var(--accent); color: var(--accent-fg); }
  .msheet-tab:focus-visible { outline: none; }
  .msheet-tab:focus-visible .msheet-pill { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* ── sheet ───────────────────────────────────────────────── */
  .msheet {
    position: fixed; z-index: 30; left: 0; right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    height: 150px; max-height: calc(100% - 56px);
    display: flex; flex-direction: column;
    border-radius: 24px 24px 0 0;
    background: color-mix(in srgb, var(--surface2) 94%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(1.2); backdrop-filter: blur(18px) saturate(1.2);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 24px rgba(0, 21, 59, .12);
    color: var(--fg); font-family: var(--font);
    overflow: hidden;
  }
  .msheet.msheet-anim { transition: height .25s cubic-bezier(.2, .8, .2, 1); }
  .msheet.msheet-drag { transition: none; user-select: none; -webkit-user-select: none; }
  :root[data-theme="dark"] .msheet { box-shadow: 0 -6px 28px rgba(0, 0, 0, .45); }

  .msheet-grab {
    flex: none; height: 22px; display: grid; place-items: center;
    cursor: grab; touch-action: none; -webkit-tap-highlight-color: transparent;
  }
  .msheet-drag .msheet-grab { cursor: grabbing; }
  .msheet-grab:focus-visible { outline: none; }
  .msheet-grab:focus-visible .msheet-handle { outline: 2px solid var(--accent); outline-offset: 3px; }
  .msheet-handle {
    width: 40px; height: 5px; border-radius: 99px;
    background: color-mix(in srgb, var(--fg) 24%, transparent);
  }

  .msheet-body {
    flex: 1; min-height: 0; min-width: 0;
    overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
    touch-action: pan-y; -webkit-overflow-scrolling: touch;
    padding: 0 16px 18px;
    scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--fg) 22%, transparent) transparent;
  }
  .msheet-body::-webkit-scrollbar { width: 5px; }
  .msheet-body::-webkit-scrollbar-track { background: transparent; }
  .msheet-body::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 22%, transparent); border-radius: 99px; }

  /* the card lives in the sheet: no frame of its own */
  .msheet-body > .card {
    background: none; border: 0; border-radius: 0; box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
    padding: 0; min-width: 0; max-width: 100%; gap: 12px;
  }
  /* titles double as the drag handle */
  .msheet-body > #panel > h2, .msheet-body > #mission > h2, .msheet-body > #readout > h2,
  .msheet-body > #coastcard > h3:first-of-type, .msheet-body > #sv-panel > .card-head {
    touch-action: none; min-height: 28px; display: flex; align-items: center; gap: 6px;
  }
  .msheet-body .card > h2, .msheet-body .card > .card-head h2, .msheet-body #coastcard > h3:first-of-type {
    font: 700 17px/1.2 var(--font); letter-spacing: -.02em; color: var(--fg); text-transform: none;
  }
  .msheet-body #sv-close { display: none; }

  /* the waypoint list keeps a light frame under Survey controls */
  .msheet-body > #wp-card {
    margin-top: 12px; padding: 12px 14px;
    border: 1px solid var(--line); border-radius: 16px;
    background: color-mix(in srgb, var(--fg) 4%, transparent);
  }
  .msheet-body #wp-list { max-height: none; }
  .msheet-body .card-x { width: 40px; height: 40px; font-size: 20px; }

  /* ── touch sizes: 44–48 px targets ───────────────────────── */
  .msheet-body .sc-play { height: 48px; border-radius: 14px; font-size: 15px; }
  .msheet-body .sc-play svg { width: 16px; height: 16px; }
  .msheet-body .sc-actions { gap: 8px; }
  .msheet-body .ibtn { width: 44px; height: 44px; min-width: 40px; border-radius: 12px; }
  .msheet-body .ibtn.solid { width: 48px; height: 48px; border-radius: 14px; }
  .msheet-body .ibtn svg { width: 19px; height: 19px; }
  .msheet-body .sc-tools { margin: 0 -6px; }
  .msheet-body .sc-vals { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .msheet-body .sv { min-height: 52px; padding: 7px 2px; justify-content: center; }
  .msheet-body .sv .k { font-size: 11px; }
  .msheet-body .sv small { font-size: 11px; }
  /* 16px text keeps iOS from zooming into a focused field */
  .msheet-body #panel .sv input[type=number] { font-size: 16px; min-height: 26px; }
  .msheet-body .seg button { min-height: 44px; font-size: 14px; padding: 0 14px; }
  .msheet-body input[type=number], .msheet-body select.sel { height: 44px; font-size: 16px; border-radius: 12px; }
  .msheet-body .btn { min-height: 44px; font-size: 14px; border-radius: 12px; }
  .msheet-body .ctrl label { font-size: 11px; }
  .msheet-body .row { flex-wrap: wrap; }
  .msheet-body .hint { font-size: 12px; }
  .msheet-body .info { min-width: 22px; min-height: 22px; }

  /* readout: a bit roomier */
  .msheet-body #readout .depth { font-size: 34px; }
  .msheet-body #readout .where, .msheet-body #readout .srcline, .msheet-body #readout .coastline { font-size: 13px; }

  /* canvases take the sheet's width */
  .msheet-body canvas { width: 100%; max-width: 100%; }
}

/* setup (and sign-in) cover the dashboard: no tabs there */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  body:has(#setup:not([hidden])) .msheet,
  body:has(#setup:not([hidden])) .msheet-tabs,
  #app-root[hidden] .msheet, #app-root[hidden] .msheet-tabs { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .msheet.msheet-anim { transition: none; }
  .msheet-pill { transition: none; }
}

/* Integration: at peek height the sheet shows the title and the Simulate
   row (as in the mock); the region line is already in the top bar. */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  .msheet-body > #panel > .sc-actions { order: 1; }
  .msheet-body > #panel > :not(h2):not(.sc-actions) { order: 2; }
  .msheet-body > #panel > #region-name { display: none; }
}


/* ── Mission: Planner | Summary in one full-height sheet ──────────
   #ms-sbody lives in .msheet-msum on phones; the floating summary card
   is not needed there (app.js still toggles its hidden attribute). */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  html.msheet-on #map-wrap #ms-summary, html.msheet-on #ms-summary:not([hidden]) { display: none !important; }

  .msheet-body > #mission > h2 { justify-content: space-between; }
  .msheet-sub {
    margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font: 500 12px/1.2 var(--font); letter-spacing: 0; color: var(--fg2);
  }
  #mission .msheet-mseg { display: flex; width: 100%; }
  #mission .msheet-mseg button { flex: 1; min-height: 44px; font-weight: 600; }
  #mission .msheet-mseg button[aria-disabled="true"]:not([aria-pressed="true"]) { opacity: .5; }
  #mission .msheet-mseg button[aria-disabled="true"][aria-pressed="true"] { opacity: .7; }

  /* one view at a time */
  #mission.msheet-sum > .seg:not(.msheet-mseg), #mission.msheet-sum > #ms-body { display: none !important; }
  #mission:not(.msheet-sum) > .msheet-msum { display: none; }
  .msheet-msum { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .msheet-empty {
    margin: 4px 0 0; padding: 22px 16px; text-align: center;
    font: 500 14px/1.45 var(--font); color: var(--fg2);
    border: 1px dashed var(--line); border-radius: 16px;
  }
  .msheet-empty[hidden], .msheet-msum #ms-sbody[hidden] { display: none; }

  /* the summary scrolls with the sheet, not on its own */
  .msheet-msum #ms-sbody {
    flex: none; overflow: visible; padding: 0; gap: 12px; min-width: 0; max-width: 100%;
    -webkit-mask-image: none; mask-image: none;
  }
  .msheet-msum #ms-res { font-size: 13px; gap: 12px; }

  /* headline tiles */
  .msheet-msum #ms-res .tiles { gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msheet-msum #ms-res .ms-tile {
    min-height: 64px; padding: 10px 12px; border-radius: 14px; border-color: color-mix(in srgb, var(--fg) 12%, transparent);
    background: color-mix(in srgb, var(--fg) 4%, transparent);
  }
  .msheet-msum #ms-res .tl { font-size: 10.5px; }
  .msheet-msum #ms-res .tv { font-size: 18px; line-height: 1.3; }
  .msheet-msum #ms-res .ts { font-size: 11px; }

  /* folding sections: 44 px headers */
  .msheet-msum .ms-sec { padding-top: 0; border-top-color: color-mix(in srgb, var(--fg) 12%, transparent); }
  .msheet-msum .ms-sec > summary {
    min-height: 44px; font-size: 12px; -webkit-tap-highlight-color: transparent;
  }
  .msheet-msum .ms-sec > summary::after { width: 8px; height: 8px; margin-right: 6px; }
  .msheet-msum .ms-rows { gap: 8px 12px; margin: 2px 0 10px; }
  .msheet-msum #ms-res .k { font-size: 13px; }
  .msheet-msum #ms-res .v { font-size: 13px; }
  .msheet-msum #ms-res .big .v { font-size: 15px; }
  .msheet-msum #ms-res .ms-rows:has(.ms-pat) { gap: 8px; }

  /* compare patterns: big tappable rows */
  .msheet-msum .ms-pat {
    min-height: 56px; padding: 10px 14px; gap: 4px; justify-content: center;
    border-radius: 14px; border-color: color-mix(in srgb, var(--fg) 12%, transparent); -webkit-tap-highlight-color: transparent;
  }
  .msheet-msum .ms-pat.pick { border-color: var(--accent2); }
  .msheet-msum .mp-name { font-size: 15px; }
  .msheet-msum .mp-cov { font-size: 14px; }
  .msheet-msum .mp-sub { font-size: 12px; }
  .msheet-msum .ms-warn { font-size: 13px; padding: 10px 12px; border-radius: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .msheet-msum .ms-sec > summary::after, .msheet-msum .ms-pat { transition: none; }
}

/* Integration: with the sheet at full height, notifications move from the
   top (where they would cover the sheet's title, switch and first tiles) to
   just above the tab bar. */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  html:has(#msheet[data-snap="full"]) #toasts {
    top: auto; bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 10px);
    flex-direction: column-reverse;
  }
}

/* Portrait tablets (phone layout, wider than a phone): the sheet keeps the
   full width, its content stays in a readable centred column. */
@media (pointer: coarse) and (orientation: portrait) and (min-width: 641px) and (max-width: 1100px) {
  .msheet-body { padding-left: max(24px, calc((100% - 680px) / 2)); padding-right: max(24px, calc((100% - 680px) / 2)); }
  .msheet-tab { font-size: 12px; }
}

/* ── Phone landscape (a phone on its side, at most 500 px tall) ──────
   The tab bar becomes a rail on the left (under the top bar) and the
   sheet a side panel on the right that slides open or closed
   (mobile-sheet.js: peek = closed, half/full = open; it publishes
   --m-sheet-w, the px covered at the right). Widths: --mland-rail and
   --mland-side, defined in mobile-map.css.
   Every rule also needs html.mland-on (zero specificity via :where()):
   mobile-sheet.js decides landscape, and keeps portrait while a field is
   typed into on an upright phone whose keyboard shrinks the page. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  :where(html.mland-on) .msheet-tabs {
    top: var(--mmap-top, 48px); right: auto; bottom: 0; left: 0;
    width: var(--mland-rail, 64px); height: auto;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px)) calc(4px + env(safe-area-inset-left, 0px));
    grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(5, minmax(0, 1fr));
    align-items: center; align-content: stretch;
    border-top: 0; border-right: 1px solid var(--line);
  }
  :where(html.mland-on) .msheet-tab { height: 100%; max-height: 64px; justify-content: center; gap: 2px; padding: 0; font-size: 10px; }
  :where(html.mland-on) .msheet-pill { width: 44px; height: 28px; }

  :where(html.mland-on) .msheet {
    top: var(--mmap-top, 48px); bottom: 0; left: auto; right: 0;
    width: var(--mland-side, 340px); height: auto !important; max-height: none;
    border-radius: 20px 0 0 0;
    border-top: 0; border-left: 1px solid var(--line);
    box-shadow: -6px 0 24px rgba(0, 21, 59, .12);
  }
  :root:where(.mland-on)[data-theme="dark"] .msheet { box-shadow: -6px 0 28px rgba(0, 0, 0, .45); }
  :where(html.mland-on) .msheet.msheet-anim { transition: transform var(--mland-ease, .25s ease), visibility 0s linear .25s; }
  :where(html.mland-on) .msheet.msheet-anim:not(.msheet-closed) { transition: transform var(--mland-ease, .25s ease); }
  :where(html.mland-on) .msheet.msheet-closed { visibility: hidden; }

  /* the handle runs down the panel's left edge: swipe right to close */
  :where(html.mland-on) .msheet-grab { position: absolute; z-index: 1; left: 0; top: 0; bottom: 0; width: 20px; height: auto; }
  :where(html.mland-on) .msheet-handle { width: 5px; height: 40px; }
  :where(html.mland-on) .msheet-body { padding: 14px calc(14px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) 22px; }
  :where(html.mland-on) .msheet-body .sc-vals { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* notifications: top of the free map area, whatever the snap */
  :where(html.mland-on) #toasts, html:where(.mland-on):has(#msheet[data-snap="full"]) #toasts {
    top: calc(var(--mmap-top, 48px) + 8px); bottom: auto; flex-direction: column;
    left: calc(var(--mland-rail, 64px) + (100vw - var(--mland-rail, 64px) - var(--m-sheet-w, 0px)) / 2);
    width: min(440px, calc(100vw - var(--mland-rail, 64px) - var(--m-sheet-w, 0px) - 24px));
  }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) and (prefers-reduced-motion: reduce), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) and (prefers-reduced-motion: reduce) {
  .msheet.msheet-anim, .msheet.msheet-anim:not(.msheet-closed) { transition: none; }
}
