:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --schulform-width: 200px;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --radius-md: 8px;
    --radius-lg: 12px;
}

body {
    background-color: var(--bg-color);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text-color);
    line-height: 1.5;
}
  
  
h1, h2 {
    text-align: center;
    margin: 12px 0;
    font-weight: 600;
    color: var(--text-color);
    font-size: 1.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.page-icon {
    color: var(--primary-color);
    font-size: 1.875rem;
}

.intro-section {
    text-align: center;
    padding: 12px 20px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(37, 99, 235, 0.02));
    border-radius: var(--radius-lg);
    border: 1px solid rgba(37, 99, 235, 0.1);
}

.intro-section p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-color);
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

  #main-container {
    display: flex;
    flex-direction: column;
    padding: 12px;
    min-height: calc(100vh - 100px);
    gap: 8px;
    margin-bottom: 0;
}

#search-container {
    width: 100%;
    max-width: 600px;
    position: relative;
    margin: 0 0 8px 0;
    z-index: 1000;
}

#map-and-filters {
    display: flex;
    gap: 12px;
    flex: 1 1 auto;
    height: calc(100vh - 180px);
    min-height: 600px;
    align-items: stretch;
    overflow: hidden;
}

#map {
    flex: 1;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    height: 100%;
    min-height: 100%;
}

#filters-sidebar {
    width: 280px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    order: 2;
    height: 100%;
    overflow: hidden;
}

.filter-box {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    background: white;
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.filter-box h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-box h3 button {
    font-size: 0.813rem;
    padding: 3px 6px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-box h3 button:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

#search-container {
    width: 100%;
    max-width: 600px;
    position: relative;
    margin: 0 0 16px 0;
    z-index: 10000;
}

.search-with-button {
    display: flex;
    gap: 12px;
    align-items: stretch;
    border: none;
    position: relative;
    z-index: 10000;
}

#search-input {
    width: calc(100% - var(--schulform-width));
    border: 2px solid var(--border-color);
    padding: 14px;
    font-size: 1rem;
    box-sizing: border-box;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    min-width: 0; /* Allows flex shrinking */
}

#search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}


  
  #search-suggestions {
    list-style: none;
    padding: 0;
    margin: 4px 0 0 0;
    border: 1px solid var(--border-color);
    max-height: 250px;
    overflow-y: auto;
    position: absolute;
    width: calc(100% - var(--schulform-width));
    background: white;
    z-index: 1000;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

#search-suggestions li {
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

#search-suggestions li:last-child {
    border-bottom: none;
}

#search-suggestions li:hover {
    background-color: var(--bg-color);
    color: var(--primary-color);
}
  
  /* Move container to the left and make map bigger */
#container {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 20px;
    padding: 20px;
    height: calc(100vh - 140px); /* Adjust for header and footer */
  }
  
  #filters {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .filter-container {
    padding: 15px;
    border: 1px solid #ccc;
    background: #f9f9f9;
    border-radius: 5px;
    font-size: 14px;
    white-space: nowrap;
    overflow-x: auto;
  }
  
  #filters label {
    display: inline-block;
    margin-right: 10px;
    margin-bottom: 4px;
    cursor: pointer;
  }
  
  #filters button {
    font-size: 10px;
    padding: 2px 5px;
    margin-left: 4px;
    cursor: pointer;
  }  
  
  #map {
    flex: 1;
    min-height: 500px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

#map:hover {
    box-shadow: 0 8px 16px -4px rgba(0,0,0,0.1);
}

.info.legend {
    background: white;
    padding: 16px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.875rem;
    line-height: 1.4;
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    max-width: 300px;
}

.info.legend h4 {
    margin: 0 0 12px 0;
    font-weight: 600;
    color: var(--text-color);
}

.info.legend i {
    width: 20px;
    height: 20px;
    float: left;
    margin-right: 10px;
    opacity: 0.8;
    border-radius: 4px;
    transition: opacity 0.2s ease;
}

.info.legend i:hover {
    opacity: 1;
}

.info.legend .legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-md);
    transition: background-color 0.2s ease;
}

.info.legend .legend-item:hover {
    background-color: var(--bg-color);
}
  
  .legend-title-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.legend-help-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    cursor: help;
    transition: all 0.2s ease;
    position: relative;
}

.legend-help-icon:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

.legend-tooltip {
    position: absolute;
    width: 300px;
    background: white;
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-color);
    visibility: hidden;
    opacity: 0;
    transition: all 0.2s ease;
    transform: translateY(10px);
    z-index: 1000;
    bottom: calc(100% - 50px);  /* Adjust vertical position to be more centered */
    right: calc(100% + 12px);   /* Position to the left of the legend */
    left: auto;                 /* Remove left positioning */
    transform: none;            /* Remove transform since we're using right positioning */
}

.legend-help-icon:hover .legend-tooltip {
    visibility: visible;
    opacity: 1;
    transform: none;
}

.legend-tooltip p {
    margin: 0 0 12px 0;
}

.legend-tooltip p:last-child {
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .legend-tooltip {
        width: 250px;
        bottom: calc(100% - 50px);
        right: calc(100% + 12px);
        left: auto;
        transform: none;
    }
}

@media (max-width: 1200px) {
    #main-container {
        padding: 16px;
    }

    #filters-sidebar {
        width: 240px;
        min-width: 240px;
    }

    .info.legend {
        max-width: none;
        width: auto;
    }
}

@media (max-width: 768px) {
    #map-and-filters {
        flex-direction: column;
    }

    #search-container {
        position: relative;
        top: 0;
        left: 0;
        padding: 0;
        margin-bottom: 16px;
    }

    #filters-sidebar {
        width: 100%;
        margin-bottom: 16px;
        order: 2;
    }

    #map {
        width: 100%;
        height: 60vh;
        order: 1;
    }

    #search-container {
        padding: 0 16px;
    }

    .tutorial-content {
        padding: 24px;
        width: calc(100% - 32px);
        margin: 16px;
    }

    .tutorial-steps {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .feedback-popup {
        width: calc(100% - 48px);
        bottom: 16px;
        right: 16px;
        left: 16px;
    }

    .feedback-floating-button {
        bottom: 16px;
        right: 16px;
        font-size: 0.875rem;
        padding: 10px 16px;
    }

    .search-with-button {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }

    #search-input {
        flex: 1 1 100%;
        order: 1;
    }

    .schulform-dropdown {
        margin: 0;
        flex: 1;
        order: 2;
    }

    #location-button {
        order: 3;
    }

    .schulform-content {
        left: 0;
        right: 0;
    }
    .tutorial-content {
        padding: 0;
        width: 100%;
        margin: 0;
    }

    .tutorial-steps {
        grid-template-columns: 1fr;
        gap: 16px;
        margin: 16px 0;
        min-height: auto;
    }

    .tutorial-step {
        padding: 16px;
    }

    .tutorial-step h3 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    .tutorial-controls {
        flex-direction: column-reverse;
        gap: 16px;
        align-items: stretch;
        text-align: center;
        margin-top: 24px;
        padding-top: 20px;
    }

    .tutorial-controls button {
        width: 100%;
        margin-bottom: 12px;
    }
}

@media (max-width: 480px) {
    h2 {
        font-size: 1.5rem;
        margin: 16px 0;
    }

    .filter-box {
        padding: 16px;
    }

    #search-input {
        padding: 12px;
        font-size: 0.875rem;
    }

    #location-button {
        padding: 12px;
        font-size: 0.875rem;
    }
}

/* Make per-school feedback popup smaller and more usable on phones */
@media (max-width: 520px) {
  .feedback-popup {
    top: 12% !important;
    left: 50% !important;
    transform: translate(-50%, 0) !important;
    width: calc(100% - 32px) !important;
    max-width: 340px !important;
    padding: 12px !important;
    box-shadow: 0 6px 12px rgba(0,0,0,0.18);
  }

  .feedback-popup h3 {
    font-size: 1rem;
    margin-bottom: 8px;
  }

  .feedback-popup textarea {
    height: 72px !important;
    font-size: 0.95rem;
  }

  .feedback-popup button {
    padding: 8px 10px !important;
    font-size: 0.95rem !important;
    border-radius: 6px !important;
  }
}

  footer {
    text-align: center;
    padding: 12px;
    background-color: #f8f8f8;
    border-top: 1px solid #ccc;
    width: 100%;
    position: relative;
    height: 60px;
    box-sizing: border-box;
    margin-top: auto;
  }

  footer a {
    color: #333;
    text-decoration: none;
    margin: 0 10px;
  }

  footer a:hover {
    text-decoration: underline;
  }

  footer p {
    margin-bottom: 10px;
  }

  .feedback-popup {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translate(-50%, 0);
  background: white;
  border: 1px solid #ccc;
  padding: 20px;
  width: 300px;
  z-index: 9999;
  box-shadow: 0 0 15px rgba(0,0,0,0.3);
}

.feedback-popup textarea {
  width: 100%;
  height: 100px;
  margin-bottom: 10px;
}

.feedback-floating-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: #008cff;
  color: white;
  border: none;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 1000;
}

.general-feedback-popup {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 24px;
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 300px;
    z-index: 10000;
    border: 1px solid var(--border-color);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
}

.general-feedback-popup.visible {
    display: block;
    transform: translateY(0);
    opacity: 1;
}

.ad-banner, .sponsor-banner {
  padding: 24px;
  background: linear-gradient(to bottom right, #ffffff, #f8f9fa);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  height: 100%;
  min-height: 0;
  /* Ensure it matches map height */
  align-self: stretch;
}

.ad-banner h3, .sponsor-banner h3 {
  font-size: 0.9em;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 15px;
  letter-spacing: 1px;
}
.ad-placeholder, .sponsor-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0; /* This is important for flex containers */
}
.ad-info, .sponsor-info {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.ad-title, .sponsor-title {
  font-size: 1.2em;
  font-weight: bold;
  color: var(--text-color);
  margin: 0;
}
.ad-description, .sponsor-description {
  color: #555;
  font-size: 0.95em;
  line-height: 1.4;
  margin: 0;
}
.ad-benefits, .sponsor-benefits {
  list-style: none;
  padding: 0;
  margin: 10px 0;
  text-align: left;
}
.ad-benefits li, .sponsor-benefits li {
  color: #444;
  font-size: 0.9em;
  margin: 8px 0;
}
.ad-cta, .sponsor-cta {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid var(--border-color);
}
.ad-contact, .sponsor-contact {
  font-size: 0.9em;
  color: #666;
  margin: 5px 0;
}
.ad-email, .sponsor-email {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  display: block;
  margin: 5px 0;
}
.ad-email:hover, .sponsor-email:hover {
  text-decoration: underline;
}
.ad-note, .sponsor-note {
  font-size: 0.85em;
  color: #888;
  margin: 5px 0;
  font-style: italic;
}

@media (max-width: 768px) {
  #map-and-filters {
    flex-direction: column;
    margin-top: 8px;
    gap: 16px;
    height: auto;
    min-height: auto;
  }

  #filters-sidebar {
    width: 100%;
    margin-bottom: 16px;
    order: 2;
    height: auto;
    min-height: auto;
    flex: none;
  }

  .ad-banner {
    width: 100%;
    padding: 16px;
    height: auto;
    min-height: 200px;
    flex: none;
    margin-top: 16px;
    order: 3;
  }

  .ad-placeholder {
    min-height: auto;
    height: auto;
  }

  #map {
    width: 100%;
    height: 60vh;
    order: 1;
    flex: none;
  }

  .ad-title {
    font-size: 1em;
  }

  .ad-description {
    font-size: 0.875em;
  }

  .ad-benefits {
    margin: 8px 0;
  }

  .ad-benefits li {
    font-size: 0.85em;
    margin: 6px 0;
  }

  .ad-cta {
    margin-top: 12px;
    padding-top: 12px;
  }

  .tutorial-content {
    padding: 0;
    width: 100%;
    margin: 0;
  }

  .tutorial-steps {
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 16px 0;
    min-height: auto;
  }

  .tutorial-step {
    padding: 16px;
  }

  .tutorial-step h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
  }

  .tutorial-controls {
    flex-direction: column-reverse;
    gap: 16px;
    align-items: stretch;
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
  }

  .tutorial-controls button {
    width: 100%;
    margin-bottom: 12px;
  }

  .legend-tooltip {
    right: calc(100% + 12px);   /* Position to the left of the legend */
    left: auto;                 /* Remove left positioning */
    transform: none;            /* Remove transform since we're using right positioning */
  }
}
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
    display: none;
    z-index: 1000;
    text-align: center;
}

.loading-spinner.show {
    display: block;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 10px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Mobile Responsive Design */
@media (max-width: 768px) {
  #main-container {
    padding: 10px;
  }

  #map-and-filters {
    flex-direction: column;
  }

  #search-container {
    position: relative;
    top: 0;
    left: 0;
    padding: 0;
    margin-bottom: 16px;
  }

  #filters-sidebar {
    width: 100%;
    margin-bottom: 10px;
    order: 2;
  }

  #map {
    height: 60vh;
    order: 1;
  }

  .search-with-button {
    flex-direction: column;
    gap: 5px;
  }

  #search-input {
    width: 100%;
  }

  .dropdown-container {
    width: 100%;
  }

  .search-with-button {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    width: 100%;
  }

  #search-input {
    flex: 2;
    width: auto;
    order: 1;
  }

  .schulform-dropdown {
    margin: 0;
    flex: 1;
    width: auto;
    order: 2;
  }

  #location-button {
    order: 3;
  }

  .schulform-content {
    left: -100px;
    right: 0;
    max-width: 300px;
    position: absolute;
  }
  .tutorial-content {
    padding: 0;
    width: 100%;
    margin: 0;
  }

  .tutorial-steps {
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 16px 0;
    min-height: auto;
  }

  .tutorial-step {
    padding: 16px;
  }

  .tutorial-step h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
  }

  .tutorial-controls {
    flex-direction: column-reverse;
    gap: 16px;
    align-items: stretch;
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
  }

  .tutorial-controls button {
    width: 100%;
    margin-bottom: 12px;
  }

  .legend-tooltip {
    right: calc(100% + 12px);   /* Position to the left of the legend */
    left: auto;                 /* Remove left positioning */
    transform: none;            /* Remove transform since we're using right positioning */
  }
}

/* Mobile: align the right edge of the dropdown with the trigger button */
@media (max-width: 520px) {
  .schulform-dropdown { position: relative; }
  .schulform-content {
    left: auto !important;
    right: 0 !important; /* align right edge with trigger */
    max-width: 320px;
    box-sizing: border-box;
  }
}

/* Tutorial/Help Styles */
.tutorial-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 29999;
  pointer-events: none;
}

.tutorial-backdrop.show {
  display: block;
}

.tutorial-popup {
  display: none;
  position: fixed;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  background: white;
  padding: 16px;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  z-index: 30000; /* raised so nothing overlays it on mobile */
  width: 90vw;
  max-width: 500px;
  height: auto;
  max-height: 70vh;
  overflow: hidden;
  pointer-events: auto;
}

.tutorial-close-top {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.06);
  border: none;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 1rem;
  z-index: 30004;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tutorial-close-top:active { transform: scale(0.98); }

.tutorial-popup.show {
  display: flex;
  flex-direction: column;
}

.tutorial-content {
  background: white;
  padding: 12px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  position: relative;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch; /* allow content to fill width */
  overflow: auto; /* enable scrolling */
  flex: 1 1 auto;
  min-height: 0; /* allow flex children to shrink and allow scrolling */
}

.tutorial-popup.visible .tutorial-content {
    transform: translateY(0);
}

.tutorial-steps {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 8px 0;
  height: auto;
  width: 100%;
  max-width: 100%;
  justify-items: center; /* center each grid cell */
}

.tutorial-step {
  padding: 12px;
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center; /* center content inside the card */
  text-align: center;  /* center text inside the card */
  font-size: 0.8rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  width: 100%;
}

/* Mobile: keep tutorial compact */
@media (max-width: 720px) {
  .tutorial-popup {
    width: calc(100% - 24px) !important;
    max-width: calc(100% - 24px) !important;
    padding: 12px;
    max-height: 75vh;
  }

  .tutorial-content {
    padding: 10px;
    gap: 10px;
  }

  .tutorial-steps {
    gap: 8px;
    margin: 6px 0;
  }

  .tutorial-step {
    padding: 10px;
    font-size: 0.75rem;
  }

  .tutorial-step h3 {
    font-size: 0.95rem;
    margin-bottom: 6px;
  }

  .tutorial-step p {
    font-size: 0.7rem;
    line-height: 1.3;
  }
}

/* Extra-small screens (phones): make even tighter */
@media (max-width: 420px) {
  .tutorial-popup {
    width: calc(100% - 16px) !important;
    max-width: calc(100% - 16px) !important;
    padding: 10px;
    max-height: 80vh;
  }

  .tutorial-content {
    padding: 12px;
  }

  .tutorial-steps {
    gap: 10px;
  }

  .tutorial-step {
    width: 100% !important;
    padding: 12px;
    font-size: 0.85rem;
  }

  .tutorial-popup h2, .tutorial-popup #tutorial-title {
    font-size: 1.25rem;
    margin-bottom: 8px;
  }
}

/* Ensure tutorial content can scroll and controls stay tappable on very small screens */
@media (max-width: 520px) {
  .tutorial-popup {
    max-height: 85vh; /* allow some room for browser UI */
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .tutorial-content {
    overflow: auto;
    max-height: calc(85vh - 80px); /* leave space for sticky controls */
    padding-bottom: 12px;
  }

  .tutorial-controls {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,0.98));
    padding: 10px 12px;
    z-index: 30003; /* keep controls above other popup content */
    pointer-events: auto; /* ensure taps reach controls */
    display: flex;
    gap: 8px;
    flex-direction: column-reverse;
    border-top: 1px solid rgba(0,0,0,0.04);
  }

  .tutorial-controls button { 
    width: 100%; 
    pointer-events: auto;
    touch-action: manipulation;
  }

  /* Make legend act as a drop-up that can scroll without covering the whole map */
  .info.legend {
    max-height: 45vh;
    overflow: auto;
    bottom: 16px !important;
    top: auto !important;
  }

  /* Slightly lift bottomright map controls so legend doesn't overlap controls */
  .leaflet-bottom .leaflet-control {
    margin-bottom: 68px;
  }
}

.tutorial-step:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.tutorial-step h3 {
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    color: var(--primary-color);
    font-weight: 600;
}

.tutorial-step p {
    margin: 0;
    color: var(--text-color);
    line-height: 1.4;
    font-size: 0.75rem;
}

#tutorial-title,
.tutorial-popup h2 {
    font-size: 1.1rem;
    margin: 0 0 8px 0;
    font-weight: 600;
    color: var(--primary-color);
}

.tutorial-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    pointer-events: auto;
    z-index: 30003;
    gap: 8px;
}

.tutorial-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-color);
    cursor: pointer;
    transition: color 0.2s ease;
    pointer-events: auto;
    white-space: nowrap;
}

.tutorial-controls button {
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.tutorial-controls label:hover {
    color: var(--primary-color);
}

.tutorial-controls input[type="checkbox"] {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tutorial-controls input[type="checkbox"]:checked {
    border-color: var(--primary-color);
    background-color: var(--primary-color);
}

.tutorial-controls button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.tutorial-controls button:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.tutorial-controls button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.feedback-floating-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all 0.2s ease;
    z-index: 1000;
}

.feedback-floating-button:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.feedback-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 400px;
    max-width: 90%;
    z-index: 1000;
    border: 1px solid var(--border-color);
}

.feedback-popup h3 {
    margin: 0 0 16px 0;
    font-size: 1.125rem;
    color: var(--text-color);
}

.feedback-popup textarea {
    width: 100%;
    height: 120px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-family: inherit;
    resize: vertical;
}

.feedback-popup button {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.feedback-popup button:first-of-type {
    background: var(--primary-color);
    color: white;
    border: none;
    margin-right: 8px;
}

.feedback-popup button:last-of-type {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.feedback-popup button:hover {
    transform: translateY(-1px);
}

.feedback-popup button:first-of-type:hover {
    background: var(--primary-hover);
}

.feedback-popup button:last-of-type:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.general-feedback-popup textarea {
    width: 100%;
    height: 120px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-family: inherit;
    resize: vertical;
}

.general-feedback-popup .feedback-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.general-feedback-popup button {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.general-feedback-popup .submit-button {
    background: var(--primary-color);
    color: white;
    border: none;
}

.general-feedback-popup .submit-button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.general-feedback-popup .cancel-button {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.general-feedback-popup .cancel-button:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

/* Accessibility Improvements */
.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* Focus styles for better keyboard navigation */
a:focus,
button:focus,
input:focus {
  outline: 2px solid #008cff;
  outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #008cff;
  color: white;
  padding: 8px;
  z-index: 1000;
}

.skip-link:focus {
  top: 0;
}

/* Distance measurement styles */
.distance-control {
  background: white;
  padding: 10px;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0,0,0,0.1);
  margin: 10px;
}

.distance-info {
  margin-top: 5px;
  font-size: 12px;
  color: #666;
  border-top: 1px solid #eee;
  padding-top: 5px;
}

.distance-info p {
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.distance-info p:first-child {
  font-weight: bold;
  color: #333;
}

.help-button {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all 0.2s ease;
    z-index: 1000;
}

.help-button:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
    box-shadow: 0 8px 16px -4px rgba(0,0,0,0.2);
}

.popup-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.popup-header {
    margin-bottom: 8px;
}

.distance-info {
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

.distance-info p {
    margin: 4px 0;
}

.popup-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.popup-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.popup-footer a:hover {
    text-decoration: underline;
}

.nur-button {
    font-size: 0.813rem;
    padding: 3px 6px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 6px;
}

.nur-button:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.schulform-dropdown {
    position: relative;
    width: var(--schulform-width);
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px;
    font-size: 1rem;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    color: var(--text-color);
}

.dropdown-trigger:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
}

.schulform-content {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    min-width: 280px;
    z-index: 10000;
}

.schulform-content.show {
    display: block;
}

.schulform-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.schulform-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#type-filters {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.legend-title-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.legend-toggle {
  margin-left: auto;
  background: transparent;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
}

.legend-toggle .material-icons {
  font-size: 18px;
  color: var(--text-color);
}

.legend-collapsible {
  transition: max-height 0.28s ease, opacity 0.18s ease;
  max-height: 1000px; /* large default to fit all items */
  overflow: hidden;
}

.legend-collapsible.collapsed {
  max-height: 0;
  opacity: 0;
}

.legend-help-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    cursor: help;
    transition: all 0.2s ease;
    position: relative;
}

.legend-help-icon:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

.legend-tooltip {
    position: absolute;
    width: 300px;
    background: white;
    padding: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-color);
    visibility: hidden;
    opacity: 0;
    transition: all 0.2s ease;
    transform: translateY(10px);
    z-index: 1000;
    bottom: calc(100% - 50px);  /* Adjust vertical position to be more centered */
    right: calc(100% + 12px);   /* Position to the left of the legend */
    left: auto;                 /* Remove left positioning */
    transform: none;            /* Remove transform since we're using right positioning */
}

.legend-help-icon:hover .legend-tooltip {
    visibility: visible;
    opacity: 1;
    transform: none;
}

.legend-tooltip p {
    margin: 0 0 12px 0;
}

.legend-tooltip p:last-child {
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .legend-tooltip {
        width: 250px;
        bottom: calc(100% - 50px);
        right: calc(100% + 12px);
        left: auto;
        transform: none;
    }
}
