:root {
    --primary: #0d6efd;
    --sidebar-width: 250px;
    --topbar-height: 66px;
    --sidebar-bg: #111827;
}

* { box-sizing: border-box; }
body { font-family: 'Poppins', system-ui, sans-serif; background: #f5f7fb; font-size: 14px; color: #1f2937; }
a { text-decoration: none; }

/* ---------- Buttons & links follow the school colour ---------- */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary); border-color: var(--primary); filter: brightness(.92); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }
.text-primary { color: var(--primary) !important; }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }
.page-link { color: var(--primary); }

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width);
    background: var(--sidebar-bg); color: #fff; z-index: 1050;
    display: flex; flex-direction: column; transition: transform .25s ease;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.08); min-height: var(--topbar-height); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.sidebar-brand:hover { color: #fff; }
.sidebar-logo { width: 38px; height: 38px; border-radius: 8px; object-fit: contain; background: #fff; padding: 3px; flex-shrink: 0; }
.placeholder-logo { display: flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; font-size: 17px; }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.sidebar-brand-text small { font-size: 10px; color: #9ca3af; }
.sidebar-close { display: none; background: none; border: 0; color: #fff; font-size: 18px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar-section { color: #6b7280; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; padding: 14px 10px 6px; }
.sidebar-link { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: #d1d5db; font-size: 13px; margin-bottom: 2px; }
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-link.active { background: var(--primary); color: #fff; }

.sidebar-footer { padding: 10px; border-top: 1px solid rgba(255,255,255,.08); margin: 0; }
.sidebar-logout { width: 100%; display: flex; align-items: center; gap: 11px; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: #fca5a5; font-size: 13px; }
.sidebar-logout:hover { background: rgba(220,53,69,.15); }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1040; }

/* ---------- Main area ---------- */
.main { margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar-height); background: #fff; border-bottom: 1px solid #e5e7eb;
    display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
    position: sticky; top: 0; z-index: 1000;
}
.topbar-title { font-size: 17px; font-weight: 600; margin: 0; }
.sidebar-toggle { display: none; width: 38px; height: 38px; border: 0; border-radius: 8px; background: #f3f4f6; }
.topbar-user { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px 6px; border-radius: 8px; }
.topbar-user:hover { background: #f3f4f6; }
.topbar-user strong { font-size: 12px; line-height: 1.2; }
.topbar-user small { font-size: 11px; }
.avatar-initials { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }

.content { flex: 1; padding: 24px; }
.app-footer { padding: 14px 24px; color: #9ca3af; font-size: 12px; border-top: 1px solid #e5e7eb; background: #fff; }

/* ---------- Components ---------- */
.card { border: 0; border-radius: 12px; box-shadow: 0 2px 12px rgba(17,24,39,.05); }
.card-header { background: #fff; font-weight: 600; border-bottom: 1px solid #f1f1f4; padding: 14px 18px; border-radius: 12px 12px 0 0 !important; }
.table > :not(caption) > * > * { padding: 10px 12px; vertical-align: middle; }
.table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #6b7280; background: #f9fafb; font-weight: 600; }
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.form-label .req { color: #dc3545; }
.form-section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: #6b7280; border-bottom: 1px solid #eef0f3; padding-bottom: 6px; margin: 8px 0 14px; }

.stat-card { display: flex; align-items: center; gap: 14px; padding: 18px; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { color: #6b7280; font-size: 12px; }

.photo-sm { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.photo-lg { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 4px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.1); }
.initials-sm { width: 38px; height: 38px; font-size: 13px; }
.initials-lg { width: 120px; height: 120px; font-size: 40px; }
.detail-list dt { color: #6b7280; font-weight: 500; font-size: 12px; }
.detail-list dd { margin-bottom: 12px; }

.assign-grid th, .assign-grid td { text-align: center; white-space: nowrap; }
.assign-grid th:first-child, .assign-grid td:first-child { text-align: left; position: sticky; left: 0; background: #fff; }

/* ---------- Timeline (class history) ---------- */
.timeline { list-style: none; padding: 0 0 0 30px; margin: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 11px; top: 4px; bottom: 4px; width: 2px; background: #eef0f3; }
.timeline li { position: relative; padding-bottom: 14px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline-dot { position: absolute; left: -30px; top: 0; width: 24px; height: 24px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 10px; }

/* ---------- Import preview ---------- */
.import-table td, .import-table th { white-space: nowrap; font-size: 12.5px; }
.row-error { background: #fff5f5 !important; }
.row-warning { background: #fffbeb !important; }

/* ---------- SBA score sheet ---------- */
.sheet-header > div { padding: 2px 8px 2px 0; }
.sheet-header .sh-label { color: #6b7280; }
.sheet-header .sh-value { font-weight: 600; }
.score-wrap { max-height: 70vh; }
.score-table { font-size: 12.5px; }
.score-table thead th { position: sticky; top: 0; z-index: 2; background: #f3f4f6; text-transform: none; letter-spacing: 0; font-size: 11.5px; vertical-align: middle; }
.score-table thead tr:nth-child(2) th { top: 38px; }
.score-table .sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; }
.score-table thead .sticky-col { z-index: 3; background: #f3f4f6; }
.score-input { width: 58px; min-width: 58px; text-align: center; padding: 2px 4px; }
.remark-input { min-width: 170px; }
.score-table td.calc { background: #f9fafb; }
.sticky-footer { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -2px 8px rgba(0,0,0,.05); }
.status-cell { min-width: 120px; }

/* ---------- Report cards table ---------- */
.report-table thead th { background: #f3f4f6; z-index: 2; }
.report-table .sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; }
.report-table thead .sticky-col { z-index: 3; background: #f3f4f6; }

/* ---------- Attendance register ---------- */
.att-options .btn { min-width: 38px; }
.att-options .btn-check:checked + .btn-outline-success { background: #198754; color: #fff; }
.att-options .btn-check:checked + .btn-outline-danger  { background: #dc3545; color: #fff; }
.att-options .btn-check:checked + .btn-outline-warning { background: #ffc107; color: #000; }
.att-options .btn-check:checked + .btn-outline-secondary { background: #6c757d; color: #fff; }

/* ---------- Auth pages ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: #f5f7fb; }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { width: 72px; height: 72px; object-fit: contain; }

/* ---------- Mobile ---------- */
@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: none; }
    .sidebar-overlay.show { display: block; }
    .sidebar-close { display: block; }
    .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .main { margin-left: 0; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
}

@media print {
    .sidebar, .topbar, .app-footer, .no-print { display: none !important; }
    .main { margin: 0; }
}

/* SMS preview bubble */
.sms-bubble { display: inline-block; max-width: 520px; background: #e9f5ee; border-radius: 14px 14px 14px 4px; padding: 10px 14px; font-size: .92rem; white-space: pre-wrap; }
.card-link-hover:hover { box-shadow: 0 2px 10px rgba(0,0,0,.08); border-color: var(--bs-primary, #0d6efd); }

/* Photo picker (webcam / choose picture) */
.photo-picker { text-align: center; }
.pp-frame { width: 150px; height: 200px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #f1f4f7; border: 2px dashed #cfd8e0; display: flex; align-items: center; justify-content: center; }
.pp-frame .pp-preview { width: 100%; height: 100%; object-fit: cover; }
.pp-empty { color: #8a96a3; }
.pp-stage { position: relative; background: #111; border-radius: 10px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 62vh; margin: 0 auto; }
.pp-video, .pp-shot { width: 100%; height: 100%; object-fit: cover; display: block; }
.pp-video { transform: scaleX(-1); } /* mirror the live view like a selfie camera; the saved photo is not mirrored */
.pp-guide { position: absolute; inset: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; }
.pp-face { width: 58%; height: 60%; border: 3px dashed rgba(255,255,255,.75); border-radius: 50%; margin-top: -6%; box-shadow: 0 0 0 2000px rgba(0,0,0,.18); }
.pp-shot:not(.d-none) ~ .pp-guide { display: none; }
.pp-status { position: absolute; left: 10px; right: 10px; bottom: 10px; background: rgba(0,0,0,.7); color: #fff; padding: 8px 10px; border-radius: 8px; display: none; }
.pp-status.pp-error { background: rgba(170, 30, 30, .9); }
.pp-modal.pp-fallback { background: rgba(0,0,0,.5); }
