:root {
    /* Light Mode Variables */
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --sidebar-width: 260px;
    --header-height: 60px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
}

[data-theme="dark"] {
    /* Dark Mode Variables */
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --input-bg: #0f172a;
    --input-border: #475569;
}

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin-bottom: 60px; /* Space for mobile floating buttons if needed */
}

:root[data-palette="ocean"] {
    --primary-color: #2dd4bf;
    --primary-hover: #14b8a6;
}

:root[data-palette="sunset"] {
    --primary-color: #f59e0b;
    --primary-hover: #ef4444;
}

:root[data-palette="forest"] {
    --primary-color: #10b981;
    --primary-hover: #059669;
}

:root[data-palette="neon"] {
    --primary-color: #a78bfa;
    --primary-hover: #6366f1;
}

/* Card Styles */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    border-radius: 12px;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
}

/* Sidebar Styles */
.sidebar {
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    transition: transform 0.3s ease-in-out;
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    z-index: 1020;
}

.sidebar .list-group-item {
    background-color: transparent;
    color: var(--text-secondary);
    border: none;
    margin: 4px 12px;
    border-radius: 8px;
    padding: 12px 16px;
    transition: all 0.2s;
}

.sidebar .list-group-item:hover {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
}

.sidebar .list-group-item.active {
    background-color: var(--primary-color);
    color: white;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
}

/* Navbar */
.navbar {
    background-color: var(--bg-card) !important;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 1030;
    height: var(--header-height);
}

.btn-primary {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: #fff !important;
}

.btn-primary:hover {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
}

.btn-outline-primary {
    color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-outline-primary:hover {
    color: #fff !important;
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.navbar-brand, .nav-link, .navbar-text {
    color: var(--text-primary) !important;
}

/* Main Content Wrapper */
.main-wrapper {
    margin-left: var(--sidebar-width);
    padding: 20px;
    padding-top: calc(var(--header-height) + 20px);
    transition: margin-left 0.3s ease-in-out;
    min-height: 100vh;
}

/* Form Elements */
.form-control, .form-select {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.25);
}

/* Theme Toggle Button */
.theme-toggle {
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    color: var(--text-primary);
    background: transparent;
    border: none;
}

.theme-toggle:hover {
    background-color: rgba(0,0,0,0.05);
}

[data-theme="dark"] .theme-toggle:hover {
    background-color: rgba(255,255,255,0.1);
}

/* Mobile Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        top: var(--header-height);
        height: calc(100vh - var(--header-height));
        z-index: 1035;
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0,0,0,0.2);
    }

    .main-wrapper {
        margin-left: 0;
    }
    
    .navbar-toggler {
        display: block !important;
        border: none;
        color: var(--text-primary);
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0,0.5);
        z-index: 1030;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

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

/* Utilities */
.text-primary-theme {
    color: var(--primary-color) !important;
}

.bg-body-theme {
    background-color: var(--bg-body) !important;
}

.palette-picker {
    display: flex;
    align-items: center;
    gap: 8px;
}

.palette-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.palette-swatch:hover {
    transform: scale(1.1);
}

/* --- Dashboard & Attendance Specific Styles --- */

/* GPS Indicator */
.gps-indicator {
    position: fixed;
    top: calc(var(--header-height) + 10px);
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.8rem;
    z-index: 1002;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
}

/* Sync Status Indicator */
.sync-indicator {
    position: fixed;
    top: calc(var(--header-height) + 60px);
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.8rem;
    z-index: 1002;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.sync-indicator.syncing {
    background: rgba(255, 152, 0, 0.9);
    animation: pulse 2s infinite;
}

.sync-indicator.synced {
    background: rgba(76, 175, 80, 0.9);
}

.sync-indicator.offline {
    background: rgba(244, 67, 54, 0.9);
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

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

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

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

.stat-card.success::before { background: #10b981; }
.stat-card.info::before { background: var(--primary-color); }
.stat-card.warning::before { background: #f59e0b; }

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

.stat-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1;
}

.stat-card.success .stat-value { color: #10b981; }
.stat-card.info .stat-value { color: var(--primary-color); }
.stat-card.warning .stat-value { color: #f59e0b; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

/* Floating Attendance Buttons */
.floating-attendance {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .floating-attendance {
        bottom: 70px; /* Above bottom nav if existed, or just higher */
        right: 15px;
        flex-direction: row;
        justify-content: center;
        width: 100%;
        right: 0;
        padding: 0 15px;
    }
    
    .floating-attendance .attendance-btn {
        flex: 1;
        min-width: 140px;
        padding: 12px 15px;
        font-size: 0.9rem;
    }
}

.attendance-btn {
    border: none;
    border-radius: 12px;
    padding: 15px 20px;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 160px;
    color: white;
}

.attendance-btn:active { transform: scale(0.95); }
.attendance-btn.btn-primary { background: var(--primary-color); }
.attendance-btn.btn-danger { background: #ef4444; }

/* Camera UI */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    border-radius: 15px;
    overflow: hidden;
    background: #000;
}

#video, #canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
}

.face-frame {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 250px; height: 300px;
    border: 3px solid rgba(76, 175, 80, 0.8);
    border-radius: 15px;
    box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    display: none;
}

.capture-indicator {
    position: absolute;
    bottom: 20px; left: 0; right: 0;
    text-align: center;
    color: white;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 10px;
    margin: 0 20px;
}
