:root {
    --primary-color: #007AFF;
    --success-color: #34C759;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    --border-glass: 1px solid rgba(255, 255, 255, 0.18);
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    background-color: #f2f2f7;
    overflow: hidden; /* Prevent scrolling on mobile */
    -webkit-tap-highlight-color: transparent;
}

#map {
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

/* Glassmorphism Controls Container */
.controls-container {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 300px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); /* Safari */
    border-radius: 16px;
    box-shadow: var(--shadow-glass);
    z-index: 1000;
    padding: 10px 12px;
    box-sizing: border-box;
    transition: transform 0.3s ease-out;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
}

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

.control-title {
    font-size: 13px;
    font-weight: 700;
    margin: 0;
}

.stats-card {
    display: flex;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.stat-item {
    text-align: center;
    flex: 1;
}

.stat-value {
    font-size: 16px;
    font-weight: 800;
    color: var(--primary-color);
    display: block;
}

.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Slider Style */
.slider-container {
    margin-bottom: 10px;
}

.slider-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
    font-weight: 500;
}

/* Mobile: keep panel as bottom sheet but smaller */
@media (max-width: 768px) {
    .controls-container {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        max-height: 35vh;
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 28px;
    width: 28px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    cursor: pointer;
    margin-top: -12px;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #d1d1d6;
    border-radius: 2px;
}

input[type=range]:focus {
    outline: none;
}

/* Loading Overlay */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

/* Route Management Modal Styles */
#route-management-modal {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#route-management-modal > div {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

#routes-table {
    font-size: 13px;
}

#routes-table thead th {
    user-select: none;
    position: sticky;
    top: 0;
    background: #f5f5f7;
    z-index: 10;
}

#routes-table tbody tr:hover {
    background: #f9f9fb;
}

#routes-table tbody tr:last-child {
    border-bottom: none;
}

.sort-icon {
    display: inline-block;
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.5;
}

#route-search:focus,
#route-status-filter:focus {
    outline: 2px solid #007AFF;
    outline-offset: 2px;
}