/* Apple Maps inspired design */
:root {
  --apple-blue: #007AFF;
  --apple-blue-light: #007AFF20;
  --apple-green: #34C759;
  --apple-red: #FF3B30;
  --apple-orange: #FF9500;
  --apple-yellow: #FFCC00;
  --apple-purple: #AF52DE;
  --apple-pink: #FF2D92;
  --apple-gray: #8E8E93;
  --apple-gray-light: #F2F2F7;
  --apple-gray-dark: #1C1C1E;
  --apple-background: #000000;
  --apple-surface: #1C1C1E;
  --apple-text: #FFFFFF;
  --apple-text-secondary: #8E8E93;
  --apple-separator: #38383A;
  --apple-blur: rgba(28, 28, 30, 0.8);
  --apple-blur-light: rgba(242, 242, 247, 0.8);
  --apple-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --apple-shadow-light: 0 2px 10px rgba(0, 0, 0, 0.1);
  --apple-radius: 12px;
  --apple-radius-large: 20px;
  --apple-font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--apple-font);
  background: var(--apple-background);
  color: var(--apple-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Full screen map */
#map {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  cursor: default !important;
}

/* Override Leaflet default cursors */
.leaflet-container {
  cursor: default !important;
}

.leaflet-dragging .leaflet-container,
.leaflet-dragging .leaflet-clickable {
  cursor: default !important;
}

.leaflet-clickable {
  cursor: default !important;
}

/* Top Search Bar with Embedded Avatar (Google Maps style) */
.apple-search-bar {
  position: fixed;
  top: 60px;
  left: 20px;
  right: 20px;
  z-index: 1002;
  max-width: 600px;
  margin: 0 auto;
}

.search-container {
  display: flex;
  align-items: center;
  background: var(--apple-blur);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: 28px;
  padding: 8px;
  box-shadow: var(--apple-shadow);
  border: 1px solid var(--apple-separator);
}

.search-avatar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-left: 5px;
  flex-shrink: 0;
}

.search-avatar {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: var(--apple-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.search-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
}

.search-input-container {
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 8px 16px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.search-input-container:focus-within {
  border-color: var(--apple-blue);
  background: rgba(255, 255, 255, 0.15);
}

.search-icon {
  color: var(--apple-gray);
  margin-right: 8px;
  flex-shrink: 0;
}

.search-input-container input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--apple-text);
  outline: none;
  font-family: var(--apple-font);
  font-weight: 500;
}

.search-input-container input::placeholder {
  color: var(--apple-gray);
}

/* Search suggestions */
.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--apple-blur);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: 0 0 16px 16px;
  box-shadow: var(--apple-shadow);
  z-index: 1003;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 4px;
  border: 1px solid var(--apple-separator);
}

.search-suggestion {
  padding: 16px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--apple-separator);
  transition: background 0.2s ease;
  display: flex;
    align-items: center;
    gap: 12px;
  }
  
.search-suggestion:hover {
  background: rgba(255, 255, 255, 0.1);
}

.search-suggestion:last-child {
  border-bottom: none;
}

.search-suggestion-icon {
  color: var(--apple-blue);
  flex-shrink: 0;
}

.search-suggestion-text {
  flex: 1;
  font-size: 16px;
  color: var(--apple-text);
  font-weight: 500;
}

.search-suggestion-type {
  font-size: 14px;
  color: var(--apple-gray);
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 8px;
  border-radius: 8px;
}

.add-camera-suggestion {
  background: rgba(0, 122, 255, 0.1);
  border-left: 4px solid var(--apple-blue);
}

/* Floating Controls Container - simpler positioning */
.floating-controls {
  position: fixed;
  bottom: calc(40vh + 20px);  /* Default position - updated by JavaScript */
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 1000;
  transition: bottom 0.3s ease;
  pointer-events: none;
}

.floating-controls > * {
  pointer-events: all;
}

/* Controls positioning - layers on left, location + add on right */
.controls-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.controls-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* Specific positioning adjustments for reorganized controls */
.layers-btn {
  /* Move layers button a little higher */
  margin-bottom: -4px;
}

.locate-btn {
  /* Ensure proper spacing below layers button */
  margin-top: 0px;
}

.add-camera-btn {
  /* Move add camera button a little lower */
  margin-top: 16px;
}

/* Apple Maps style floating buttons */
.apple-control-btn {
  width: 44px;
  height: 44px;
  background: var(--apple-blur);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: none;
  border-radius: var(--apple-radius);
    display: flex;
    align-items: center;
    justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--apple-shadow-light);
  color: var(--apple-text);
}

.apple-control-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--apple-shadow);
}

.apple-control-btn:active {
  transform: scale(0.95);
}

/* Add camera button - center of floating controls */
.apple-add-btn {
  width: 56px;
  height: 56px;
  background: var(--apple-blue);
  border: none;
  border-radius: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--apple-shadow);
  color: white;
/*  margin: 0 20px;*/
}

.apple-add-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(0, 122, 255, 0.4);
}

.apple-add-btn:active {
  transform: scale(0.95);
}

/* Bottom Sheet (Apple Maps style) - Clean three-state implementation */
.apple-bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  height: 100vh;
  background: var(--apple-blur);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: var(--apple-radius-large) var(--apple-radius-large) 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
  z-index: 1001;
  transform: translateY(100%);    /* start fully hidden */
  transition: transform 0.3s ease;
  will-change: transform;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: none;            /* handle custom drag */
}

/* Sheet handle for swiping */
.sheet-handle {
  width: 60px;
  height: 8px;
  background: var(--apple-gray);
  border-radius: 4px;
  margin: 12px auto 8px;
  cursor: grab;
  transition: all 0.2s ease;
  opacity: 0.8;
  position: relative;
}

.sheet-handle:hover {
  background: var(--apple-text-secondary);
  opacity: 1;
  transform: scaleX(1.1);
}

.sheet-handle:active {
  cursor: grabbing;
}

/* Larger touch target for mobile swiping */
.sheet-handle::before {
  content: '';
  position: absolute;
  top: -30px;
  left: -60px;
  right: -60px;
  bottom: -20px;
  background: transparent;
}

/* Sheet header - also draggable */
.sheet-header {
  padding: 0px 20px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--apple-separator);
  margin-bottom: 0;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.sheet-header:active {
  cursor: grabbing;
}

.sheet-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--apple-text);
}

.sheet-controls {
  display: flex;
  gap: 4px;
  background: rgba(118, 118, 128, 0.24);
  border-radius: 10px;
  padding: 3px;
}

.sheet-tab {
  background: transparent;
  border: none;
  padding: 8px 20px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 60px;
}

.sheet-tab.active {
  background: var(--apple-text);
  color: var(--apple-background);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Sheet content */
.sheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

.camera-list-view {
  padding: 0 20px 80px 20px; /* Added 80px bottom padding to prevent off-bounds */
}

  #cameraList {
  list-style: none;
    padding: 0;
    margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

/* Mobile override - stack vertically */
@media (max-width: 768px) {
  #cameraList {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
}

#cameraList li {
  background: var(--apple-surface);
    border-radius: 20px;
  margin-bottom: 0;
  padding: 0;
  box-shadow: var(--apple-shadow);
  border: none;
  overflow: hidden;
  transition: all 0.2s ease;
}

/* Smaller cards for desktop */
@media (min-width: 769px) {
  #cameraList li {
    margin-bottom: 0;
  }
  
  .cam-header {
    padding: 12px !important;
  }
  
  .cam-controls {
    padding: 0 12px 12px 12px !important;
  }
  
  .video-container {
    padding: 0 12px 12px 12px !important;
  }
  
  .archive-panel {
    padding: 12px !important;
  }
}

#cameraList li:hover {
  transform: translateY(-1px);
  box-shadow: var(--apple-shadow);
}

.cam-header {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 12px;
}

.cam-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--apple-blue-light);
  border-radius: 50%;
  flex-shrink: 0;
}

.cam-info {
  flex: 1;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.cam-info:hover {
  opacity: 0.7;
}

.cam-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--apple-text);
  margin: 0 0 4px 0;
}



.cam-actions {
  display: flex;
  gap: 8px;
}

.cam-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none; 
  background: rgba(118, 118, 128, 0.12);
  color: var(--apple-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer; 
  transition: all 0.2s ease;
}

.cam-action-btn:hover {
  background: rgba(118, 118, 128, 0.24);
  color: var(--apple-text);
}

.cam-action-btn.delete-btn:hover {
  background: #ff3b30;
  color: white;
}

.cam-status {
  font-size: 18px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.cam-status.available {
  color: #34c759;
  background: rgba(52, 199, 89, 0.1);
}

.cam-status.restricted {
  color: var(--apple-text-secondary);
  background: rgba(118, 118, 128, 0.12);
}

/* Camera controls in list */
.cam-controls {
  display: flex;
  gap: 8px;
  padding: 0 16px 16px 16px;
}

.cam-controls.user-controls {
  padding: 0 16px 16px 16px;
}

.cam-control-btn {
  flex: 1;
  height: 44px;
  border-radius: var(--apple-radius-medium);
  border: none;
  background: rgba(118, 118, 128, 0.12);
  color: var(--apple-text);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--apple-font);
}

.cam-control-btn:hover {
  background: rgba(118, 118, 128, 0.24);
}

.cam-control-btn.primary {
  background: var(--apple-blue);
  color: white;
}

.cam-control-btn.primary:hover {
  background: var(--apple-blue-dark);
}

.cam-restricted {
  padding: 20px 16px;
  text-align: center;
  color: var(--apple-text-secondary);
}

.cam-restricted p {
  margin: 0 0 16px 0;
  font-size: 15px;
}

.subscribe-btn {
  background: var(--apple-blue);
  color: white;
  border: none;
  border-radius: var(--apple-radius-medium);
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.subscribe-btn:hover {
  background: var(--apple-blue-dark);
}

/* Video container in list */
.video-container {
  padding: 0 16px 16px 16px;
}

.video-container video {
  width: 100%;
  max-height: 200px;
  border-radius: var(--apple-radius-medium);
  background: #000;
  object-fit: contain;
}

.archive-panel {
  padding: 16px;
  background: rgba(118, 118, 128, 0.12);
  border-top: 1px solid rgba(118, 118, 128, 0.24);
}

.archive-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.archive-controls label {
  font-size: 14px;
  color: var(--apple-text);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.archive-controls input,
.archive-controls select {
  padding: 8px 12px;
  border: 1px solid rgba(118, 118, 128, 0.24);
  border-radius: var(--apple-radius-small);
  background: var(--apple-surface);
  color: var(--apple-text);
  font-size: 14px;
}

.btn-load-archive {
  background: var(--apple-blue);
  color: white;
  border: none;
  border-radius: var(--apple-radius-small);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.btn-load-archive:hover {
  background: var(--apple-blue-dark);
}

/* Layers popup with previews */
.apple-popup {
  position: fixed;
  bottom: 185px;  /* Adjusted slightly higher for repositioned layers button */
  left: 20px;
  background: var(--apple-blur);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: 16px;
  box-shadow: var(--apple-shadow);
  z-index: 1002;
    opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  min-width: 220px;
}

.apple-popup.show {
    opacity: 1;
    transform: translateY(0);
  pointer-events: all;
}

.popup-content {
  padding: 20px;
}

.popup-content h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--apple-text);
  text-align: center;
}

.layer-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.layer-option {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 12px;
  border-radius: 12px;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
}

.layer-option:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--apple-blue);
}

.layer-option input[type="radio"] {
  display: none; 
}

.layer-option input[type="radio"]:checked + .layer-preview + span {
  color: var(--apple-blue);
  font-weight: 600;
}

.layer-option input[type="radio"]:checked {
  background: var(--apple-blue);
}

.layer-option.checked {
  background: rgba(0, 122, 255, 0.1);
  border-color: var(--apple-blue);
}

.layer-preview {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  margin-right: 12px;
  background-size: cover;
  background-position: center;
  border: 2px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.default-preview {
  background: #f5f5f5;
  background-image: 
    repeating-linear-gradient(0deg, #e0e0e0, #e0e0e0 1px, transparent 1px, transparent 4px),
    repeating-linear-gradient(90deg, #e0e0e0, #e0e0e0 1px, transparent 1px, transparent 4px);
  background-size: 8px 8px;
  position: relative;
}

.default-preview::after {
  content: '🗺';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
}

.satellite-preview {
  background: #1a365d;
  background-image: 
    radial-gradient(circle at 20% 30%, #2b6cb0 15%, transparent 15%),
    radial-gradient(circle at 80% 70%, #065f46 20%, transparent 20%),
    radial-gradient(circle at 60% 20%, #744210 10%, transparent 10%);
  background-size: 15px 15px, 20px 20px, 12px 12px;
  position: relative;
}

.satellite-preview::after {
  content: '🌍';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
}

.terrain-preview {
  background: linear-gradient(135deg, 
    #065f46 0%, 
    #34d399 25%, 
    #fbbf24 50%, 
    #a78bfa 75%, 
    #6b7280 100%
  );
  background-image: 
    repeating-linear-gradient(45deg, 
      transparent 0px, 
      transparent 3px, 
      rgba(255,255,255,0.15) 3px, 
      rgba(255,255,255,0.15) 6px
    );
  position: relative;
}

.terrain-preview::after {
  content: '⛰️';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
}

.layer-option span {
  font-size: 16px;
  color: var(--apple-text);
  font-weight: 500;
  flex: 1;
}

/* Light mode adjustments */
@media (prefers-color-scheme: light) {
  :root {
    --apple-background: #F2F2F7;
    --apple-surface: #FFFFFF;
    --apple-text: #000000;
    --apple-text-secondary: #8E8E93;
    --apple-separator: #C6C6C8;
    --apple-blur: rgba(255, 255, 255, 0.8);
    --apple-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --apple-shadow-light: 0 2px 10px rgba(0, 0, 0, 0.05);
  }
  
  .search-input-container {
    background: rgba(0, 0, 0, 0.05);
  }
  
  .search-input-container input {
    color: var(--apple-text);
  }
  
  .sheet-controls {
    background: #E5E5EA;
  }
  
  .sheet-tab.active {
    background: white;
    color: var(--apple-text);
  }
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .apple-search-bar {
    top: 50px;
    left: 16px;
    right: 16px;
  }
  

  
  .search-container {
    padding: 6px;
  }
  
  .search-avatar {
    width: 36px;
    height: 36px;
    border-radius: 18px;
    font-size: 14px;
  }
  
  .floating-controls {
    bottom: 160px;
    left: 16px;
    right: 16px;
  }
  
  .apple-bottom-sheet {
    transform: translateY(calc(100% - 120px));
  }
  
  .sheet-header {
    padding: 12px 16px 0;
    padding-bottom: 12px;
  }
  
  .sheet-header h2 {
    font-size: 20px;
  }
  
  .camera-list-view {
    padding: 0 16px 100px 16px; /* Increased bottom padding for mobile */
  }
  
  .apple-popup {
    bottom: 185px;  /* Adjusted to match desktop */
    left: 16px;
  }
  
  /* Smaller controls on mobile */
  .apple-control-btn {
    width: 40px;
    height: 40px;
  }
  
  .apple-add-btn {
    width: 50px;
    height: 50px;
    border-radius: 25px;
  }

  /* Go back button responsive */
  .go-back-btn {
    padding: 6px 10px;
    font-size: 13px;
  }
}

/* Note: Old dragging classes removed - transition is now managed by JavaScript */

/* Modals - Apple style */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

.modal-content {
  background: var(--apple-surface);
  border-radius: var(--apple-radius-large);
  box-shadow: var(--apple-shadow);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  transform: scale(1);
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform, opacity;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(118, 118, 128, 0.12);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  color: var(--apple-gray);
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(118, 118, 128, 0.24);
}

/* Auth tabs */
.auth-tabs {
  display: flex;
  background: rgba(118, 118, 128, 0.12);
  border-radius: 8px;
  padding: 2px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--apple-text);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
}

.auth-tab.active {
  background: var(--apple-text);
  color: var(--apple-background);
}

/* Form inputs */
.modal-content input,
.modal-content select,
.modal-content textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid rgba(118, 118, 128, 0.24);
  border-radius: 10px;
  background: rgba(118, 118, 128, 0.12);
  color: var(--apple-text);
  font-size: 16px;
  margin-bottom: 12px;
  font-family: var(--apple-font);
  outline: none;
  transition: all 0.2s ease;
  appearance: none;
}

.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
  border-color: var(--apple-blue);
  background: rgba(0, 122, 255, 0.1);
}

.modal-content input::placeholder,
.modal-content textarea::placeholder {
  color: var(--apple-text-secondary);
}

/* Form labels */
.modal-content label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--apple-text);
}

.modal-content label span {
  color: var(--apple-red);
  margin-left: 2px;
}

/* Toggle switch */
.input-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(118, 118, 128, 0.24);
  transition: 0.3s;
  border-radius: 28px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--apple-blue);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.toggle-text {
  font-size: 14px;
  color: var(--apple-text);
  font-weight: 500;
}

/* Buttons */
.modal-content button {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: var(--apple-blue);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 8px;
  font-family: var(--apple-font);
}

.modal-content button:hover {
  background: #0056CC;
  transform: scale(1.02);
}

.modal-content button:active {
  transform: scale(0.98);
}

.modal-buttons {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-buttons button {
  flex: 1;
  margin-top: 0;
}

.modal-buttons button:first-child {
  background: rgba(118, 118, 128, 0.24);
  color: var(--apple-text);
}

.modal-buttons button:first-child:hover {
  background: rgba(118, 118, 128, 0.36);
}

/* Delete button specific styling */
#deleteCameraBtn {
  background: var(--apple-red) !important;
  color: white !important;
}

#deleteCameraBtn:hover {
  background: #d70015 !important;
  transform: scale(1.02);
}

/* Menu panel */
.menu-panel {
  position: fixed;
  top: 0;
  right: -100%;
  width: 300px;
  height: 100vh;
  background: var(--apple-blur);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
  z-index: 1500;
  transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  flex-direction: column;
}

.menu-panel.open {
  right: 0;
}

.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 1400;
    opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  }

.menu-overlay.open {
    opacity: 1;
  pointer-events: all;
}

.menu-header {
  padding: 60px 20px 20px;
  border-bottom: 1px solid var(--apple-separator);
}

.menu-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: var(--apple-text);
}

.menu-close {
  position: absolute;
  top: 50px;
  right: 20px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--apple-text);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  transition: background 0.2s ease;
}

.menu-close:hover {
  background: rgba(118, 118, 128, 0.12);
}

.menu-content {
  flex: 1;
  padding: 20px;
}

.menu-item {
  width: 100%;
  padding: 16px 20px;
  border: none;
  background: rgba(118, 118, 128, 0.12);
  color: var(--apple-text);
  font-size: 16px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 8px;
  text-align: left;
  font-family: var(--apple-font);
}

.menu-item:hover {
  background: rgba(118, 118, 128, 0.24);
  transform: scale(1.02);
}



/* Animations */
@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Toast notifications */
.toast {
  position: fixed;
  top: 140px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--apple-blur);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--apple-text);
  padding: 12px 20px;
  border-radius: 20px;
  box-shadow: var(--apple-shadow);
  z-index: 2001;
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
  transition: all 0.3s ease;
  font-size: 14px;
  font-weight: 500;
  max-width: 300px;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-left: 4px solid var(--apple-green);
}

.toast.error {
  border-left: 4px solid var(--apple-red);
}

/* Hide elements that are not needed in Apple Maps style */
.top-bar,
.controls-container,
.map-controls-left,
.map-controls-right,
.grid-add-btn,
header.site-header {
  display: none !important;
}

/* Ensure map controls are properly hidden */
.leaflet-control-container .leaflet-top.leaflet-right,
.leaflet-control-container .leaflet-top.leaflet-left,
.leaflet-control-container .leaflet-bottom.leaflet-right,
.leaflet-control-container .leaflet-bottom.leaflet-left {
  display: none;
}

/* Hide default leaflet popup close button */
.leaflet-popup-close-button {
  display: none !important;
}

/* Apple-style Map popups and video popups */
.leaflet-popup-content-wrapper {
  background: rgba(28, 28, 30, 0.95) !important;
  backdrop-filter: blur(40px) !important;
  -webkit-backdrop-filter: blur(40px) !important;
  border-radius: 16px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  padding: 0 !important;
  overflow: hidden !important;
  max-width: 320px !important;
  min-width: 280px !important;
}

.leaflet-popup-content {
  color: #ffffff !important;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 16px !important;
}

.leaflet-popup-tip {
  background: rgba(28, 28, 30, 0.95) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: 4px !important;
}

.video-popup, .map-click-popup {
  min-width: 280px;
  max-width: 320px;
  padding: 16px;
  position: relative;
  background: transparent;
  border-radius: 16px;
}

.popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.6) !important;
  color: #ffffff !important;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.popup-close:hover {
  background: rgba(0, 0, 0, 0.8) !important;
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.delete-btn {
  position: absolute;
  top: 16px;
  right: 60px;
  background: rgba(255, 59, 48, 0.9) !important;
  color: white !important;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  z-index: 1000;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3);
}

.delete-btn:hover {
  background: rgba(255, 59, 48, 1) !important;
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.4);
}

.popup-title {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
  margin: 0 0 12px 0;
  padding-right: 80px;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.popup-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.popup-controls button,
.popup-controls select {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--apple-font);
  flex: 1;
  min-width: 70px;
}

.popup-controls button:hover,
.popup-controls select:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.popup-controls button:active {
  transform: translateY(0);
  background: var(--apple-blue);
  color: white;
}

.popup-video {
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  margin: 8px 0;
}

.popup-video video {
  width: 100%;
  max-width: 280px;
  height: auto;
  max-height: 160px;
  border-radius: 12px;
  background: #000;
  object-fit: contain;
  display: block;
}

.archive-panel {
  margin-top: 16px;
  padding: 16px;
  background: rgba(118, 118, 128, 0.08);
  border-radius: var(--apple-radius-medium);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.archive-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--apple-text);
}

.archive-panel input,
.archive-panel select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--apple-radius-small);
  background: rgba(255, 255, 255, 0.05);
  color: var(--apple-text);
  font-size: 14px;
  margin-bottom: 12px;
}

.btn-load-archive {
  width: 100%;
  background: var(--apple-blue);
  color: white;
  border: none;
  border-radius: var(--apple-radius-medium);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

/* Map click popup styling */
.map-click-popup h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--apple-text);
  margin: 0 0 8px 0;
}

.map-click-popup .coords {
  font-size: 12px;
  color: var(--apple-text-secondary);
  margin-bottom: 12px;
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', monospace;
}

.map-click-popup button {
  width: 100%;
  padding: 10px 16px;
  background: var(--apple-blue);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--apple-font);
}

.map-click-popup button:hover {
  background: #0056CC;
  transform: translateY(-1px);
}

/* Profile Page Styles (Apple-like) */
.profile-container {
  background: var(--apple-background);
  color: var(--apple-text);
  min-height: 100vh;
  overflow-y: auto;
}

.profile-card {
  background: var(--apple-blur);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-radius: var(--apple-radius-large);
  box-shadow: var(--apple-shadow);
  margin: 20px;
  padding: 24px;
}

.profile-sidebar {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
}

.profile-main {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
}

.avatar {
  background: var(--apple-blue);
  border: 3px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 20px rgba(0, 122, 255, 0.3);
}

.info-group {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--apple-separator);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.subscription-status {
  background: rgba(52, 199, 89, 0.2);
  color: var(--apple-green);
  border: 1px solid var(--apple-green);
}

.status-expired {
  background: rgba(255, 59, 48, 0.2);
  color: var(--apple-red);
  border: 1px solid var(--apple-red);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .modal-content {
    width: 95%;
    padding: 20px;
  }
  
  .menu-panel {
    width: 100%;
    right: -100%;
  }
  
  .apple-popup {
    left: 10px;
    right: 10px;
    max-width: none;
  }
  
  .popup-controls {
    flex-direction: column;
  }
  
  .popup-controls button,
  .popup-controls select {
    width: 100%;
  }
  
  .apple-search-bar {
    left: 12px;
    right: 12px;
  }
  
  .floating-controls {
    left: 12px;
    right: 12px;
  }
}

/* Go back button for modals */
.go-back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(118, 118, 128, 0.12);
  border: none;
  border-radius: 20px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--apple-text);
  transition: all 0.2s ease;
  font-family: var(--apple-font);
}

.go-back-btn:hover {
  background: rgba(118, 118, 128, 0.24);
  transform: translateX(-2px);
}

.go-back-btn svg {
  flex-shrink: 0;
}