/* Hasaan Academy — mobile-first styles (UI_UX_GUIDELINES). Designed at 360 px first. */
:root {
    --ha-navy: #12396b;
    --ha-blue: #1c5595;
    --ha-gold: #f3b329;
    --ha-red: #c91e24;
    --ha-green: #18845a;
    --ha-bg: #f3f6fb;
    --ha-topbar-h: 56px;
    --ha-bottomnav-h: 64px;
    --bs-primary: #12396b;
    --bs-primary-rgb: 18, 57, 107;
    --bs-link-color: #12396b;
    --bs-link-hover-color: #1c5595;
    --bs-body-font-size: 1rem;
}

html { font-size: 16px; }
body {
    background: var(--ha-bg);
    color: #1d2633;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}
h1, .h1 { font-size: 1.375rem; }
h2, .h2 { font-size: 1.1875rem; }
h3, .h3 { font-size: 1.0625rem; }

/* Primary buttons and links in brand navy (contrast ≥ 4.5:1 with white). Written as plain properties because the
   bundled Bootstrap 5.1 does not read the --bs-btn-* / --bs-link-* variables (those arrived in 5.2/5.3). */
a { color: var(--ha-navy); }
a:hover { color: var(--ha-blue); }
.btn-primary, .btn-primary:disabled, .btn-primary.disabled { color: #fff; background-color: var(--ha-navy); border-color: var(--ha-navy); }
.btn-primary:hover, .btn-primary:focus { color: #fff; background-color: var(--ha-blue); border-color: var(--ha-blue); }
.btn-primary:active, .btn-primary.active { color: #fff; background-color: #0d2b52; border-color: #0d2b52; }
.btn-outline-primary { color: var(--ha-navy); border-color: var(--ha-navy); }
.btn-outline-primary:hover, .btn-outline-primary:active, .btn-outline-primary.active { color: #fff; background-color: var(--ha-navy); border-color: var(--ha-navy); }
.text-bg-primary { color: #fff !important; background-color: var(--ha-navy) !important; }
/* The bundled Bootstrap is 5.1, which has no .text-bg-* helpers (added in 5.2). Without these, the light pills
   rendered white text on a white card. Colours chosen for WCAG AA contrast with their text. */
.text-bg-light { color: #1d2633 !important; background-color: #f1f4f9 !important; }
.text-bg-success { color: #fff !important; background-color: var(--ha-green) !important; }
.text-bg-secondary { color: #fff !important; background-color: #5b6676 !important; }
.text-bg-warning { color: #1d2633 !important; background-color: #ffc107 !important; }
.btn, .form-control, .form-select { min-height: 48px; }
/* Keep the label vertically centred now that buttons are taller than Bootstrap's default. */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn-lg { min-height: 52px; }
.btn:focus-visible, a:focus-visible, .form-control:focus { outline: 3px solid var(--ha-gold); outline-offset: 2px; }

.skip-link { position: absolute; left: 8px; top: 8px; z-index: 2000; background: #fff; padding: 8px 12px; }

/* ---------- Top bar ---------- */
.app-topbar {
    position: sticky; top: 0; z-index: 1030;
    display: flex; align-items: center; gap: 12px;
    height: var(--ha-topbar-h); padding: 0 16px;
    background: var(--ha-navy); color: #fff;
}
.app-brand { font-weight: 700; font-size: .95rem; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
/* CR-02 item 4: the logo keeps its square proportions; white tile so it reads on the navy bar. */
.app-brand-logo { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 6px; flex-shrink: 0; }
.app-sidebar-logo { display: flex; justify-content: center; padding: 4px 0 12px; margin-bottom: 8px; border-bottom: 1px solid #dde3ec; }
.app-sidebar-logo img { width: 120px; height: auto; aspect-ratio: 1 / 1; object-fit: contain; }
.auth-logo { display: block; width: 160px; max-width: 50%; height: auto; aspect-ratio: 1 / 1; object-fit: contain; margin: 0 auto 12px; }
.print-logo { height: auto; aspect-ratio: 1 / 1; object-fit: contain; }
.app-title { margin: 0; font-size: 1rem; font-weight: 500; opacity: .9; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-title::before { content: "·"; margin-right: 10px; opacity: .6; }
.app-user { align-items: center; gap: 8px; max-width: 320px; }
.app-back {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 48px; height: 48px; margin-left: -12px; border-radius: 50%;
    color: #fff; font-size: 1.35rem; text-decoration: none;
}
.app-back:hover, .app-back:focus-visible { color: #fff; background: rgba(255,255,255,.12); }
/* On phones the back arrow replaces the brand so the title keeps its room. */
@media (max-width: 767.98px) {
    .app-back ~ .app-title::before { content: none; }
    .app-topbar:has(.app-back) .app-brand { display: none; }
}

/* ---------- Shell ---------- */
.app-shell { display: flex; }
.app-main { flex: 1; min-width: 0; padding: 16px; max-width: 1200px; }
.has-nav .app-main { padding-bottom: calc(var(--ha-bottomnav-h) + 24px); }
.no-nav .app-main { margin: 0 auto; width: 100%; }
.app-main:focus { outline: none; }

/* ---------- Bottom navigation (phones, tablets) ---------- */
.app-bottomnav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1030;
    display: flex; height: var(--ha-bottomnav-h);
    background: #fff; border-top: 1px solid #dde3ec;
    padding-bottom: env(safe-area-inset-bottom);
}
.app-bottomnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 56px; gap: 2px;
    color: #4a5566; text-decoration: none; font-size: .8125rem;
    background: transparent; border: 0;
}
.app-bottomnav-item .bi { font-size: 1.35rem; }
.app-bottomnav-item.active { color: var(--ha-navy); font-weight: 600; }
.app-bottomnav-item.active .bi { color: var(--ha-navy); }

.app-more .offcanvas-body { padding-top: 0; }
.app-more.offcanvas-bottom { height: auto; max-height: 80vh; }
.app-more-link {
    display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 4px;
    color: #1d2633; text-decoration: none; border-bottom: 1px solid #eef1f6; font-size: 1rem;
}
.app-more-link .bi { font-size: 1.25rem; color: var(--ha-navy); }

/* ---------- Sidebar (desktop ≥ 992 px) ---------- */
.app-sidebar {
    flex-direction: column; gap: 2px;
    width: 240px; flex-shrink: 0; padding: 16px 12px;
    position: sticky; top: var(--ha-topbar-h); height: calc(100vh - var(--ha-topbar-h));
    background: #fff; border-right: 1px solid #dde3ec;
}
.app-sidebar-link {
    display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px;
    border-radius: 8px; color: #1d2633; text-decoration: none;
}
.app-sidebar-link:hover { background: #eef2f8; }
.app-sidebar-link.active { background: #e3eaf5; color: var(--ha-navy); font-weight: 600; }
.app-sidebar-link .bi { font-size: 1.15rem; color: var(--ha-navy); }

@media (min-width: 992px) {
    .has-nav .app-main { padding: 24px; padding-bottom: 24px; }
    h1, .h1 { font-size: 1.6rem; }
}

/* ---------- Components ---------- */
.card { border-color: #dde3ec; border-radius: 12px; }
.auth-card { max-width: 440px; margin: 24px auto; }
.auth-card .card-body > h2, .auth-card .card-body > h2 + p { text-align: center; }
.kpi .card-body { padding: 12px 14px; }
.kpi-label { font-size: .875rem; color: #4a5566; }
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--ha-navy); line-height: 1.2; }
.kpi-hint { font-size: .8125rem; color: #5b6676; }
.class-card .card-body { min-height: 72px; }

.empty-state { text-align: center; padding: 32px 16px; color: #4a5566; }
.empty-state > .bi { font-size: 2.5rem; color: #8a96a8; display: block; margin-bottom: 8px; }

.touch-check { min-height: 48px; display: flex; align-items: center; gap: 10px; padding-left: 0; }
.touch-check .form-check-input { width: 1.5rem; height: 1.5rem; margin: 0; float: none; flex-shrink: 0; }

.app-alerts:empty { display: none; }
.invalid-feedback:empty { display: none !important; }
.field-validation-error { color: var(--ha-red); }
.input-validation-error { border-color: var(--ha-red); }
.validation-summary-valid { display: none; }

.btn .spinner-border { width: 1rem; height: 1rem; border-width: .15em; }

/* ---------- Lists: cards on phones, table from 768 px (UI_UX_GUIDELINES §5) ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 0 16px;
    border: 1px solid #c9d2df; border-radius: 999px; background: #fff;
    color: #1d2633; text-decoration: none; font-size: .9375rem;
}
.chip:hover { background: #eef2f8; color: #1d2633; }
.chip.active { background: var(--ha-navy); border-color: var(--ha-navy); color: #fff; font-weight: 600; }
.section-tabs .chip { font-weight: 600; }

.list-cards { display: grid; gap: 8px; }
.list-card {
    display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 14px;
    background: #fff; border: 1px solid #dde3ec; border-radius: 12px;
    color: #1d2633; text-decoration: none;
}
.list-card:hover { background: #f7f9fc; color: #1d2633; }
.list-card-body { flex: 1; min-width: 0; }
.list-card-title { font-weight: 700; overflow-wrap: anywhere; }
.list-card-meta { font-size: .875rem; color: #4a5566; }
.list-card .bi-chevron-right { color: #8a96a8; }

/* overflow: clip (not hidden) keeps the rounded corners without becoming a scroll container, so the sticky header still sticks to the page. */
.table-card { background: #fff; border: 1px solid #dde3ec; border-radius: 12px; overflow: clip; }
.table-card .table { margin: 0; }
.table-card thead th { position: sticky; top: var(--ha-topbar-h); background: #f7f9fc; font-weight: 600; font-size: .875rem; color: #4a5566; }
.table-card td, .table-card th { vertical-align: middle; padding: 10px 14px; }
.table-card td.text-wrap-anywhere { overflow-wrap: anywhere; }

.detail-list .list-group-item { display: flex; justify-content: space-between; gap: 16px; }
.detail-list .list-group-item > span:last-child { text-align: right; overflow-wrap: anywhere; min-width: 0; }

/* ---------- Forms: sticky action bar above the bottom nav on phones ---------- */
.form-actions {
    position: sticky; bottom: var(--ha-bottomnav-h); z-index: 5;
    display: flex; gap: 8px; margin: 16px -16px 0; padding: 12px 16px;
    background: var(--ha-bg); border-top: 1px solid #dde3ec;
}
.form-actions .btn { flex: 1; }
@media (min-width: 992px) {
    .form-actions { position: static; margin: 16px 0 0; padding: 0; border: 0; background: transparent; }
    .form-actions .btn { flex: 0 0 auto; min-width: 140px; }
}
.required::after { content: " *"; color: var(--ha-red); }
.min-w-0 { min-width: 0; }
.form-section { font-size: .8125rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #4a5566; margin: 8px 0 12px; }
.form-section:not(:first-of-type) { margin-top: 24px; padding-top: 16px; border-top: 1px solid #eef1f6; }

/* Horizontal scrollable chips for profile tabs (STUDENT_MANAGEMENT §C.8). Scrolls inside itself, never the page. */
.chip-scroll { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
.chip-scroll::-webkit-scrollbar { display: none; }
.chip-scroll .chip { flex-shrink: 0; }

/* Student card with a separate call button (tel: link, Admin only). */
.list-card-split { padding: 0; }
.list-card-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; padding: 12px 14px; color: inherit; text-decoration: none; }
.list-card-call {
    display: flex; align-items: center; justify-content: center; width: 56px; align-self: stretch; flex-shrink: 0;
    border-left: 1px solid #dde3ec; color: var(--ha-navy); font-size: 1.25rem; text-decoration: none;
}

/* Attendance status badges: text + colour (UI_UX §4.1). */
.att-p { background: var(--ha-green); color: #fff; }
.att-a { background: var(--ha-red); color: #fff; }
.att-l { background: #ffc107; color: #1d2633; }
.att-lv { background: #0b6fa4; color: #fff; }
.pagination .page-link { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; color: var(--ha-navy); }
.pagination .page-item.active .page-link { background: var(--ha-navy); border-color: var(--ha-navy); color: #fff; }
.pre-line { white-space: pre-line; }

/* ---------- Checkbox lists (class / subject / teacher pickers): big tap targets, 1 column on phones ---------- */
.check-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 576px) { .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 992px) { .check-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.check-tile {
    margin: 0; padding: 10px 12px; min-height: 52px; cursor: pointer;
    background: #fff; border: 1px solid #c9d2df; border-radius: 10px; overflow-wrap: anywhere;
}
.check-tile:has(.form-check-input:checked) { border-color: var(--ha-navy); background: #eef2f8; }
.check-tile .form-check-label { cursor: pointer; min-width: 0; }

/* ---------- Confirmation dialogs: bottom sheet on phones (UI_UX_GUIDELINES §5) ---------- */
@media (max-width: 575.98px) {
    .modal-sheet .modal-dialog { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; max-width: none; }
    .modal-sheet .modal-content { border-radius: 16px 16px 0 0; border: 0; padding-bottom: env(safe-area-inset-bottom); }
    .modal-sheet.fade .modal-dialog { transform: translateY(100%); }
    .modal-sheet.show .modal-dialog { transform: none; }
    .modal-sheet .modal-footer { flex-direction: column-reverse; align-items: stretch; }
    .modal-sheet .modal-footer > * { margin: 4px 0; }
}

@media print {
    .app-topbar, .app-sidebar, .app-bottomnav, .app-more, .btn { display: none !important; }
    body { background: #fff; }
    .app-main { padding: 0; }
}

/* Close (×) buttons on alerts, dialogs and the More menu: 48 × 48 px touch target (UI_UX_GUIDELINES §4.3). */
.btn-close,
.modal-header .btn-close,
.offcanvas-header .btn-close { box-sizing: content-box; width: 1em; height: 1em; padding: 16px; margin: -12px -12px -12px auto; }
.alert-dismissible .btn-close { padding: 16px; margin: 0; }

/* ---------- Attendance sheet (ATTENDANCE_MANAGEMENT §A.5, §A.11) ---------- */
.att-head {
    position: sticky; top: var(--ha-topbar-h); z-index: 6;
    margin: -16px -16px 12px; padding: 12px 16px 8px;
    background: var(--ha-bg); border-bottom: 1px solid #dde3ec;
}
@media (min-width: 992px) { .att-head { margin: -24px -24px 12px; padding: 16px 24px 8px; } }
.att-summary { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.att-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 2px 12px; border-radius: 999px; font-size: .9375rem; }
.att-chip b { font-size: 1.05rem; }
.att-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; }
.att-tools .chip { padding: 0 14px; }

.att-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.att-row { background: #fff; border: 1px solid #dde3ec; border-radius: 12px; padding: 10px 12px; min-height: 56px; }
.att-row.is-readonly { background: #f7f9fc; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.att-row.att-row-error { border: 2px solid var(--ha-red); background: #fff5f5; } /* CR-01 BR-TAT-10 */
.att-row[data-status="Absent"]:not(.is-readonly) { border-left: 4px solid var(--ha-red); }
.att-row[data-status="Late"]:not(.is-readonly) { border-left: 4px solid #e0a800; }
.att-row[data-status="OnLeave"]:not(.is-readonly) { border-left: 4px solid #0b6fa4; }
.att-name { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; min-width: 0; }
.att-row.is-readonly .att-name { margin-bottom: 0; }

/* 4 equal buttons filling the row; ≥ 48 px; selected = solid colour + check icon; text label always present. */
.att-seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.att-btn {
    display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 48px; margin: 0;
    border: 2px solid #c9d2df; border-radius: 10px; background: #fff; color: #1d2633;
    font-weight: 600; cursor: pointer; user-select: none;
}
.att-long { display: none; }
@media (min-width: 576px) { .att-short { display: none; } .att-long { display: inline; } }
.btn-check:focus-visible + .att-btn { outline: 3px solid var(--ha-gold); outline-offset: 2px; }
.btn-check:checked + .att-btn::before { content: "\2713"; font-weight: 700; }
.btn-check:checked + .att-btn-p { background: var(--ha-green); border-color: var(--ha-green); color: #fff; }
.btn-check:checked + .att-btn-a { background: var(--ha-red); border-color: var(--ha-red); color: #fff; }
.btn-check:checked + .att-btn-l { background: #ffc107; border-color: #e0a800; color: #1d2633; }
.btn-check:checked + .att-btn-lv { background: #0b6fa4; border-color: #0b6fa4; color: #fff; }

.att-note { margin-top: 6px; }
.att-note > summary { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--ha-navy); cursor: pointer; list-style: none; }
.att-note > summary::-webkit-details-marker { display: none; }

/* The sticky save bar never covers the last row (§A.11): the list ends with matching space. */
form[data-attendance] { padding-bottom: 8px; }
.att-save .btn { flex: 1 1 100%; }

/* Teacher Home class cards: taken / not taken (§A.5.1) */
.class-card.is-pending { border-left: 4px solid #e0a800; }
.class-card.is-taken { border-left: 4px solid var(--ha-green); }
.class-card-link { display: flex; align-items: center; gap: 6px; min-height: 48px; padding: 0 16px; border-top: 1px solid #eef1f6; color: var(--ha-navy); text-decoration: none; }

/* Teacher attendance month grid (desktop) scrolls inside its card; month calendar (mobile). */
.month-grid { overflow-x: auto; }
.month-grid th, .month-grid td { padding: 6px 4px; font-size: .8125rem; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head { text-align: center; font-size: .75rem; color: #4a5566; font-weight: 600; }
.cal-cell { min-height: 52px; background: #fff; border: 1px solid #dde3ec; border-radius: 8px; padding: 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cal-empty { background: transparent; border: 0; }
.cal-day { font-size: .75rem; color: #4a5566; }

/* ---------- Fees (FEE_MANAGEMENT §9, §13) ---------- */
.pay-line.is-selected { border-color: var(--ha-navy); }
.receipt { position: relative; max-width: 720px; overflow: hidden; }
.receipt-grid { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); gap: 4px 12px; margin-bottom: 12px; }
.receipt-grid dt { font-weight: 400; color: #4a5566; }
.receipt-grid dd { margin: 0; overflow-wrap: anywhere; }
.receipt-lines th, .receipt-lines td { font-size: .875rem; }
.receipt-mark {
    position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-24deg);
    font-size: 5rem; font-weight: 800; color: rgba(201, 30, 36, .16); pointer-events: none; letter-spacing: .1em;
}
.receipt-copy { color: rgba(18, 57, 107, .12); }
@media print {
    .no-print, .app-alerts { display: none !important; }
    .receipt { border: 0; max-width: none; }
    .receipt .card-body { padding: 0; }
    .receipt-mark { color: rgba(0, 0, 0, .15); }
}

/* ---------- SMS (SMS_INTEGRATION §5.4: RTL Sindhi preview, line breaks kept) ---------- */
.sms-preview {
    white-space: pre-line; text-align: right; font-size: 1.05rem; line-height: 1.8;
    font-family: "Noto Naskh Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
    background: #f7f9fc; border: 1px solid #dde3ec; border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere;
}
.check-tile.is-disabled { opacity: .75; cursor: default; }
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }

/* ---------- Reports (REPORTS_AND_EXPORTS §3, §9) ---------- */
.report-heading { margin-bottom: 12px; }
.report-filters > summary { list-style: none; cursor: pointer; }
.report-filters > summary::-webkit-details-marker { display: none; }
.screen-more { display: none !important; }
.print-only { display: none; }
.png-canvas { width: 100%; height: auto; display: block; border-radius: 8px; }
.fee-chart { width: 100%; height: auto; }
.fee-chart .axis { stroke: #c9d2df; }
.fee-chart .bar-expected { fill: var(--ha-navy); }
.fee-chart .bar-collected { fill: var(--ha-green); }
.fee-chart .tick { font-size: 13px; fill: #4a5566; }
.legend { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: middle; }
.legend-expected { background: var(--ha-navy); }
.legend-collected { background: var(--ha-green); }
@media print {
    @page { size: A4 portrait; margin: 12mm; }
    .screen-more { display: revert !important; }
    tr.screen-more { display: table-row !important; }
    .print-only { display: block; }
    .report-cards { display: none !important; }
    .report-table { display: block !important; }
    .report-table thead { display: table-header-group; }   /* repeat headers on each page */
    .report-table td a, .report a { color: inherit; text-decoration: none; }
    .form-actions, .report-filters { display: none !important; }
}

/* ---------- Student photo (ID-048) ---------- */
.student-photo { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; background: #eef2f7; }
.student-photo-lg { width: 120px; height: 120px; }
.student-photo-empty { display: inline-flex; align-items: center; justify-content: center; color: #6b7686; font-size: 2.5rem; }
.student-photo-empty[hidden], .student-photo[hidden] { display: none; }
