/* ============================================
   UNEVA Tracking - Styles
   ============================================ */

:root {
    /* Цветовая палитра */
    --bg-primary: #0a0e14;
    --bg-secondary: #0d1219;
    --bg-card: #111820;
    --bg-card-hover: #151d27;
    --bg-elevated: #1a2332;
    
    --border-color: #1e2a3a;
    --border-color-light: #2a3a4d;
    --border-accent: #2563eb;
    
    --text-primary: #e6edf5;
    --text-secondary: #8b9ab0;
    --text-muted: #5c6a7e;
    
    --accent-primary: #2563eb;
    --accent-primary-hover: #3b82f6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    
    /* Тени */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.3);
    
    /* Размеры */
    --sidebar-width: 340px;
    --header-height: 56px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    
    /* Анимации */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* ============================================
   Reset & Base
   ============================================ */

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* ============================================
   Layout
   ============================================ */

.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--accent-primary), #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.icon-btn.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Sidebar Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge {
    background: var(--accent-primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
}

/* Bikes List */
.bikes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    gap: 12px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Bike Card */
.bike-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.bike-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-primary);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.bike-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-color-light);
}

.bike-card.selected {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.bike-card.selected::before {
    opacity: 1;
}

.bike-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.bike-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.bike-icon.locked {
    background: rgba(239, 68, 68, 0.15);
}

.bike-icon.unlocked {
    background: rgba(16, 185, 129, 0.15);
}

.bike-info {
    flex: 1;
    min-width: 0;
}

.bike-id {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bike-model {
    font-size: 12px;
    color: var(--text-secondary);
}

.bike-lock-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.bike-lock-badge.locked {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.bike-lock-badge.unlocked {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
}

.bike-card-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
}

.bike-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
}

.bike-stat svg {
    opacity: 0.7;
}

.bike-stat-value {
    color: var(--text-primary);
    font-weight: 500;
}

.bike-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-muted);
}

.sync-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 500;
}

.sync-badge.pending {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-warning);
}

.sync-badge.synced {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.online {
    background: var(--accent-success);
    box-shadow: 0 0 8px var(--accent-success);
}

.status-dot.offline {
    background: var(--accent-danger);
}

/* ============================================
   Main Content - Map
   ============================================ */

.main-content {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#map {
    flex: 1;
    width: 100%;
    min-height: 0; /* Важно для flex */
    background: #f5f5f5;
}

/* Leaflet Customizations - светлая тема */
.leaflet-container {
    background: #f5f5f5;
    font-family: inherit;
}

.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important;
    color: #666 !important;
    font-size: 10px !important;
    padding: 2px 8px !important;
    border-radius: 4px 0 0 0 !important;
}

.leaflet-control-attribution a {
    color: #333 !important;
}

/* Кнопки зума для светлой карты */
.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-elevated) !important;
}

/* Кастомный маркер */
.custom-marker {
    position: relative;
}

.marker-pin {
    width: 36px;
    height: 36px;
    border-radius: 50% 50% 50% 0;
    background: var(--accent-primary);
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.3);
    border: 3px solid rgba(255, 255, 255, 0.9);
    transition: all var(--transition-fast);
}

.marker-pin.locked {
    background: var(--accent-danger);
}

.marker-pin.unlocked {
    background: var(--accent-success);
}

.marker-pin.moving {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 3px 10px rgba(0,0,0,0.3), 0 0 0 0 rgba(37, 99, 235, 0.4); }
    50% { box-shadow: 0 3px 10px rgba(0,0,0,0.3), 0 0 0 15px rgba(37, 99, 235, 0); }
}

.marker-icon {
    transform: rotate(45deg);
    font-size: 16px;
}

.marker-speed {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

/* Popup для светлой карты */
.leaflet-popup-content-wrapper {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-radius: var(--border-radius) !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border-color);
}

.leaflet-popup-tip {
    background: var(--bg-card) !important;
}

.leaflet-popup-close-button {
    color: var(--text-secondary) !important;
}

.popup-content {
    padding: 4px;
}

.popup-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.popup-icon {
    font-size: 24px;
}

.popup-title {
    font-weight: 600;
    font-size: 14px;
}

.popup-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.popup-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 12px;
}

.popup-stat {
    display: flex;
    flex-direction: column;
}

.popup-stat-label {
    color: var(--text-muted);
    font-size: 11px;
}

.popup-stat-value {
    font-weight: 500;
}

/* ============================================
   Info Panel - Фиксированная нижняя панель
   ============================================ */

.info-panel {
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    max-height: 45vh;
    min-height: 60px;
    transition: max-height var(--transition-normal);
    overflow: hidden;
}

.info-panel.collapsed {
    max-height: 60px;
}

.info-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    background: var(--bg-card);
    flex-shrink: 0;
}

.selected-bike-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.bike-icon-large {
    width: 44px;
    height: 44px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.bike-details h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.bike-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.close-panel-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.close-panel-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.info-panel.collapsed .close-panel-btn svg {
    transform: rotate(180deg);
}

.info-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    align-content: start;
}

/* ============================================
   Info Sections - 4 колонки
   ============================================ */

.info-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    min-width: 0;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.section-header svg {
    color: var(--accent-primary);
    flex-shrink: 0;
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.info-item .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.info-item .value {
    font-size: 14px;
    font-weight: 500;
    word-break: break-word;
}

/* Payment Status */
.payment-status {
    margin-bottom: 12px;
}

.payment-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.payment-badge.paid {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
}

.payment-badge.overdue {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.payment-badge.pending {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-warning);
}

/* Buyout Progress */
.buyout-progress {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 8px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-success));
    border-radius: 999px;
    transition: width var(--transition-normal);
}

/* Telemetry Grid */
.telemetry-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.telemetry-card {
    background: var(--bg-elevated);
    border-radius: var(--border-radius-sm);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.telemetry-icon {
    font-size: 18px;
    opacity: 0.9;
}

.telemetry-data {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.telemetry-value {
    font-size: 14px;
    font-weight: 600;
}

.telemetry-label {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Window Switch */
.window-switch {
    display: flex;
    margin-left: auto;
    background: var(--bg-elevated);
    border-radius: 999px;
    padding: 2px;
    flex-shrink: 0;
}

.window-switch button {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 999px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.window-switch button:hover {
    color: var(--text-primary);
}

.window-switch button.active {
    background: var(--accent-primary);
    color: white;
}

/* Control Status Bar */
.control-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-radius: var(--border-radius-sm);
    gap: 10px;
    flex-wrap: wrap;
}

.current-state {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.state-label {
    color: var(--text-muted);
}

.state-value {
    font-weight: 600;
}

.state-value.locked {
    color: var(--accent-danger);
}

.state-value.unlocked {
    color: var(--accent-success);
}

.sync-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.sync-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-success);
}

.sync-indicator.pending .sync-dot {
    background: var(--accent-warning);
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Control Buttons */
.control-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    font-size: 12px;
    font-weight: 600;
    transition: all var(--transition-fast);
}

.control-btn svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.control-btn span {
    white-space: nowrap;
}

.control-btn.unlock {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.control-btn.unlock:hover {
    background: rgba(16, 185, 129, 0.25);
}

.control-btn.lock {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.control-btn.lock:hover {
    background: rgba(239, 68, 68, 0.25);
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 1400px) {
    .info-panel-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
        min-width: 280px;
    }
    
    .info-panel-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 35vh;
        min-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .main-content {
        height: 65vh;
    }
    
    .info-panel {
        max-height: 50vh;
    }
    
    .info-panel-content {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Track color dot & active button
   ============================================ */

.track-color-dot {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.5);
}

.bike-icon {
    position: relative;
}

.icon-btn.active {
    background: var(--accent-primary);
    color: white;
}

.icon-btn.active:hover {
    background: var(--accent-primary-hover);
}

/* Selected marker highlight */
.custom-marker.selected .marker-pin {
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.4), 0 3px 10px rgba(0,0,0,0.3);
    transform: rotate(-45deg) scale(1.1);
}