/* Linear Design Tokens */
:root {
  --canvas: #08090a;
  --surface-1: #141516;
  --surface-2: #1c1d1f;
  --surface-3: #232428;
  --divider: #23252a;
  --primary: #5e6ad2;
  --primary-pressed: #4f58b8;
  --primary-tint: rgba(94, 106, 210, 0.16);
  --text-primary: #f7f8f8;
  --text-secondary: #8a8f98;
  --text-tertiary: #5c5f6a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  --touch-target: 48px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Roboto", "Segoe UI", sans-serif;
  background-color: var(--canvas);
  color: var(--text-primary);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  user-select: none;
}

/* App Header & Segmented Tabs */
.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: var(--safe-top) 16px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(8, 9, 10, 0.9) 0%, rgba(8, 9, 10, 0) 100%);
  pointer-events: none;
}

.app-header > * {
  pointer-events: auto;
}

.nav-tabs {
  display: flex;
  background: rgba(20, 21, 22, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid var(--divider);
  border-radius: var(--radius-pill);
  padding: 4px;
}

.tab-btn {
  height: 38px;
  padding: 0 16px;
  min-width: 44px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.tab-btn.active {
  background: var(--surface-3);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-action-label {
  height: 38px;
  padding: 0 14px;
  min-width: 44px;
  border-radius: var(--radius-pill);
  background: rgba(20, 21, 22, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--divider);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-action-label:hover {
  background: var(--surface-3);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-action-label:active {
  transform: scale(0.96);
}

.btn-primary-highlight {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}

.btn-primary-highlight:hover {
  background: var(--primary-pressed) !important;
}

.btn-icon {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-pill);
  background: rgba(20, 21, 22, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid var(--divider);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:active {
  transform: scale(0.94);
  background: var(--surface-3);
}

/* Active Panorama Title & Metadata HUD Badge */
.active-pano-hud {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: rgba(20, 21, 22, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--divider);
  border-radius: var(--radius-pill);
  padding: 4px 14px;
  min-height: 38px;
  max-width: 420px;
  text-align: left;
  pointer-events: auto;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  transition: all 0.2s ease;
}

.hud-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hud-edit-btn {
  background: var(--surface-3);
  border: 1px solid var(--divider);
  color: var(--text-primary);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.hud-edit-btn:hover {
  background: var(--primary-tint);
  border-color: var(--primary);
}

.active-pano-hud .hud-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.25;
}

.active-pano-hud .hud-meta {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.2;
  margin-top: 1px;
}

@media (max-width: 640px) {
  .app-header {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: max(8px, env(safe-area-inset-top)) 12px 6px 12px;
  }
  .nav-tabs {
    order: 1;
    padding: 3px;
  }
  .tab-btn {
    height: 34px;
    padding: 0 10px;
    font-size: 13px;
  }
  .header-actions {
    order: 2;
    gap: 6px;
  }
  .btn-action-label {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }
  .active-pano-hud {
    order: 3;
    width: 100%;
    max-width: 100%;
    justify-content: space-between;
    margin-top: 2px;
    padding: 4px 12px;
  }
  .active-pano-hud .hud-title {
    max-width: 220px;
    font-size: 12px;
  }
  .active-pano-hud .hud-meta {
    font-size: 10px;
  }
}

/* Tab Views */
.view-container {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.view-container.hidden {
  display: none !important;
}

#panorama-container {
  width: 100%;
  height: 100%;
  background: #000;
}

#map-container {
  width: 100%;
  height: 100%;
  background: var(--canvas);
}

/* Floating Bottom Control Deck */
.floating-deck {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 68px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 21, 22, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--divider);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* When the sheet is expanded, hide the floating deck smoothly so it never blocks the gallery grid */
.floating-deck.sheet-open,
.bottom-sheet:not(.collapsed) ~ .floating-deck,
#viewer-view:has(.bottom-sheet:not(.collapsed)) .floating-deck {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(24px);
}

.deck-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.15s ease;
}

.deck-btn:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

.deck-btn.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 0 12px var(--primary-tint);
}

/* Retractable Bottom Sheet / Full Gallery Sheet */
.bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1050;
  height: 72vh;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: rgba(14, 15, 17, 0.96);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--divider);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.65);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
  touch-action: pan-y;
}

/* Collapsed peek state: shows only the handle zone and filter bar (60px) + safe bottom */
.bottom-sheet.collapsed {
  transform: translateY(calc(100% - 62px - var(--safe-bottom)));
}

.sheet-handle-zone {
  width: 100%;
  padding: 8px 0 4px 0;
  cursor: grab;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
}

.sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--text-tertiary);
  transition: background 0.2s ease, width 0.2s ease;
}

.sheet-handle-zone:hover .sheet-handle,
.sheet-handle-zone:active .sheet-handle {
  background: var(--text-secondary);
  width: 52px;
}

.sheet-header {
  flex-shrink: 0;
  padding: 2px 14px 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.album-filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.album-filter-bar::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  border: 1px solid var(--divider);
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  min-height: 32px;
}
.chip-btn.active {
  background: var(--primary-tint);
  border-color: var(--primary);
  color: var(--text-primary);
}

.chip-action {
  background: rgba(94, 106, 210, 0.15) !important;
  border: 1px dashed var(--primary) !important;
  color: #c4c9ff !important;
  font-weight: 600 !important;
}
.chip-action:hover {
  background: rgba(94, 106, 210, 0.3) !important;
}

.gallery-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 14px calc(var(--safe-bottom) + 24px) 14px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
  }
}

.gallery-card {
  position: relative;
  height: 130px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.gallery-card:active {
  transform: scale(0.97);
}

.gallery-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 16px rgba(94, 106, 210, 0.5);
}

.gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-card .card-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 10px 6px 10px;
  background: linear-gradient(180deg, transparent 0%, rgba(8, 9, 10, 0.92) 100%);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gallery-card .card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.gallery-card .card-meta {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  gap: 4px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface-1);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.modal-card h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input, .form-select {
  width: 100%;
  height: 44px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0 12px;
  font-size: 14px;
}

.btn-primary {
  width: 100%;
  height: var(--touch-target);
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary:active {
  background: var(--primary-pressed);
}

/* Leaflet dark styling */
.leaflet-popup-content-wrapper {
  background: var(--surface-1) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--divider);
  border-radius: var(--radius-md) !important;
}
.leaflet-popup-tip {
  background: var(--surface-1) !important;
}
