:root {
    --kstu-navy: #13234b;
    --kstu-navy-2: #1d3270;
    --kstu-gold: #c9a227;
    --kstu-bg: #f3f5f9;
    --bottom-nav-h: 62px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body { background: var(--kstu-bg); font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", sans-serif; font-size: .925rem;
       -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: rgba(19, 35, 75, .08); }
a, button, .btn, .form-check-input, .form-check-label, label, select { touch-action: manipulation; }

/* ------------------------------------------------------------------ auth pages */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { max-width: 900px; width: 100%; border: 0; overflow: hidden; box-shadow: 0 10px 40px rgba(19, 35, 75, .12); }
.auth-brand { background: linear-gradient(160deg, var(--kstu-navy), var(--kstu-navy-2)); color: #fff; }
.auth-brand img { max-width: 190px; }
.auth-brand .motto { color: var(--kstu-gold); letter-spacing: .15em; font-size: .8rem; }
@media (max-width: 767.98px) {
    .auth-wrap { align-items: flex-start; padding: 0; }
    .auth-card { border-radius: 0; box-shadow: none; min-height: 100vh; min-height: 100dvh; }
    .auth-brand { padding-top: max(1rem, env(safe-area-inset-top, 0px)) !important; }
    .auth-brand img.auth-logo { width: 54px; max-width: 54px; }
    .auth-brand .auth-name { font-size: 1rem; }
    .auth-brand .motto { font-size: .7rem; }
    .auth-card .btn { padding-top: .65rem; padding-bottom: .65rem; }
}

/* ------------------------------------------------------------------ app shell */
.sidebar { width: 250px; background: var(--kstu-navy); }
.sidebar .brand { padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); color: #fff; }
.sidebar .brand img { width: 42px; }
.sidebar .nav-link { color: rgba(255,255,255,.78); padding: .6rem 1rem; border-radius: .5rem; margin: 2px 10px; display: flex; align-items: center; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.07); }
.sidebar .nav-link.active { color: var(--kstu-navy); background: var(--kstu-gold); font-weight: 600; }
.sidebar .nav-link i { width: 24px; display: inline-block; flex-shrink: 0; }
.sidebar .section { color: rgba(255,255,255,.45); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; padding: 14px 20px 4px; }
.sidebar .btn-close { filter: invert(1) grayscale(1) brightness(2); }
.sidebar .nav-logout { color: #f1a7a7; }
.sidebar .nav-logout:hover { color: #fff; background: rgba(220, 53, 69, .25); }

/* Desktop: the sidebar is fixed on the left (Bootstrap's offcanvas-lg is neutralised). */
@media (min-width: 992px) {
    .sidebar.offcanvas-lg { position: fixed; top: 0; left: 0; bottom: 0; z-index: 1030; width: 250px; background: var(--kstu-navy) !important;
                            display: flex !important; flex-direction: column; visibility: visible; transform: none; }
    .main { margin-left: 250px; }
}
/* Phone / tablet: the sidebar is a slide-out drawer (offcanvas). */
@media (max-width: 991.98px) {
    .sidebar.offcanvas-lg { --bs-offcanvas-width: min(300px, 86vw); background: var(--kstu-navy); color: #fff; }
    .sidebar .nav-link { padding: .8rem 1rem; font-size: 1rem; }
    .sidebar .menu-scroll { padding-bottom: calc(16px + var(--safe-bottom)); }
}

.main { min-height: 100vh; }
.topbar { background: #fff; border-bottom: 1px solid #e5e8ef; padding-top: max(.5rem, env(safe-area-inset-top, 0px)) !important; }
.topbar .brand-mini img { width: 30px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: #dfe3ec; }
.photo-lg { width: 120px; height: 140px; object-fit: cover; border-radius: .5rem; background: #dfe3ec; }
.card { border: 0; box-shadow: 0 1px 3px rgba(19, 35, 75, .08); }
.card-header { background: #fff; font-weight: 600; }
.stat .value { font-size: 1.4rem; font-weight: 700; color: var(--kstu-navy); }
.stat .label { color: #6c7489; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.btn-kstu { background: var(--kstu-navy); color: #fff; }
.btn-kstu:hover, .btn-kstu:focus { background: var(--kstu-navy-2); color: #fff; }
.btn-kstu:disabled { background: var(--kstu-navy); color: #fff; opacity: .65; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: #6c7489; }
.page-title { font-size: 1.5rem; }
.table-check-rows tbody tr:has(input:not(:disabled)) { cursor: pointer; }
.table-check-rows tbody tr:has(input:checked) > * { background-color: #eef2fb; }

/* Bottom tab bar (phones and tablets) */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035; background: #fff; border-top: 1px solid #e5e8ef;
              display: flex; padding-bottom: var(--safe-bottom); box-shadow: 0 -2px 12px rgba(19, 35, 75, .06); }
.bottom-nav a, .bottom-nav button { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
              height: var(--bottom-nav-h); color: #6c7489; text-decoration: none; font-size: .68rem; font-weight: 600; background: none; border: 0; }
.bottom-nav i { font-size: 1.3rem; line-height: 1; }
.bottom-nav .active { color: var(--kstu-navy); }
.bottom-nav .active i { color: var(--kstu-navy); }
.bottom-nav .active::after { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--kstu-gold); }
.bottom-nav a, .bottom-nav button { position: relative; }

@media (max-width: 991.98px) {
    main.content { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 20px) !important; }
}

/* ------------------------------------------------------------------ phones */
@media (max-width: 575.98px) {
    body { font-size: .95rem; }
    main.content { padding: 12px !important; }
    .page-title { font-size: 1.25rem; }
    .card-header { padding: .7rem .9rem; }
    .card-body { padding: .9rem; }
    .stat .value { font-size: 1.2rem; }
    .stat .label { font-size: .68rem; }
    .photo-lg { width: 96px; height: 112px; }
    .alert { padding: .7rem .85rem; }
    /* Action rows: stack, and make their buttons full width and easy to tap. */
    .action-row { flex-direction: column; align-items: stretch !important; }
    .action-row .btn, .btn-mobile-block { width: 100%; padding-top: .65rem; padding-bottom: .65rem; }
    /* Choice questions (radios / checkboxes in a row) become full-width tappable rows. */
    .choice-list .form-check-inline { display: flex; align-items: center; margin: 0 0 .5rem; padding: .7rem .8rem .7rem 2.4rem;
                                      border: 1px solid #dee2e6; border-radius: .5rem; background: #fff; }
    .choice-list .form-check-inline .form-check-input { margin-left: -1.6rem; }
    .choice-list .form-check-inline:has(.form-check-input:checked) { border-color: var(--kstu-navy); background: #eef2fb; }
}

/* A bar that stays in view above the bottom tab bar while the page scrolls (phones). */
@media (max-width: 991.98px) {
    .sticky-mobile-action { position: sticky; bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px); z-index: 1020;
                            box-shadow: 0 -4px 18px rgba(19, 35, 75, .14) !important; }
}

/* ------------------------------------------------------------------ stacked tables on phones
   Add .table-stack to a table: under 576px each row becomes a card. Cells get their
   column name (data-label, filled in from the header by portal.js) as a small caption.
   .m-code / .m-title: shown first, as the row's heading. .m-full: full-width cell.
   .m-check: checkbox shown before the heading. .m-action: full-width button row. */
@media (max-width: 575.98px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tfoot { display: block; width: 100%; }
    .table-stack tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .9rem; padding: .8rem .9rem;
                      border-bottom: 1px solid #e9ecf2; }
    .table-stack tbody tr:last-child { border-bottom: 0; }
    .table-stack td, .table-stack th { display: inline-flex; align-items: baseline; gap: .3rem; padding: 0 !important; border: 0 !important;
                                       text-align: left !important; background: none !important; white-space: normal; }
    .table-stack td[data-label]:not(.m-code):not(.m-title):not(.m-full):not(.m-check):not(.m-action):not([colspan])::before {
        content: attr(data-label); color: #7a8296; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
    .table-stack td:empty { display: none; }
    .table-stack .m-check { order: -2; }
    .table-stack .m-code { order: -1; font-weight: 700; color: var(--kstu-navy); }
    .table-stack .m-title { order: 0; flex: 1 1 60%; font-weight: 600; }
    .table-stack .m-full, .table-stack td[colspan] { flex: 1 1 100%; }
    .table-stack .m-action { flex: 1 1 100%; }
    .table-stack .m-action .btn, .table-stack .m-action form { width: 100%; }
    .table-stack .m-key { font-weight: 700; font-size: 1rem; }
    .table-stack tfoot tr { background: #f6f7fa; }
    .table-stack tfoot th:empty { display: none; }
    .table-responsive:has(> .table-stack) { overflow-x: visible; }
}

/* ------------------------------------------------------------------ print */
@media print {
    .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
    .main { margin-left: 0 !important; }
    body { background: #fff; }
    .card { box-shadow: none; }
}

/* Save / submit button that stays reachable at the bottom of long forms on phones. */
@media (max-width: 991.98px) {
    .sticky-mobile-action-plain { position: sticky; bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px); z-index: 1020; }
    .sticky-mobile-action-plain .btn { box-shadow: 0 6px 18px rgba(19, 35, 75, .25); }
}
