/*
 * Dark mode for the admin panel (Bootstrap 4 admin template), the student
 * portal and the login pages. Everything is scoped to html[data-theme="dark"],
 * so light mode is exactly the original design.  Theme is set by /js/theme.js.
 */

:root {
    --t-bg: #edf1f5;
}

html[data-theme="dark"] {
    --t-bg: #0f141b;          /* page */
    --t-surface: #18202b;     /* cards, panels */
    --t-surface-2: #212b38;   /* table heads, inputs, hover */
    --t-surface-3: #2a3646;   /* active / pressed */
    --t-border: #2f3b4c;
    --t-text: #e3e8ef;
    --t-text-strong: #f5f7fa;
    --t-muted: #98a4b5;
    --t-link: #8ab4ff;
    --t-focus: rgba(138, 180, 255, .35);
}

/* ------------------------------------------------------------------ toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-width: 38px;
    height: 38px;
    padding: 0 .6rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .35);
    background: transparent;
    color: inherit;
    cursor: pointer;
    line-height: 1;
    transition: background-color .15s ease, border-color .15s ease;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .12); }
.theme-toggle:focus-visible { outline: 2px solid var(--t-link, #2563eb); outline-offset: 2px; }
.theme-toggle i { font-size: 1rem; }

/* Floating toggle on pages without a navbar (login screens) */
.theme-toggle--floating {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1050;
    color: #374151;
    border-color: #d1d5db;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}
.theme-toggle--floating:hover { background: #f3f4f6; }
html[data-theme="dark"] .theme-toggle--floating {
    color: var(--t-text);
    border-color: var(--t-border);
    background: var(--t-surface);
}
html[data-theme="dark"] .theme-toggle--floating:hover { background: var(--t-surface-2); }

@media (prefers-reduced-motion: no-preference) {
    html.theme-ready body,
    html.theme-ready .card,
    html.theme-ready .page-wrapper { transition: background-color .2s ease, color .2s ease; }
}

/* ============================================================ base & text */
html[data-theme="dark"],
html[data-theme="dark"] body {
    background-color: var(--t-bg) !important;
    color: var(--t-text);
    border-top-color: var(--t-border);
}
html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3,
html[data-theme="dark"] h4, html[data-theme="dark"] h5, html[data-theme="dark"] h6,
html[data-theme="dark"] .h1, html[data-theme="dark"] .h2, html[data-theme="dark"] .h3,
html[data-theme="dark"] .h4, html[data-theme="dark"] .h5, html[data-theme="dark"] .h6,
html[data-theme="dark"] .card-title,
html[data-theme="dark"] label,
html[data-theme="dark"] dt,
html[data-theme="dark"] strong,
html[data-theme="dark"] th { color: var(--t-text-strong); }

html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .card-subtitle,
html[data-theme="dark"] .form-text,
html[data-theme="dark"] small.text-muted,
html[data-theme="dark"] .stat-label { color: var(--t-muted) !important; }
html[data-theme="dark"] .text-dark { color: var(--t-text) !important; }

html[data-theme="dark"] a { color: var(--t-link); }
html[data-theme="dark"] a.btn, html[data-theme="dark"] .nav-link,
html[data-theme="dark"] .sidebar-nav a, html[data-theme="dark"] .navbar-brand { color: inherit; }

html[data-theme="dark"] hr { border-top-color: var(--t-border); }
html[data-theme="dark"] code { color: #ff8fb1; background: transparent; }
html[data-theme="dark"] .border, html[data-theme="dark"] .border-bottom,
html[data-theme="dark"] .border-top { border-color: var(--t-border) !important; }
html[data-theme="dark"] .bg-white, html[data-theme="dark"] .bg-light { background-color: var(--t-surface) !important; }
html[data-theme="dark"] .shadow, html[data-theme="dark"] .shadow-lg, html[data-theme="dark"] .shadow-sm {
    box-shadow: 0 2px 12px rgba(0, 0, 0, .45) !important;
}

/* ============================================================ admin chrome */
html[data-theme="dark"] .page-wrapper,
html[data-theme="dark"] #main-wrapper { background: var(--t-bg) !important; }
html[data-theme="dark"] .preloader { background: var(--t-bg) !important; }
html[data-theme="dark"] .preloader .loader__label { color: var(--t-text); }

html[data-theme="dark"] .left-sidebar { background: #121821 !important; box-shadow: 1px 0 0 var(--t-border); }
html[data-theme="dark"] .sidebar-nav { background: transparent !important; }
html[data-theme="dark"] .sidebar-nav ul li a { color: #a9b4c4; }
html[data-theme="dark"] .sidebar-nav ul li a:hover,
html[data-theme="dark"] .sidebar-nav ul li a.active,
html[data-theme="dark"] .sidebar-nav ul li a:hover i,
html[data-theme="dark"] .sidebar-nav ul li a.active i { color: var(--t-link) !important; }
html[data-theme="dark"] .sidebar-nav > ul > li.active > a { border-left-color: var(--t-link) !important; color: var(--t-link) !important; }
html[data-theme="dark"] .sidebar-nav ul li.nav-small-cap { color: #6b7789; }
html[data-theme="dark"] .sidebar-nav ul li ul { background: transparent; }
html[data-theme="dark"] .user-profile, html[data-theme="dark"] .user-pro-body { background: transparent !important; }

html[data-theme="dark"] .topbar { background: #16233f !important; }
html[data-theme="dark"] .topbar .top-navbar .navbar-header { background: #121821 !important; }

html[data-theme="dark"] .footer {
    background: var(--t-surface) !important;
    color: var(--t-muted);
    border-top: 1px solid var(--t-border);
}
html[data-theme="dark"] .page-titles { background: transparent; }
html[data-theme="dark"] .breadcrumb { background: transparent; }
html[data-theme="dark"] .breadcrumb-item, html[data-theme="dark"] .breadcrumb-item.active,
html[data-theme="dark"] .breadcrumb-item a, html[data-theme="dark"] .breadcrumb-item + .breadcrumb-item::before { color: var(--t-muted) !important; }

/* Notification dropdown in the admin topbar */
html[data-theme="dark"] .mailbox .drop-title { color: var(--t-text-strong); border-bottom-color: var(--t-border); }
html[data-theme="dark"] .mailbox .message-center a { border-bottom-color: var(--t-border); color: var(--t-text); }
html[data-theme="dark"] .mailbox .message-center a:hover { background: var(--t-surface-2); }
html[data-theme="dark"] .mailbox .message-center a .mail-contnet h5 { color: var(--t-text-strong); }
html[data-theme="dark"] .mailbox .message-center a .mail-contnet span { color: var(--t-muted); }

/* ============================================================ cards */
html[data-theme="dark"] .card {
    background-color: var(--t-surface) !important;
    color: var(--t-text);
    border-color: var(--t-border);
}
html[data-theme="dark"] .card-header, html[data-theme="dark"] .card-footer {
    background-color: var(--t-surface-2);
    border-color: var(--t-border);
}

/* ============================================================ tables */
html[data-theme="dark"] .table { color: var(--t-text); }
html[data-theme="dark"] .table th,
html[data-theme="dark"] .table td,
html[data-theme="dark"] .table thead th,
html[data-theme="dark"] .table-bordered,
html[data-theme="dark"] .table-bordered th,
html[data-theme="dark"] .table-bordered td { border-color: var(--t-border) !important; }
html[data-theme="dark"] .table thead th,
html[data-theme="dark"] .thead-light th { background-color: var(--t-surface-2) !important; color: var(--t-text-strong) !important; }
html[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) { background-color: rgba(255, 255, 255, .03); }
html[data-theme="dark"] .table-hover tbody tr:hover { background-color: rgba(255, 255, 255, .06); color: var(--t-text); }
html[data-theme="dark"] table.dataTable tbody tr { background-color: transparent; }

/* DataTables controls */
html[data-theme="dark"] .dataTables_wrapper .dataTables_length,
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter,
html[data-theme="dark"] .dataTables_wrapper .dataTables_info,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate { color: var(--t-muted) !important; }
html[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
html[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background: var(--t-surface-2); color: var(--t-text); border: 1px solid var(--t-border);
}
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button { color: var(--t-text) !important; }
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current,
html[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--t-surface-3) !important; border-color: var(--t-border) !important; color: var(--t-text-strong) !important;
}
html[data-theme="dark"] .page-link { background: var(--t-surface); border-color: var(--t-border); color: var(--t-text); }
html[data-theme="dark"] .page-item.active .page-link { background: #2c5bd6; border-color: #2c5bd6; color: #fff; }
html[data-theme="dark"] .page-item.disabled .page-link { background: var(--t-surface); color: var(--t-muted); }

/* ============================================================ forms */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .custom-select,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] input[type="text"], html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="password"], html[data-theme="dark"] input[type="tel"],
html[data-theme="dark"] input[type="date"], html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="search"] {
    background-color: var(--t-surface-2) !important;
    color: var(--t-text) !important;
    border-color: var(--t-border) !important;
}
html[data-theme="dark"] .form-control::placeholder { color: #7d8898; opacity: 1; }
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .custom-select:focus {
    border-color: var(--t-link) !important;
    box-shadow: 0 0 0 .2rem var(--t-focus) !important;
}
html[data-theme="dark"] .form-control:disabled,
html[data-theme="dark"] .form-control[readonly] { background-color: var(--t-surface) !important; color: var(--t-muted) !important; }
html[data-theme="dark"] .custom-select {
    /* re-draw the arrow in a light colour */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23c7d0dc' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right .75rem center !important;
    background-size: 8px 10px !important;
}
html[data-theme="dark"] .input-group-text {
    background-color: var(--t-surface-3);
    color: var(--t-text);
    border-color: var(--t-border);
}
html[data-theme="dark"] .form-control.is-invalid { border-color: #f87171 !important; }
html[data-theme="dark"] input[type="file"].form-control { color: var(--t-muted) !important; }

/* ============================================================ buttons */
html[data-theme="dark"] .btn-light {
    background: var(--t-surface-2); border-color: var(--t-border); color: var(--t-text);
}
html[data-theme="dark"] .btn-light:hover { background: var(--t-surface-3); color: var(--t-text-strong); }
html[data-theme="dark"] .btn-outline-secondary { color: #c3ccd8; border-color: #5a6779; }
html[data-theme="dark"] .btn-outline-secondary:hover { background: var(--t-surface-3); color: #fff; }
html[data-theme="dark"] .btn-outline-primary { color: var(--t-link); border-color: var(--t-link); }
html[data-theme="dark"] .btn-outline-primary:hover { background: var(--t-link); color: #0b1220; }
html[data-theme="dark"] .btn-outline-dark { color: var(--t-text); border-color: var(--t-muted); }
html[data-theme="dark"] .close { color: var(--t-text); text-shadow: none; opacity: .8; }

/* ============================================================ dropdowns & modals */
html[data-theme="dark"] .dropdown-menu {
    background-color: var(--t-surface);
    border-color: var(--t-border);
    color: var(--t-text);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
html[data-theme="dark"] .dropdown-item { color: var(--t-text); }
html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus { background-color: var(--t-surface-2); color: var(--t-text-strong); }
html[data-theme="dark"] .dropdown-divider { border-top-color: var(--t-border); }

html[data-theme="dark"] .modal-content { background-color: var(--t-surface); color: var(--t-text); border-color: var(--t-border); }
html[data-theme="dark"] .modal-header, html[data-theme="dark"] .modal-footer { border-color: var(--t-border); }
html[data-theme="dark"] .modal-backdrop.show { opacity: .7; }

html[data-theme="dark"] .list-group-item { background-color: var(--t-surface); border-color: var(--t-border); color: var(--t-text); }

/* ============================================================ alerts & badges */
html[data-theme="dark"] .alert-success { background: #0f2e22; border-color: #1d5c42; color: #a7f3d0; }
html[data-theme="dark"] .alert-danger  { background: #3a1517; border-color: #6b2428; color: #fecaca; }
html[data-theme="dark"] .alert-warning { background: #3a2c0c; border-color: #6b5214; color: #fde68a; }
html[data-theme="dark"] .alert-info    { background: #0f2a3a; border-color: #1c4f6b; color: #bae6fd; }
html[data-theme="dark"] .alert a { color: inherit; text-decoration: underline; }
html[data-theme="dark"] .badge-light { background: var(--t-surface-3); color: var(--t-text); }
html[data-theme="dark"] .badge-secondary { background: #4b5563; }
html[data-theme="dark"] .badge-warning { background: #b7791f; color: #fff; }

/* Status colours that were tuned for white backgrounds */
html[data-theme="dark"] .text-success { color: #4ade80 !important; }
html[data-theme="dark"] .text-danger  { color: #f87171 !important; }
html[data-theme="dark"] .text-primary { color: var(--t-link) !important; }
html[data-theme="dark"] .text-info    { color: #67e8f9 !important; }

/* ============================================================ login page (staff) */
html[data-theme="dark"] .login-container {
    background: var(--t-surface) !important;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .5) !important;
}
html[data-theme="dark"] .login-title { color: var(--t-text-strong) !important; }

/* ============================================================ printing */
@media print {
    html[data-theme="dark"] body,
    html[data-theme="dark"] .card,
    html[data-theme="dark"] .page-wrapper { background: #fff !important; color: #000 !important; }
    html[data-theme="dark"] .card *, html[data-theme="dark"] .table th, html[data-theme="dark"] .table td { color: #000 !important; }
    html[data-theme="dark"] .table th, html[data-theme="dark"] .table td,
    html[data-theme="dark"] .table thead th { background: #fff !important; border-color: #dee2e6 !important; }
    .theme-toggle { display: none !important; }
}
