/* Map (index.php) page styles */

/* Dark theme for Leaflet popups */
.dark-popup .leaflet-popup-content-wrapper {
    background-color: #343a40;
    color: #f8f9fa;
}

.dark-popup .leaflet-popup-tip {
    background-color: #343a40;
}

.dark-popup .leaflet-popup-close-button {
    color: #f8f9fa !important;
}

.dark-popup .leaflet-popup-close-button:hover {
    color: #adb5bd !important;
}

:root {
    --navbar-height: 56px;
    --bg-dark: #212529;
    --panel-dark: #343a40;
    --panel-border: #495057;
    --text-light: #f8f9fa;
}

/* Base layout below fixed navbar */
body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-light);
}

/* Fixed navbar */
.navbar {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
}

/* Fullscreen map below navbar and above bottom coord panel (40px) */
#map {
    height: calc(100vh - var(--navbar-height) - 40px);
    width: 100%;
    position: absolute;
    top: var(--navbar-height);
    left: 0;
    z-index: 1;
}

/* Prevent Leaflet container from overlapping bottom panel */
#map .leaflet-container {
    height: 100%;
    max-height: calc(100vh - var(--navbar-height) - 40px);
}

/* Prevent any map overlay from blocking the bottom panel */
#map .leaflet-bottom {
    bottom: 10px; /* Add padding from the bottom */
}

/* Ensure the Leaflet tile pane doesn't overflow and block the bottom panel */
#map .leaflet-tile-pane,
#map .leaflet-overlay-pane,
#map .leaflet-shadow-pane {
    max-height: calc(100vh - var(--navbar-height) - 40px);
}

/* Leaflet popup styling to match dark theme */
.leaflet-popup-content-wrapper {
    min-width: 200px;
    background-color: var(--panel-dark);
    color: var(--text-light);
}
.leaflet-popup-tip {
    background-color: var(--panel-dark);
}
.popup-links {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.popup-edit-link,
.popup-delete-link,
.popup-health-link {
    font-size: 0.85em;
    text-align: right;
    display: block;
    margin-top: 5px;
    color: #0d6efd;
    text-decoration: underline;
    cursor: pointer;
}
.popup-edit-link:hover,
.popup-delete-link:hover,
.popup-health-link:hover {
    color: #4dabf7;
    text-decoration: none;
}
/* Override styles for dropdown menu items */
.dropdown-item.popup-edit-link,
.dropdown-item.popup-delete-link,
.dropdown-item.popup-health-link,
.dropdown-item.popup-requested-dump-link,
.dropdown-item.popup-called-in-missed-link {
    font-size: 0.9em;
    text-align: left;
    display: block;
    margin-top: 0;
    color: #fff;
    text-decoration: none;
    cursor: pointer;
}
.dropdown-item.popup-edit-link i,
.dropdown-item.popup-delete-link i,
.dropdown-item.popup-health-link i,
.dropdown-item.popup-requested-dump-link i,
.dropdown-item.popup-called-in-missed-link i {
    margin-right: 8px;
}
.dropdown-item.popup-delete-link i {
    color: #dc3545;
}
.dropdown-item.popup-edit-link:hover,
.dropdown-item.popup-health-link:hover,
.dropdown-item.popup-requested-dump-link:hover,
.dropdown-item.popup-called-in-missed-link:hover {
    background-color: #495057;
    color: #fff;
}
.dropdown-item.popup-delete-link:hover {
    background-color: #495057;
    color: #fff;
}
.focus-marker-link {
    color: #0d6efd;
    text-decoration: underline;
    cursor: pointer;
}
.focus-marker-link:hover {
    color: #4dabf7;
    text-decoration: none;
}

/* Bottom coordinate/info panel */
#coord-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    background: var(--panel-dark);
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    font-size: 14px;
    border-top: 1px solid var(--panel-border);
    color: var(--text-light);
}
#coord-panel button {
    position: relative;
    z-index: 1002;
}
#coord-panel .dropdown {
    margin-left: auto;
}
#coord-panel .dropdown-menu {
    z-index: 1050;
}
#coord-panel .dev-badge {
    background-color: #ffc107;
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

/* Modal and form theming to dark */
.modal-content {
    background-color: var(--panel-dark);
    color: var(--text-light);
}
.modal-header,
.modal-footer {
    border-color: var(--panel-border);
}
.form-control,
.form-select {
    background-color: #495057;
    color: var(--text-light);
    border-color: #6c757d;
}
.form-control:focus,
.form-select:focus {
    background-color: #495057;
    color: var(--text-light);
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Tables and buttons */
.table {
    color: var(--text-light);
}
.table-dark {
    --bs-table-bg: var(--panel-dark);
    --bs-table-border-color: var(--panel-border);
}
.btn-primary:hover {
    background-color: #4dabf7;
    border-color: #4dabf7;
}
.btn-success:hover {
    background-color: #51cf66;
    border-color: #51cf66;
}
.btn-danger:hover {
    background-color: #ff6b6b;
    border-color: #ff6b6b;
}

/* Labels and checkbox pairs */
.form-label {
    text-align: right;
    padding-right: 10px;
}
.checkbox-pair {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}
.checkbox-pair label {
    margin-right: 1rem;
    margin-bottom: 0;
    width: 150px;
    text-align: right;
}
.checkbox-pair input {
    margin-right: 0.5rem;
}

/* Weekday input styles */
.weekday-label {
    text-align: center;
    font-size: 0.9em;
}
.weekday-input {
    width: 100%;
    padding: 0.25rem;
    font-size: 0.9em;
}
.health-number-input {
    width: 100px;
}

/* Route Progress Panel */
#route-progress-panel {
    position: absolute;
    top: 75px;
    left: 10px;
    background: rgba(18, 18, 18, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 12px;
    min-width: 280px;
    max-width: 350px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    z-index: 500;
    color: #fff;
    font-size: 13px;
    pointer-events: auto; /* Allow interactions with the panel itself */
}

.progress-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.progress-header strong {
    font-size: 14px;
}

#progress-toggle {
    font-size: 16px;
    line-height: 1;
}

.progress-body {
    max-height: 400px;
    overflow-y: auto;
}

.progress-body.collapsed {
    display: none;
}

.route-progress-item {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.route-progress-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.route-progress-name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}

.route-progress-link {
    color: #4fc1ff;
    text-decoration: none;
    transition: color 0.2s ease;
}

.route-progress-link:hover {
    color: #7dd3fc;
    text-decoration: underline;
}

.route-progress-stats {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 6px;
}

.route-progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
}

.route-progress-bar-segment {
    height: 100%;
    transition: width 0.3s ease;
}

.route-progress-bar-issue {
    background-color: #dc3545;
}

.route-progress-bar-warning {
    background-color: #fd7e14;
}

.route-progress-bar-success {
    background-color: #198754;
}

/* Scrollbar for progress body */
.progress-body::-webkit-scrollbar {
    width: 6px;
}

.progress-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.progress-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.progress-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Map Legend */
#map-legend {
    position: absolute;
    top: 75px;
    right: 10px;
    background: rgba(18, 18, 18, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 12px;
    min-width: 220px;
    max-width: 300px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    z-index: 500;
    color: #fff;
    font-size: 13px;
    pointer-events: auto; /* Allow interactions with the panel itself */
}

/* Search results should be above the legend */
#navSearchResults {
    z-index: 1050 !important;
}

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-header strong {
    font-size: 14px;
}

#legend-toggle {
    font-size: 16px;
    line-height: 1;
}

.legend-filter-section {
    padding: 0 0 10px 0;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.legend-filter-section .form-label {
    margin-bottom: 4px;
    color: rgba(255, 255, 255, 0.8);
}

.legend-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.legend-body.collapsed {
    display: none;
}

#legend-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    cursor: pointer;
}

.legend-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    padding: 4px 4px;
}

.legend-item-static {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.legend-toggle {
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.legend-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.legend-icon svg {
    width: 18px;
    height: 18px;
}

.legend-icon i {
    font-size: 14px;
}

.legend-label {
    flex: 1;
    font-size: 12px;
    user-select: none;
}

/* Scrollbar styling for legend */
.legend-body::-webkit-scrollbar {
    width: 6px;
}

.legend-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.legend-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.legend-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}


/* Dark theme Select2 styling - Swapped colors and height adjustment */

/* Select2 selection box (the main input) - now uses dropdown color */
.select2-container--default .select2-selection--single {
    background-color: #343a40;
    border: 1px solid #495057;
    color: #fff;
    min-height: calc(1.5em + 0.75rem + 2px); /* Match Bootstrap form-select height */
    height: calc(1.5em + 0.75rem + 2px);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #fff;
    line-height: calc(1.5em + 0.75rem); /* Vertically center text */
    padding-left: 0.75rem;
    padding-right: 3.5rem; /* Make room for both clear button and arrow */
}

/* Arrow container */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: calc(1.5em + 0.75rem + 2px);
    top: 0;
    right: 0.5rem;
    width: 1.5rem;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #fff transparent transparent transparent;
    border-width: 5px 4px 0 4px;
    left: 50%;
    margin-left: -4px;
    margin-top: -2px;
    position: absolute;
    top: 50%;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent #fff transparent;
    border-width: 0 4px 5px 4px;
    margin-top: -5px;
}

/* Clear button (X) - positioned to the left of the arrow */
.select2-container--default .select2-selection--single .select2-selection__clear {
    color: #fff;
    cursor: pointer;
    float: none;
    font-size: 1.2em;
    font-weight: bold;
    height: 100%;
    margin-right: 0;
    position: absolute;
    right: 2rem; /* Position to the left of the arrow */
    top: 50%;
    transform: translateY(-50%);
    width: 1.5rem;
    text-align: center;
    line-height: 1;
}

.select2-container--default .select2-selection--single .select2-selection__clear:hover {
    color: #dc3545;
}

/* Adjust rendered text when clear button is visible */
.select2-container--default .select2-selection--single.select2-selection--clearable .select2-selection__rendered {
    padding-right: 4.5rem; /* Extra space when clear button is visible */
}

/* Focus state */
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Dropdown panel - now uses lighter select box color */
.select2-dropdown {
    background-color: #212529;
    border: 1px solid #495057;
}

/* Search input in dropdown */
.select2-container--default .select2-search--dropdown .select2-search__field {
    background-color: #343a40;
    border: 1px solid #495057;
    color: #fff;
    padding: 0.375rem 0.75rem;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-color: #86b7fe;
    outline: 0;
}

/* Dropdown options */
.select2-container--default .select2-results__option {
    background-color: #212529;
    color: #fff;
    padding: 0.375rem 0.75rem;
}

/* Highlighted option (hover) */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: #0d6efd;
    color: #fff;
}

/* Selected option */
.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: #343a40;
    color: #fff;
}

/* Placeholder styling */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #6c757d;
}

/* Ensure Select2 appears above modal */
.select2-container {
    z-index: 9999 !important;
}

.select2-dropdown {
    z-index: 9999 !important;
}

/* Disabled state */
.select2-container--default.select2-container--disabled .select2-selection--single {
    background-color: #212529;
    cursor: not-allowed;
    opacity: 0.65;
}

/* Loading state */
.select2-container--default .select2-results__option--loading {
    color: #6c757d;
}

/* No results message */
.select2-container--default .select2-results__option--disabled {
    color: #6c757d;
}


/* Animated call-in pins cycling through day colors */
.pin-no-schedule path,
.legend-no-schedule {
    animation: cycleColors 5s infinite;
}

@keyframes cycleColors {
    0% { fill: #FF6384; }    /* Monday - red/pink */
    20% { fill: #36A2EB; }   /* Tuesday - blue */
    40% { fill: #FFCE56; }   /* Wednesday - yellow */
    60% { fill: #4BC0C0; }   /* Thursday - teal */
    80% { fill: #9966FF; }   /* Friday - purple */
    100% { fill: #FF6384; }  /* Back to Monday */
}

/* Truck marker styles */
.truck-marker {
    transition: transform 0.3s ease-out;
}

.truck-marker svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

/* Mobile adjustments */
@media (max-width: 576px) {
    .form-label {
        text-align: left;
        padding-right: 0;
    }
    .checkbox-pair label {
        text-align: left;
        width: auto;
        margin-bottom: 0.25rem;
    }
    .checkbox-pair {
        flex-direction: column;
        align-items: flex-start;
    }
    .form-control,
    .form-select {
        margin-bottom: 10px;
    }
    .weekday-label {
        font-size: 0.8em;
    }
    .weekday-input {
        font-size: 0.8em;
        padding: 0.2rem;
    }
    .health-number-input {
        width: 100%;
    }
    #map-legend {
        top: auto;
        bottom: 80px;
        right: 10px;
        min-width: 180px;
    }
}