/* ==========================================================================
   Adapt — on phones, things that would pop up next to a button open as a
   bottom sheet instead: dropdown menus, context menus, Moey dropdown lists
   (.form-select) and datepicker calendars. Same markup; nothing to add.

   Easier to reach with a thumb, never cut off at the screen edge, and you can
   drag it down (or tap outside) to close.
   data-moey-adapt="false" on the element, a parent or <html> keeps the pop-up.
   moey.js adds .is-sheet when it opens on a screen under 576px wide.
   ========================================================================== */

.is-sheet[popover] {
  --mo-menu-max-height: min(80dvh, calc(100dvh - 3rem));
  position: fixed;
  inset: auto 0 0 !important;
  width: 100%;
  min-width: 0 !important;
  max-width: none;
  max-height: var(--mo-menu-max-height);
  margin: 0;
  padding: 0 .75rem calc(.75rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--mo-bg-raised);
  border: 0;
  border-radius: var(--mo-radius-card) var(--mo-radius-card) 0 0;
  box-shadow: 0 -.5rem 2rem rgb(0 0 0 / .18);
  scale: none;
  transform-origin: bottom center;
  touch-action: pan-y;
}
.is-sheet[popover]::backdrop { background: rgb(0 0 0 / .4); }
html:has(.is-sheet:popover-open) { overflow: hidden; }

/* The handle (and the field's name, when it has one) — stays at the top while the list scrolls */
.is-sheet[popover]::before {
  position: sticky;
  top: 0;
  z-index: 3;
  display: block;
  flex-shrink: 0;
  min-height: 1.5rem;
  padding: 1.375rem .5rem .5rem;
  margin: 0 -.75rem .25rem;
  font-size: .9375rem;
  font-weight: var(--mo-font-weight-semibold, 600);
  color: var(--mo-fg-body);
  text-align: center;
  content: attr(data-sheet-title);
  background:
    linear-gradient(var(--mo-border-color-strong), var(--mo-border-color-strong)) center .625rem / 2.25rem 4px no-repeat,
    var(--mo-bg-raised);
  border-radius: 2px;
  cursor: grab;
}
.is-sheet[popover]:not([data-sheet-title])::before { padding-bottom: 0; min-height: 0; height: 1.5rem; }

/* Bigger targets for fingers */
.is-sheet .menu-item { min-height: 2.875rem; font-size: 1rem; }
.is-sheet .menu-header { padding-top: .75rem; }
.is-sheet .select-search { top: 3rem; margin-top: 0; padding-top: 0; }

/* A calendar in a sheet: centered, with larger days */
.datepicker.is-sheet { --mo-dp-cell: min(2.75rem, calc((100vw - 2rem) / 7)); }
.datepicker.is-sheet .datepicker-body,
.datepicker.is-sheet .datepicker-months { justify-content: center; }
.datepicker.is-sheet .datepicker-main { margin-inline: auto; }
.datepicker.is-sheet .datepicker-foot > .btn { min-height: 2.5rem; }

/* Slide up (the menu's own zoom is switched off) */
@media (prefers-reduced-motion: no-preference) {
  .is-sheet[popover]:popover-open { animation: mo-adapt-up .24s cubic-bezier(.2, .8, .2, 1); }
  .menu.is-sheet[popover] { transition: none; }
  .is-sheet[popover].is-dragging { animation: none; }
  @keyframes mo-adapt-up { from { translate: 0 100%; } }
}
.is-sheet[popover].is-dragging { transition: none; user-select: none; }
.is-sheet[popover].is-settling { transition: translate .2s ease; }

/* Touch: long-press opens a context menu, so don't let the phone's own callout take over */
@media (hover: none) { [data-moey-context] { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } }
