/* ═══════════════════════════════════════════════════
   ALERTIFY — Premium Dark Theme
   Drowsiness Prevention System
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ─── CSS Custom Properties ─── */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border-glass: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.3);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.3);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.4);
    --critical: #dc2626;
    --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
    --gradient-danger: linear-gradient(135deg, #ef4444, #dc2626);
    --gradient-success: linear-gradient(135deg, #10b981, #059669);
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.15);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-secondary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-primary); }

/* ─── Layout ─── */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-brand {
    padding: 24px;
    border-bottom: 1px solid var(--border-glass);
    text-align: center;
}

.sidebar-brand h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.sidebar-brand span {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}

.nav-link:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
    transform: translateX(4px);
}

.nav-link.active {
    background: var(--accent-glow);
    color: var(--accent-secondary);
    border-left: 3px solid var(--accent-primary);
}

.nav-link .icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-glass);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.logout-btn {
    display: block;
    text-align: center;
    padding: 8px;
    margin-top: 8px;
    border-radius: var(--radius-xs);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 500;
    transition: var(--transition);
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 32px;
}

.page-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.page-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ─── Glass Cards ─── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 24px;
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: var(--shadow-glow);
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ─── Grid ─── */
.grid { display: grid; gap: 24px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ─── Stats Cards ─── */
.stat-card {
    text-align: center;
    padding: 28px 20px;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.stat-value.success { background: var(--gradient-success); -webkit-background-clip: text; background-clip: text; }
.stat-value.danger { background: var(--gradient-danger); -webkit-background-clip: text; background-clip: text; }

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 8px;
}

/* ─── Feature Cards ─── */
.feature-card {
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
}

.feature-card:hover { transform: translateY(-4px); }

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
    display: block;
}

.feature-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.feature-card p {
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px var(--accent-glow); color: white; }

.btn-success { background: var(--gradient-success); color: white; }
.btn-danger { background: var(--gradient-danger); color: white; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
}
.btn-outline:hover { background: var(--bg-glass); color: var(--text-primary); }

.btn-lg { padding: 16px 32px; font-size: 1rem; border-radius: var(--radius); }
.btn-block { width: 100%; }

/* ─── Camera / Detection Area ─── */
.detection-area {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    aspect-ratio: 16/9;
    max-height: 480px;
}

.detection-area video, .detection-area canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detection-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.9rem;
    backdrop-filter: blur(10px);
    align-self: flex-start;
}

.status-badge.awake {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid var(--success);
    color: var(--success);
    box-shadow: 0 0 20px var(--success-glow);
}

.status-badge.drowsy {
    background: rgba(245, 158, 11, 0.2);
    border: 1px solid var(--warning);
    color: var(--warning);
    box-shadow: 0 0 20px var(--warning-glow);
    animation: pulse-warning 1s infinite;
}

.status-badge.critical {
    background: rgba(239, 68, 68, 0.3);
    border: 2px solid var(--danger);
    color: white;
    box-shadow: 0 0 30px var(--danger-glow);
    animation: pulse-danger 0.5s infinite;
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes pulse-danger {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

.alert-message {
    text-align: center;
    padding: 16px;
    background: rgba(220, 38, 38, 0.9);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1.2rem;
    animation: shake 0.5s infinite;
    display: none;
}

.alert-message.show { display: block; }

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

/* ─── Upload Zone ─── */
.upload-zone {
    border: 2px dashed var(--border-glass);
    border-radius: var(--radius);
    padding: 48px 32px;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent-primary);
    background: var(--accent-glow);
}

.upload-zone .icon { font-size: 3rem; margin-bottom: 16px; display: block; }
.upload-zone h3 { font-size: 1.1rem; margin-bottom: 8px; }
.upload-zone p { color: var(--text-muted); font-size: 0.85rem; }

/* ─── Result Display ─── */
.result-card {
    padding: 32px;
    text-align: center;
}

.result-status {
    font-size: 3rem;
    margin-bottom: 8px;
}

.result-label {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.result-confidence {
    font-size: 1rem;
    color: var(--text-muted);
}

/* ─── Table ─── */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-glass);
}

.data-table th {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    font-weight: 700;
}

.data-table tr:hover td {
    background: var(--bg-glass);
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* ─── Forms ─── */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Auth Pages ─── */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.auth-card .brand {
    text-align: center;
    margin-bottom: 32px;
}

.auth-card .brand h1 {
    font-size: 2rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-card .brand p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ─── Messages ─── */
.message {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.85rem;
}

.message-success { background: rgba(16, 185, 129, 0.1); border: 1px solid var(--success); color: var(--success); }
.message-error { background: rgba(239, 68, 68, 0.1); border: 1px solid var(--danger); color: var(--danger); }
.message-info { background: rgba(99, 102, 241, 0.1); border: 1px solid var(--accent-primary); color: var(--accent-secondary); }

/* ─── Pagination ─── */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
}

.pagination a, .pagination span {
    padding: 8px 14px;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
}

.pagination .current {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* ─── Progress Bar ─── */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-glass);
    border-radius: 4px;
    overflow: hidden;
    margin: 16px 0;
}

.progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* ─── Video Results Timeline ─── */
.timeline { margin-top: 24px; }
.timeline-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-glass);
}

.timeline-time {
    font-size: 0.9rem;
    color: var(--text-muted);
    min-width: 80px;
    font-family: 'Courier New', monospace;
}

/* ─── Safety Score Gauge ─── */
.gauge-container {
    text-align: center;
    padding: 20px;
}

.gauge-value {
    font-size: 4rem;
    font-weight: 900;
    line-height: 1;
}

.gauge-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 8px;
}

/* ─── Image Preview ─── */
.image-preview {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 16px 0;
}

/* ─── Mobile Menu Button ─── */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xs);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
}

.mobile-menu-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}
.mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
}
.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* ─── Sidebar Overlay ─── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90;
}

.sidebar-overlay.show {
    display: block;
}

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
    }
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content { margin-left: 0; padding: 16px; padding-top: 64px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ─── Filter bar ─── */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.filter-bar select {
    padding: 8px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-bar select:focus { outline: none; border-color: var(--accent-primary); }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 4rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.2rem; color: var(--text-secondary); margin-bottom: 8px; }
