/* CSS Custom Properties - Global Design System */
:root {
    /* Typography Scale - rem based for accessibility */
    --text-xs: 0.75rem;      /* 12px */
    --text-sm: 0.875rem;     /* 14px */
    --text-base: 1rem;       /* 16px */
    --text-lg: 1.125rem;     /* 18px */
    --text-xl: 1.25rem;      /* 20px */
    --text-2xl: 1.5rem;      /* 24px */
    --text-3xl: 1.8rem;      /* Match our existing title size */
    
    /* Route Planner Color Palette */
    --route-bg-dark: #34495e;
    --route-bg-darker: #2c3e50;
    --route-text-light: white;
    --route-border: #4a6278;
    --route-accent: #3498db;
    --route-success: #27ae60;
    --route-danger: #e74c3c;
    --route-drag-handle: #95a5a6;
    
    /* Spacing */
    --route-padding: 12px;
    --route-margin: 8px;
    --route-border-radius: 6px;
}

/* Semantic Typography Classes */
.heading-primary {
    font-size: var(--text-3xl);
    font-weight: 600;
    margin: 0;
}

.heading-secondary {
    font-size: var(--text-2xl);
    font-weight: 600;
    margin: 0;
}

.heading-tertiary {
    font-size: var(--text-xl);
    font-weight: 500;
    margin: 0;
}

.text-body {
    font-size: var(--text-base);
    line-height: 1.6;
}

.text-small {
    font-size: var(--text-sm);
    line-height: 1.4;
}

.text-xs {
    font-size: var(--text-xs);
    line-height: 1.3;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.header {
    background: #2c3e50;
    color: white;
    padding: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 1000;
    position: relative;
    min-height: 50px;
}

.header h1 {
    margin: 0;
    font-size: 1.2rem;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group input[type="text"] {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.control-group button {
    padding: 5px 10px;
    border: 1px solid #3498db;
    background: #ecf0f1;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.control-group button:hover {
    background: #3498db;
    color: white;
}

.controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.7rem;
    margin-right: 1rem;
}

.controls input[type="checkbox"] {
    transform: scale(1.0);
}

/* Map container - account for header + bottom toolbar */
#map {
    height: calc(100vh - 66px - 70px);
    width: 100%;
}

/* Tower Details Panel */
.tower-panel {
    position: fixed;
    top: 80px;
    right: -400px;
    width: 400px;
    height: calc(100vh - 80px);
    background: white;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    transition: right 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
}

.tower-panel.active {
    right: 0;
}

.panel-header {
    background: #34495e;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

#closePanel {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

#closePanel:hover {
    background-color: rgba(255,255,255,0.1);
}

.panel-content {
    padding: 1rem;
}

/* Tower Details */
.tower-details p {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.tower-details h4 {
    margin: 1rem 0 0.5rem 0;
    color: #2c3e50;
    border-bottom: 1px solid #ecf0f1;
    padding-bottom: 0.5rem;
}

.service-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.service-item h5 {
    color: #27ae60;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.service-item p {
    margin-bottom: 0.3rem;
}

/* Enhanced tower data styling */
.enhanced-data {
    background: #e8f4fd;
    border: 2px solid #3498db;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.enhanced-data h4 {
    color: #2c3e50;
    margin-top: 0;
    margin-bottom: 0.8rem;
    font-size: 1.1rem;
}

.enhanced-data h5 {
    color: #34495e;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.sector-detail {
    background: #2c3e50;
    border: 1px solid #4a6278;
    border-radius: 5px;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: white;
}

.sector-detail p {
    margin: 0.3rem 0;
}

.sector-detail strong {
    color: #ecf0f1;
}

.service-item button {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    transition: background-color 0.2s;
}

.service-item button:hover {
    background: #2980b9;
}

/* Popup styles */
.tower-popup {
    min-width: 200px;
}

.tower-popup h4 {
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.tower-popup ul {
    margin: 0.5rem 0;
    padding-left: 1.2rem;
}

.tower-popup li {
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}

.tower-popup button {
    background: #27ae60;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    width: 100%;
}

.tower-popup button:hover {
    background: #219a52;
}

/* Mobile Bottom Toolbar */
.mobile-toolbar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #2c3e50;
    border-top: 1px solid #34495e;
    z-index: 3000;
    height: 70px;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: #bdc3c7;
    cursor: pointer;
    transition: all 0.2s;
    padding: 8px 4px;
}

.mobile-tab:hover, .mobile-tab.active {
    color: #3498db;
    background: rgba(52, 152, 219, 0.1);
}

.mobile-tab i {
    font-size: 20px;
    margin-bottom: 4px;
}

.mobile-tab span {
    font-size: 10px;
    font-weight: 500;
}

/* Mobile Bottom Panels */
.mobile-panel {
    display: none;
    position: fixed;
    bottom: 70px;
    left: 0;
    right: 0;
    background: #2c3e50;
    border-top: 1px solid #3498db;
    max-height: 50vh;
    overflow-y: auto;
    z-index: 2999;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
    color: white;
}

/* Full-screen Route Planner */
#newRoutePanel {
    max-height: none !important;
    height: calc(100vh - 70px) !important;
    top: 0 !important;
    bottom: 70px !important;
    background: #2c3e50 !important;
    border-top: none !important;
    box-shadow: none !important;
}

/* Mobile Route Section Containers */
#newRoutePanel .route-section {
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid #4a6278;
    border-radius: 8px;
    background: #34495e;
}

#newRoutePanel .route-section .heading-secondary {
    color: white;
    margin-top: 0;
    margin-bottom: 15px;
}

/* Route Planner header styling */
#newRoutePanel .mobile-panel-header {
    background: #2c3e50 !important;
    padding: 20px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 3000 !important;
}

#newRoutePanel .mobile-panel-header .heading-primary {
    color: #ecf0f1 !important;
}

#newRoutePanel .mobile-close {
    color: #ecf0f1 !important;
    font-size: 24px !important;
}

/* Route Planner content styling */
#newRoutePanel .mobile-panel-content {
    background: #2c3e50 !important;
    min-height: calc(100vh - 140px) !important;
    padding: 20px !important;
    color: white !important;
    max-width: 1000px !important;
    margin: 0 auto !important;
}

.mobile-panel.active {
    display: block;
}

.mobile-panel-header {
    background: #34495e;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mobile-panel-header .heading-primary {
    color: white;
}

.mobile-close {
    background: none;
    border: none;
    font-size: 28px;
    color: white;
    cursor: pointer;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-panel-content {
    padding: 20px;
    background: #2c3e50;
    color: white;
}

/* Mobile Filter Items */
.mobile-filter-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 16px;
    cursor: pointer;
}

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

.mobile-filter-item input[type="checkbox"] {
    transform: scale(1.5);
}

/* Mobile Inputs */
.mobile-input {
    width: 100%;
    padding: 15px;
    border: 1px solid #4a6278;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 15px;
    background: #2c3e50;
    color: white;
}

.mobile-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.mobile-input::placeholder {
    color: #bdc3c7;
}

/* Hide desktop header controls - use bottom toolbar for all devices */
.header .controls {
    display: none !important;
}

/* Show bottom toolbar on all devices */
.mobile-toolbar {
    display: flex !important;
}

/* Desktop/Mobile Component Visibility */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }
}

@media (min-width: 769px) {
    .mobile-only { display: none !important; }
    .desktop-only { display: block !important; }
}


/* Clean Mobile Elevation Panel - DEBUG VERSION */
.elevation-mobile-panel {
    position: fixed !important;
    bottom: -50vh !important;
    left: 0 !important;
    width: 100vw !important;
    height: 45vh !important;
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%) !important; /* Professional dark blue */
    border-radius: 20px 20px 0 0 !important;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.3) !important;
    transition: bottom 0.3s ease, height 0.3s ease !important;
    z-index: 9999 !important;
}

.elevation-mobile-panel.active {
    bottom: 0px !important;  /* Stick to bottom of viewport, not 70px */
}

.elevation-mobile-panel.active.expanded {
    height: 90vh !important;
    max-height: 90vh !important;
    bottom: 0px !important;
}

.elevation-mobile-panel.active.minimized {
    height: 70px !important;
    max-height: 70px !important;
    bottom: 0px !important;
}

/* Panel Handle */
.elevation-panel-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
}

.handle-bar {
    width: 40px;
    height: 3px;
    background: #bdc3c7;
    border-radius: 2px;
}

/* Panel Header */
.elevation-panel-header {
    padding: 25px 15px 10px 15px;
    background: #34495e;
    border-bottom: 1px solid #4a6278;
}

.elevation-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.elevation-header-content h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 18px;
}

.elevation-count {
    background: #e3f2fd;
    color: #1976d2;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}

.elevation-close-btn {
    background: #e74c3c;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Panel Content */
.elevation-panel-content {
    padding: 15px;
    height: calc(100% - 80px);
    overflow-y: auto;
}

.elevation-instructions {
    background: #34495e;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 15px;
    text-align: center;
    color: white;
    color: #2e7d2e;
}

.elevation-results {
    max-height: 200px;
    overflow-y: auto;
}

.elevation-result-item {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 8px;
    border-left: 3px solid #3498db;
}

.elevation-value {
    font-size: 20px;
    font-weight: bold;
    color: white;
}

.elevation-coords {
    font-size: 11px;
    color: #bdc3c7;
    font-family: monospace;
}

.elevation-clear-btn {
    background: #526274;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 10px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.elevation-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.elevation-icon {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.elevation-panel-header h3 {
    margin: 0;
    color: white;
    font-size: 20px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.elevation-count {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    backdrop-filter: blur(5px);
}

.elevation-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
}

.elevation-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Elevation Panel Content */
.elevation-panel-content {
    padding: 20px;
    height: calc(100% - 100px);
    overflow-y: auto;
    background: #2c3e50;
    color: white;
    backdrop-filter: blur(10px);
}

.elevation-instructions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: #34495e;
    border-radius: 15px;
    margin-bottom: 20px;
    border: 1px solid #4a6278;
}

.instruction-icon {
    font-size: 24px;
    color: white;
}

.elevation-instructions p {
    margin: 0;
    color: white;
    font-weight: 500;
    font-size: 16px;
}

/* Elevation Results */
.elevation-results {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.elevation-result-item {
    background: #2c3e50;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: white;
    border: 1px solid #4a6278;
    border-left: 4px solid #667eea;
}

.elevation-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.elevation-value {
    font-size: 24px;
    font-weight: bold;
    color: white;
}

.elevation-coords {
    font-size: 12px;
    color: #bdc3c7;
    font-family: monospace;
}

.elevation-details {
    font-size: 14px;
    color: #bdc3c7;
}

/* Fix elevation panel desktop content background */
#elevationPanel .panel-content,
#elevationResults {
    background: #2c3e50;
    color: white;
}

/* Fix measure panel desktop content background */
#measurePanel .panel-content,
#measureResults {
    background: #2c3e50;
    color: white;
}

/* Elevation Actions */
.elevation-actions {
    display: flex;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid rgba(0,0,0,0.1);
}

.elevation-clear-btn {
    background: #526274;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(82, 98, 116, 0.3);
}

.elevation-clear-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(82, 98, 116, 0.4);
}

.btn-icon {
    font-size: 18px;
}


.mobile-sheet-header {
    background: #34495e;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 60px;
    box-sizing: border-box;
    position: relative;
}

.drag-indicator {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
}

.mobile-sheet-header h3 {
    margin: 0;
    font-size: 1.2rem;
    flex-grow: 1;
}

.mobile-sheet-header button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.mobile-sheet-header button:hover {
    background-color: rgba(255,255,255,0.1);
}

.mobile-sheet-content {
    padding: 1.2rem;
    height: calc(100% - 80px);
    overflow-y: auto;
}

.mobile-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 15px;
}

.mobile-btn:hover {
    background: #c0392b;
}

/* Enhanced Mobile Framework */
@media (max-width: 768px), (max-height: 500px) {
    
    /* Mobile Bottom Sheet - MUST be inside mobile media query */
    
    /* Adjust map height for mobile */
    #map {
        height: calc(100vh - 66px - 70px) !important; /* header + toolbar */
    }
    /* Mobile header - simplified */
    .header {
        justify-content: center;
        padding: 0.6rem;
    }
    
    .header h1 {
        font-size: 1.1rem;
        text-align: center;
    }
    
    .control-group {
        justify-content: center;
        gap: 0.8rem;
        flex-wrap: wrap;
    }
    
    /* Mobile service labels - larger touch targets */
    .controls label {
        font-size: 1.0rem;
        margin-right: 1.5rem;
        padding: 0.3rem;
    }
    
    /* Mobile search inputs - full width */
    .control-group input[type="text"] {
        width: 100%;
        max-width: 200px;
        padding: 10px;
        font-size: 16px; /* Prevents zoom on iOS */
        margin-bottom: 0.5rem;
    }
    
    /* Mobile toolbar icons - larger touch targets */
    .control-group span {
        font-size: 1.8em !important;
        margin: 0 12px !important;
        padding: 8px;
        border-radius: 8px;
        background: rgba(255,255,255,0.1);
    }
    
    /* Mobile gear icon */
    #adminGear {
        padding: 8px;
        border-radius: 8px;
        background: rgba(255,255,255,0.1);
    }
    
    /* Mobile map - full height */
    #map {
        height: calc(100vh - 140px);
        width: 100%;
    }
    
    /* Mobile panels - different behavior for different panels */
    .tower-panel, .stats-panel {
        width: 100vw;
        right: -100vw;
        top: 0;
        height: 100vh;
        z-index: 2000;
        border-left: none;
        border-top: 3px solid #3498db;
    }
    
    .tower-panel.active, .stats-panel.active {
        right: 0;
    }
    
    /* Legacy drag handle - now handled by mobile-bottom-sheet */
    
    /* Panel header controls */
    .panel-controls {
        display: flex !important;
        flex-direction: row !important;
        gap: 8px;
        align-items: center !important;
        justify-content: flex-end !important;
        flex-wrap: nowrap !important;
    }
    
    .panel-controls button {
        background: none;
        border: none;
        color: white;
        font-size: 1.5rem;
        cursor: pointer;
        padding: 0;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background-color 0.2s;
        flex-shrink: 0;
    }
    
    .panel-controls button:hover {
        background-color: rgba(255,255,255,0.1);
    }
    
    /* Ensure elevation panel header layout is correct */
    #elevationPanel .panel-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        background: #34495e !important;
        color: white !important;
        padding: 1rem !important;
        min-height: 60px !important;
        box-sizing: border-box !important;
        flex-wrap: nowrap !important;
    }
    
    #elevationPanel .panel-header h3 {
        margin: 0 !important;
        font-size: 1.2rem !important;
        flex-grow: 1 !important;
        flex-shrink: 0 !important;
    }
    
    /* Mobile panel headers - larger close buttons */
    #elevationPanel .panel-header .panel-controls button {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.8rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }
    
    /* Mobile panel content - touch-friendly */
    .panel-content {
        padding: 1.2rem;
        font-size: 1rem;
    }
    
    /* Mobile route stops - larger drag handles and remove buttons */
    .route-stop {
        padding: 15px;
        margin: 8px 0;
        font-size: 1rem;
    }
    
    .remove-stop {
        width: 32px;
        height: 32px;
        font-size: 18px;
        min-width: 32px;
        min-height: 32px;
        flex-shrink: 0;
    }
    
    .drag-handle {
        font-size: 1.2em;
        margin-right: 12px;
    }
    
    /* Mobile buttons - larger touch targets */
    button {
        min-height: 44px;
        padding: 12px 16px !important;
        font-size: 1rem !important;
        border-radius: 6px;
    }
    
    /* Mobile numbered markers - slightly larger */
    .marker-number {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    
    /* Mobile history items - touch-friendly */
    .history-item {
        padding: 16px;
        margin: 12px 0;
        font-size: 1rem;
    }
    
    /* Mobile form inputs - prevent zoom */
    input[type="text"], input[type="date"] {
        font-size: 16px !important;
        padding: 12px !important;
        border-radius: 6px;
    }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
    .header {
        padding: 0.8rem;
    }
    
    .controls {
        gap: 1rem;
    }
    
    .tower-panel, .stats-panel {
        width: 60%;
        right: -60%;
    }
    
    .tower-panel.active, .stats-panel.active {
        right: 0;
    }
    
    /* Tablet uses desktop elevation panel */
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Statistics and Measure Panels */
.stats-panel, .measure-panel {
    position: fixed;
    top: 80px;
    right: -450px;
    width: 420px;
    height: 80%;
    background: #2c3e50;
    border: none;
    border-radius: 12px 0 0 12px;
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    transition: right 0.3s ease;
    z-index: 1001;
    overflow-y: auto;
    color: white;
}

.stats-panel.active, .measure-panel.active {
    right: 20px;
}

/* Route Planner gets special full-screen treatment */
.route-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1001;
    overflow-y: auto;
    color: white;
    display: none;
    padding: 20px;
}

.route-panel.active {
    display: block;
}

/* Route Panel Content Container - Optimized width for better readability */
.route-panel .panel-container {
    padding: 20px;
    max-width: 750px;
    margin: 0 auto;
    background: #2c3e50;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.route-panel .panel-header {
    background: #34495e;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    margin: -20px -20px 20px -20px;
    border-radius: 12px 12px 0 0;
}

.route-panel .panel-header .heading-primary {
    color: white;
}

.route-panel .panel-header .close-link {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 15px;
    display: inline-block;
}

.route-panel .panel-header .close-link:hover {
    text-decoration: underline;
}

.measure-panel .panel-header {
    background: #34495e;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    margin: -20px -20px 20px -20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.measure-panel .panel-header h3 {
    margin: 0;
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    flex-grow: 1;
    padding-left: 10px;
}

.measure-panel .panel-header .heading-primary {
    color: white;
}

.measure-panel .panel-header .close-link {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 15px;
    display: inline-block;
}

.measure-panel .panel-header .close-link:hover {
    text-decoration: underline;
}

.stats-panel .panel-header button,
.measure-panel .panel-header button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.stats-panel .panel-header button:hover,
.measure-panel .panel-header button:hover {
    background-color: rgba(255,255,255,0.1);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.stat-item h4 {
    margin: 0 0 8px 0;
    color: #34495e;
    font-size: 14px;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #3498db;
}

.stats-details {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #ecf0f1;
}

.stats-details h5 {
    margin-bottom: 10px;
    color: #2c3e50;
}

.stats-details p {
    margin: 5px 0;
    font-size: 14px;
    color: #7f8c8d;
}

/* Measure Panel */
.measure-panel .panel-content {
    padding: 20px;
}

/* Route Planner Container Styling */
.measure-panel .route-section,
.route-panel .route-section {
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid #4a6278;
    border-radius: 8px;
    background: #34495e !important;
    color: white !important;
}

.measure-panel .route-section .heading-secondary,
.route-panel .route-section .heading-secondary {
    color: white;
    margin-top: 0;
    margin-bottom: 15px;
}

/* Route sections default to white text on dark background */
.measure-panel .route-section,
.route-panel .route-section {
    color: white !important;
}

/* Route Summary specifically - ensure white text */
#newRouteCalcs,
#newRouteCalcs *,
#newRouteCalcs strong,
#newRouteCalcs span {
    color: white !important;
}

/* Route Stops - using custom properties */
.route-stop {
    color: var(--route-text-light);
    background: var(--route-bg-dark);
    border: 1px solid var(--route-border);
}

.route-stop.homebase {
    color: var(--route-text-light);
    background: var(--route-bg-darker);
    border-color: var(--route-accent);
}

.route-stop *,
.route-stop strong,
.route-stop span {
    color: var(--route-text-light);
}

/* Route Planner Customer Stops - Component-based classes */
.route-planner__customer-stop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--route-padding);
    margin: var(--route-margin) 0;
    background: var(--route-bg-dark);
    border: 1px solid var(--route-border);
    border-radius: var(--route-border-radius);
    cursor: move;
    color: var(--route-text-light);
}

.route-planner__customer-stop--non-billable {
    opacity: 0.7;
}

.route-planner__drag-handle {
    color: var(--route-drag-handle);
    margin-right: 8px;
    font-weight: bold;
    cursor: grab;
    font-size: 16px;
    user-select: none;
}

.route-item.homebase {
    color: white !important;
    background: #2c3e50 !important;
}

.route-item.homebase * {
    color: white !important;
}

.measure-panel button {
    margin-top: 10px;
    padding: 8px 16px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.measure-panel button:hover {
    background: #c0392b;
}

#measureResults {
    margin: 15px 0;
    padding: 15px;
    background: #2c3e50;
    border-radius: 12px;
    color: white;
    font-weight: bold;
    border: 1px solid #4a6278;
    border-left: 4px solid #667eea;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Mobile-specific measure-panel adjustments for iPhone */
@media (max-width: 480px) {
    .measure-panel {
        right: -100vw !important; /* Start completely off-screen */
        width: 95vw !important;    /* Use 95% of viewport width */
        height: 85vh !important;   /* Reduce height slightly */
        top: 10px !important;      /* Move closer to top */
        border-radius: 12px !important; /* Keep rounded corners */
    }
    
    .measure-panel.active {
        right: 2.5vw !important;  /* Center with 2.5% margin on each side */
    }
    
    .measure-panel .panel-content {
        padding: 15px !important; /* Reduce padding for mobile */
        font-size: 14px !important; /* Slightly smaller text */
    }
    
    .measure-panel .panel-content div[style*="padding: 15px"] {
        padding: 12px !important; /* Reduce padding on CPE cards */
    }
    
    .measure-panel .panel-content p {
        font-size: 13px !important; /* Smaller text in cards */
        margin: 3px 0 !important;
    }
    
    .measure-panel .panel-content h4 {
        font-size: 15px !important; /* Smaller headings */
        margin: 0 0 8px 0 !important;
    }
}

/* Route Planner Styles */
.route-stop {
    padding: 10px;
    margin: 5px 0;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white !important;
}

.route-stop.homebase {
    background: #e8f4fd;
    border-color: #3498db;
}

.route-stop.draggable {
    cursor: move;
    transition: background-color 0.2s;
}

.route-stop.draggable:hover {
    background: #e9ecef;
}

.drag-handle {
    color: #6c757d;
    margin-right: 8px;
    font-weight: bold;
    cursor: grab;
}

.drag-handle:active {
    cursor: grabbing;
}

.remove-stop {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-stop:hover {
    background: #c82333;
}

/* Route History Styles */
.history-item {
    padding: 12px;
    margin: 8px 0;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.history-item:hover {
    background: #e9ecef;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.history-stats {
    color: #6c757d;
    font-size: 0.9em;
}

.history-details {
    color: #495057;
    font-size: 0.85em;
    line-height: 1.3;
}

/* Numbered Route Markers */
.numbered-marker {
    background: none !important;
    border: none !important;
}

.marker-number {
    background: #e74c3c;
    color: white;
    border: 3px solid white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}