/* === CSS Reset & Base Styles === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    overflow: hidden;
}

/* === Container & Layout === */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* === Header === */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

.header-stats {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.stat-label {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-bottom: 0.2rem;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.1);
    padding: 0.5rem 1rem;
    border-radius: 20px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff4757;
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background: #2ed573;
    animation: none;
}

.status-text {
    font-size: 0.9rem;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* === Controls === */
.controls {
    background: white;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 999;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #f1f2f6;
    color: #333;
    border: 1px solid #ddd;
}

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

.btn-secondary.active {
    background: #2ed573;
    color: white;
    border-color: #2ed573;
}

.btn-icon {
    font-size: 1rem;
}

.select {
    padding: 0.7rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    cursor: pointer;
}

/* === Map === */
.map-container {
    flex: 1;
    position: relative;
    z-index: 1;
}

#map {
    width: 100%;
    height: 100%;
}

/* === Sidebar === */
.sidebar {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    transition: right 0.3s ease;
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.sidebar.active {
    right: 0;
}

.sidebar-header {
    background: #667eea;
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 1.3rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.2rem;
}

.sidebar-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

/* === Loading Overlay === */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* === Footer === */
.footer {
    background: #34495e;
    color: white;
    padding: 1rem 2rem;
    text-align: center;
    font-size: 0.8rem;
}

.footer a {
    color: #3498db;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* === Custom Leaflet Styles === */
.custom-marker {
    background: #667eea;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.custom-marker.low-battery {
    background: #ff4757;
}

.custom-marker.moving {
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

/* === Responsive Design === */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-stats {
        gap: 1rem;
    }
    
    .controls {
        flex-wrap: wrap;
        padding: 1rem;
    }
    
    .sidebar {
        width: 100%;
        right: -100%;
    }
    
    .stat-item {
        min-width: 60px;
    }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.8rem;
    }
}

/* === Popup Styles === */
.leaflet-popup-content {
    margin: 8px 12px;
    line-height: 1.4;
}

.popup-title {
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #667eea;
}

.popup-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.popup-info span {
    font-size: 0.9rem;
}

.battery-low {
    color: #ff4757;
    font-weight: bold;
}

.battery-ok {
    color: #2ed573;
    font-weight: bold;
}

/* === History Trail Styles === */
.history-trail {
    stroke: #667eea;
    stroke-width: 3;
    stroke-opacity: 0.7;
    fill: none;
    stroke-dasharray: 5, 5;
    animation: dash 30s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -1000;
    }
}

/* === Cluster Styles === */
.cluster-bikes-list {
    margin-top: 1rem;
    max-height: 200px;
    overflow-y: auto;
}

.cluster-bikes-header {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e1e8ed;
}

.cluster-bike-item {
    background: #f8f9fa;
    border: 1px solid #e1e8ed;
    border-radius: 4px;
    padding: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
}

.cluster-bike-item.clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.cluster-bike-item.clickable:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: translateX(2px);
    box-shadow: 0 1px 4px rgba(102, 126, 234, 0.15);
}

.cluster-bike-more {
    font-style: italic;
    color: #666;
    text-align: center;
    padding: 0.5rem;
    border-top: 1px dashed #ccc;
    margin-top: 0.5rem;
}

.cluster-bikes-container {
    max-height: 300px;
    overflow-y: auto;
}

.cluster-bike-detail {
    background: #f8f9fa;
    border: 1px solid #e1e8ed;
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cluster-bike-detail:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.bike-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.bike-meta {
    font-size: 0.8rem;
    color: #666;
}

.battery-indicator {
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    background: #e9ecef;
}

.bike-type {
    font-size: 0.8rem;
    color: #666;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    background: #e9ecef;
}