/* Reset browser styles */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: 14px;
    color: #333;
    background-color: #fff;
}

/* Main layout container */
.container {
    display: flex;
    height: 100vh;
}

/* Sidebar panel */
.sidebar {
    width: 350px;
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    border: none;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
    position: relative;
    transition: width 0.3s ease-in-out, padding 0.3s ease-in-out;
}

.sidebar.sidebar-collapsed {
    width: 0;
    padding-left: 0; /* Remove padding when collapsed */
    padding-right: 0; /* Remove padding when collapsed */
    overflow: hidden; /* Hide content that might overflow the 0 width */
}

.sidebar-content {
    position: relative;
    padding: 0;
    overflow: hidden;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar h1 {
    margin: 8px 0 10px 0;
    padding-bottom: 8px;
    font-size: 1.3em;
    color: #343a40;
    border-bottom: 1px solid #d3d7db;
}

.sidebar-section {
    margin-bottom: 10px;
    border-bottom: 1px solid #e9ecef;
}
.sidebar-section:last-of-type { /* Remove border from last section */
     border-bottom: none;
}

.sidebar-section-header {
    padding: 10px 0;
    cursor: default;
    list-style: none;
    display: flex;
    align-items: center;
}

.sidebar-section-header h2 {
    font-size: 1.1em;
    margin: 0;
    color: #495057;
    flex-grow: 1;
    font-weight: 600;
}

.sidebar-section-content {
    padding: 12px 0 15px 0;
}
.sidebar-section-content.controls,
.sidebar-section-content.results-controls {
    /* Resetting previous rule specifics */
    margin-bottom: 0;
    padding-bottom: 15px; /* Keep padding */
    border-bottom: none; /* Border is now on the <details> element */

}


.checkbox-control-group {
    display: flex;
    align-items: center;
    margin-top: 8px;
    margin-bottom: 8px;
}

.checkbox-control-group label {
    margin-bottom: 0; /* Remove default block margin */
    margin-right: 8px; /* Space between label and checkbox */
    /* Inherit font styles from general label rule */
}

.checkbox-control-group input[type="checkbox"] {
    margin: 0; /* Remove default checkbox margin */
    vertical-align: middle; /* Align checkbox nicely */
}

/* REMOVED specific rule for #show-unnamed-roads-checkbox as wrapper handles layout */
/* #show-unnamed-roads-checkbox { ... } */

/* Ensure labels align nicely with their controls - Reverted */
/* .sidebar-section-content.results-controls > label { */
    /* margin-bottom: 0; */ /* Align with other items */
    /* margin-right: 4px; */ /* Small space after label */
/* } */


/* General Controls Styling */
.sidebar button {
    padding: 8px 12px;
    margin-top: 5px; /* Add top margin */
    margin-bottom: 8px;
    margin-right: 5px;
    cursor: pointer;
    background-color: #0d6efd; /* Updated Bootstrap blue */
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
}
.sidebar button:hover:not(:disabled) {
    background-color: #0b5ed7;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
}
.sidebar button:disabled {
    cursor: not-allowed;
    background-color: #6c757d;
    opacity: 0.7;
}

/* Specific styling for icon buttons */
.sidebar .icon-button {
    padding: 6px 10px; /* Adjusted padding for better icon fit */
    font-size: 1em; /* Use standard font size for emojis/icons */
    min-width: 36px; /* Ensure a minimum width, adjust as needed */
    text-align: center;
    flex-shrink: 0; /* Prevent buttons from shrinking */
    margin-left: 4px; /* Space between buttons or input/button */
    line-height: 1; /* Ensure consistent height */
    height: 30px; /* Match typical input height */
    box-sizing: border-box; /* Include padding/border in height */
}

/* Removed .location-input specific rule */
.sidebar .address-search { /* Now refers to the container div */
    /* display: flex; /* Flex is now on the inner group */
    /* align-items: center; /* Alignment is now on the inner group */
    margin-bottom: 5px; /* Reduced margin below the group */
    position: relative; /* Keep for suggestions positioning */
}
/* New style for the input group container */
.sidebar .location-input-group {
    display: flex;
    align-items: center; /* Vertically align input and buttons */
    width: 100%; /* Take full width */
    margin-bottom: 5px; /* Space below the group */
}

.sidebar .location-input-group input#location-search-input {
    flex-grow: 1; /* Input takes remaining space */
    margin-right: 0; /* Reset margin */
    margin-bottom: 0;
    width: auto;
    height: 30px; /* Match button height */
    box-sizing: border-box;
}
/* Removed styles for #geocode-address-btn */
.sidebar #coords-display { /* Now positioned after the input group */
    font-size: 0.85em;
    color: #6c757d;
    margin-top: 0; /* Reset top margin */
    margin-bottom: 10px; /* Add margin below */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar label {
    display: block;
    margin-bottom: 5px; /* Slightly increase space below labels */
    font-size: 0.9em;
    color: #495057;
    font-weight: 500; /* Slightly bolder labels */
}

/* General Input/Select Styling (excluding those in flex groups) */
.sidebar input[type="number"]:not(.radius-input),
.sidebar input[type="text"]:not(.address-search input):not(.search-input),
.sidebar select:not(.radius-select) {
    width: calc(100% - 16px); /* Apply width only if not in specific flex groups */
    padding: 6px 8px;
    margin-bottom: 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    background-color: #fff;
}
/* Styling for items specifically within flex groups */

#loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#loading-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  border: 6px solid #f3f3f3;
  border-top: 6px solid #0d6efd;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  margin-top: 10px;
  color: #fff;
  font-size: 1.2em;
}
.sidebar .location-input-group input#location-search-input {
    padding: 6px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    background-color: #fff;
    margin-bottom: 0; /* Remove bottom margin for inline elements */
}
/* Remove height override from here if set above */


/* Container for radius input and select */
/* Legacy radius-input-group styles - replaced by radius-group */

/* --- Road List Styling --- */
#road-list {
    list-style: none;
    padding: 0;
    margin: 10px 0; /* Add margin top/bottom */
    padding-bottom: 10px;
}

.road-group {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    overflow: hidden;
}

.road-group:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 0 0 2px rgba(13, 110, 253, 0.2);
    transform: translateY(-3px) scale(1.01);
    border-color: rgba(13, 110, 253, 0.3);
}

.road-group:last-child {
    margin-bottom: 0;
}

.road-group-header { /* The <summary> element */
    padding: 12px 16px;
    cursor: pointer;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    transition: all 0.2s ease;
    list-style: none;
    border-bottom: 1px solid #e9ecef;
}

.road-group-header::-webkit-details-marker {
    display: none;
}

.road-group-header:hover {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.15);
    transform: scale(1.01);
}

.road-group[open] > .road-group-header {
    background: linear-gradient(135deg, #dee2e6 0%, #d1d7db 100%);
    border-bottom-color: #d1d7db;
}

.road-group-header.highlighted {
    background: linear-gradient(135deg, #cce5ff 0%, #b3d9ff 100%);
    border-bottom-color: #99ccff;
}

/* NEW: Wrapper inside the summary */
.summary-content-wrapper {
    display: flex;
    align-items: center;
    width: 100%; /* Take full width of summary */
}

/* NEW: Style for the marker span */
.group-marker {
    display: inline-block;
    margin-left: 8px; /* Space AFTER checkbox */
    margin-right: 8px; /* Space BEFORE name */
    font-size: 0.8em;
    transition: transform 0.2s ease;
    color: #6c757d;
    /* order: 2; */ /* Marker is second - Temporarily removed for diagnosis */
    line-height: 1; /* Prevent extra vertical space */
}
/* Rotate the new marker span */
.road-group[open] .group-marker {
    transform: rotate(90deg);
}

.road-group-header .road-group-checkbox { /* Checkbox */
    /* order: 1; */ /* Checkbox is first - Temporarily removed for diagnosis */
    flex-shrink: 0; /* Prevent checkbox from shrinking */
    margin: 0; /* Reset margin */
}

.road-group-name { /* Name */
    font-weight: 500; /* Slightly less bold */
    flex-grow: 1;
    color: #495057; /* Darker text */
    /* order: 3; */ /* Name is third - Temporarily removed for diagnosis */
    margin: 0; /* Reset margin */
}
.segment-count { font-size: 0.85em; color: #6c757d; }

.segment-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: #ffffff;
}

.segment-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f8f9fa;
    display: flex;
    align-items: center;
    font-size: 0.9em;
    transition: all 0.2s ease;
    background: #ffffff;
}

.segment-item:hover {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    transform: translateX(4px) scale(1.02);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.2);
    border-left: 3px solid #2196f3;
}

.segment-item.highlighted {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-left: 3px solid #2196f3;
}

.segment-item:last-child {
    border-bottom: none;
}

.segment-item .road-select-checkbox {
    margin-right: 12px;
    flex-shrink: 0;
    cursor: pointer;
    transform: scale(1.1);
}

.segment-item .segment-text {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 500;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 0.3em;
    padding-right: 10px; /* Reduce padding */
    flex-wrap: wrap; /* Enable wrapping */
}

.segment-item .osm-speed,
.segment-item .waze-speed,
.segment-item .missing-speed {
    max-width: 100px; /* Constrain tag width */
    overflow: hidden; /* Prevent overflow */
    text-overflow: ellipsis; /* Add ellipsis for overflowed text */
    font-size: 0.75em; /* Reduce font size */
    padding: 1px 4px; /* Reduce padding */
}

.segment-item .missing-speed {
    color: #dc3545;
    font-style: italic;
    font-size: 0.85em;
    background: #f8d7da;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* Was .waze-speed, now renamed for OSM data */
.segment-item .osm-speed {
    color: #28a745; /* Green text for OSM */
    font-style: italic;
    font-size: 0.85em;
    background: #d4edda; /* Green background for OSM */
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* This class now defines the blue style for Waze data */
.segment-item .waze-speed {
    color: #005F5F; /* Darker Cyan/Teal for text - for readability */
    font-style: italic;
    font-size: 0.85em;
    background: #A0E7E5; /* Lighter, more Cyan background for Waze */
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}


/* Styles removed for old edit bar */

/* Map container styling */
#map {
    flex-grow: 1;
    height: 100%;
}

/* --- Edit Drawer Styling --- */

.edit-drawer {
    position: fixed; /* Position relative to viewport */
    top: 0;
    left: 350px; /* Position it to the right of the sidebar */
    width: 280px; /* Adjust width as needed */
    height: 100%;
    background: #ffffff; /* White background */
    border-left: 1px solid #ced4da; /* Separator line */
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15); /* Shadow on the left */
    padding: 15px;
    box-sizing: border-box;
    /* Base state: hidden via transform */
    transform: translateX(-100%); /* Move left by own width, hiding it */
    /* Initial visibility state */
    opacity: 0;
    visibility: hidden;
    /* Transition transform and opacity ONLY */
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    z-index: 1010; /* Ensure it's above map layers AND controls */
    /* Flex layout applied only when expanded */
    /* display: flex; */
    /* flex-direction: column; */
}

/* Show drawer only when expanded */
.edit-drawer.drawer-expanded {
    /* left: 350px; /* Keep left: 350px from base rule */
    transform: translateX(0); /* Remove the translation */
    opacity: 1;
    visibility: visible;
    display: flex; /* Apply flex layout when expanded */
    flex-direction: column;
}


/* Scroll to Top Button - Updated for new layout */
.scroll-to-top-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    font-size: 18px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
    transition: all 0.3s ease;
    z-index: 1000;
    border: 2px solid #ffffff;
}

.scroll-to-top-btn:hover {
    background: linear-gradient(135deg, #0b5ed7 0%, #0a58ca 100%);
    transform: translateY(-4px) scale(1.1);
    box-shadow: 0 10px 25px rgba(13, 110, 253, 0.5), 0 0 0 3px rgba(255, 255, 255, 0.3);
}

.scroll-to-top-btn.visible {
    opacity: 1;
    visibility: visible;
}

.sidebar.sidebar-collapsed .scroll-to-top-btn {
    display: none;
}

/* Styling for content inside the drawer */
.edit-drawer h3 {
    margin-top: 10px; /* Space below close button */
    margin-bottom: 15px;
    font-size: 1.1em;
    color: #343a40;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 8px;
}

/* Styling for the new selected roads list */
.edit-drawer .selected-roads-list {
    list-style: none;
    padding: 0 0 0 2px; /* Minimal left padding */
    margin: 0 0 2px 0; /* Minimized space below the list */
    overflow-y: auto;
    overflow-x: auto;
    white-space: nowrap;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    background-color: #f8f9fa;
    min-height: 50px;
}
.edit-drawer .selected-roads-list li {
    padding: 4px 4px 4px 0; /* Reduce right and remove left padding */
}

.edit-drawer .selected-roads-list li {
    padding: 4px 8px;
    font-size: 0.85em;
    color: #495057;
    border-bottom: 1px solid #e9ecef;
}

.edit-drawer .selected-roads-list li:last-child {
    border-bottom: none;
}

.edit-drawer label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: #495057;
    font-weight: 500;
}

.edit-drawer .maxspeed-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.edit-drawer .maxspeed-row input[type="number"] {
    width: 100px;
    margin-bottom: 0;
}
.edit-drawer .maxspeed-row select {
    width: 80px;
    margin-bottom: 0;
}

.edit-drawer input[type="number"],
.edit-drawer select {
    width: 100%; /* Full width within drawer */
    padding: 8px;
    margin-bottom: 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
    box-sizing: border-box; /* Include padding in width */
}

.edit-drawer select {
     width: calc(100% - 110px); /* Adjust width relative to button */
     display: inline-block;
     vertical-align: middle;
     margin-right: 5px;
}

/* Changeset comment textarea styling */
.edit-drawer textarea#changeset-comment {
    width: 100%;
    min-height: 36px;
    max-height: 80px;
    padding: 8px;
    font-size: 0.95em;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    color: #222;
    margin-bottom: 12px;
    box-sizing: border-box;
    resize: vertical;
}
.edit-drawer textarea#changeset-comment::placeholder {
    color: #b0b0b0;
    opacity: 1;
}

.edit-drawer input#edit-maxspeed {
    width: 100px; /* Fixed width for speed input */
    display: inline-block;
    vertical-align: middle;
    margin-right: 5px;
}


.edit-drawer button#apply-edit-btn {
    width: 100%;
    padding: 10px;
    margin-top: auto; /* Push button to the bottom */
    margin-bottom: 0; /* Remove default bottom margin if any */
    background-color: #28a745; /* Green for apply */
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.edit-drawer button#apply-edit-btn:hover {
    background-color: #218838;
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 16px rgba(40, 167, 69, 0.3);
}

.edit-drawer #edit-status {
    font-size: 0.85em;
    margin-top: 10px;
    color: #6c757d;
    min-height: 1.2em; /* Reserve space */
}

/* --- Autocomplete Suggestions --- */
.address-search {
    position: relative;
}

/* .address-search already has position: relative */

#address-suggestions {
  position: absolute;
  top: calc(100% + 2px); /* Position below the input group, with a small gap */
  left: 0;
  /* Adjust right based on button widths if needed, or keep full width */
  right: 0; /* Span the width of the parent container (.address-search) */
  background-color: white;
  border: 1px solid #ccc;
  border-top: none;
  max-height: 150px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: none; /* Hidden by default */
  box-sizing: border-box;
}


/* Style for individual suggestion items */
#address-suggestions .suggestion-item {
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  font-size: 0.9em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#address-suggestions .suggestion-item:last-child {
  border-bottom: none;
}

#address-suggestions .suggestion-item:hover,
#address-suggestions .suggestion-item.suggestion-active { /* For keyboard navigation */
  background-color: #e3f2fd;
  transform: translateX(2px);
  box-shadow: 0 2px 8px rgba(33, 150, 243, 0.2);
  border-left: 3px solid #2196f3;
}

#address-suggestions .suggestion-item.error {
    color: #dc3545; /* Error color */
    font-style: italic;
    cursor: default;
}

.sidebar.sidebar-collapsed {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden; /* Hide content when collapsed */
    border-left: none; /* Hide border when collapsed */
    box-shadow: none; /* Hide shadow when collapsed */
}

.sidebar-edge-handle {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 80px;
    background-color: rgba(108, 117, 125, 0.25); /* Subtle, semi-transparent grey */
    border-radius: 0 4px 4px 0; /* Rounded on the outer edge when on the left */
    z-index: 1010; /* Ensure it's above sidebar content, adjust as needed */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.3s ease-in-out, background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.sidebar-edge-handle .handle-icon {
    color: #ffffff;
    font-size: 1.2em;
    font-weight: bold;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s ease-in-out;
}

/* Hover State */
.sidebar-edge-handle:hover {
    background-color: rgba(108, 117, 125, 0.6); /* More opaque on hover */
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.2); /* Subtle shadow for depth */
}

.sidebar-edge-handle:hover .handle-icon {
    opacity: 1; /* Show icon on hover */
}

/* Focus State for Accessibility */
.sidebar-edge-handle:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 1px;
    background-color: rgba(108, 117, 125, 0.5);
}

.sidebar-edge-handle:focus .handle-icon {
    opacity: 1; /* Ensure icon is visible on focus too */
}

/* State-specific positioning and icon direction */
.sidebar-edge-handle.collapsed-state {
    left: 0;
    border-radius: 0 4px 4px 0; /* Rounded right when on left edge */
}

.sidebar-edge-handle.expanded-state {
    left: 338px; /* Sidebar width (350px) - Handle width (12px) = 338px */
    border-radius: 4px 0 0 4px; /* Rounded left when on right edge of sidebar */
}
@media (max-width: 768px) {
    .edit-drawer {
        left: 0;
        z-index: 1020;
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.25);
    }
}
.edit-success {
    color: #198754; /* Bootstrap success green */
    font-weight: 500; /* Slightly bolder */
}

/* Style for the checkmark emoji */
.edit-success .success-checkmark {
    display: inline-block; /* Ensure proper alignment */
    margin-right: 5px; /* Space after checkmark */
    font-size: 1.1em; /* Slightly larger checkmark */
    vertical-align: middle; /* Align with text */
}

/* Ensure hover doesn't override success color */
.segment-item.edit-success:hover {
    background-color: #e9f5ec; /* Lighter green background on hover */
    color: #198754; /* Keep text green */
}
.road-group-header.edit-success:hover {
    background-color: #e9f5ec; /* Lighter green background on hover */
    color: #198754; /* Keep text green */
}
.road-group[open] > .road-group-header.edit-success {
     background-color: #d1e7dd; /* Slightly darker green when open */
     color: #198754; /* Keep text green */
}
.edit-success {
    color: #28a745 !important; /* Green text color */
    font-weight: 500;
    transition: color 0.3s ease;
}

.success-checkmark {
    margin-right: 5px;
    font-size: 0.9em;
    vertical-align: middle;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* Edit drawer specific success styles */
.edit-drawer .selected-roads-list li.edit-success {
    background-color: rgba(40, 167, 69, 0.1); /* Light green background */
    border-left: 3px solid #28a745;
    padding-left: 5px; /* Compensate for border */
}

/* Header Section */
.sidebar-header {
    flex-shrink: 0;
    padding: 15px 20px 10px 20px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-top {
    position: relative;
}

.header-top h1 {
    margin: 0;
    font-size: 1.4em;
    font-weight: 700;
    color: #343a40;
    letter-spacing: 0.5px;
}

/* Prevent blue highlighting for NERF letters when clicked */
.nerf-title {
    color: #343a40 !important;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.nerf-title:active,
.nerf-title:focus,
.nerf-title:visited {
    color: #343a40 !important;
    outline: none !important;
}

.nerf-title:hover {
    color: #343a40 !important;
}

/* Floating password input bubble */
.password-input-container {
    position: absolute !important;
    top: 100% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background: white !important;
    border: 2px solid #007bff !important;
    border-radius: 8px !important;
    padding: 12px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    z-index: 1000 !important;
    margin-top: 8px !important;
    min-width: 200px !important;
}

.password-input-container::before {
    content: '' !important;
    position: absolute !important;
    top: -8px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 0 !important;
    height: 0 !important;
    border-left: 8px solid transparent !important;
    border-right: 8px solid transparent !important;
    border-bottom: 8px solid #007bff !important;
}

.password-input-container::after {
    content: '' !important;
    position: absolute !important;
    top: -6px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 0 !important;
    height: 0 !important;
    border-left: 6px solid transparent !important;
    border-right: 6px solid transparent !important;
    border-bottom: 6px solid white !important;
}

.header-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.auth-button {
    padding: 6px 12px !important;
    font-size: 0.8em !important;
    border-radius: 20px !important;
    background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%) !important;
    border: none !important;
    color: white !important;
    font-weight: 500;
    transition: all 0.2s ease !important;
    margin: 0 !important;
}

.auth-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(13, 110, 253, 0.3);
}

.edit-toggle-btn {
    padding: 6px 8px !important;
    border-radius: 50% !important;
    background: #28a745 !important;
    border: none !important;
    color: white !important;
    font-size: 1em !important;
    transition: all 0.2s ease !important;
    margin: 0 !important;
}

.edit-toggle-btn:hover {
    background: #218838 !important;
    transform: scale(1.1);
}

/* Controls Container - Top Section */
.controls-container {
    flex: 0 0 auto; /* Don't grow, don't shrink, auto height */
    max-height: 33vh; /* Limit to approximately 1/3 of viewport */
    padding: 10px 15px; /* Reduced padding */
    background: #ffffff;
    border-bottom: 2px solid #e9ecef;
}

/* Control Cards */
.control-card {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
}

.control-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(13, 110, 253, 0.1);
    transform: translateY(-3px) scale(1.02);
    border-color: rgba(13, 110, 253, 0.3);
}

.control-card:last-child {
    margin-bottom: 0;
}

.card-title {
    margin: 0;
    padding: 6px 10px;
    font-size: 0.95em;
    font-weight: 600;
    color: #495057;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 1px solid #e9ecef;
    border-radius: 12px 12px 0 0;
}


.card-content {
    padding: 6px 8px;
}

/* Compact Filter & Sort Card */
#filter-sort-card {
    margin-bottom: 4px; /* Ultra-minimal spacing between cards */
}

#filter-sort-card .card-content {
    padding: 0; /* Remove padding for collapsed state */
}


/* Smooth fade animation for Filter & Sort button */
@keyframes soft-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Interactive Filter & Sort Title Button */
#filter-sort-card .card-title {
    text-align: center;
    color: white; /* White text for dark blue background */
    font-weight: 700;
    cursor: pointer;
    position: relative;
    margin: 0;
    padding: 6px 12px; /* Reduced vertical padding for compactness */
    border-radius: 8px;
    transition: all 0.2s ease;
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%); /* Always dark blue */
    border: 1px solid #0d47a1; /* Dark blue border */
    user-select: none;
    font-size: 0.9em; /* Slightly smaller font for compactness */
    box-shadow: 0 2px 6px rgba(13, 110, 253, 0.2); /* Enhanced shadow for dark background */
}

#filter-sort-card .card-title:hover {
    animation: soft-pulse 3s ease-in-out infinite; /* Slow smooth fade */
    transform: translateY(-3px) scale(1.05); /* More pronounced lift and scale */
    box-shadow: 0 8px 20px rgba(13, 110, 253, 0.4), 0 0 0 2px rgba(255, 255, 255, 0.8); /* Stronger shadow with glow */
}

#filter-sort-card .card-title::after {
    content: ' ⚙️';
    font-size: 0.8em;
    opacity: 0.7;
    transition: all 0.3s ease;
    margin-left: 6px;
}

#filter-sort-card:hover .card-title::after {
    content: ' ⚙️';
    opacity: 1;
    transform: rotate(90deg);
    filter: brightness(1.2); /* Brighter gear icon on dark background */
}

/* Collapsed state - minimal height */
#filter-sort-card .collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    pointer-events: none;
    margin: 0;
}

/* Expanded state - collapsible-content is the single visual panel */
#filter-sort-card:hover .collapsible-content {
    max-height: 120px; /* Sufficient for both rows */
    pointer-events: auto;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border: 2px solid rgba(13, 110, 253, 0.2);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15),
                inset 0 1px 0 rgba(255, 255, 255, 0.9);
    padding: 8px 12px 10px 12px; /* Take over padding for proper spacing of child elements */
    margin: 0; /* Ensure no margin creates gaps */
}

/* Expanded state - make card-content neutral container */
#filter-sort-card:hover .card-content {
    padding: 0; /* Remove padding - let collapsible-content handle it */
    background: transparent !important; /* Ensure no background interferes */
    border: none !important; /* No border */
    box-shadow: none !important; /* No shadow */
}

/* Smooth transitions for internal elements */
#filter-sort-card .collapsible-content .filter-sort-row,
#filter-sort-card .collapsible-content .options-row {
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease 0.1s; /* Slight delay for smoother effect */
}

/* Subtle elevation for select elements within the expanded card */
#filter-sort-card:hover .collapsible-content select.control-select {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow for elevation */
    transition: all 0.2s ease;
}

#filter-sort-card:hover .collapsible-content select.control-select:hover {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

#filter-sort-card:hover .collapsible-content select.control-select:focus {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(13, 110, 253, 0.2);
    outline: none;
}

/* Subtle elevation for mini buttons within the expanded card */
#filter-sort-card:hover .collapsible-content .mini-btn {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow for elevation */
    transition: all 0.2s ease;
}

#filter-sort-card:hover .collapsible-content .mini-btn:hover {
    box-shadow: 0 4px 8px rgba(13, 110, 253, 0.2); /* Enhanced shadow on hover */
    transform: translateY(-1px);
}

#filter-sort-card:hover .collapsible-content .filter-sort-row,
#filter-sort-card:hover .collapsible-content .options-row {
    opacity: 1;
    transform: translateY(0);
}

/* Clean 4-Line Layout */
.layout-row {
    display: flex;
    gap: 6px;
    margin-bottom: 4px;
    align-items: center;
    width: 100%;
}

.layout-row:last-child {
    margin-bottom: 0;
}

/* Line 1: Full-width Search Input */
.search-input-full {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85em;
    height: 28px;
    box-sizing: border-box;
}

/* Line 3: Icon Buttons Row */
.layout-row:nth-child(3) {
    justify-content: space-between;
}

/* Line 2: Radius Label + Input + Select */
.radius-label {
    font-size: 0.85em;
    font-weight: 500;
    color: #6c757d;
    white-space: nowrap;
    margin-right: 6px;
}

.radius-input {
    width: 50px;
    padding: 6px 4px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85em;
    height: 28px;
    box-sizing: border-box;
}

.radius-select {
    width: 70px;
    padding: 6px 4px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85em;
    height: 28px;
    box-sizing: border-box;
    background: white;
}

/* Line 3: Coordinates */
.coords-text {
    margin: 0;
    padding: 6px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.8em;
    color: #6c757d;
    border-left: 2px solid #0d6efd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    box-sizing: border-box;
}

.search-input:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.icon-btn {
    padding: 6px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #ffffff;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    box-sizing: border-box;
    flex: 1;
}

.icon-btn:hover {
    background: #f8f9fa;
    border-color: #0d6efd;
    transform: translateY(-1px);
}

.search-btn:hover {
    background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
    color: white;
}

.location-btn:hover {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.file-btn:hover {
    background: linear-gradient(135deg, #fd7e14 0%, #e55a4e 100%);
    color: white;
}


.coords-text {
    margin: 0;
    padding: 4px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.75em;
    color: #6c757d;
    border-left: 2px solid #0d6efd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


.radius-input {
    width: 55px;
    flex-shrink: 0;
    padding: 6px 6px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.85em;
}

.radius-select {
    width: 80px;
    flex-shrink: 0;
    padding: 6px 4px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.85em;
    background: white;
}

/* Action Button */
.action-btn {
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(111, 66, 193, 0.3);
}

/* Filter Sort Row */
.filter-sort-row {
    display: flex;
    gap: 12px;
}

.select-group {
    flex: 1;
}

.control-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 0.9em;
    background: white;
}

/* Options Row */
.options-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.checkbox-group {
    display: flex;
    align-items: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: #495057;
    cursor: pointer;
    margin: 0;
}

.checkbox-text {
    font-weight: 500;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 4px;
}

.mini-btn {
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background: #ffffff;
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 32px;
    text-align: center;
}

.mini-btn:hover {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
    transform: translateY(-1px);
}

/* Road List Container - Bottom Section */
.road-list-container {
    flex: 1 1 auto; /* Grow to take remaining space after controls */
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex child to shrink */
    background: #ffffff;
}

.road-list-header {
    flex-shrink: 0;
    padding: 10px 15px 8px 15px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.list-title {
    margin: 0;
    font-size: 1.1em;
    font-weight: 600;
    color: #495057;
}

.road-list-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 15px 15px 15px;
}

.road-list {
    list-style: none;
    padding: 0;
    margin: 10px 0 0 0;
}

.empty-message {
    padding: 20px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 10px 0;
}

/* Suggestions Container */
.suggestions-container {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ced4da;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}


/* Ensure proper scrolling for road list */
.road-list-content::-webkit-scrollbar {
    width: 6px;
}

.road-list-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.road-list-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.road-list-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Controls container scrollbar - removed since controls are no longer scrollable */

/* Focus states for accessibility */
.search-input:focus,
.radius-input:focus,
.radius-select:focus,
.control-select:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.mini-btn:focus,
.icon-btn:focus,
.action-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.2);
}

/* Animation for control cards */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.control-card {
    animation: slideInUp 0.3s ease-out;
}

/* Responsive adjustments */
@media (max-height: 700px) {
    .controls-container {
        max-height: 30vh;
        padding: 6px 8px;
    }
    
    .card-content {
        padding: 4px 6px;
    }
    
    .input-row {
        margin-bottom: 3px;
    }
    
    .card-title {
        padding: 4px 6px;
        font-size: 0.85em;
    }
}

@media (max-height: 500px) {
    .controls-container {
        max-height: 25vh;
        padding: 4px 6px;
    }
    
    .card-content {
        padding: 3px 4px;
    }
    
    .input-row {
        margin-bottom: 2px;
    }
    
    .sidebar-header {
        padding: 10px 15px 5px 15px;
    }
    
    .header-top h1 {
        font-size: 1.2em;
    }
}

@keyframes pulse-green {
  0%, 100% {
    background-color: #66bb6a;
    transform: scale(1);
    box-shadow: 0 0 5px rgba(102, 187, 106, 0.4);
  }
  50% {
    background-color: #388e3c;
    transform: scale(1.05);
    box-shadow: 0 0 15px 5px rgba(56, 142, 60, 0.7);
  }
}

.edit-toggle-btn.edit-button-pulse {
  animation: pulse-green 2.5s infinite ease-in-out;
  color: white;
}

/* --- Tag Styles --- */
.osm-speed,
.json-speed,
.missing-osm,
.waze-speed {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1em 0.9em;
  border-radius: 1em;
  font-size: 0.95em;
  vertical-align: middle;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.osm-speed { background: #4caf50; color: #fff; }
.json-speed { background: #ff9800; color: #fff; }
.missing-osm { background: #f8d7da !important; color: #dc3545 !important; }
.waze-speed { background: #2196f3; color: #fff; }

/* --- Segment Layout --- */
.segment-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 20px;
  box-sizing: border-box;
  gap: 0.5em;
  min-width: 0;
  overflow: hidden;
}

.segment-text {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.3em;
  margin-right: auto;
  padding-right: 1em;
}

/* --- Road List Container --- */
.road-list-content,
.segment-list {
  display: flex;
  flex-direction: column;
  flex-shrink: 1;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
  padding-right: 20px;
}

.road-list-content {
  overflow-y: auto;
  overflow-x: hidden;
}