/* ══════════════════════════════════════════════════════════════
   DriveSafe AI - Dashboard Styling
   Thiết kế Dark Mode cao cấp cho hệ thống cảnh báo buồn ngủ
   ══════════════════════════════════════════════════════════════ */

/* ─── CSS Variables (Design Tokens) ─── */
:root {
    /* Colors */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-card-hover: rgba(31, 41, 55, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-border: rgba(255, 255, 255, 0.06);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-primary: #6366f1;
    --accent-primary-glow: rgba(99, 102, 241, 0.3);
    --accent-secondary: #8b5cf6;

    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.1);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.1);
    --color-danger: #ef4444;
    --color-danger-bg: rgba(239, 68, 68, 0.1);
    --color-info: #3b82f6;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --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 30px rgba(0, 0, 0, 0.5);
    --shadow-glow-primary: 0 0 20px var(--accent-primary-glow);
    --shadow-glow-danger: 0 0 30px rgba(239, 68, 68, 0.4);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
    /* Background gradient */
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(16, 185, 129, 0.04) 0%, transparent 50%);
    background-attachment: fixed;
}

/* ══════════════════════════════════════════════════════════════
   DANGER OVERLAY - Hiển thị cảnh báo toàn màn hình
   ══════════════════════════════════════════════════════════════ */
.danger-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(239, 68, 68, 0.15);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: dangerPulse 1s ease-in-out infinite;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

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

.danger-overlay-content {
    text-align: center;
    animation: dangerBounce 0.5s ease-out;
}

.danger-icon-pulse {
    width: 100px;
    height: 100px;
    margin: 0 auto var(--space-lg);
    color: var(--color-danger);
    animation: iconPulse 0.8s ease-in-out infinite alternate;
}

.danger-overlay h1 {
    font-size: 3rem;
    font-weight: 900;
    color: var(--color-danger);
    text-shadow: 0 0 40px rgba(239, 68, 68, 0.6);
    letter-spacing: 2px;
    margin-bottom: var(--space-sm);
}

.danger-overlay p {
    font-size: 1.3rem;
    color: var(--text-primary);
    opacity: 0.9;
}

@keyframes dangerPulse {
    0%, 100% { background: rgba(239, 68, 68, 0.1); }
    50% { background: rgba(239, 68, 68, 0.25); }
}

@keyframes iconPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.15); }
}

@keyframes dangerBounce {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ══════════════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════════════ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--bg-glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-glow-primary);
}

.logo-icon svg {
    width: 24px;
    height: 24px;
}

.logo-text h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo-text .accent {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

/* Status Badge */
.status-badge {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    background: var(--color-success-bg);
    border: 1px solid rgba(16, 185, 129, 0.2);
    transition: all var(--transition-normal);
}

.status-badge.warning {
    background: var(--color-warning-bg);
    border-color: rgba(245, 158, 11, 0.3);
}

.status-badge.danger {
    background: var(--color-danger-bg);
    border-color: rgba(239, 68, 68, 0.3);
    animation: badgePulse 1s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-success);
    animation: dotPulse 2s ease-in-out infinite;
}

.status-badge.warning .status-dot {
    background: var(--color-warning);
}

.status-badge.danger .status-dot {
    background: var(--color-danger);
}

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-success);
}

.status-badge.warning .status-text {
    color: var(--color-warning);
}

.status-badge.danger .status-text {
    color: var(--color-danger);
}

/* Uptime */
.uptime-display {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

/* ══════════════════════════════════════════════════════════════
   DASHBOARD LAYOUT
   ══════════════════════════════════════════════════════════════ */
.dashboard {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: var(--space-lg);
    padding: var(--space-lg) var(--space-xl);
    max-width: 1600px;
    margin: 0 auto;
}

/* ══════════════════════════════════════════════════════════════
   VIDEO SECTION
   ══════════════════════════════════════════════════════════════ */
.video-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.video-container {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-glass-border);
    box-shadow: var(--shadow-lg);
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.video-container.warning {
    border-color: rgba(245, 158, 11, 0.4);
    box-shadow: 0 0 25px rgba(245, 158, 11, 0.15);
}

.video-container.danger {
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: var(--shadow-glow-danger);
    animation: videoDangerPulse 1.5s ease-in-out infinite;
}

@keyframes videoDangerPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 40px rgba(239, 68, 68, 0.5); }
}

.video-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent);
    z-index: 10;
}

.video-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

.rec-dot {
    width: 10px;
    height: 10px;
    background: var(--color-danger);
    border-radius: 50%;
    animation: recPulse 1.5s ease-in-out infinite;
}

@keyframes recPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50% { opacity: 0.5; box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
}

.video-fps {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--color-success);
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.video-feed {
    width: 100%;
    display: block;
    aspect-ratio: 4/3;
    object-fit: cover;
    background: #000;
}

.video-status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--space-xs) var(--space-md);
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    z-index: 10;
}

.video-status-bar span {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ─── Quick Stats ─── */
.quick-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-success);
    transition: background var(--transition-normal);
}

.stat-card.warning::before {
    background: var(--color-warning);
}

.stat-card.danger::before {
    background: var(--color-danger);
}

.stat-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-success);
}

.stat-icon svg {
    width: 20px;
    height: 20px;
}

.stat-card.warning .stat-icon { color: var(--color-warning); }
.stat-card.danger .stat-icon { color: var(--color-danger); }

.stat-info {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--color-success);
    transition: width var(--transition-normal), background var(--transition-normal);
}

.stat-card.warning .stat-bar-fill { background: var(--color-warning); }
.stat-card.danger .stat-bar-fill { background: var(--color-danger); }

/* ══════════════════════════════════════════════════════════════
   PANELS SECTION (Cột phải)
   ══════════════════════════════════════════════════════════════ */
.panels-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.panel {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition-normal);
}

.panel:hover {
    border-color: rgba(255, 255, 255, 0.1);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--bg-glass-border);
    background: var(--bg-glass);
}

.panel-header h2 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.panel-body {
    padding: var(--space-lg);
}

/* ─── Alert Indicators ─── */
.alert-indicators {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.alert-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    border: 1px solid var(--bg-glass-border);
    transition: all var(--transition-normal);
}

.alert-indicator.active {
    background: var(--color-danger-bg);
    border-color: rgba(239, 68, 68, 0.3);
    animation: alertFlash 1s ease-in-out infinite;
}

@keyframes alertFlash {
    0%, 100% { background: rgba(239, 68, 68, 0.08); }
    50% { background: rgba(239, 68, 68, 0.2); }
}

.indicator-icon {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.indicator-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.indicator-status {
    font-size: 0.75rem;
    color: var(--color-success);
    font-weight: 500;
}

.alert-indicator.active .indicator-status {
    color: var(--color-danger);
    font-weight: 700;
}

.indicator-light {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
    transition: all var(--transition-normal);
}

.alert-indicator.active .indicator-light {
    background: var(--color-danger);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
    animation: lightPulse 0.8s ease-in-out infinite alternate;
}

@keyframes lightPulse {
    0% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); transform: scale(1); }
    100% { box-shadow: 0 0 16px rgba(239, 68, 68, 0.8); transform: scale(1.2); }
}

.alert-indicator.warning-active {
    background: var(--color-warning-bg);
    border-color: rgba(245, 158, 11, 0.3);
    animation: alertWarningFlash 1s ease-in-out infinite;
}

.alert-indicator.warning-active .indicator-status {
    color: var(--color-warning);
    font-weight: 700;
}

.alert-indicator.warning-active .indicator-light {
    background: var(--color-warning);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
    animation: lightWarningPulse 0.8s ease-in-out infinite alternate;
}

@keyframes alertWarningFlash {
    0%, 100% { background: rgba(245, 158, 11, 0.08); }
    50% { background: rgba(245, 158, 11, 0.20); }
}

@keyframes lightWarningPulse {
    0% { box-shadow: 0 0 8px rgba(245, 158, 11, 0.4); transform: scale(1); }
    100% { box-shadow: 0 0 16px rgba(245, 158, 11, 0.8); transform: scale(1.2); }
}

/* ─── Stats Grid ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.mini-stat {
    text-align: center;
    padding: var(--space-md);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    border: 1px solid var(--bg-glass-border);
    transition: all var(--transition-normal);
}

.mini-stat:hover {
    transform: translateY(-2px);
    background: var(--bg-card-hover);
}

.mini-stat.total {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
    border-color: rgba(99, 102, 241, 0.2);
}

.mini-stat-value {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
}

.mini-stat.total .mini-stat-value {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mini-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── Audio Panel ─── */
.volume-control {
    margin-bottom: var(--space-lg);
}

.volume-control label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.slider-group {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.slider-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-primary);
    min-width: 40px;
    text-align: right;
}

/* Custom Range Slider */
.styled-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
    outline: none;
    transition: background var(--transition-fast);
}

.styled-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-primary-glow);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.styled-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 16px var(--accent-primary-glow);
}

.styled-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px var(--accent-primary-glow);
}

/* Audio Test Buttons */
.audio-test-buttons {
    display: flex;
    gap: var(--space-sm);
}

.btn {
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.btn-test {
    flex: 1;
    background: var(--bg-glass);
    color: var(--text-secondary);
    border: 1px solid var(--bg-glass-border);
    justify-content: center;
}

.btn-test:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-test.warning:hover {
    border-color: rgba(245, 158, 11, 0.3);
    color: var(--color-warning);
}

.btn-test.danger:hover {
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--color-danger);
}

.btn-save {
    width: 100%;
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-size: 0.85rem;
    justify-content: center;
    border-radius: var(--radius-md);
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-primary);
}

.btn-save:active {
    transform: translateY(0);
}

/* ─── Settings Panel ─── */
.setting-item {
    margin-bottom: var(--space-lg);
}

.setting-item:last-of-type {
    margin-bottom: 0;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.setting-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: var(--accent-primary);
}

.setting-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
    font-style: italic;
}

/* ─── Toggle Switch ─── */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    transition: var(--transition-normal);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition-normal);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-primary);
    box-shadow: 0 0 10px var(--accent-primary-glow);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ─── History Panel ─── */
.history-list {
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}

.history-empty {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--text-muted);
}

.history-empty svg {
    color: var(--color-success);
    opacity: 0.3;
    margin-bottom: var(--space-sm);
}

.history-empty p {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.history-empty span {
    font-size: 0.75rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xs);
    animation: historySlideIn 0.3s ease-out;
    transition: background var(--transition-fast);
}

.history-item:hover {
    background: var(--bg-glass);
}

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

.history-icon {
    font-size: 1.1rem;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    flex-shrink: 0;
}

.history-icon.eye { background: rgba(59, 130, 246, 0.1); }
.history-icon.yawn { background: rgba(245, 158, 11, 0.1); }
.history-icon.head { background: rgba(239, 68, 68, 0.1); }
.history-icon.distract { background: rgba(245, 158, 11, 0.1); }

.history-message {
    flex: 1;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.history-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════
   FOOTER
   ══════════════════════════════════════════════════════════════ */
.app-footer {
    text-align: center;
    padding: var(--space-lg) var(--space-xl);
    border-top: 1px solid var(--bg-glass-border);
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE DESIGN
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
    .dashboard {
        grid-template-columns: 1fr;
    }

    .quick-stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    html {
        font-size: 13px;
    }

    .app-header {
        flex-direction: column;
        gap: var(--space-md);
        padding: var(--space-md);
    }

    .dashboard {
        padding: var(--space-md);
    }

    .quick-stats {
        grid-template-columns: 1fr;
    }

    .audio-test-buttons {
        flex-direction: column;
    }

    .danger-overlay h1 {
        font-size: 1.8rem;
    }
}

/* ─── Dark mode scrollbar for the whole page ─── */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ─── Video Controls Bar ─── */
.video-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid var(--bg-glass-border);
    backdrop-filter: blur(8px);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.btn-camera-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-full);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    letter-spacing: 0.3px;
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-camera-toggle:hover {
    background: rgba(16, 185, 129, 0.25);
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.2);
    transform: translateY(-1px);
}

.btn-camera-toggle:not(.active) {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-camera-toggle:not(.active):hover {
    background: rgba(239, 68, 68, 0.22);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.2);
}

/* ─── Camera Offline Overlay ─── */
/* video-wrapper: container riêng cho video + overlay */
.video-wrapper {
    position: relative;
    width: 100%;
    line-height: 0; /* Xóa khoảng trống dưới ảnh inline */
}

.camera-offline-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 14, 26, 0.93);
    backdrop-filter: blur(4px);
    z-index: 10;
    border-radius: 0; /* Wrapper không có border-radius, container cha đã có */
    transition: opacity 0.3s ease;
}

.camera-offline-overlay.hidden {
    display: none;
}

.camera-offline-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    text-align: center;
}

.camera-offline-content svg {
    opacity: 0.4;
    color: var(--color-danger);
}

.camera-offline-content p {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
}

.camera-offline-content span {
    font-size: 13px;
    color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════
   DRIVER PANEL — Phần đăng ký tài xế
   ══════════════════════════════════════════════════════════════ */

.driver-name-badge {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #10b981;
    font-weight: 700;
    font-size: 0.82rem;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    letter-spacing: 0.3px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.driver-step {
    margin-bottom: 6px;
}

.driver-step-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.4);
    color: var(--accent-primary);
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.driver-input-row {
    display: flex;
    gap: 8px;
}

.driver-name-input {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--bg-glass-border);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

.driver-name-input:focus {
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.btn-driver-capture {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.btn-driver-capture:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-driver-capture:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-driver-train {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    padding: 9px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-driver-train:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Capture progress box */
.capture-progress {
    margin-top: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: rgba(99, 102, 241, 0.06);
    border: 1px dashed rgba(99, 102, 241, 0.3);
}

.capture-progress.hidden { display: none; }

.capture-progress-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.capture-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

.capture-count {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-primary);
}

.capture-bar-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.capture-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 3px;
    transition: width 0.15s ease;
}

.capture-hint {
    margin: 8px 0 0;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* ══════════════════════════════════════════════════════════════
   HISTORY PANEL — Lịch sử cảnh báo
   ══════════════════════════════════════════════════════════════ */

.btn-clear-history {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-clear-history:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--color-danger);
}

.history-list {
    max-height: 260px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.15s;
}

.history-item:last-child { border-bottom: none; }

.history-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Animation khi mục mới thêm vào */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.history-entry {
    animation: slideIn 0.2s ease forwards;
}

.history-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.history-message {
    flex: 1;
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    flex-shrink: 0;
}

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 28px 16px;
    color: var(--text-muted);
    text-align: center;
}

.history-empty svg {
    opacity: 0.3;
    color: var(--color-success);
}

.history-empty p {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0;
}

.history-empty span {
    font-size: 12px;
    color: var(--text-muted);
}
