/* Bottom Sheet component styles */

/* Design tokens for the bottom sheet */
:root {
  /* Layout */
  --bottom-sheet-max-height: 60vh;
  --sheet-offset: 0px; /* pushes map controls when sheet is open */
  /* Safe area (iOS home indicator) */
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);

  /* Handle */
  --sheet-handle-w: 40px;
  --sheet-handle-h: 4px;
  --sheet-handle-radius: 2px;
  --sheet-handle-margin: 8px; /* 2px top + 6px bottom */

  /* Header */
  --sheet-header-padding-y: 8px; /* was 15px */
  --sheet-header-padding-x: 20px;
  --sheet-header-border: 1px;
  --sheet-header-content-h: 32px; /* actual height of header content */

  /* Search */
  --sheet-search-h: 30px; /* was 34px */

  /* DataTables wrapper */
  --dt-wrapper-pt: 16px;

  /* Safety gap (scrollbar / rounding buffer) */
  --sheet-safety-gap: 4px; /* was 6px */

  /* Derived metrics */
  --sheet-offset-y: calc(
    var(--sheet-handle-h) + var(--sheet-handle-margin) + (var(--sheet-header-padding-y) * 2) +
    var(--sheet-search-h) + var(--sheet-header-border) + var(--dt-wrapper-pt) + var(--sheet-safety-gap) + var(--safe-area-bottom)
  );
  --sheet-collapsed-h: calc(
    var(--sheet-handle-h) + var(--sheet-handle-margin) + (var(--sheet-header-padding-y) * 2) +
    var(--sheet-header-border) + var(--sheet-header-content-h) + var(--sheet-safety-gap) + var(--safe-area-bottom)
  );
}

/* Keep Leaflet controls lifted above the sheet */
.leaflet-bottom.leaflet-left,
.leaflet-bottom.leaflet-right {
  bottom: var(--sheet-offset);
  transition: bottom var(--duration-medium) var(--timing-ease);
}

/* Overlay */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: calc(var(--z-sheet) - 1);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-medium) var(--timing-ease);
}

.sheet-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Bottom Sheet panel */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(60dvh - env(safe-area-inset-bottom)); /* Moderne Einheiten für mobile Safari */
  display: flex;
  flex-direction: column;
  background: var(--color-white);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-sheet);
  transition: transform var(--duration-medium) var(--timing-ease);
  overflow: hidden;
  will-change: transform;
  max-width: 100vw;
  --sheet-translate: 0px;
  transform: translateY(var(--sheet-translate))
}

.bottom-sheet.collapsed {
  --sheet-translate: calc(100% - var(--sheet-collapsed-h))
}

.bottom-sheet.expanded {
  --sheet-translate: 0px
}

.sheet-handle {
  width: var(--sheet-handle-w);
  height: var(--sheet-handle-h);
  background: var(--color-border-lighter);
  border-radius: var(--sheet-handle-radius);
  margin: 2px auto 6px;
}

.sheet-header {
  padding: var(--sheet-header-padding-y) var(--sheet-header-padding-x);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to bottom, var(--color-white), #f8f9fa);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  max-width: 100%;
  min-height: var(--sheet-header-content-h);
}

.header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title strong {
  font-size: 16px;
  line-height: 1.2;
}

#destCount {
  font-size: 12px;
  color: #666;
  line-height: 1.2;
  display: block; /* Reserve height to keep header stable */
  min-height: 1.2em;
}

/* iOS zoom-avoid font-size 16px */
.sheet-search {
  flex: 0 0 200px; /* width constraint */
  height: var(--sheet-search-h); /* explicit height */
  line-height: calc(var(--sheet-search-h) - 2px);
  padding: 4px 8px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.bottom-sheet.collapsed .sheet-search {
  display: none;
}

.sheet-content {
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0; /* allow proper flexbox scrolling children */
  /* Prevent scroll chaining to the page and provide momentum on iOS */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Scope DataTables tweaks to the bottom sheet to avoid global side effects */
.bottom-sheet .dataTables_wrapper {
  padding: 16px;
}

.bottom-sheet table.dataTable {
  width: 100% !important;
}

.bottom-sheet table.dataTable thead th {
  background: #f8f9fa;
}

.bottom-sheet div.dt-search {
  display: none !important;
}

/* Improve mobile scrolling within DataTables scroll body */
.bottom-sheet .dataTables_scrollBody {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

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