/**
 * Bottom Sheet Modal Component
 * Draggable/Expandable modal that appears from bottom
 * Snap points: hidden, collapsed (30vh), expanded (90vh)
 */

:root {
  --bottom-sheet-snap-collapsed: 30;
  --bottom-sheet-snap-half: 60;
  --bottom-sheet-snap-expanded: 90;
  --bottom-sheet-transition-duration: 350ms;
  --bottom-sheet-transition-timing: cubic-bezier(0.34, 1.56, 0.64, 1);
  --bottom-sheet-handle-height: 44px;
  --bottom-sheet-z-index: 1000;
  --bottom-sheet-vh-unit: 1vh;
}

@supports (height: 1dvh) {
  :root {
    --bottom-sheet-vh-unit: 1dvh;
  }
}

/* ============================================
   Overlay / Backdrop
   ============================================ */

.bottom-sheet-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgb(0 0 0 / 55%);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--bottom-sheet-transition-duration) ease-out;
  z-index: calc(var(--bottom-sheet-z-index) - 1);
  will-change: opacity;
}

.bottom-sheet-overlay[data-state="open"] {
  opacity: 1;
  pointer-events: auto;
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .bottom-sheet-overlay[data-state="open"] {
    -webkit-backdrop-filter: blur(1.5px);
    backdrop-filter: blur(1.5px);
  }
}

/* ============================================
   Bottom Sheet Container
   ============================================ */

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: calc(95 * var(--bottom-sheet-vh-unit));
  background-color: var(--card);
  color: var(--card-foreground);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.1);
  z-index: var(--bottom-sheet-z-index);
  transform: translateY(100%);
  transition: transform var(--bottom-sheet-transition-duration) var(--bottom-sheet-transition-timing);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  touch-action: auto;
  user-select: text;
  will-change: transform, height;
}

/* Prevent body scroll when sheet is open */
body.bottom-sheet--open {
  overscroll-behavior: none;
}

/* State: hidden (default) */
.bottom-sheet[data-state="hidden"] {
  transform: translateY(100%);
  pointer-events: none;
}

/* State: collapsed */
.bottom-sheet[data-state="collapsed"] {
  height: calc(var(--bottom-sheet-snap-collapsed) * var(--bottom-sheet-vh-unit));
  transform: translateY(0);
  pointer-events: auto;
}

/* State: half */
.bottom-sheet[data-state="half"] {
  height: calc(var(--bottom-sheet-snap-half) * var(--bottom-sheet-vh-unit));
  transform: translateY(0);
  pointer-events: auto;
}

/* State: expanded */
.bottom-sheet[data-state="expanded"] {
  height: calc(var(--bottom-sheet-snap-expanded) * var(--bottom-sheet-vh-unit));
  transform: translateY(0);
  pointer-events: auto;
}

/* Dragging state (no transition during drag) */
.bottom-sheet[data-dragging="true"] {
  transition: none;
}

/* ============================================
   Grab Handle
   ============================================ */

.bottom-sheet__handle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--bottom-sheet-handle-height);
  cursor: grab;
  padding: 12px 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.bottom-sheet__handle:active {
  cursor: grabbing;
}

.bottom-sheet__handle-bar {
  display: block;
  width: 40px;
  height: 4px;
  background-color: var(--muted-foreground);
  border-radius: 2px;
  opacity: 0.6;
}

/* ============================================
   Header
   ============================================ */

.bottom-sheet__header {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.bottom-sheet__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--card-foreground);
}

/* ============================================
   Content (Scrollable)
   ============================================ */

.bottom-sheet__content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

/* Smooth scrolling */
.bottom-sheet__content {
  scroll-behavior: smooth;
}

/* ============================================
   Animations & Transitions
   ============================================ */

/* Spring-like easing for snap animation */
@keyframes bottomSheetSnap {
  0% {
    transform: translateY(var(--y-start));
  }
  100% {
    transform: translateY(0);
  }
}

/* ============================================
   Responsive
   ============================================ */

/* On smaller screens, limit max-height */
@media (max-height: 600px) {
  :root {
    --bottom-sheet-snap-collapsed: 50;
    --bottom-sheet-snap-half: 75;
    --bottom-sheet-snap-expanded: 95;
  }
}

/* ============================================
   Dark/Light Theme Support
   ============================================ */

body[data-theme="dark"] .bottom-sheet {
  background-color: var(--card);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
}

body[data-theme="light"] .bottom-sheet {
  background-color: var(--card);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

/* ============================================
   Accessibility
   ============================================ */

.bottom-sheet:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: -2px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .bottom-sheet,
  .bottom-sheet-overlay {
    transition: none !important;
  }
}
