/**
 * School Attendance Management System (Nepal Edition)
 * Modern ERP Stylesheet - Bootstrap 5.3 + Modern Web Guidance Compliant
 */

:root {
    /* Brand & Accent Tokens */
    --brand-color-light: #1e40af;
    --brand-color-dark: #60a5fa;
    --brand-color: var(--brand-color-light);

    --surface-bg-light: #f1f5f9;
    --surface-bg-dark: #0f172a;
    --surface-card-light: #ffffff;
    --surface-card-dark: #1e293b;
    --text-main-light: #0f172a;
    --text-main-dark: #f8fafc;
    --border-color-light: #e2e8f0;
    --border-color-dark: #334155;

    --sidebar-width: 268px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: #2563eb;

    --scrollbar-track: #e2e8f0;
    --scrollbar-thumb: #94a3b8;

    /* MANDATORY: Fallback for browsers without light-dark() support */
    @media (prefers-color-scheme: dark) {
        --brand-color: var(--brand-color-dark);
        --scrollbar-track: #1e293b;
        --scrollbar-thumb: #475569;
    }

    /* Progressive enhancement with light-dark() */
    @supports (color: light-dark(white, black)) {
        --brand-color: light-dark(var(--brand-color-light), var(--brand-color-dark));
        --scrollbar-track: light-dark(#e2e8f0, #1e293b);
        --scrollbar-thumb: light-dark(#94a3b8, #475569);
    }

    /* MANDATORY: Automatically adapt native UI to user system preferences */
    color-scheme: light dark;
    accent-color: var(--brand-color);
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

html[data-bs-theme="light"] {
    color-scheme: light;
    --brand-color: var(--brand-color-light);
    -- body-bg: var(--surface-bg-light);
}

html[data-bs-theme="dark"] {
    color-scheme: dark;
    --brand-color: var(--brand-color-dark);
}

/* Legacy fallback for WebKit/Blink browsers without scrollbar-color */
@supports not (scrollbar-color: auto) {
    ::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }
    ::-webkit-scrollbar-thumb {
        background: var(--scrollbar-thumb);
        border-radius: 5px;
    }
    ::-webkit-scrollbar-track {
        background: var(--scrollbar-track);
    }
}

/* Fallback for older browsers without accent-color */
@supports not (accent-color: var(--brand-color)) {
    input[type="checkbox"].visually-hidden {
        position: absolute !important;
        clip-path: inset(50%) !important;
        overflow: hidden !important;
        width: 1px !important;
        height: 1px !important;
        margin: -1px !important;
        padding: 0 !important;
        border: 0 !important;
        white-space: nowrap !important;
    }
    input[type="range"] {
        -webkit-appearance: none;
        appearance: none;
        background: transparent;
    }
    progress {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        border: none;
        background: #cbd5e1;
        height: 8px;
        border-radius: 4px;
    }
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--surface-bg-light);
    color: var(--text-main-light);
    accent-color: var(--brand-color);
    overflow-x: hidden;
    min-height: 100vh;
}

html[data-bs-theme="dark"] body {
    background-color: var(--surface-bg-dark);
    color: var(--text-main-dark);
}

/* ERP Layout Structure */
.erp-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.erp-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease, width 0.25s ease;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.15);
}

.erp-sidebar-brand {
    padding: 1.15rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-decoration: none;
    color: #ffffff;
}

.erp-sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.erp-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.nav-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    font-weight: 700;
    padding: 0.6rem 0.75rem 0.35rem;
}

.erp-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    color: #cbd5e1;
    text-decoration: none;
    border-radius: 0.55rem;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.2rem;
    transition: background-color 0.18s ease, color 0.18s ease;
}

.erp-nav-link i {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
}

.erp-nav-link:hover {
    background-color: var(--sidebar-hover);
    color: #ffffff;
}

.erp-nav-link.active {
    background: linear-gradient(90deg, #2563eb, #1d4ed8);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.erp-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.25s ease;
}

/* Top Navbar */
.erp-topbar {
    height: 66px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color-light);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
}

html[data-bs-theme="dark"] .erp-topbar {
    background: rgba(30, 41, 59, 0.9);
    border-bottom-color: var(--border-color-dark);
}

/* Cards & Dashboard KPI Widgets */
.erp-card {
    background-color: var(--surface-card-light);
    border: 1px solid var(--border-color-light);
    border-radius: 0.85rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

html[data-bs-theme="dark"] .erp-card {
    background-color: var(--surface-card-dark);
    border-color: var(--border-color-dark);
}

.kpi-card {
    position: relative;
    overflow: hidden;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

/* Attendance Status Radio Pills */
.att-status-group {
    display: inline-flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.att-radio-label {
    cursor: pointer;
    user-select: none;
    margin: 0;
}

.att-radio-label input[type="radio"] {
    display: none;
}

.att-radio-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1.5px solid #cbd5e1;
    color: #475569;
    background: transparent;
    transition: all 0.15s ease;
}

html[data-bs-theme="dark"] .att-radio-pill {
    border-color: #475569;
    color: #cbd5e1;
}

.att-radio-label input[value="Present"]:checked + .att-radio-pill {
    background-color: #16a34a;
    border-color: #16a34a;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.35);
}

.att-radio-label input[value="Absent"]:checked + .att-radio-pill {
    background-color: #dc2626;
    border-color: #dc2626;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
}

.att-radio-label input[value="Leave"]:checked + .att-radio-pill {
    background-color: #0284c7;
    border-color: #0284c7;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

.att-radio-label input[value="Late"]:checked + .att-radio-pill {
    background-color: #d97706;
    border-color: #d97706;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.35);
}

/* Global Search Dropdown */
.global-search-wrapper {
    position: relative;
    width: 320px;
    max-width: 100%;
}

.global-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface-card-light);
    border: 1px solid var(--border-color-light);
    border-radius: 0.75rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    max-height: 380px;
    overflow-y: auto;
    z-index: 1055;
    display: none;
}

html[data-bs-theme="dark"] .global-search-results {
    background: var(--surface-card-dark);
    border-color: var(--border-color-dark);
}

/* Loading Overlay */
#globalLoadingOverlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Print Styles */
@media print {
    .erp-sidebar,
    .erp-topbar,
    .no-print,
    .breadcrumb,
    .dataTables_filter,
    .dataTables_length,
    .dataTables_paginate {
        display: none !important;
    }
    .erp-main {
        margin-left: 0 !important;
    }
    .erp-card {
        border: none !important;
        box-shadow: none !important;
    }
}

/* Mobile Responsive Sidebar */
@media (max-width: 991.98px) {
    .erp-sidebar {
        transform: translateX(-100%);
    }
    .erp-sidebar.show {
        transform: translateX(0);
    }
    .erp-main {
        margin-left: 0;
    }
    .global-search-wrapper {
        width: 200px;
    }
}
