/* Election Poster Manager PWA Styles */

/* Dark mode is always on */
:root {
  --color-primary: #2563eb;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-gray: #6b7280;
}

/* System font stack */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Remove all transitions for better performance */
* {
  transition: none !important;
}

/* Add transitions only where needed */
button, .toast, .pin-marker {
  transition: all 0.2s ease !important;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #1f2937;
}

::-webkit-scrollbar-thumb {
  background: #4b5563;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Leaflet customizations */
.leaflet-container {
  font-family: inherit;
  background: #111827;
}

.leaflet-control-layers,
.leaflet-bar {
  background: #1f2937 !important;
  border: 1px solid #374151 !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}

.leaflet-control-layers-toggle,
.leaflet-bar a {
  background-color: #1f2937 !important;
  color: #e5e7eb !important;
  border: none !important;
}

.leaflet-control-layers-toggle:hover,
.leaflet-bar a:hover {
  background-color: #374151 !important;
}

.leaflet-control-layers-expanded {
  background: #1f2937 !important;
  color: #e5e7eb !important;
  padding: 10px !important;
  /* Ensure the expanded menu doesn't overlap the toggle button */
  margin-right: 10px !important;
}

.leaflet-control-layers label {
  color: #e5e7eb !important;
  cursor: pointer;
  padding: 3px 5px !important;
  margin: 2px 0 !important;
  display: block !important;
}

.leaflet-control-layers label:hover {
  background-color: #374151 !important;
  border-radius: 4px;
}

/* Ensure layer control is always accessible */
.leaflet-control-layers {
  margin-top: 10px !important;
  margin-right: 10px !important;
}

/* Fix z-index to ensure toggle button is always clickable */
.leaflet-control-layers-toggle {
  z-index: 800 !important;
  position: relative !important;
}

.leaflet-control-layers-expanded .leaflet-control-layers-list {
  margin-top: 5px !important;
}

/* Custom marker styles */
.custom-pin-marker {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
  cursor: pointer !important;
  z-index: 1000 !important;
}

.pin-marker {
  color: var(--pin-color);
  pointer-events: all !important;
}

.pin-marker:hover {
  transform: scale(1.1);
}

.custom-pin-marker:hover {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  z-index: 1001 !important;
}

.current-location-marker {
  z-index: 1000;
}

/* Modal styles */
#popupModal {
  backdrop-filter: blur(4px);
}

/* Toast notifications */
.toast {
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.hiding {
  animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* Focus states */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Loading spinner */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* PWA install prompt */
.install-prompt {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5000;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateX(-50%) translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

/* Mobile optimizations */
@media (max-width: 640px) {
  .leaflet-control-attribution {
    display: none;
  }
  
  .leaflet-control-zoom {
    margin: 10px !important;
  }
}

/* Prevent text selection on map */
.leaflet-container {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Fix for iOS safe areas and dynamic height calculation */
@supports (padding: max(0px)) {
  main {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Dynamic height calculation for main content */
#mainContent {
  height: calc(100vh - 60px); /* Fallback */
  height: calc(100dvh - 60px); /* Dynamic viewport height for mobile */
}

/* Adjust for header height */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#appHeader {
  flex-shrink: 0;
}

#mainContent {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Ensure map container fills the space */
#mapContainer, #tableContainer {
  width: 100%;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
}

/* Camera modal styles */
#cameraModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
}

#cameraModal video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: black;
}

/* Camera capture button styling */
#captureBtn {
  position: relative;
  background: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 
              0 0 40px rgba(255, 255, 255, 0.2);
  min-width: 64px;
  min-height: 64px;
}

#captureBtn:hover {
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.7),
              0 0 60px rgba(255, 255, 255, 0.4);
}

#captureBtn:active {
  transform: scale(0.95);
}

/* Sync badge styling */
.sync-badge {
  font-size: 0.65rem;
  line-height: 1;
}

/* Ensure camera UI is always visible */
#cameraModal .absolute {
  pointer-events: auto;
}

#cameraModal .bg-gradient-to-b,
#cameraModal .bg-gradient-to-t {
  pointer-events: none;
}

#cameraModal button {
  pointer-events: auto;
}

/* Form input styles for better mobile experience */
input[type="text"],
textarea,
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  font-size: 16px; /* Prevents zoom on iOS */
}

/* Photo preview optimization */
#photoPreview img {
  object-fit: cover;
  max-height: 10rem;
  width: 100%;
  border-radius: 0.5rem;
}

/* Print styles */
@media print {
  header,
  #locationBtn,
  #toastContainer,
  .leaflet-control-container {
    display: none !important;
  }
  
  #map {
    height: 100vh !important;
  }
}

/* Pin marker styles for table view */
.pin-marker-small {
  color: var(--pin-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}