* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body,
html {
    height: 100%;
    width: 100%;
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    background: #f1f5f9;
}

#map {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Side Panel */
#vrp-panel {
    position: fixed;
    top: 15px;
    left: 15px;
    width: 370px;
    max-height: calc(100vh - 30px);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 14px 16px 10px 16px;
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Floating Action Button (shown when panel is collapsed) */
#panel-fab {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    width: 48px;
    height: 48px;
    background: #1e293b;
    color: #fff;
    border-radius: 50%;
    z-index: 1100;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}

#panel-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.panel-controls {
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.control-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 600;
    color: #334155;
    user-select: none;
}

.panel-body {
    padding: 8px 12px;
    overflow-y: auto;
    flex: 1;
}

.branch-card {
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.branch-head {
    background: #f1f5f9;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    color: #0f172a;
    border-bottom: 1px solid transparent;
    user-select: none;
}

.branch-card.open .branch-head {
    border-bottom-color: #e2e8f0;
}

.branch-routes {
    display: none;
    padding: 6px 8px;
    background: #fafafa;
}

.branch-card.open .branch-routes {
    display: block;
}

.route-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 6px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

@keyframes tripFlash {
    0% {
        background-color: #ffffff;
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
        border-color: #e2e8f0;
        transform: scale(1);
    }

    18% {
        background-color: #fef3c7;
        box-shadow: 0 0 12px 3px rgba(245, 158, 11, 0.45);
        border-color: #f59e0b;
        transform: scale(1.025);
    }

    36% {
        background-color: #ffffff;
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
        border-color: #e2e8f0;
        transform: scale(1);
    }

    54% {
        background-color: #fef3c7;
        box-shadow: 0 0 12px 3px rgba(245, 158, 11, 0.45);
        border-color: #f59e0b;
        transform: scale(1.025);
    }

    72% {
        background-color: #fef9c3;
        box-shadow: 0 0 6px 1px rgba(245, 158, 11, 0.2);
        border-color: #f59e0b;
        transform: scale(1.01);
    }

    100% {
        background-color: #ffffff;
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
        border-color: #e2e8f0;
        transform: scale(1);
    }
}

.route-card.flash-highlight {
    animation: tripFlash 0.85s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 10;
    position: relative;
}

.route-card.flash-highlight .route-head {
    background: transparent;
}

.route-head {
    padding: 7px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    user-select: none;
}

.route-head:hover {
    background: #f8fafc;
}

.route-meta {
    font-size: 11px;
    color: #64748b;
    margin-right: auto;
    white-space: nowrap;
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.arrow {
    display: inline-block;
    font-size: 11px;
    color: #94a3b8;
    transition: transform 0.2s ease;
}

.branch-card.open>.branch-head .arrow,
.route-card.open>.route-head .arrow {
    transform: rotate(-90deg);
}

.stops-list {
    display: none;
    padding: 6px 10px;
    font-size: 11px;
    background: #f8fafc;
    border-top: 1px dashed #e2e8f0;
    max-height: 180px;
    overflow-y: auto;
    list-style: none;
}

.route-card.open .stops-list {
    display: block;
}

.stops-list li {
    padding: 4px 6px;
    border-radius: 4px;
    color: #334155;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    transition: background 0.15s;
}

.stops-list li:hover {
    background: #e2e8f0;
    color: #2563eb;
    font-weight: 600;
}

/* Marker Styles */
.customer-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 2px solid #fff;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s;
}

.customer-marker:hover {
    transform: scale(1.15);
    z-index: 1000 !important;
}

.depot-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 2px solid #fff;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Modals & Dialogs */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
    border: 1px solid #e2e8f0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    direction: ltr;
}

.modal-header {
    padding: 14px 18px;
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 15px;
}

.modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    padding: 16px 18px;
    font-size: 13px;
    color: #334155;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 70vh;
    overflow-y: auto;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-weight: 600;
    font-size: 12px;
    color: #1e293b;
}

.form-group input,
.form-group textarea {
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    color: #0f172a;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.modal-footer {
    padding: 12px 18px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 8px 14px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

/* Toast notification */
#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    z-index: 4000;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

#toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

#toast.toast-error {
    background: #dc2626;
}

#toast.toast-success {
    background: #16a34a;
}

/* --- Selected Missions & Many2Many Tags Styles --- */
.selected-missions-container {
    margin-top: 6px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all 0.2s ease;
}

.selected-missions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    font-weight: 700;
    color: #166534;
}

.selected-missions-title {
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-clear-tags {
    background: none;
    border: none;
    color: #dc2626;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: background 0.15s, color 0.15s;
}

.btn-clear-tags:hover {
    background: #fee2e2;
    color: #b91c1c;
}

.m2m-tags-box {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-height: 110px;
    overflow-y: auto;
    padding: 2px 0;
}

.m2m-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #1e293b;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    user-select: none;
    transition: all 0.15s ease;
}

.m2m-tag:hover {
    border-color: #94a3b8;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.m2m-tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.3);
}

.m2m-tag-name {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.m2m-tag-remove {
    cursor: pointer;
    color: #94a3b8;
    font-size: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    margin-right: 2px;
    transition: all 0.15s ease;
}

.m2m-tag-remove:hover {
    color: #dc2626;
    background: #fee2e2;
}

/* Button to move missions to a specific trip in Route Panel */
.btn-move-to-trip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    min-width: 24px;
    background: #16a34a;
    color: #ffffff;
    border: none;
    border-radius: 5px;
    font-size: 11px;
    cursor: pointer;
    margin-right: auto;
    margin-left: 4px;
    box-shadow: 0 1px 2px rgba(22, 163, 74, 0.3);
    transition: background 0.15s, transform 0.15s;
}

.btn-move-to-trip:hover {
    background: #15803d;
    transform: scale(1.1);
}

.btn-move-to-trip:active {
    transform: scale(0.95);
}

/* Button inside Leaflet Marker Popup */
.btn-popup-move {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    background: #16a34a;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(22, 163, 74, 0.3);
    transition: all 0.15s ease;
}

.btn-popup-move:hover {
    background: #15803d;
    transform: scale(1.1);
    box-shadow: 0 2px 5px rgba(22, 163, 74, 0.4);
}

.btn-popup-move:active {
    transform: scale(0.95);
}

/* Visual ring / pulse for markers selected to be moved */
@keyframes markerSelectPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.8), 0 2px 5px rgba(0, 0, 0, 0.35);
    }

    70% {
        box-shadow: 0 0 0 7px rgba(22, 163, 74, 0), 0 2px 5px rgba(0, 0, 0, 0.35);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0), 0 2px 5px rgba(0, 0, 0, 0.35);
    }
}

.customer-marker.selected-for-move {
    border: 2px solid #22c55e !important;
    animation: markerSelectPulse 1.5s infinite;
    transform: scale(1.15);
    z-index: 1500 !important;
}

/* Leaflet Layer Switcher & Zoom Controls Styling */
.leaflet-control-layers {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    border-radius: 10px !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12) !important;
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(8px);
    padding: 6px 10px !important;
}

.leaflet-control-layers-expanded {
    padding: 10px 14px !important;
}

.leaflet-control-layers-base label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: color 0.15s;
}

.leaflet-control-layers-base label:last-child {
    margin-bottom: 0;
}

.leaflet-control-layers-base label:hover {
    color: #2563eb;
}

.leaflet-control-layers-base input[type="radio"] {
    accent-color: #2563eb;
    width: 15px;
    height: 15px;
    cursor: pointer;
    margin: 0;
}

.leaflet-control-zoom {
    border-radius: 8px !important;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    border: 1px solid #cbd5e1 !important;
}

.leaflet-control-zoom a {
    color: #1e293b !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(4px);
    transition: background 0.15s;
}

.leaflet-control-zoom a:hover {
    background: #f1f5f9 !important;
    color: #2563eb !important;
}

body:not(.has-selected-missions) .btn-move-to-trip,
body:not(.has-selected-missions) .btn-popup-move {
    display: none !important;
}