/* ==========================================================================
   MORAI AV Platform - Dark Dashboard Theme
   ========================================================================== */

/* ---------- CSS Variables ---------- */
:root {
    /* Background colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-card-hover: #263548;
    --bg-input: #0f172a;
    --bg-overlay: rgba(15, 23, 42, 0.85);

    /* Border colors */
    --border-color: #334155;
    --border-light: #475569;

    /* Text colors */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Accent colors */
    --accent-cyan: #22d3ee;
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --accent-yellow: #eab308;
    --accent-orange: #f97316;
    --accent-red: #ef4444;
    --accent-purple: #a855f7;

    /* Functional colors */
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --shadow-glow-cyan: 0 0 20px rgba(34, 211, 238, 0.15);
    --shadow-glow-red: 0 0 30px rgba(239, 68, 68, 0.4);

    /* Sizing */
    --navbar-height: 56px;
    --statusbar-height: 32px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-xs: 4px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-primary);
}

a {
    color: var(--accent-cyan);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-primary);
}

/* ---------- Navbar ---------- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 1000;
    gap: 24px;
    box-shadow: var(--shadow-md);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.nav-logo {
    font-size: 24px;
    line-height: 1;
}

.nav-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.nav-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    justify-content: center;
}

.nav-tab {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.nav-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
    color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.1);
}

.nav-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-green);
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

/* ---------- Live Dot Animation ---------- */
.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
    }
    50% {
        opacity: 0.7;
        box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
    }
}

/* ---------- Page Container & Pages ---------- */
#page-container {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    right: 0;
    bottom: var(--statusbar-height);
    overflow: hidden;
}

.page {
    display: none;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.page.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

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

.page-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* ---------- Live Tracking Layout ---------- */
.live-layout {
    display: flex;
    height: 100%;
    width: 100%;
}

.live-layout > .map-container {
    flex: 0 0 70%;
    position: relative;
}

.live-layout > .side-panel {
    flex: 0 0 30%;
}

/* ---------- Map ---------- */
.map-container {
    position: relative;
    height: 100%;
    min-height: 300px;
}

.map {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

/* Override Leaflet dark tiles background */
.leaflet-container {
    background: #1a1a2e;
}

.map-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 500;
    display: flex;
    gap: 8px;
}

/* ---------- Side Panel ---------- */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    overflow-y: auto;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-color);
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    transition: border-color var(--transition-fast);
}

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

.card-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.chart-card {
    min-height: 260px;
}

.chart-card canvas {
    max-height: 220px;
}

/* ---------- Stat Values ---------- */
.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 36px;
    font-weight: 700;
    color: var(--accent-cyan);
    line-height: 1.1;
}

.stat-unit {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-value-sm {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.stat-row + .stat-row {
    border-top: 1px solid var(--border-color);
}

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

/* ---------- Status Indicator ---------- */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.status-dot--active {
    background: var(--accent-green);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.status-dot--warning {
    background: var(--accent-yellow);
    box-shadow: 0 0 8px rgba(234, 179, 8, 0.5);
}

.status-dot--danger {
    background: var(--accent-red);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(8px);
}

.badge-success {
    color: var(--accent-green);
    border-color: rgba(34, 197, 94, 0.3);
    background: rgba(34, 197, 94, 0.1);
}

.badge-warning {
    color: var(--accent-yellow);
    border-color: rgba(234, 179, 8, 0.3);
    background: rgba(234, 179, 8, 0.1);
}

.badge-danger {
    color: var(--accent-red);
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.1);
}

.badge-info {
    color: var(--accent-blue);
    border-color: rgba(59, 130, 246, 0.3);
    background: rgba(59, 130, 246, 0.1);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #ffffff;
}

.btn-primary:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.btn-secondary {
    background: var(--bg-input);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

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

.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: var(--border-radius-xs);
}

.btn-sm.active,
.speed-btn.active,
.period-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #ffffff;
}

/* ---------- Data Table ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
    cursor: pointer;
}

.data-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.data-table td {
    padding: 10px 14px;
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table td:first-child {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.trip-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px;
}

/* ---------- Event Log ---------- */
.event-log {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.event-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-input);
    border-radius: var(--border-radius-xs);
    font-size: 12px;
    border-left: 3px solid var(--border-color);
    animation: slideInRight 0.3s ease;
}

.event-item--collision {
    border-left-color: var(--accent-red);
}

.event-item--hard_brake {
    border-left-color: var(--accent-orange);
}

.event-item--hard_accel {
    border-left-color: var(--accent-yellow);
}

.event-item--hard_steer {
    border-left-color: var(--accent-purple);
}

.event-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 55px;
}

.event-text {
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ---------- Trip Detail ---------- */
.trip-detail {
    flex: 1;
    overflow: hidden;
}

.trip-detail-layout {
    display: flex;
    height: 100%;
}

.trip-detail-layout > .map-container {
    flex: 0 0 70%;
    display: flex;
    flex-direction: column;
}

.trip-detail-layout > .map-container > .map {
    flex: 1;
}

.trip-detail-layout > .side-panel {
    flex: 0 0 30%;
}

/* ---------- Replay Controls ---------- */
.replay-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.replay-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.replay-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(34, 211, 238, 0.4);
}

.replay-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 6px rgba(34, 211, 238, 0.4);
}

#replay-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.speed-buttons {
    display: flex;
    gap: 4px;
}

/* ---------- Heatmap Layout ---------- */
.heatmap-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.heatmap-layout > .map-container {
    flex: 0 0 70%;
}

.heatmap-layout > .side-panel {
    flex: 0 0 30%;
}

/* ---------- Filter Bar ---------- */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 16px;
}

.filter-bar label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.filter-bar label:hover {
    color: var(--text-primary);
}

.filter-bar input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent-cyan);
    cursor: pointer;
}

/* ---------- Period Selector ---------- */
.period-selector {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--border-radius-sm);
    padding: 2px;
    border: 1px solid var(--border-color);
}

/* ---------- Report Stat Cards ---------- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 16px 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    transition: all var(--transition-fast);
}

.stat-card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-glow-cyan);
}

.stat-card .stat-card-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-card .stat-card-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-cyan);
    line-height: 1.1;
}

.stat-card .stat-card-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-card .stat-card-trend {
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

.stat-card .stat-card-trend.up {
    color: var(--accent-green);
}

.stat-card .stat-card-trend.down {
    color: var(--accent-red);
}

/* ---------- Charts Grid ---------- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 12px;
    padding: 0 20px 16px;
}

/* ---------- Status Bar ---------- */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--statusbar-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 24px;
    z-index: 1000;
    font-size: 11px;
    color: var(--text-muted);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}

/* ---------- Collision Overlay ---------- */
.collision-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(239, 68, 68, 0.08);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: collision-flash 0.6s ease-in-out infinite alternate;
    backdrop-filter: blur(2px);
}

@keyframes collision-flash {
    0% {
        background: rgba(239, 68, 68, 0.05);
    }
    100% {
        background: rgba(239, 68, 68, 0.15);
    }
}

.collision-alert-box {
    background: var(--bg-card);
    border: 2px solid var(--accent-red);
    border-radius: var(--border-radius);
    padding: 40px 60px;
    text-align: center;
    box-shadow: var(--shadow-glow-red);
    animation: pulse-box 1s ease-in-out infinite alternate;
}

@keyframes pulse-box {
    0% {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
        transform: scale(1);
    }
    100% {
        box-shadow: 0 0 50px rgba(239, 68, 68, 0.6);
        transform: scale(1.02);
    }
}

.collision-icon {
    font-size: 64px;
    line-height: 1;
    margin-bottom: 12px;
    animation: shake 0.4s ease-in-out infinite;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.collision-text {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-red);
    margin-bottom: 8px;
}

.collision-detail {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ---------- Toast Notifications ---------- */
.toast-container {
    position: fixed;
    bottom: calc(var(--statusbar-height) + 12px);
    left: 16px;
    z-index: 8000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    color: var(--text-primary);
    pointer-events: auto;
    animation: slideInLeft 0.35s ease;
    max-width: 360px;
}

.toast--success {
    border-left: 3px solid var(--accent-green);
}

.toast--warning {
    border-left: 3px solid var(--accent-yellow);
}

.toast--error {
    border-left: 3px solid var(--accent-red);
}

.toast--info {
    border-left: 3px solid var(--accent-blue);
}

.toast-exit {
    animation: slideOutLeft 0.3s ease forwards;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutLeft {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-60px);
    }
}

/* ---------- Hotspot Ranking ---------- */
#hotspot-ranking .hotspot-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

#hotspot-ranking .hotspot-item:last-child {
    border-bottom: none;
}

#hotspot-ranking .hotspot-rank {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
    width: 24px;
}

#hotspot-ranking .hotspot-name {
    flex: 1;
    color: var(--text-secondary);
}

#hotspot-ranking .hotspot-count {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--accent-red);
}

/* ---------- Safety Stats ---------- */
#safety-stats .safety-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

#safety-stats .safety-stat-row:last-child {
    border-bottom: none;
}

#safety-stats .safety-stat-label {
    color: var(--text-secondary);
}

#safety-stats .safety-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--text-primary);
}

/* ---------- Trip Summary ---------- */
#trip-summary .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}

#trip-summary .summary-row:last-child {
    border-bottom: none;
}

#trip-summary .summary-label {
    color: var(--text-muted);
}

#trip-summary .summary-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--text-primary);
}

/* ---------- Score Badge in Tables ---------- */
.score-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
}

.score-badge--high {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
}

.score-badge--mid {
    background: rgba(234, 179, 8, 0.15);
    color: var(--accent-yellow);
}

.score-badge--low {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

/* ---------- Status Chip ---------- */
.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.status-chip--complete {
    background: rgba(34, 197, 94, 0.12);
    color: var(--accent-green);
}

.status-chip--active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent-blue);
}

.status-chip--error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--accent-red);
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(60px);
    }
}

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

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

/* ---------- Utility Classes ---------- */
.text-mono {
    font-family: 'JetBrains Mono', monospace;
}

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

.text-cyan {
    color: var(--accent-cyan);
}

.text-green {
    color: var(--accent-green);
}

.text-yellow {
    color: var(--accent-yellow);
}

.text-red {
    color: var(--accent-red);
}

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

.mt-8 {
    margin-top: 8px;
}

.mt-16 {
    margin-top: 16px;
}

.mb-8 {
    margin-bottom: 8px;
}

.gap-8 {
    gap: 8px;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.hidden {
    display: none !important;
}

/* ---------- Loading Skeleton ---------- */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-card) 25%,
        var(--bg-card-hover) 50%,
        var(--bg-card) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--border-radius-xs);
}

@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ---------- Empty State ---------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
}

.empty-state-icon {
    font-size: 48px;
    opacity: 0.4;
}

.empty-state-text {
    font-size: 14px;
}

/* ---------- Progress Bar ---------- */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-cyan);
    border-radius: 2px;
    transition: width var(--transition-normal);
}

/* ---------- Danger Zone Bar (for heatmap risk levels) ---------- */
.risk-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}

.risk-bar-track {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.risk-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width var(--transition-normal);
}

.risk-bar-fill--high {
    background: var(--accent-red);
}

.risk-bar-fill--mid {
    background: var(--accent-yellow);
}

.risk-bar-fill--low {
    background: var(--accent-green);
}

/* ---------- Responsive (Tablet) ---------- */
@media (max-width: 1024px) {
    .live-layout {
        flex-direction: column;
    }

    .live-layout > .map-container {
        flex: 0 0 55%;
    }

    .live-layout > .side-panel {
        flex: 0 0 45%;
    }

    .trip-detail-layout {
        flex-direction: column;
    }

    .trip-detail-layout > .map-container,
    .trip-detail-layout > .side-panel {
        flex: none;
    }

    .trip-detail-layout > .map-container {
        height: 50%;
    }

    .trip-detail-layout > .side-panel {
        height: 50%;
    }

    .heatmap-layout {
        flex-direction: column;
    }

    .heatmap-layout > .map-container {
        flex: 0 0 55%;
    }

    .heatmap-layout > .side-panel {
        flex: 0 0 45%;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------- Responsive (Mobile) ---------- */
@media (max-width: 640px) {
    .nav-tabs {
        gap: 2px;
    }

    .nav-tab {
        padding: 6px 10px;
        font-size: 11px;
    }

    .nav-title {
        display: none;
    }

    .filter-bar {
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-value {
        font-size: 28px;
    }

    .replay-controls {
        flex-wrap: wrap;
    }

    .status-bar {
        gap: 12px;
        font-size: 10px;
        overflow-x: auto;
    }
}

/* ---------- AI Chatbot ---------- */
.chatbot-toggle {
    position: fixed;
    bottom: 52px;
    right: 24px;
    z-index: 7000;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(145deg, #2563eb, #1e40af);
    border: 2px solid rgba(96, 165, 250, 0.4);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg), 0 0 24px rgba(59, 130, 246, 0.35), inset 0 1px 1px rgba(255,255,255,0.15);
    transition: all var(--transition-fast);
    overflow: hidden;
}

.chatbot-toggle:hover {
    transform: scale(1.12) translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 36px rgba(59, 130, 246, 0.55), inset 0 1px 1px rgba(255,255,255,0.2);
}

.chatbot-toggle--active {
    background: linear-gradient(145deg, #dc2626, #b91c1c);
    border-color: rgba(248, 113, 113, 0.4);
    box-shadow: var(--shadow-lg), 0 0 24px rgba(239, 68, 68, 0.35);
}

/* 3D Car Icon */
.chatbot-car-icon {
    position: relative;
    width: 44px;
    height: 36px;
    animation: car-float 2.5s ease-in-out infinite;
}

@keyframes car-float {
    0%, 100% { transform: translateY(0) translateX(0); }
    25% { transform: translateY(-3px) translateX(1.5px); }
    50% { transform: translateY(-1px) translateX(-1px); }
    75% { transform: translateY(-4px) translateX(0.5px); }
}

/* Shadow under car */
.car-shadow {
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 4px;
    background: radial-gradient(ellipse, rgba(0,0,0,0.4) 0%, transparent 70%);
    border-radius: 50%;
    animation: shadow-pulse 2.5s ease-in-out infinite;
}

@keyframes shadow-pulse {
    0%, 100% { width: 30px; opacity: 0.5; }
    25% { width: 26px; opacity: 0.35; }
    75% { width: 24px; opacity: 0.3; }
}

/* Speed lines */
.car-speed-lines {
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.car-speed-lines span {
    display: block;
    height: 1.5px;
    background: linear-gradient(to left, rgba(147, 197, 253, 0.7), transparent);
    border-radius: 1px;
    animation: speed-line 0.8s ease-in-out infinite;
}

.car-speed-lines span:nth-child(1) { width: 8px; animation-delay: 0s; }
.car-speed-lines span:nth-child(2) { width: 12px; animation-delay: 0.15s; }
.car-speed-lines span:nth-child(3) { width: 6px; animation-delay: 0.3s; }

@keyframes speed-line {
    0%, 100% { opacity: 0.3; transform: translateX(0); }
    50% { opacity: 1; transform: translateX(-3px); }
}

.car-body {
    position: relative;
    width: 100%;
    height: 100%;
    animation: car-bounce 1.2s ease-in-out infinite;
}

@keyframes car-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    30% { transform: translateY(-1.5px) rotate(-1.2deg); }
    60% { transform: translateY(0.5px) rotate(0.6deg); }
}

.car-top {
    position: absolute;
    top: 2px;
    left: 12px;
    width: 18px;
    height: 10px;
    background: linear-gradient(180deg, #93c5fd, #60a5fa);
    border-radius: 8px 8px 0 0;
    border: 1px solid rgba(255,255,255,0.3);
    border-bottom: none;
}

.car-bottom {
    position: absolute;
    top: 10px;
    left: 4px;
    width: 36px;
    height: 12px;
    background: linear-gradient(180deg, #f8fafc, #e2e8f0);
    border-radius: 4px 8px 3px 3px;
    border: 1px solid rgba(255,255,255,0.4);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    animation: car-body-shine 3s ease-in-out infinite;
}

@keyframes car-body-shine {
    0%, 100% { background: linear-gradient(180deg, #f8fafc, #e2e8f0); }
    50% { background: linear-gradient(180deg, #ffffff, #f1f5f9); }
}

/* Window with reflection */
.car-window {
    position: absolute;
    top: 4px;
    left: 15px;
    width: 12px;
    height: 7px;
    background: linear-gradient(180deg, rgba(34, 211, 238, 0.7), rgba(34, 211, 238, 0.3));
    border-radius: 5px 5px 0 0;
    overflow: hidden;
}

.car-window-shine {
    position: absolute;
    top: -2px;
    left: -4px;
    width: 6px;
    height: 14px;
    background: linear-gradient(120deg, transparent, rgba(255,255,255,0.5), transparent);
    transform: skewX(-20deg);
    animation: window-shine 2.5s ease-in-out infinite;
}

@keyframes window-shine {
    0%, 100% { left: -6px; opacity: 0; }
    40% { opacity: 0; }
    50% { left: 4px; opacity: 1; }
    60% { opacity: 0; }
    61%, 100% { left: 14px; opacity: 0; }
}

/* Headlight with beam */
.car-headlight {
    position: absolute;
    top: 12px;
    right: 3px;
    width: 3px;
    height: 3px;
    background: var(--accent-yellow);
    border-radius: 50%;
    box-shadow: 0 0 4px var(--accent-yellow), 0 0 8px rgba(234, 179, 8, 0.5);
    animation: headlight-blink 2s ease-in-out infinite;
}

.car-headlight::after {
    content: '';
    position: absolute;
    top: -1px;
    right: -8px;
    width: 10px;
    height: 5px;
    background: linear-gradient(to right, rgba(234, 179, 8, 0.25), transparent);
    border-radius: 0 4px 4px 0;
    animation: headlight-beam 2s ease-in-out infinite;
}

@keyframes headlight-blink {
    0%, 85%, 100% { opacity: 1; box-shadow: 0 0 4px var(--accent-yellow), 0 0 8px rgba(234, 179, 8, 0.5); }
    90% { opacity: 0.4; box-shadow: 0 0 2px var(--accent-yellow); }
    95% { opacity: 1; box-shadow: 0 0 6px var(--accent-yellow), 0 0 12px rgba(234, 179, 8, 0.6); }
}

@keyframes headlight-beam {
    0%, 85%, 100% { opacity: 0.8; }
    90% { opacity: 0.2; }
    95% { opacity: 1; }
}

/* Taillight */
.car-taillight {
    position: absolute;
    top: 12px;
    left: 5px;
    width: 2px;
    height: 3px;
    background: var(--accent-red);
    border-radius: 1px;
    box-shadow: 0 0 3px var(--accent-red), 0 0 6px rgba(239, 68, 68, 0.4);
    animation: taillight-glow 1.5s ease-in-out infinite;
}

@keyframes taillight-glow {
    0%, 100% { opacity: 0.7; box-shadow: 0 0 3px var(--accent-red); }
    50% { opacity: 1; box-shadow: 0 0 6px var(--accent-red), 0 0 10px rgba(239, 68, 68, 0.5); }
}

/* Wheels with hub detail */
.car-wheel {
    position: absolute;
    bottom: 2px;
    width: 9px;
    height: 9px;
    background: conic-gradient(#374151, #1f2937, #4b5563, #1f2937, #374151);
    border-radius: 50%;
    border: 1.5px solid #6b7280;
    box-shadow: 0 1px 2px rgba(0,0,0,0.5);
    animation: wheel-spin 0.5s linear infinite;
}

.car-wheel-hub {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 3px;
    background: radial-gradient(circle, #9ca3af, #6b7280);
    border-radius: 50%;
}

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

.car-wheel--front {
    right: 6px;
}

.car-wheel--rear {
    left: 7px;
}

/* Exhaust smoke */
.car-exhaust {
    position: absolute;
    bottom: 6px;
    left: -2px;
    display: flex;
    gap: 0;
}

.exhaust-puff {
    display: block;
    width: 4px;
    height: 4px;
    background: radial-gradient(circle, rgba(148, 163, 184, 0.6), transparent);
    border-radius: 50%;
    animation: exhaust 1.2s ease-out infinite;
}

.exhaust-puff:nth-child(1) { animation-delay: 0s; }
.exhaust-puff:nth-child(2) { animation-delay: 0.4s; }
.exhaust-puff:nth-child(3) { animation-delay: 0.8s; }

@keyframes exhaust {
    0% {
        opacity: 0.7;
        transform: translate(0, 0) scale(0.5);
    }
    50% {
        opacity: 0.4;
        transform: translate(-6px, -2px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-14px, -5px) scale(1.5);
    }
}

/* Sparkle effects */
.car-sparkle {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 4px #fff, 0 0 8px rgba(255,255,255,0.5);
    animation: sparkle 3s ease-in-out infinite;
    pointer-events: none;
}

.car-sparkle--1 {
    top: 4px;
    right: 6px;
    animation-delay: 0s;
}

.car-sparkle--2 {
    top: 10px;
    left: 14px;
    animation-delay: 1.5s;
}

@keyframes sparkle {
    0%, 20%, 100% { opacity: 0; transform: scale(0); }
    10% { opacity: 1; transform: scale(1); }
    15% { opacity: 0.5; transform: scale(0.5); }
}

/* AI Badge pulse */
.car-ai-badge {
    position: absolute;
    bottom: -2px;
    right: -4px;
    font-size: 7px;
    font-weight: 800;
    background: var(--accent-cyan);
    color: #0f172a;
    padding: 1px 5px;
    border-radius: 4px;
    letter-spacing: 0.05em;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4), 0 0 8px rgba(34, 211, 238, 0.3);
    line-height: 1.2;
    animation: ai-badge-pulse 2s ease-in-out infinite;
}

@keyframes ai-badge-pulse {
    0%, 100% { box-shadow: 0 1px 3px rgba(0,0,0,0.4), 0 0 6px rgba(34, 211, 238, 0.2); }
    50% { box-shadow: 0 1px 3px rgba(0,0,0,0.4), 0 0 14px rgba(34, 211, 238, 0.5); }
}

/* Hover turbo boost */
.chatbot-toggle:hover .car-speed-lines span {
    animation-duration: 0.3s;
}

.chatbot-toggle:hover .car-wheel {
    animation-duration: 0.2s;
}

.chatbot-toggle:hover .exhaust-puff {
    animation-duration: 0.6s;
}

.chatbot-toggle:hover .car-body {
    animation-duration: 0.6s;
}

.chatbot-toggle:hover .car-headlight::after {
    width: 14px;
    background: linear-gradient(to right, rgba(234, 179, 8, 0.4), transparent);
}

.chatbot-panel {
    position: fixed;
    bottom: 112px;
    right: 24px;
    z-index: 7000;
    width: 400px;
    height: 520px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: slideInUp 0.3s ease;
    overflow: hidden;
}

.chatbot-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chatbot-header-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.chatbot-header-model {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.12);
    padding: 2px 8px;
    border-radius: 10px;
}

.chatbot-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.chatbot-close:hover {
    color: var(--text-primary);
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-msg {
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

.chatbot-msg--user {
    align-self: flex-end;
}

.chatbot-msg--ai {
    align-self: flex-start;
}

.chatbot-msg-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chatbot-msg--user .chatbot-msg-label {
    text-align: right;
}

.chatbot-msg-text {
    padding: 10px 14px;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
}

.chatbot-msg--user .chatbot-msg-text {
    background: var(--accent-blue);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.chatbot-msg--ai .chatbot-msg-text {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 2px;
}

.chatbot-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
}

.chatbot-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-cyan);
    animation: chatbot-bounce 1.4s ease-in-out infinite;
}

.chatbot-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatbot-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chatbot-form {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    flex-shrink: 0;
}

.chatbot-form input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition-fast);
}

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

.chatbot-form input::placeholder {
    color: var(--text-muted);
}

.chatbot-form input:disabled {
    opacity: 0.5;
}

@media (max-width: 640px) {
    .chatbot-panel {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 100px;
        height: 60vh;
    }
}
