/* Responsive shell: desktop sidebar, tablet drawer, mobile fires dialog */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  overflow-x: hidden;
}

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--header-h);
  padding: 0 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: var(--z-header);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-right: 4px;
}

.header-logo {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  border-radius: 50%;
  background: #fff6e8;
  box-shadow: 0 0 0 1px rgb(230 140 40 / 0.28);
}

.header-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.header-updated {
  color: var(--text-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  margin-right: auto;
}

.app-body {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #1b2838;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  min-width: 240px;
  max-width: min(560px, 80vw);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  min-height: 0;
  position: relative;
  z-index: var(--z-drawer);
}

.sidebar-resizer {
  flex-shrink: 0;
  width: 8px;
  margin-left: -4px;
  cursor: col-resize;
  touch-action: none;
  position: relative;
  z-index: calc(var(--z-drawer) + 1);
  background: transparent;
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  border-radius: 1px;
  background: transparent;
}

.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after,
.sidebar-resizer.is-dragging::after {
  background: var(--accent);
}

body.sidebar-collapsed .sidebar,
body.sidebar-collapsed .sidebar-resizer {
  display: none;
}

.sidebar-scroll {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.drawer-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--overlay);
  z-index: calc(var(--z-drawer) - 1);
  border: 0;
  padding: 0;
}

.btn.hamburger {
  display: inline-flex;
}

.overflow-wrap {
  position: relative;
}

.overflow-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
}

.overflow-wrap.is-open .overflow-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn.header-more,
.btn.header-fires {
  display: none;
}

.panel-chrome {
  display: none;
}

/* Desktop / tablet: in-flow sidebar, toggled by the header menu button */
@media (min-width: 768px) {
  .sidebar {
    height: 100%;
  }
}

/* Mobile <768: full-screen map; search/lists open as a dialog */
@media (max-width: 767px) {
  .header {
    height: var(--header-h-mobile);
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .header-title {
    font-size: 1rem;
  }

  .header-logo {
    width: 30px;
    height: 30px;
  }

  .header-updated,
  .header .header-desktop-only,
  .header .menu.header-desktop-only {
    display: none;
  }

  .btn.header-more,
  .btn.header-fires {
    display: inline-flex;
  }

  body.panel-open .header-fires {
    background: var(--surface-hover);
  }

  .btn.hamburger,
  .sidebar-resizer {
    display: none !important;
  }

  .panel-chrome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    padding: 4px 8px 4px 14px;
    border-bottom: 1px solid var(--border);
  }

  .panel-chrome-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
  }

  .sidebar {
    display: none;
    position: absolute;
    left: 8px;
    right: 8px;
    top: 8px;
    bottom: auto;
    width: auto;
    height: min(88dvh, calc(100% - 16px));
    max-height: calc(100% - 16px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    z-index: var(--z-modal);
    transform: none;
    padding-bottom: env(safe-area-inset-bottom);
  }

  body.panel-open .sidebar {
    display: flex;
  }

  body.panel-open .drawer-backdrop {
    display: block;
    z-index: calc(var(--z-modal) - 1);
  }

  .sidebar-scroll {
    overflow-y: auto;
  }

  .leaflet-bottom {
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .timeline-dock {
    left: 8px;
    right: 8px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
  }

  body.timeline-open .near-me-fab {
    display: none;
  }

  body.timeline-open .leaflet-bottom {
    bottom: calc(148px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
