/* =============================================================================
   Bottom sheet
   -----------------------------------------------------------------------------
   Replaces both Bootstrap offcanvases. Three snap points (peek / half / full)
   driven by a translateY on a fixed, full-height element — so dragging never
   reflows, and the collapsing iOS URL bar cannot make it jump.

   Above 900px the same element becomes a docked side panel; only CSS changes,
   the component's JS is identical.
   ========================================================================== */

.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;

  height: 92dvh;
  max-height: 92dvh;

  background: var(--surface);
  border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-3);

  /* Start fully off-screen; sheet.js drives this variable. */
  --sheet-y: 100%;
  transform: translate3d(0, var(--sheet-y), 0);
  transition: transform var(--dur-slow) var(--ease);
  will-change: transform;

  overscroll-behavior: contain;
  touch-action: pan-y;
}
.sheet[data-dragging="true"] { transition: none; }
.sheet[hidden] { display: none; }

/* --------------------------------- Grabber ------------------------------- */

.sheet-grab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  cursor: grab;
  touch-action: none;   /* the drag handler owns this gesture entirely */
}
.sheet-grab::before {
  content: '';
  width: 40px; height: 5px;
  border-radius: var(--r-full);
  background: var(--border-strong);
}
.sheet[data-dragging="true"] .sheet-grab { cursor: grabbing; }

/* --------------------------------- Header -------------------------------- */

.sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3) var(--sp-2);
  min-height: 44px;
  touch-action: none;   /* dragging from the header works too */
}
.sheet-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-sub {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-dim);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------- Body --------------------------------- */

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 var(--sp-3);
  padding-bottom: calc(var(--sp-6) + var(--safe-b));
}
/* At the peek snap there is nothing to scroll to — lock it so a downward drag
   moves the sheet instead of fighting a scroll container that cannot move. */
.sheet[data-snap="peek"] .sheet-body { overflow-y: hidden; }

/* A one-line summary shown at the peek snap, so the map stays usable. */
.sheet-peek {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4) var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}
/* :not([hidden]) matters — this selector outranks the UA's [hidden] rule, so
   without it a view that has no peek summary still reserves the empty row. */
.sheet[data-snap="peek"] .sheet-peek:not([hidden]) { display: flex; }
.sheet:not([data-snap="peek"]) .sheet-peek { display: none; }

/* --------------------------- Sticky action bar --------------------------- */

.sheet-actions {
  flex: 0 0 auto;
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  padding-bottom: calc(var(--sp-2) + var(--safe-b));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.sheet-actions > * { flex: 1 1 0; min-width: 0; }

/* -------------------------------- Views ---------------------------------- */
/* Views are swapped inside one sheet so the drag/snap logic exists once. */

.view { animation: view-in var(--dur) var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

/* ------------------------------- Desktop --------------------------------- */

@media (min-width: 900px) {
  .sheet {
    top: calc(var(--topbar-h) + var(--safe-t) + var(--sp-3));
    bottom: calc(var(--sp-3) + var(--safe-b));
    left: calc(var(--sp-3) + var(--safe-l));
    right: auto;
    width: 400px;
    height: auto;
    max-height: none;
    border-radius: var(--r-xl);
    border: 1px solid var(--border);

    /* Slide horizontally instead of vertically; --sheet-x is set by sheet.js. */
    --sheet-x: 0%;
    transform: translate3d(var(--sheet-x), 0, 0);
  }
  .sheet-grab { display: none; }
  .sheet-head { padding-top: var(--sp-3); }
  .sheet-peek { display: none !important; }
  .sheet[data-snap="peek"] .sheet-body { overflow-y: auto; }

  .dock {
    left: calc(var(--sp-3) + var(--safe-l) + 400px + var(--sp-3));
    transform: none;
  }
  .dock[data-tucked="true"] { transform: translateY(calc(100% + var(--sp-6))); }
  /* With the panel docked open the map's usable centre shifts right. */
  .resume-follow { left: calc(50% + 200px); }
}
