/* ==========================================================================
   LoadPortal – design layer on top of Bootstrap 5.3
   Palette follows the school seal: royal blue, deep navy, gold.
   ========================================================================== */

:root,
[data-bs-theme=light] {
  --bs-primary: #1d4ed8;
  --bs-primary-rgb: 29, 78, 216;
  --bs-link-color: #1d4ed8;
  --bs-link-color-rgb: 29, 78, 216;
  --bs-link-hover-color: #1a3fb0;
  --bs-link-hover-color-rgb: 26, 63, 176;
  --bs-body-bg: #f3f5fa;
  --bs-body-color: #1b2437;
  --bs-body-font-size: .95rem;
  --bs-border-radius: .6rem;

  --lp-navy: #0b1f4d;
  --lp-navy-2: #12306f;
  --lp-gold: #f5b301;
  --lp-border: #e3e8f2;
  --lp-muted: #667085;
  --lp-soft: #f7f9fe;
  --lp-radius: 14px;
  --lp-shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 18px rgba(16, 24, 40, .06);
  --lp-sidebar-w: 268px;
}

html { -webkit-text-size-adjust: 100%; }
body { background: var(--bs-body-bg); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.min-w-0 { min-width: 0; }
.tabular { font-variant-numeric: tabular-nums; }

/* Bootstrap component tuning ------------------------------------------- */
.btn { font-weight: 500; }
.btn-primary {
  --bs-btn-bg: #1d4ed8; --bs-btn-border-color: #1d4ed8;
  --bs-btn-hover-bg: #1a43b8; --bs-btn-hover-border-color: #1a43b8;
  --bs-btn-active-bg: #173a9e; --bs-btn-active-border-color: #173a9e;
  --bs-btn-disabled-bg: #1d4ed8; --bs-btn-disabled-border-color: #1d4ed8;
  --bs-btn-focus-shadow-rgb: 29, 78, 216;
}
.btn-outline-primary {
  --bs-btn-color: #1d4ed8; --bs-btn-border-color: #b9c8f5;
  --bs-btn-hover-bg: #1d4ed8; --bs-btn-hover-border-color: #1d4ed8;
  --bs-btn-active-bg: #1d4ed8; --bs-btn-active-border-color: #1d4ed8;
  --bs-btn-focus-shadow-rgb: 29, 78, 216;
}
.form-control, .form-select { border-color: #d5dcec; }
.form-control:focus, .form-select:focus {
  border-color: #7c9cf0;
  box-shadow: 0 0 0 .2rem rgba(29, 78, 216, .15);
}
.progress { background: #e9eef8; }
.progress-bar { background-color: var(--bs-primary); }
.progress-bar.bg-gold { background-color: var(--lp-gold); }
.btn-icon { border: 0; background: transparent; color: inherit; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; }
.btn-icon:hover { background: rgba(127, 140, 170, .16); color: inherit; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app-shell { min-height: 100vh; }

.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--lp-sidebar-w); z-index: 1040;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--lp-navy) 0%, #0d2762 100%);
  color: #cbd5ee;
  transform: translateX(-100%); transition: transform .25s ease;
  box-shadow: 8px 0 30px rgba(8, 16, 40, .25);
}
.app-sidebar.open { transform: none; }
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 1035; background: rgba(8, 16, 40, .55);
  opacity: 0; visibility: hidden; transition: opacity .2s ease;
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.1rem 1rem; color: #fff; }
.sidebar-brand img { border-radius: 50%; background: #fff; padding: 2px; }
.sidebar-brand .brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: .01em; }
.sidebar-brand small { color: #93a4d1; font-size: .72rem; }

.sidebar-nav { padding: .5rem .75rem; flex: 1; overflow-y: auto; }
.nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: #7e90bf; padding: .9rem .75rem .4rem; }
.nav-link-lp {
  display: flex; align-items: center; gap: .8rem; padding: .7rem .85rem; margin-bottom: .2rem;
  color: #cbd5ee; text-decoration: none; border-radius: 10px; font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.nav-link-lp i { width: 1.2rem; text-align: center; opacity: .85; }
.nav-link-lp:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-link-lp.active { background: rgba(255, 255, 255, .13); color: #fff; box-shadow: inset 3px 0 0 var(--lp-gold); }

.sidebar-foot { padding: .9rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.user-chip { display: flex; align-items: center; gap: .7rem; color: #fff; }
.user-chip .btn-icon { color: #cbd5ee; }
.user-name { font-weight: 600; font-size: .9rem; max-width: 140px; }
.avatar {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  background: var(--lp-gold); color: var(--lp-navy); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.role-badge { background: rgba(245, 179, 1, .18); color: #ffd45e; font-weight: 600; text-transform: capitalize; margin-top: 2px; }

.app-main { min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
  position: sticky; top: 0; z-index: 1020; height: 64px;
  display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--lp-border);
}
.page-title { font-size: 1.15rem; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-select { width: auto; max-width: 200px; font-weight: 500; }

.app-content { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 1.25rem 1rem 2rem; outline: none; }
.app-footer { text-align: center; color: var(--lp-muted); font-size: .8rem; padding: 1rem; }

@media (min-width: 992px) {
  .app-sidebar { transform: none; box-shadow: none; }
  .sidebar-backdrop { display: none; }
  .app-main { margin-left: var(--lp-sidebar-w); }
  .app-topbar { padding: 0 1.75rem; }
  .app-content { padding: 1.75rem; }
}

/* ==========================================================================
   Cards, headers, stats
   ========================================================================== */
.lp-card { background: #fff; border: 1px solid var(--lp-border); border-radius: var(--lp-radius); box-shadow: var(--lp-shadow); margin-bottom: 1.25rem; }
.lp-card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--lp-border); }
.lp-card-body { padding: 1.25rem; }
.lp-card-footer { padding: .9rem 1.25rem; border-top: 1px solid var(--lp-border); background: var(--lp-soft); border-radius: 0 0 var(--lp-radius) var(--lp-radius); }
.card-title { font-size: 1.05rem; font-weight: 700; margin: 0; }
.card-sub { margin: .15rem 0 0; color: var(--lp-muted); font-size: .85rem; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
@media (min-width: 992px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.1rem; } }
.stat-card { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.1rem; background: #fff; border: 1px solid var(--lp-border); border-radius: var(--lp-radius); box-shadow: var(--lp-shadow); min-width: 0; }
.stat-icon { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.stat-icon.blue { background: #e4ebff; color: #1d4ed8; }
.stat-icon.gold { background: #fff3cf; color: #a77800; }
.stat-icon.teal { background: #dcf5ef; color: #0b7a62; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--lp-muted); font-size: .8rem; }
.stat-card.wide { grid-column: span 2; }
@media (min-width: 992px) { .stat-card.wide { grid-column: span 1; } }
.stat-progress { flex: 1; min-width: 0; }
.stat-progress .row-line { display: flex; align-items: center; gap: .5rem; font-size: .78rem; color: var(--lp-muted); }
.stat-progress .row-line + .row-line { margin-top: .45rem; }
.stat-progress .tag { width: 3.6rem; flex: 0 0 auto; }
.stat-progress .progress { flex: 1; height: 7px; }
.stat-progress .pct { width: 2.6rem; text-align: right; font-weight: 600; color: var(--bs-body-color); }

.subject-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem 1.5rem; padding: 1.25rem; }
.block-badge { background: var(--lp-navy); color: #fff; font-weight: 700; letter-spacing: .02em; padding: .45rem .8rem; border-radius: 10px; font-size: 1rem; }
.subject-meta { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; color: var(--lp-muted); font-size: .88rem; margin-top: .45rem; }
.subject-meta i { color: #8aa0d6; width: 1rem; text-align: center; margin-right: .25rem; }
.back-link { display: inline-flex; align-items: center; gap: .4rem; background: none; border: 0; padding: 0; color: var(--lp-muted); font-weight: 500; margin-bottom: .75rem; }
.back-link:hover { color: var(--bs-primary); }

.search-box { position: relative; min-width: 240px; flex: 1 1 240px; max-width: 360px; }
.search-box i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: #98a2b8; pointer-events: none; }
.search-box .form-control { padding-left: 2.4rem; }

.empty { text-align: center; padding: 3rem 1.25rem; color: var(--lp-muted); }
.empty i { font-size: 2.2rem; color: #b9c5e6; margin-bottom: .75rem; display: block; }

.skel { display: block; border-radius: 10px; background: linear-gradient(90deg, #eceff6 25%, #f6f8fc 37%, #eceff6 63%); background-size: 400% 100%; animation: skel 1.4s ease infinite; }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ==========================================================================
   Tables
   ========================================================================== */
.lp-table { margin: 0; --bs-table-bg: transparent; vertical-align: middle; }
.lp-table thead th {
  background: var(--lp-soft); color: var(--lp-muted); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--lp-border); white-space: nowrap; padding: .75rem 1rem;
}
.lp-table td { padding: .85rem 1rem; border-color: var(--lp-border); }
.lp-table tbody tr:last-child td { border-bottom: 0; }
.lp-table.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f6f8ff; }
.lp-table .name-link { font-weight: 600; color: var(--bs-body-color); text-decoration: none; }
.lp-table .name-link:hover { color: var(--bs-primary); }
.w-prog { min-width: 130px; }

.mini-progress { display: flex; align-items: center; gap: .5rem; }
.mini-progress .progress { flex: 1; height: 6px; min-width: 60px; }
.mini-progress small { width: 2.6rem; text-align: right; color: var(--lp-muted); }

.pill { display: inline-block; min-width: 2.6rem; text-align: center; padding: .25rem .6rem; border-radius: 999px; font-weight: 700; font-size: .85rem; background: #e4ebff; color: #1d4ed8; }
.pill.inc { background: #fff1cc; color: #8a5d00; }
.pill.drp { background: #fde1e1; color: #b42318; }
.pill.none { background: transparent; color: #b4bccd; font-weight: 400; }

.badge-soft { font-weight: 600; background: #eef1f8; color: #475467; }
.badge-soft.ok { background: #dcf5ef; color: #0b7a62; }
.badge-soft.warn { background: #fff1cc; color: #8a5d00; }
.badge-soft.off { background: #fde1e1; color: #b42318; }

/* Grades -------------------------------------------------------------- */
.grade-input { width: 5.2rem; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; text-transform: uppercase; padding: .35rem .4rem; }
.grade-input:disabled { background: #f3f5fa; color: #475467; opacity: 1; }
.grade-input.is-invalid { background-image: none; }
tr.row-dirty > td { background: #fffaeb !important; }
.lock-note { color: #8a5d00; font-size: .8rem; }
.th-tools { display: inline-flex; align-items: center; gap: .4rem; }
.th-tools .btn { --bs-btn-padding-y: .1rem; --bs-btn-padding-x: .4rem; --bs-btn-font-size: .7rem; text-transform: none; letter-spacing: 0; }

.savebar {
  position: sticky; bottom: 0; z-index: 25; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem;
  padding: .8rem 1rem; margin-top: -.25rem; margin-bottom: 1rem;
  background: #fff; border: 1px solid var(--lp-border); border-radius: var(--lp-radius);
  box-shadow: 0 -6px 22px rgba(16, 24, 40, .1);
}
.savebar .grow { flex: 1 1 200px; min-width: 0; }

.form-switch .form-check-input { cursor: pointer; width: 2.6em; height: 1.35em; }
.form-switch .form-check-input:checked { background-color: #12a37f; border-color: #12a37f; }
.status-text { font-weight: 600; }
.status-text.ok { color: #0b7a62; }
.status-text.no { color: #b42318; }

/* ==========================================================================
   Mobile: tables become stacked cards
   ========================================================================== */
@media (max-width: 767.98px) {
  .app-topbar { padding: 0 .5rem; }
  .term-select { max-width: 150px; font-size: .8rem; }
  .lp-card-header, .lp-card-body { padding: 1rem; }
  .search-box { max-width: none; min-width: 0; flex-basis: 100%; }
  .stat-value { font-size: 1.35rem; }

  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tbody { padding: .75rem; }
  .rtable tr {
    background: #fff; border: 1px solid var(--lp-border); border-radius: 12px;
    margin-bottom: .75rem; padding: .35rem .9rem; box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  }
  .rtable tr:last-child { margin-bottom: 0; }
  .rtable td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .5rem 0; border: 0; border-bottom: 1px dashed var(--lp-border); text-align: right;
    background: transparent !important; box-shadow: none;
  }
  .rtable td:last-child { border-bottom: 0; }
  .rtable td::before {
    content: attr(data-label); flex: 0 0 34%; text-align: left;
    font-size: .72rem; font-weight: 700; color: var(--lp-muted); text-transform: uppercase; letter-spacing: .05em;
  }
  .rtable td.cell-title { display: block; text-align: left; padding-top: .7rem; }
  .rtable td.cell-title::before { display: none; }
  .rtable td.cell-actions { display: block; text-align: left; padding-bottom: .7rem; }
  .rtable td.cell-actions::before { display: none; }
  .rtable td.cell-actions .btn-group-lp { justify-content: stretch; }
  .rtable td.cell-actions .btn { flex: 1 1 auto; }
  .rtable .w-prog { min-width: 0; }
  .rtable .mini-progress { flex: 1; justify-content: flex-end; max-width: 60%; }
  .rtable td.cell-hide-sm { display: none; }
  tr.row-dirty { background: #fffaeb; }
  .grade-input { width: 5.5rem; }
  .savebar { border-radius: 12px; margin-left: -.25rem; margin-right: -.25rem; }
  .savebar .btn { flex: 1 1 auto; }
}
.btn-group-lp { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }

/* ==========================================================================
   Sign-in (also used by 404 and setup)
   ========================================================================== */
.login-body { background: var(--bs-body-bg); min-height: 100vh; }
.login-shell { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: 100vh; }

.login-brand {
  position: relative; overflow: hidden; color: #fff;
  display: flex; flex-direction: column; justify-content: center; padding: 4rem 4.5rem;
  background:
    radial-gradient(900px 500px at 0% -10%, rgba(29, 78, 216, .75) 0%, transparent 60%),
    radial-gradient(600px 400px at 100% 110%, rgba(245, 179, 1, .22) 0%, transparent 60%),
    linear-gradient(160deg, #0b1f4d 0%, #0e2a66 60%, #12306f 100%);
}
.login-logo { border-radius: 50%; background: #fff; padding: 4px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); margin-bottom: 1.5rem; }
.login-brand h1 { font-size: 2.6rem; font-weight: 800; letter-spacing: -.01em; margin: 0 0 .25rem; }
.login-brand .school { color: #b8c6ea; font-size: 1.05rem; margin-bottom: 2.25rem; }
.login-points { list-style: none; padding: 0; margin: 0; display: grid; gap: .9rem; }
.login-points li { display: flex; align-items: center; gap: .85rem; color: #dbe4fb; }
.login-points i { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .12); color: var(--lp-gold); }

.login-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.login-card {
  width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--lp-border);
  border-radius: 18px; padding: 2.25rem; box-shadow: 0 18px 50px rgba(16, 24, 40, .12);
}
.login-card h2 { font-size: 1.6rem; font-weight: 800; margin-bottom: .25rem; }
.login-card .input-group-text { background: var(--lp-soft); color: #8a97b4; border-color: #d5dcec; }
.login-foot { color: var(--lp-muted); font-size: .8rem; margin: 1.5rem 0 0; text-align: center; }

@media (max-width: 991.98px) {
  .login-shell { grid-template-columns: 1fr; min-height: 0; }
  .login-brand { padding: 2rem 1.5rem 4.5rem; align-items: center; text-align: center; }
  .login-logo { width: 72px; height: 72px; margin-bottom: 1rem; }
  .login-brand h1 { font-size: 1.8rem; }
  .login-brand .school { font-size: .9rem; margin-bottom: 0; }
  .login-points { display: none; }
  .login-panel { margin-top: -3rem; padding-top: 0; justify-content: flex-start; }
  .login-card { padding: 1.5rem; }
}
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

@media (prefers-reduced-motion: reduce) {
  .app-sidebar, .sidebar-backdrop, .skel, .shake { transition: none; animation: none; }
}

/* ==========================================================================
   Neutralise the Bootswatch "Cerulean" skin that ships in the bundled
   Bootstrap file: flat buttons, dark headings, white form fields/modals.
   ========================================================================== */
:root, [data-bs-theme=light] { --bs-heading-color: #101828; }
.btn, .btn-primary, .btn-outline-primary { background-image: none; text-shadow: none; }
.form-control, .form-select, .form-control:focus, .form-select:focus { background-color: #fff; }
.form-control:disabled, .form-select:disabled { background-color: #f3f5fa; }
.modal { --bs-modal-bg: #fff; --bs-modal-border-radius: 16px; }
.modal-content { border: 0; box-shadow: 0 24px 60px rgba(16, 24, 40, .25); }
.login-brand h1 { color: #fff; }
.btn-light { --bs-btn-bg: #eef1f8; --bs-btn-border-color: #eef1f8; --bs-btn-hover-bg: #e2e7f3; --bs-btn-hover-border-color: #e2e7f3; --bs-btn-disabled-bg: #f3f5fa; --bs-btn-disabled-border-color: #f3f5fa; }
.toast { box-shadow: 0 10px 30px rgba(16, 24, 40, .2); border-radius: 12px; }

/* Fixes from visual review */
.grade-input { display: inline-block; vertical-align: middle; }
.alert-warning { --bs-alert-bg: #fff7df; --bs-alert-border-color: #f6dd9b; --bs-alert-color: #6b4a00; }
.term-select { max-width: 250px; }
@media (max-width: 767.98px) { .term-select { max-width: 170px; } }
.app-sidebar { box-shadow: none; }
.app-sidebar.open { box-shadow: 8px 0 30px rgba(8, 16, 40, .35); }
@media (min-width: 992px) { .app-sidebar.open { box-shadow: none; } }
.savebar { padding-bottom: max(.8rem, env(safe-area-inset-bottom)); }
@media (max-width: 991.98px) { .stat-grid .stat-card:nth-child(3) { grid-column: span 2; } }

/* --- v2.1 additions --- */
.stat-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 992px) { .stat-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.save-status { font-size: .88rem; font-weight: 600; }
.grade-input.saved-flash { border-color: #12a37f !important; box-shadow: 0 0 0 .2rem rgba(18, 163, 127, .25) !important; }
.btn-success { --bs-btn-bg: #12a37f; --bs-btn-border-color: #12a37f; --bs-btn-hover-bg: #0e8a6b; --bs-btn-hover-border-color: #0e8a6b; --bs-btn-active-bg: #0c7a5f; --bs-btn-active-border-color: #0c7a5f; background-image: none; }
.alert-info { --bs-alert-bg: #e9f1ff; --bs-alert-border-color: #c6d9fb; --bs-alert-color: #1a3a78; }
@media (max-width: 767.98px) { .w-100-sm { width: 100%; } .w-100-sm .btn { flex: 1 1 auto; } }
.final-hint { font-style: italic; }
.term-select { max-width: 310px; }
@media (max-width: 767.98px) { .term-select { max-width: 175px; } }
.text-success { color: #0b7a62 !important; }

/* Final column is hidden until the registrar approves the midterm */
.hide-final .col-final { display: none !important; }
.btn-outline-danger { --bs-btn-color: #b42318; --bs-btn-border-color: #f0b8b3; --bs-btn-hover-bg: #b42318; --bs-btn-hover-border-color: #b42318; --bs-btn-active-bg: #b42318; --bs-btn-active-border-color: #b42318; background-image: none; }
