/* ===================================
   Driver Drowsiness Detection - Styles
   Modern, Professional UI Design
   =================================== */

:root {
    /* Colors - Light Theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;

    /* Accent Colors */
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

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

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-color: #334155;
}

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

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

.hidden {
    display: none !important;
}

/* ===== Loading Screen ===== */
.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    color: white;
    padding: var(--spacing-lg);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    margin: 0 auto var(--spacing-lg);
    animation: spin 1s linear infinite;
}

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

.loading-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.loading-status {
    font-size: 0.875rem;
    opacity: 0.8;
    margin-bottom: var(--spacing-lg);
}

.loading-bar {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress {
    height: 100%;
    width: 30%;
    background: white;
    border-radius: var(--radius-full);
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(400%);
    }
}

/* ===== App Container ===== */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-md) var(--spacing-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 70px;
    /* Fixed height for calculation */
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo i {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    gap: var(--spacing-sm);
}

/* ===== Alert Banner ===== */
.alert-banner {
    background: var(--gradient-danger);
    color: white;
    padding: var(--spacing-md);
    text-align: center;
    animation: pulse-alert 0.5s ease infinite alternate;
}

@keyframes pulse-alert {
    from {
        opacity: 1;
    }

    to {
        opacity: 0.8;
    }
}

.alert-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    font-weight: 600;
    font-size: 1rem;
}

.alert-content i {
    font-size: 1.25rem;
    animation: shake 0.5s ease infinite;
}

@keyframes shake {

    0%,
    100% {
        transform: rotate(0);
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--spacing-lg);
    padding: var(--spacing-lg);
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* ===== Video Section ===== */
.video-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    width: 100%;
}

.video-container {
    position: relative;
    background: var(--bg-tertiary);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    width: 100%;
    /* Default for mobile/tablet */
    aspect-ratio: 4/3;
}

#video,
#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#video {
    object-fit: contain;
    background: black;
    transform: scaleX(-1);
}

#overlay {
    pointer-events: none;
    background: transparent;
    transform: scaleX(-1);
    object-fit: contain;
}

.video-badges {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    left: auto;
    display: flex;
    gap: var(--spacing-sm);
    z-index: 10;
}

.badge {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
}

.badge-success {
    background: rgba(16, 185, 129, 0.9);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.9);
}

.video-controls {
    position: absolute;
    bottom: var(--spacing-md);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--spacing-sm);
    z-index: 10;
    width: 90%;
    justify-content: center;
}

/* ===== Quick Stats ===== */
.quick-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    box-shadow: var(--shadow-sm);
}

.stat-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
}

.eye-icon {
    background: var(--gradient-primary);
}

.mouth-icon {
    background: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
}

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

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

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-fast);
}

.stat-bar-fill.mar {
    background: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
}

.stat-bar-fill.danger {
    background: var(--gradient-danger);
}

/* ===== Dashboard Section (Sidebar) ===== */
.dashboard-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    /* For desktop height constraint */
    overflow-y: auto;
    padding-right: 5px;
    /* Space for scrollbar */
}

/* Score Card */
.score-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: var(--spacing-lg);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.score-circle {
    position: relative;
    width: 120px;
    height: 120px;
}



.score-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.score-bg {
    fill: none;
    stroke: var(--bg-tertiary);
    stroke-width: 6;
}

.score-fill {
    fill: none;
    stroke: url(#gradient-good);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 0.5s ease;
}

.score-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

#score-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
}

.score-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.status-label {
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-block;
    margin-top: var(--spacing-sm);
}

.status-good {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-success);
}

.status-moderate {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-warning);
}

.status-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-danger);
}

/* Counters Grid */
.counters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
}

.counter-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    box-shadow: var(--shadow-sm);
}

.counter-card i {
    font-size: 1rem;
    color: var(--accent-primary);
}

.counter-info {
    display: flex;
    flex-direction: column;
}

.counter-value {
    font-size: 1.1rem;
    font-weight: 700;
}

.counter-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Chart & Settings Cards */
.chart-card,
.settings-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-sm);
}

.chart-container {
    height: 120px;
    width: 100%;
}

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.setting-item {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: var(--spacing-sm);
    align-items: center;
}

.setting-item label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.setting-item input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 44px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

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

.btn-icon,
#upload-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
}

.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-md);
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: auto;
}

.footer strong {
    color: var(--text-primary);
}

.footer a {
    color: var(--accent-primary);
    text-decoration: none;
}


/* ===== RESPONSIVE / SINGLE PAGE LAYOUT ===== */

/* Desktop (Single Page View) - min 1024px */
@media (min-width: 1024px) {

    /* Lock layout to viewport height */
    .app {
        height: 100vh;
        /* Use viewport height directly */
        width: 100vw;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .header {
        height: 64px;
        padding: 0 var(--spacing-xl);
        flex-shrink: 0;
        z-index: 20;
    }

    .footer {
        height: auto;
        padding: var(--spacing-sm);
        flex-shrink: 0;
        z-index: 20;
        position: relative;
        background: var(--bg-secondary);
        /* Ensure opaque background */
        border-top: 1px solid var(--border-color);
    }

    .main-content {
        flex: 1;
        /* Take all remaining vertical space */
        height: auto;
        min-height: 0;
        /* CRITICAL: Allows flex child to shrink below content size */
        padding: var(--spacing-md) var(--spacing-xl);
        gap: var(--spacing-md);
        display: grid;
        grid-template-columns: 1fr 300px;
        grid-template-rows: minmax(0, 1fr);
        /* CRITICAL: Constrains grid height */
        overflow: hidden;
        /* Prevent body scroll, children handle scroll */
    }

    .video-section {
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: var(--spacing-md);
        overflow: hidden;
    }

    .video-container {
        flex: 1;
        /* Take all remaining vertical space */
        max-height: none;
        aspect-ratio: auto;
        /* Let flex determine ratio */
        width: 100%;
        min-height: 0;
        /* Important for flex child scrolling/sizing */
        border-radius: var(--radius-lg);
    }

    #video {
        object-fit: contain;
        /* Ensure full frame visibility */
        background: #000;
    }

    .quick-stats {
        /* Stats stay at bottom of video column, taking natural height */
        flex-shrink: 0;
    }

    .dashboard-section {
        /* Sidebar scrolls internally if needed */
        height: 100%;
        overflow-y: auto;
        padding-right: 4px;
        gap: var(--spacing-md);
    }


}

/* Tablet & Mobile (below 1024px) - Vertical Scroll Allowed */
@media (max-width: 1023px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
        padding: var(--spacing-md);
    }

    .video-container {
        max-height: 60vh;
    }

    .dashboard-section {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-md);
    }

    .score-card {
        grid-row: span 2;
    }
}

/* Mobile (below 768px) */
@media (max-width: 767px) {
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .logo span {
        display: block;
    }

    .main-content {
        padding: var(--spacing-sm);
    }

    .video-container {
        aspect-ratio: 3/4;
        max-height: 70vh;
    }

    .dashboard-section {
        grid-template-columns: 1fr;
    }

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

    .video-controls {
        width: 100%;
        padding: 0 var(--spacing-md);
    }

    .btn {
        width: 100%;
    }
}