/* ============================================================
 * Bottom Sheet — Phase 10 Sprint 0 (2026-05-09)
 *
 * Pattern modal natif iOS/Android. Sur mobile (< lg = < 1024px),
 * le sheet glisse depuis le bas avec drag-to-dismiss, snap points
 * (peek 25%, half 50%, full 90vh), backdrop blur.
 *
 * Sur desktop (>= lg), bascule en modal centered classique pour
 * cohérence avec le reste de l'app (`.bs-sheet--desktop-modal`).
 *
 * Driver Stimulus : `app/javascript/controllers/bottom_sheet_controller.js`.
 * ============================================================ */

/* ---- Backdrop -------------------------------------------------- */
.bs-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 1040; /* under sheet, above content */
  pointer-events: auto;
}

.bs-backdrop--visible {
  opacity: 1;
}

/* ---- Sheet container ------------------------------------------- */
.bs-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1050;
  background: var(--bg-surface, #ffffff);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
  /* Lock to viewport bottom */
  max-height: 90dvh;
  max-height: 90vh; /* fallback older browsers */
}

.bs-sheet[hidden] {
  display: none !important;
}

.bs-sheet--open {
  transform: translateY(0);
}

/* Snap points — height + max-height */
.bs-sheet--peek {
  max-height: 25dvh;
  max-height: 25vh;
}
.bs-sheet--half {
  max-height: 55dvh;
  max-height: 55vh;
}
.bs-sheet--full {
  max-height: 90dvh;
  max-height: 90vh;
}

/* ---- Handle (drag area) ---------------------------------------- */
.bs-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.75rem 0 0.5rem;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.bs-handle::before {
  content: "";
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: var(--text-tertiary, #cbd5e1);
}

.bs-handle:active {
  cursor: grabbing;
}

/* ---- Header (title + close button) ----------------------------- */
.bs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
}

.bs-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.bs-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-surface-hover, #f8fafc);
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s;
}

.bs-close:hover,
.bs-close:focus-visible {
  background: var(--border-default, #e2e8f0);
  outline: none;
}

/* ---- Content (scrollable) -------------------------------------- */
.bs-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1.25rem 1.5rem;
}

.bs-footer {
  border-top: 1px solid var(--border-light, #f1f5f9);
  padding: 0.875rem 1.25rem;
  background: var(--bg-surface);
  /* Always visible above safe-area */
  padding-bottom: max(0.875rem, env(safe-area-inset-bottom));
}

/* ---- Scroll lock body when sheet open -------------------------- */
body.bs-scroll-lock {
  overflow: hidden;
  /* Prevent iOS bounce-scroll behind backdrop */
  position: fixed;
  width: 100%;
}

/* ---- Desktop fallback : centered modal ------------------------- */
@media (min-width: 1024px) {
  .bs-sheet--desktop-modal {
    left: 50%;
    right: auto;
    bottom: 50%;
    transform: translate(-50%, 50%) scale(0.95);
    width: min(90vw, 560px);
    max-height: 80vh;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    opacity: 0;
  }

  .bs-sheet--desktop-modal.bs-sheet--open {
    transform: translate(-50%, 50%) scale(1);
    opacity: 1;
  }

  /* Hide drag handle on desktop — useless without touch */
  .bs-sheet--desktop-modal .bs-handle {
    display: none;
  }
}

/* ---- Reduced motion -------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .bs-sheet,
  .bs-backdrop,
  .bs-sheet--desktop-modal {
    transition: none !important;
  }
}
