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

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-hover: #1a1a1a;
    --border: #2a2a2a;
    --text: #e5e5e5;
    --text-muted: #737373;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* --- Login Screen --- */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 380px;
    max-width: 90vw;
}

.login-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.login-card p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 28px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: #525252;
}

.btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.error-msg {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

.error-msg.visible {
    display: block;
}

/* --- Main App Layout --- */
.app-layout {
    display: none;
    height: 100vh;
    position: relative;
}

.app-layout.active {
    display: flex;
}

/* --- Sidebar --- */
.sidebar {
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.add-device-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    transition: all 0.15s;
}

.add-device-btn:hover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

/* --- Tracked Devices List --- */
.tracked-devices-list {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
}

.tracked-device-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: background 0.15s;
}

.tracked-device-card:hover {
    background: var(--surface-hover);
}

.tracked-device-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
    50% { opacity: 0.7; box-shadow: 0 0 8px 2px currentColor; }
}

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

.tracked-device-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tracked-device-model {
    font-size: 11px;
    color: var(--text-muted);
}

.tracked-device-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s;
    opacity: 0;
}

.tracked-device-card:hover .tracked-device-remove {
    opacity: 1;
}

.tracked-device-remove:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.no-devices {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 16px;
}

/* --- Sidebar Divider --- */
.sidebar-divider {
    height: 1px;
    background: var(--border);
}

/* --- History Section --- */
.history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-header {
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-device-select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: var(--font);
    cursor: pointer;
    outline: none;
    max-width: 160px;
}

.date-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
}

.date-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.date-item:hover {
    background: var(--surface-hover);
}

.date-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

.date-item-title {
    font-size: 13px;
    font-weight: 500;
}

.date-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.date-list-empty {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 40px 20px;
}

/* --- Playback Controls --- */
.playback-bar {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: none;
}

.playback-bar.active {
    display: block;
}

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

.playback-date {
    font-size: 13px;
    font-weight: 600;
}

.playback-distance {
    font-size: 12px;
    color: var(--text-muted);
}

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

.play-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.scrubber {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.scrubber::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.speed-select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: var(--font);
    cursor: pointer;
    outline: none;
}

.back-to-live-btn {
    width: 100%;
    margin-top: 12px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font);
    text-align: center;
    transition: all 0.15s;
}

.back-to-live-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

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

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

/* --- Info Panel --- */
.info-panel {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 24px;
    display: none;
    gap: 28px;
    z-index: 1000;
    backdrop-filter: blur(12px);
}

.info-panel.active {
    display: flex;
}

.info-item {
    text-align: center;
}

.info-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.info-value {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- Add Device Modal --- */
.device-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.device-modal.active {
    display: flex;
}

.device-modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    width: 480px;
    max-width: 90vw;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.device-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.device-modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.device-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    transition: color 0.15s;
}

.device-modal-close:hover {
    color: var(--text);
}

.device-modal-desc {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 20px;
}

.device-picker-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.device-picker-list li {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.device-picker-list li:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.device-picker-info {
    flex: 1;
}

.device-name {
    font-size: 14px;
    font-weight: 500;
}

.device-model {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

.device-picker-coords {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    font-family: 'SF Mono', 'Fira Code', monospace;
    background: var(--bg);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.device-picker-loading {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 40px 20px;
    list-style: none;
}

/* --- Sidebar Toggle (mobile) --- */
.sidebar-toggle {
    display: none;
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 1001;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    align-items: center;
    justify-content: center;
}

/* --- Device Tooltip --- */
.device-tooltip {
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    font-family: var(--font) !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    padding: 4px 10px !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
}

.device-tooltip::before {
    border-top-color: var(--border) !important;
}

/* --- Mobile --- */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 1001;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .info-panel {
        bottom: 12px;
        left: 12px;
        right: 12px;
        transform: none;
        gap: 12px;
        justify-content: space-around;
        flex-wrap: wrap;
    }

    .login-card,
    .device-modal-card {
        margin: 16px;
    }
}

/* --- Loading spinner --- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Leaflet overrides for dark mode */
.leaflet-control-zoom a {
    background: var(--surface) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

.leaflet-control-attribution {
    background: rgba(10, 10, 10, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--text-muted) !important;
}
