/* ── CSS Custom Properties (Dark theme is default) ─────────── */
:root {
    --bg-main:        #1e1e2e;
    --bg-sidebar:     #252537;
    --bg-card:        #2a2a3e;
    --bg-input:       #1e1e2e;
    --bg-table-row:   #2a2a3e;
    --bg-table-hover: #33334d;
    --bg-navbar:      #252537;
    --text-primary:   #cdd6f4;
    --text-secondary: #a6adc8;
    --text-muted:     #6c7086;
    --accent:         #7c6af7;
    --accent-hover:   #6a57e0;
    --accent-light:   rgba(124,106,247,0.15);
    --border-color:   #363655;
    --sidebar-width:  260px;
    --navbar-height:  60px;
    --shadow:         0 4px 24px rgba(0,0,0,0.3);
    --shadow-sm:      0 2px 8px rgba(0,0,0,0.2);
    --radius:         10px;
    --radius-sm:      6px;
    --transition:     0.22s ease;
    --success:        #a6e3a1;
    --danger:         #f38ba8;
    --warning:        #f9e2af;
    --info:           #89dceb;
    --font:           'Inter', system-ui, -apple-system, sans-serif;

    /* Bootstrap 5 CSS variable overrides (dark is default) */
    --bs-body-color:       #cdd6f4;
    --bs-body-bg:          #1e1e2e;
    --bs-emphasis-color:   #cdd6f4;
    --bs-secondary-color:  #a6adc8;
    --bs-tertiary-color:   #6c7086;
    --bs-border-color:     #363655;
    --bs-heading-color:    #cdd6f4;
    --bs-link-color:       #7c6af7;
    --bs-link-hover-color: #6a57e0;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; }

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

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform var(--transition);
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
    min-height: var(--navbar-height);
}
.sidebar-logo .logo-icon {
    width: 34px; height: 34px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.sidebar-logo .logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    line-height: 1.2;
}
.sidebar-logo .logo-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: block;
    line-height: 1;
}

.nav-section {
    padding: 10px 0 4px;
}
.nav-section-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 6px 20px 4px;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 450;
    border-radius: 0;
    transition: color var(--transition), background var(--transition);
    cursor: pointer;
    white-space: nowrap;
    border-left: 3px solid transparent;
}
.nav-link .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 0.92rem;
    flex-shrink: 0;
}
.nav-link:hover {
    color: var(--text-primary);
    background: var(--accent-light);
    border-left-color: transparent;
}
.nav-link.active {
    color: var(--accent);
    background: var(--accent-light);
    border-left-color: var(--accent);
    font-weight: 600;
}
.sidebar-bottom {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-avatar {
    width: 34px; height: 34px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-username { font-size: 0.88rem; font-weight: 500; color: var(--text-primary); }
.sidebar-role     { font-size: 0.72rem; color: var(--text-muted); }

/* ── Navbar ─────────────────────────────────────────────────── */
.top-navbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--navbar-height);
    background: var(--bg-navbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 1030;
    gap: 12px;
    transition: left var(--transition);
}
.navbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: auto;
}
.navbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.navbar-btn {
    width: 36px; height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    display: flex; align-items: center; justify-content: center;
}
.navbar-btn:hover { background: var(--accent-light); color: var(--accent); }
.hamburger-btn { display: none; }

/* ── Main Content ────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    padding: 28px;
    min-height: calc(100vh - var(--navbar-height));
    width: calc(100% - var(--sidebar-width));
    transition: margin-left var(--transition), width var(--transition);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-body { padding: 20px; }
.card-footer {
    background: transparent;
    border-top: 1px solid var(--border-color);
    padding: 14px 20px;
}

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 22px 24px;
    display: flex;
    align-items: center;
    gap: 18px;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
    width: 52px; height: 52px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.stat-icon.purple  { background: rgba(124,106,247,0.18); color: var(--accent); }
.stat-icon.blue    { background: rgba(137,220,235,0.18); color: var(--info); }
.stat-icon.green   { background: rgba(166,227,161,0.18); color: var(--success); }
.stat-icon.orange  { background: rgba(249,226,175,0.18); color: var(--warning); }
.stat-icon.red     { background: rgba(243,139,168,0.18); color: var(--danger); }
.stat-value  { font-size: 1.9rem; font-weight: 700; line-height: 1; color: var(--text-primary); }
.stat-label  { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }
.stat-trend  { font-size: 0.78rem; margin-top: 4px; }
.stat-trend.up   { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ── Tables ─────────────────────────────────────────────────── */
.table {
    color: var(--text-primary);
    border-color: var(--border-color);
    margin: 0;
}
.table thead th {
    background: var(--bg-sidebar);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border-color);
    padding: 12px 16px;
    white-space: nowrap;
}
.table tbody td {
    padding: 11px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.88rem;
}
.table tbody tr:hover td { background: var(--bg-table-hover); }
.table-actions { white-space: nowrap; text-align: right; }
.table-actions .btn { padding: 4px 9px; font-size: 0.8rem; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-label {
    font-size: 0.83rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 5px;
}
.form-control, .form-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    padding: 9px 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124,106,247,0.2);
    outline: none;
}
.form-control::placeholder { color: var(--text-muted); }
.form-select option { background: var(--bg-card); }
.form-check-input {
    background-color: var(--bg-input);
    border-color: var(--border-color);
}
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { box-shadow: 0 0 0 3px rgba(124,106,247,0.2); }
textarea.form-control { resize: vertical; min-height: 90px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    padding: 8px 18px;
    transition: all var(--transition);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-primary {
    /* Reset Bootstrap 5 local CSS variables so Bootstrap's own --bs-btn-active-bg etc.
       can never revert the button to Bootstrap's default blue (#0d6efd). */
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--accent-hover);
    --bs-btn-hover-border-color: var(--accent-hover);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--accent-hover);
    --bs-btn-active-border-color: var(--accent-hover);
    --bs-btn-disabled-bg: var(--accent);
    --bs-btn-disabled-border-color: var(--accent);
    /* Direct property overrides with !important as belt-and-suspenders */
    background-color: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #fff !important;
}
.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    color: #fff !important;
}
.btn-outline-primary {
    --bs-btn-color: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--accent);
    --bs-btn-hover-border-color: var(--accent);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--accent);
    --bs-btn-active-border-color: var(--accent);
    border-color: var(--accent) !important;
    color: var(--accent) !important;
    background-color: transparent !important;
}
.btn-outline-primary:hover {
    background-color: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}
.btn-secondary {
    background: var(--bg-sidebar);
    border-color: var(--border-color);
    color: var(--text-secondary);
}
.btn-secondary:hover { background: var(--border-color); color: var(--text-primary); }
.btn-danger { background: #f38ba8; border-color: #f38ba8; color: #1e1e2e; }
.btn-danger:hover { background: #e07a97; border-color: #e07a97; color: #1e1e2e; }
.btn-success { background: #a6e3a1; border-color: #a6e3a1; color: #1e1e2e; }
.btn-success:hover { background: #95d290; border-color: #95d290; color: #1e1e2e; }
.btn-warning { background: #f9e2af; border-color: #f9e2af; color: #1e1e2e; }
.btn-sm { padding: 5px 11px; font-size: 0.8rem; }
.btn-icon { padding: 7px 10px; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
    font-size: 0.73rem;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 20px;
}
.badge.bg-primary   { background: var(--accent) !important; }
.badge.bg-success   { background: #2d6a4f !important; color: var(--success) !important; }
.badge.bg-danger    { background: #6b2737 !important; color: var(--danger) !important; }
.badge.bg-warning   { background: #6b5a2b !important; color: var(--warning) !important; }
.badge.bg-info      { background: #234c54 !important; color: var(--info) !important; }
.badge.bg-secondary { background: var(--border-color) !important; color: var(--text-secondary) !important; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
    border-radius: var(--radius-sm);
    border: 1px solid;
    padding: 12px 16px;
    font-size: 0.88rem;
}
.alert-success { background: rgba(166,227,161,0.12); border-color: rgba(166,227,161,0.3); color: var(--success); }
.alert-danger  { background: rgba(243,139,168,0.12); border-color: rgba(243,139,168,0.3); color: var(--danger); }
.alert-warning { background: rgba(249,226,175,0.12); border-color: rgba(249,226,175,0.3); color: var(--warning); }
.alert-info    { background: rgba(137,220,235,0.12); border-color: rgba(137,220,235,0.3); color: var(--info); }

/* ── Modals ─────────────────────────────────────────────────── */
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
}
.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 18px 22px;
}
.modal-title { font-weight: 600; font-size: 1rem; }
.modal-body  { padding: 22px; }
.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 14px 22px;
}
.btn-close { filter: invert(0.7) brightness(1.5); }
.modal-backdrop { background: rgba(0,0,0,0.65); }

/* ── Page Header ────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-title .page-icon {
    color: var(--accent);
    font-size: 1.3rem;
}

/* ── DataTables overrides ────────────────────────────────────── */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.85rem;
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 14px;
}
.dataTables_wrapper .paginate_button {
    padding: 4px 10px !important;
    border-radius: var(--radius-sm) !important;
    color: var(--text-secondary) !important;
}
.dataTables_wrapper .paginate_button.current,
.dataTables_wrapper .paginate_button:hover {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}
div.dt-container {
    color: var(--text-primary);
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast-container { z-index: 9999; }
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    min-width: 280px;
}
.toast-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.82rem;
}

/* ── Breadcrumb ─────────────────────────────────────────────── */
.breadcrumb { font-size: 0.82rem; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }
.breadcrumb-item a { color: var(--text-muted); }
.breadcrumb-item.active { color: var(--text-secondary); }

/* ── Loading Spinner ────────────────────────────────────────── */
.spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.spinner-border { color: var(--accent); }

/* ── Progress Bar ────────────────────────────────────────────── */
.progress {
    background: var(--bg-input);
    border-radius: 20px;
    height: 8px;
}
.progress-bar { background: var(--accent); border-radius: 20px; transition: width 0.4s; }

/* ── Tabs ────────────────────────────────────────────────────── */
.nav-tabs {
    border-bottom: 1px solid var(--border-color);
}
.nav-tabs .nav-link {
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 18px;
    font-size: 0.88rem;
    border-radius: 0;
    margin-bottom: -1px;
}
.nav-tabs .nav-link:hover { color: var(--text-primary); border-bottom-color: var(--border-color); }
.nav-tabs .nav-link.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: transparent;
    font-weight: 600;
}
.tab-content { padding-top: 20px; }

/* ── Schedule Grid ───────────────────────────────────────────── */
.day-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: default;
}
.day-badge.active   { background: var(--accent); color: #fff; }
.day-badge.inactive { background: var(--border-color); color: var(--text-muted); }

/* ── Sidebar overlay (mobile) ───────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1035;
}

/* ── Utility ─────────────────────────────────────────────────── */
.text-accent   { color: var(--accent); }
.text-muted    { color: var(--text-muted) !important; }
.gap-2         { gap: 8px; }
.fw-semibold   { font-weight: 600; }
.rounded-pill  { border-radius: 50px !important; }
.cursor-pointer { cursor: pointer; }

/* ── Chart containers ────────────────────────────────────────── */
.chart-container { position: relative; }
canvas { max-width: 100%; }

/* ── Login page ─────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
    padding: 20px;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo .logo-circle {
    width: 56px; height: 56px;
    background: var(--accent);
    border-radius: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.7rem;
    color: #fff;
    margin-bottom: 12px;
}
.login-title { font-size: 1.45rem; font-weight: 700; margin-bottom: 4px; }
.login-sub   { font-size: 0.85rem; color: var(--text-muted); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.open { display: block; }
    .top-navbar { left: 0; }
    .main-content { margin-left: 0; width: 100%; padding: 16px; }
    .hamburger-btn { display: flex; }
}
@media (max-width: 576px) {
    .page-header { flex-direction: column; align-items: flex-start; }
    .stat-value  { font-size: 1.5rem; }
    .login-card  { padding: 28px 20px; }
}

/* ── FullCalendar event text contrast ───────────────────────
   Event background and text colour are set via JS (calendar.js)
   using a luminance calculation. Force all child text elements
   to inherit the parent colour so that broad theme CSS rules
   (e.g. .card-body *) cannot accidentally override them.      */
.fc-event .fc-event-main,
.fc-event .fc-event-main-frame,
.fc-event .fc-event-title-container,
.fc-event .fc-event-title,
.fc-event .fc-event-time,
.fc-event a { color: inherit !important; }
