:root {
    --sidebar-w: 300px;
    --brand: #1d4e89;
    --brand-dark: #133a68;
    --surface: #f4f6fa;
}

body { background: var(--surface); font-size: .925rem; }
.min-w-0 { min-width: 0; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); background: var(--brand-dark); color: #cfd9e8;
    position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 1040;
    transition: transform .2s ease;
}
.sidebar-brand { display: flex; gap: .75rem; align-items: center; padding: 1.1rem 1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,.12); display: grid; place-items: center; font-size: 1.3rem; flex-shrink: 0; }
.brand-logo { width: 44px; height: 44px; object-fit: contain; border-radius: 50%; background: #fff; padding: 2px; flex-shrink: 0; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: .95rem; }
.brand-text small { font-size: .72rem; color: #9fb3cf; line-height: 1.3; margin-top: .15rem; }
.sidebar-nav { padding: .75rem .6rem 2rem; }
.sidebar-nav .nav-heading { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7f95b5; padding: 1rem .75rem .35rem; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .7rem; color: #cfd9e8; padding: .55rem .75rem; border-radius: 8px; font-size: .9rem; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav .nav-link.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 1rem; background: #fff; padding: .75rem 1.5rem; border-bottom: 1px solid #e3e8ef; }
.page-title { font-size: 1.25rem; font-weight: 600; margin: 0; }
.breadcrumb a { text-decoration: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; }
.content { padding: 1.5rem; flex: 1; }
.footer { padding: 1rem 1.5rem; border-top: 1px solid #e3e8ef; background: #fff; }

.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: none; }
    .sidebar.show + .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1030; }
    .main { margin-left: 0; }
    .content { padding: 1rem; }
    .topbar { padding: .75rem 1rem; }
}

/* ---------- Components ---------- */
.card { border: 1px solid #e3e8ef; border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: #fff; border-bottom: 1px solid #eef1f5; font-weight: 600; padding: .85rem 1.1rem; border-radius: 12px 12px 0 0 !important; }
.stat-card { display: flex; align-items: center; gap: 1rem; padding: 1.1rem; }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; flex-shrink: 0; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { color: #6b7a90; font-size: .8rem; }
.bg-soft-primary { background: #e7effa; color: #1d4e89; }
.bg-soft-success { background: #e6f5ec; color: #1f7a45; }
.bg-soft-warning { background: #fdf3e1; color: #9a6400; }
.bg-soft-danger  { background: #fde8e8; color: #b42318; }
.bg-soft-info    { background: #e3f4f8; color: #0e6d86; }
.bg-soft-purple  { background: #efe9fb; color: #5b3aa8; }

.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7a90; background: #f8fafc; white-space: nowrap; }
.table-grades input.form-control { max-width: 110px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 160px; }
.empty-state { text-align: center; color: #8391a7; padding: 2.5rem 1rem; }
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: .5rem; }
.remark-item { border-left: 3px solid var(--brand); padding: .6rem .9rem; background: #fafbfd; border-radius: 0 8px 8px 0; margin-bottom: .75rem; }
.attendance-options .btn { min-width: 72px; }
.profile-photo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: #e7effa; display: grid; place-items: center; font-size: 2.2rem; color: var(--brand); }
dl.info dt { font-weight: 500; color: #6b7a90; font-size: .8rem; }
dl.info dd { margin-bottom: .6rem; }
.chart-box { position: relative; height: 280px; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #133a68 0%, #1d4e89 55%, #2f6fb5 100%); padding: 1rem; }
.auth-card { width: 100%; max-width: 410px; border-radius: 16px; }

/* ---------- Collapsible sidebar ---------- */
:root { --sidebar-rail: 72px; }
.sidebar, .main { transition: width .2s ease, margin-left .2s ease, transform .2s ease; }
.sidebar-toggle { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 10px; flex-shrink: 0; }
.sidebar-toggle i { font-size: 1.5rem; line-height: 1; }
.sidebar-nav .nav-link span, .sidebar-nav .nav-heading { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (min-width: 992px) {
    html.sidebar-collapsed .sidebar { width: var(--sidebar-rail); overflow-x: hidden; }
    html.sidebar-collapsed .main { margin-left: var(--sidebar-rail); }
    html.sidebar-collapsed .brand-text,
    html.sidebar-collapsed .sidebar-nav .nav-link span { display: none; }
    html.sidebar-collapsed .sidebar-brand { justify-content: center; padding-left: .5rem; padding-right: .5rem; }
    html.sidebar-collapsed .sidebar-nav { padding-left: .5rem; padding-right: .5rem; }
    html.sidebar-collapsed .sidebar-nav .nav-link { justify-content: center; padding: .6rem 0; position: relative; }
    html.sidebar-collapsed .sidebar-nav .nav-link i { font-size: 1.2rem; width: auto; }
    /* Section headings become thin dividers in the rail. */
    html.sidebar-collapsed .sidebar-nav .nav-heading { font-size: 0; padding: 0; margin: .6rem .75rem; border-top: 1px solid rgba(255,255,255,.12); }
}
@media (prefers-reduced-motion: reduce) { .sidebar, .main { transition: none; } }

/* ---------- Responsive layout (320px phones to wide desktops) ---------- */
.content { min-width: 0; }
.topbar .breadcrumb { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.topbar .breadcrumb-item { overflow: hidden; text-overflow: ellipsis; }
.card-header.d-flex, .card-footer.d-flex { flex-wrap: wrap; gap: .5rem; }
.card-header { overflow-wrap: anywhere; }
.filter-bar > .form-control, .filter-bar > .form-select { flex: 1 1 160px; }
.pagination { flex-wrap: wrap; }
.btn, .badge { white-space: normal; }
.table td .btn, .table td .badge, .stat-card .badge { white-space: nowrap; }
.chart-box canvas { max-width: 100%; }

@media (max-width: 991.98px) {
    .sidebar { width: min(var(--sidebar-w), 85vw); }
}
@media (max-width: 575.98px) {
    body { font-size: .9rem; }
    .content { padding: .75rem; }
    .topbar { gap: .5rem; padding: .5rem .75rem; }
    .topbar .breadcrumb { display: none; }
    .page-title { font-size: 1.05rem; }
    .card-header { padding: .7rem .8rem; }
    .stat-card { padding: .8rem; gap: .65rem; }
    .stat-card .stat-icon { width: 38px; height: 38px; font-size: 1.1rem; }
    .stat-card .stat-value { font-size: 1.2rem; }
    .filter-bar > * { flex: 1 1 100%; max-width: none !important; min-width: 0 !important; }
    .filter-bar > .ms-auto { margin-left: 0 !important; }
    .chart-box { height: 230px; }
    .profile-photo { width: 72px; height: 72px; font-size: 1.6rem; }
    .modal-dialog { margin: .5rem; }
}

/*
 * Stacked tables: on phones each row becomes a card, so a gradebook or attendance sheet
 * needs no sideways scrolling. Cells name themselves through data-label. Screen only, so
 * printed reports are untouched.
 */
@media screen and (max-width: 575.98px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr { border: 1px solid #e3e8ef; border-radius: 10px; margin: .6rem .6rem 0; width: auto; padding: .35rem .2rem; background: #fff; }
    .table-stack tr:last-child { margin-bottom: .6rem; }
    .table-stack > :not(caption) > * > * { border-bottom: 0; padding: .3rem .6rem; }
    .table-stack td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7a90; margin-bottom: .15rem; }
    .table-stack td.stack-hide { display: none; }
    .table-stack td.empty-state { border: 0; }
    .table-stack .table-grades input.form-control, .table-stack input.form-control { max-width: none; }
    .table-stack .attendance-options { display: grid; grid-template-columns: repeat(2, 1fr); width: 100%; }
    .table-stack .attendance-options .btn { min-width: 0; border-radius: 6px !important; margin: 0 !important; }
    .table-stack .attendance-options { gap: .35rem; }
}

/* Sticky first column for wide tables that scroll sideways, so the learner stays visible. */
.table-sticky-first th:first-child, .table-sticky-first td:first-child { position: sticky; left: 0; z-index: 1; background: #fff; }
.table-sticky-first thead th:first-child { background: #f8fafc; z-index: 2; }

/* ---------- Lazy content and live lists ---------- */
.lazy-state { padding: 1.25rem; text-align: center; }
[data-live-region] { position: relative; transition: opacity .15s; }
[data-live-region].is-loading { opacity: .55; pointer-events: none; }
[data-live-region].is-loading::after { content: ''; position: absolute; top: .75rem; right: .75rem; width: 1rem; height: 1rem; border: 2px solid #1d4e89; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.list-footer { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; }
.list-footer .form-select { width: auto; }

/* ---------- Tooltips ---------- */
.tooltip { --bs-tooltip-max-width: min(280px, calc(100vw - 24px)); }
[data-tip-bound]:not(a):not(button):not(.btn) { cursor: help; }
[data-tip-bound]:focus-visible { outline: 2px solid #1d4e89; outline-offset: 2px; border-radius: 4px; }

/* ---------- Notifications (notify.js): slide in at the top right ---------- */
.notify-stack { position: fixed; top: 1rem; right: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .6rem; width: min(380px, calc(100vw - 2rem)); pointer-events: none; }
.notify {
    --notify-accent: #1d4e89; --notify-soft: #e7effa;
    position: relative; overflow: hidden; pointer-events: auto;
    display: flex; align-items: flex-start; gap: .75rem;
    padding: .9rem .85rem 1rem 1rem; background: #fff; color: #1f2933;
    border: 1px solid #e3e8ef; border-left: 4px solid var(--notify-accent); border-radius: 12px;
    box-shadow: 0 12px 28px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
    animation: notify-in .32s cubic-bezier(.21, 1.02, .73, 1) both;
}
.notify:focus { outline: 2px solid var(--notify-accent); outline-offset: 2px; }
.notify-success { --notify-accent: #1f7a45; --notify-soft: #e6f5ec; }
.notify-error   { --notify-accent: #b42318; --notify-soft: #fde8e8; }
.notify-warning { --notify-accent: #9a6400; --notify-soft: #fdf3e1; }
.notify-info    { --notify-accent: #1d4e89; --notify-soft: #e7effa; }
.notify-icon { flex-shrink: 0; width: 36px; height: 36px; padding: 7px; border-radius: 10px; color: var(--notify-accent); background: var(--notify-soft); }
.notify-body { flex: 1; min-width: 0; padding-top: .1rem; }
.notify-title { font-weight: 600; font-size: .9rem; line-height: 1.3; }
.notify-message { font-size: .85rem; color: #4b5563; line-height: 1.4; margin-top: .15rem; overflow-wrap: anywhere; }
.notify-close { flex-shrink: 0; width: 28px; height: 28px; padding: 5px; margin: -.2rem -.2rem 0 0; border: 0; border-radius: 8px; background: transparent; color: #6b7a90; cursor: pointer; }
.notify-close:hover { background: #f1f4f8; color: #1f2933; }
.notify-close:focus-visible { outline: 2px solid var(--notify-accent); }
.notify-close svg { width: 100%; height: 100%; }
.notify-timer { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--notify-accent); opacity: .35; transform-origin: left; animation: notify-timer linear forwards; }
.notify-paused .notify-timer { animation-play-state: paused; }
.notify-leave { animation: notify-out .25s ease-in forwards; }
@keyframes notify-in { from { opacity: 0; transform: translateX(110%); } to { opacity: 1; transform: none; } }
@keyframes notify-out { to { opacity: 0; transform: translateX(110%); } }
@keyframes notify-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (max-width: 575.98px) {
    .notify-stack { top: .5rem; right: .5rem; left: .5rem; width: auto; }
    @keyframes notify-in { from { opacity: 0; transform: translateY(-120%); } to { opacity: 1; transform: none; } }
    @keyframes notify-out { to { opacity: 0; transform: translateY(-120%); } }
}
@media (prefers-reduced-motion: reduce) {
    .notify, .notify-leave { animation-duration: 1ms; }
    .notify-timer { display: none; }
}
@media print { .notify-stack { display: none; } }

/* ---------- Password fields (password.js): Caps Lock warning, hidden until Caps Lock is on ---------- */
.caps-warning { display: none; font-size: .8rem; color: #8a5a00; margin-top: .35rem; }
.caps-warning.show { display: block; }

/* ---------- Notification bell ---------- */
.notify-bell .btn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 10px; }
.notify-menu { width: min(360px, calc(100vw - 1.5rem)); max-height: min(480px, 75vh); overflow-y: auto; }
.notify-item .notify-dot { flex-shrink: 0; width: 8px; height: 8px; margin-top: .45rem; border-radius: 50%; background: transparent; }
.notify-item.unread { background: #f3f7fd; }
.notify-item.unread .notify-dot { background: #1d4e89; }
.notify-body-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
