/* Base styles with Android optimizations */
body {
  font-family: 'Rubik', sans-serif;
  margin: 2em;
  background: #f4f4f4;
  color: #333;
  /* Android optimizations */
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  position: relative;
}

/* Prevent zoom on input focus (Android) */
input[type="text"],
input[type="file"],
input[type="number"],
select {
  font-size: 16px; /* Prevents zoom on iOS/Android */
  width: 100%;
  padding: 0.6em;
  margin-top: 0.5em;
  margin-bottom: 1em;
  border: 1px solid #ccc;
  border-radius: 4px;
  /* Android optimizations */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: white;
  box-sizing: border-box;
}

/* Fix for Android file input */
input[type="file"] {
  padding: 0.4em;
  border: 2px dashed #ccc;
  background: #fafafa;
  cursor: pointer;
}

header {
  display: flex;
  align-items: center;
  margin-bottom: 1em;
  flex-wrap: wrap;
}

header img {
  height: 60px;
  margin-right: 1em;
  /* Prevent image flickering on Android */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

h1 {
  font-family: 'Righteous', cursive;
  font-size: 2.2em;
  margin: 0;
  color: #2c3e50;
}

form {
  background: white;
  padding: 1em;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  margin-bottom: 2em;
  /* Prevent form from disappearing during transitions */
  position: relative;
  z-index: 1;
  /* Android hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

input[type="submit"], button {
  background: #2c3e50;
  color: white;
  border: none;
  padding: 0.7em 1.5em;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  font-size: 16px; /* Prevents zoom on mobile */
  /* Android optimizations */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  /* Prevent button from disappearing during loading */
  position: relative;
  z-index: 2;
}

input[type="submit"]:hover, button:hover {
  background: #34495e;
}

input[type="submit"]:active, button:active {
  background: #2c3e50;
  transform: translateY(1px);
}

/* Disabled state for loading */
input[type="submit"]:disabled, button:disabled {
  background: #95a5a6;
  cursor: not-allowed;
  transform: none;
}

.options-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5em;
  margin-bottom: 1em;
}

.toggle-container {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1em;
  cursor: pointer;
  font-weight: bold;
  color: #2c3e50;
  /* Android touch optimizations */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 0.25em 0;
  min-height: 44px; /* Minimum touch target size */
}

.toggle-container input[type="checkbox"] {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
  background-color: #ccc;
  border-radius: 24px;
  transition: background-color 0.3s ease;
  /* Android hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
  /* Android hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-container input:checked + .toggle-slider {
  background-color: #2c3e50;
}

.toggle-container input:checked + .toggle-slider::before {
  transform: translateX(26px);
}

#map {
  height: 400px;
  margin-bottom: 1em;
  /* Prevent map from causing layout issues */
  position: relative;
  z-index: 1;
  /* Android hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* Loading overlay improvements */
#loadingOverlay {
  /* Ensure it's always on top */
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 9999 !important;
  /* Better visibility on Android */
  background: rgba(255, 255, 255, 0.95) !important;
  /* Hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  /* Prevent scrolling behind overlay */
  overflow: hidden;
}

/* When overlay is shown, prevent body scroll */
body.loading-active {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* Android-specific media queries */
@media (max-width: 600px) {
  body { 
    margin: 1em; 
    /* Ensure minimum font size on Android */
    font-size: 16px;
  }
  
  header { 
    flex-direction: column; 
    align-items: flex-start; 
  }
  
  header img { 
    margin-bottom: 0.5em; 
  }
  
  h1 { 
    font-size: 1.8em; 
  }
  
  form {
    padding: 0.75em;
  }
  
  input[type="text"],
  input[type="file"],
  input[type="number"],
  select {
    font-size: 16px; /* Critical for preventing zoom */
    padding: 0.75em;
  }
  
  input[type="submit"], button {
    font-size: 16px;
    padding: 0.75em 1.25em;
    width: 100%;
  }
  
  .toggle-container {
    min-height: 48px; /* Larger touch target on mobile */
  }
  
  #map {
    height: 300px;
  }
}

/* High DPI Android devices */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Ensure crisp rendering on high-DPI Android screens */
  * {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* Landscape orientation fixes for Android */
@media (orientation: landscape) and (max-height: 500px) {
  body {
    margin: 1em;
  }
  
  header {
    margin-bottom: 0.5em;
  }
  
  h1 {
    font-size: 1.5em;
  }
  
  #map {
    height: 250px;
  }
}

/* Details/expandable sections */
details.expandable {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  padding: 1em;
  margin-bottom: 1.5em;
  /* Android hardware acceleration */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

details.expandable summary {
  font-weight: bold;
  font-size: 1.1em;
  color: #2c3e50;
  cursor: pointer;
  list-style: none;
  position: relative;
  padding-left: 1.2em;
  /* Android touch optimizations */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}

details.expandable summary::before {
  content: "▶";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) rotate(0deg);
  transition: transform 0.2s ease-in-out;
  /* Android hardware acceleration */
  -webkit-transform: translateY(-50%) rotate(0deg) translateZ(0);
}

details.expandable[open] summary::before {
  transform: translateY(-50%) rotate(90deg);
  -webkit-transform: translateY(-50%) rotate(90deg) translateZ(0);
}

details.expandable ul {
  margin-top: 1em;
  padding-left: 1.2em;
  list-style: disc;
}

/* Prevent text selection on interactive elements */
.toggle-container,
details.expandable summary,
input[type="submit"],
button {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Focus styles for accessibility */
input:focus,
select:focus,
button:focus {
  outline: 2px solid #2c3e50;
  outline-offset: 2px;
}

/* Android Chrome specific fixes */
@supports (-webkit-appearance: none) {
  select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
  }
}