/* ============================================================================
   MAP VIEW - Grid/Map Toggle & Map Container (Step 9)
   ============================================================================ */

/* Header Row 2: 5-Column Layout */
.header-row-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 16px 12px;
}

/* Spacers - flexible width to balance layout */
.header-spacer {
  flex: 1;
}

/* Keep actions core centered */
.header-actions-core {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* View Toggle Container */
.header-view-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 4px;
  flex-shrink: 0;
}

/* View Toggle Buttons */
.view-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  color: rgba(255, 255, 255, 0.5);
}

.view-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}

.view-toggle-btn:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* Active toggle state */
.view-toggle-btn.active {
  background: white;
  color: var(--primary);
}

.view-toggle-btn.active:hover {
  background: rgba(255, 255, 255, 0.95);
}

/* SVG icon in grid button */
.view-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* Map emoji icon */
.view-toggle-btn .map-icon {
  font-size: 18px;
  line-height: 1;
}

/* Hide toggle in Single Yoink View */
.single-yoink-active .header-view-toggle {
  display: none;
}

/* ============================================================================
   MAP CONTAINER
   ============================================================================ */

.map-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 180px); /* Account for header */
  min-height: 400px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-secondary);
  box-shadow: 0 2px 8px var(--shadow);
}

.google-map {
  width: 100%;
  height: 100%;
}

/* Center on Me Button */
.center-on-me-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: white;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: all 0.2s;
  z-index: 10;
}

.center-on-me-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  transform: scale(1.05);
}

.center-on-me-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================================================
   MAP SLOT (Container inside each panel where map moves to)
   ============================================================================ */

.map-slot {
  /* Empty by default - only contains map when map view is active */
  display: block;
  position: relative; /* For positioning map controls overlay */
}

/* When map is inside the slot, it fills the available space */
.map-slot .map-container {
  margin: 0;
  border-radius: 12px;
}

/* ============================================================================
   MAP CONTROLS OVERLAY - Floating buttons on map
   ============================================================================ */

.map-controls-overlay {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: white;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  color: var(--leather-mid, #5D4037);
  transition: all 0.2s ease;
}

.map-control-btn:hover {
  background: #f5f5f5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.map-control-btn:active {
  transform: scale(0.95) translateY(0);
}

.map-control-btn:focus-visible {
  outline: 2px solid var(--brass, #B8860B);
  outline-offset: 2px;
}

.map-control-btn svg {
  width: 20px;
  height: 20px;
}

/* Loading state for zoom to position button */
.map-control-btn.loading {
  pointer-events: none;
  background: #f0f0f0;
}

.map-control-btn.loading svg {
  animation: spin 0.8s linear infinite;
}

/* Unavailable state (location not available) */
.map-control-btn.unavailable {
  background: #fee2e2;
  color: #dc2626;
}

.map-control-btn.unavailable svg {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* Legacy center-on-me-btn styles for backwards compatibility */
.center-on-me-btn:active {
  transform: scale(0.95);
}

.center-on-me-btn svg {
  width: 20px;
  height: 20px;
}

/* Loading state for center button */
.center-on-me-btn.loading {
  pointer-events: none;
}

.center-on-me-btn.loading svg {
  animation: spin 0.8s linear infinite;
}

/* ============================================================================
   MAP VIEW STATE - Show/Hide Logic
   ============================================================================ */

/* When map is active, hide grid and show map */
.map-view-active .yoinks-grid,
.map-view-active #yoinks-grid,
.map-view-active #category-yoinks-grid,
.map-view-active #user-yoinks-grid,
.map-view-active #location-yoinks-grid {
  display: none !important;
}

.map-view-active .map-container {
  display: block !important;
}

/* When grid is active (default), show grid and hide map */
.grid-view-active .map-container {
  display: none !important;
}

/* Filter bar should remain visible in map view */
.map-view-active .filter-bar,
.map-view-active .panel-header {
  display: block;
}

/* ============================================================================
   MAP INFO WINDOW (Google Maps Popup)
   ============================================================================ */

.map-info-window {
  padding: 12px;
  max-width: 280px;
  font-family: inherit;
}

.map-info-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px 0;
  line-height: 1.3;
}

.map-info-image-wrapper {
  cursor: pointer;
  margin: 0 -12px 10px -12px;
  transition: opacity 0.2s;
}

.map-info-image-wrapper:hover {
  opacity: 0.85;
}

.map-info-image-link {
  cursor: pointer;
}

.map-info-address {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.map-info-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  text-align: center;
}

.map-info-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
}

.map-info-btn:hover {
  background: var(--primary-hover);
}

/* ============================================================================
   MAP RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
  .header-row-actions {
    padding: 0 12px 10px;
    gap: 8px;
    /* Safety net: allow horizontal scroll if content overflows */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
  }

  .header-row-actions::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }

  /* On mobile, reduce spacer flex to keep toggle visible */
  .header-spacer {
    flex: 0.5;
    min-width: 0; /* Allow spacers to shrink fully */
  }

  .header-spacer:first-child,
  .header-spacer:last-child {
    flex: 0;
    width: 0;
  }

  /* Prevent toggles from shrinking */
  .header-scope-toggle,
  .header-view-toggle {
    flex-shrink: 0;
  }

  .view-toggle-btn {
    width: 32px;
    height: 28px;
  }
  
  .view-toggle-btn svg {
    width: 16px;
    height: 16px;
  }
  
  .view-toggle-btn .map-icon {
    font-size: 16px;
  }
  
  .map-container {
    height: calc(100vh - 200px);
    min-height: 300px;
    border-radius: 8px;
  }
  
  .center-on-me-btn {
    bottom: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 480px) {
  .header-view-toggle {
    padding: 3px;
    gap: 2px;
  }

  .view-toggle-btn {
    width: 30px;
    height: 26px;
  }

  /* Icon-only mode on mobile - hide text, show icons */
  .btn-icon {
    display: inline;
  }

  .btn-text {
    display: none;
  }

  .btn-core {
    padding: 8px 12px;
    min-width: 40px;
  }

  .header-actions-core {
    gap: 8px;
  }
}

/* ============================================================================
   NARROW MOBILE - Tighter spacing for very small screens
   ============================================================================ */

@media (max-width: 360px) {
  .btn-core {
    padding: 8px 10px;
    min-width: 36px;
  }

  .header-actions-core {
    gap: 6px;
  }

  .header-row-actions {
    gap: 6px;
  }
}

/* ============================================================================
   REDUCED MOTION - Map View
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .center-on-me-btn:hover {
    transform: none;
  }
  
  .center-on-me-btn:active {
    transform: none;
  }
  
  .center-on-me-btn.loading svg {
    animation: none;
  }
}

/* Bounds Filter Indicator */
.bounds-filter-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  margin-bottom: 12px;
  background: #e8f4fd;
  border: 1px solid #4a90d9;
  border-radius: 8px;
  font-size: 14px;
  color: #2563eb;
}

.bounds-filter-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bounds-filter-clear {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: white;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #4a90d9;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bounds-filter-clear:hover {
  background: #4a90d9;
  color: white;
}

@media (max-width: 480px) {
  .bounds-filter-indicator {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  
  .bounds-filter-clear {
    justify-content: center;
  }
}

/* Map Info Window Image */
.map-info-image {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.map-info-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

/* Leaderboard enhancements */
.leaderboard-row-you {
  background: rgba(124, 77, 255, 0.1);
  border-left: 3px solid var(--primary);
}

.you-badge {
  font-size: 10px;
  background: var(--primary);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
  font-weight: 600;
}

.leaderboard-separator {
  text-align: center;
  color: var(--text-muted);
  padding: 8px 0;
  font-size: 16px;
  letter-spacing: 4px;
}

.leaderboard-gap-hint {
  text-align: center;
  font-size: 12px;
  color: var(--primary);
  padding: 4px 0 8px;
  font-weight: 500;
}

/* See More pill */
.category-pill-see-more {
  background: var(--bg-tertiary, #f0f0f0);
  border: 1px dashed var(--border-color, #ccc);
  color: var(--text-secondary, #666);
}

.category-pill-see-more:hover {
  background: var(--bg-secondary, #e8e8e8);
  border-style: solid;
}

/* Go To button in category modal */
.category-goto-btn {
  padding: 4px 12px;
  font-size: 0.75rem;
  background: var(--primary-light, #e8f4ff);
  color: var(--primary, #007bff);
  border: 1px solid var(--primary, #007bff);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.category-goto-btn:hover {
  background: var(--primary, #007bff);
  color: white;
}

/* Select button in category modal (for Create Yoink selection mode) */
.category-select-btn {
  padding: 4px 12px;
  font-size: 0.75rem;
  background: #22c55e;
  color: white;
  border: 1px solid #22c55e;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: all 0.15s ease;
}

.category-select-btn:hover {
  background: #16a34a;
  border-color: #16a34a;
}

/* Actions container in modal */
.category-actions-inline {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

