/* Mutare Polytechnic Student Portal Styles */

/* ==========================================================================
   Corporate palette - green & gold (site chrome only)
   ========================================================================== */
:root {
    --mp-green: #198754;
    --mp-green-dark: #146c43;
    --mp-green-darker: #0f5132;
    --mp-gold: #ffc107;
}

/* Opt-in corporate styling for pages that should carry the brand rather than
   Bootstrap's blue (login, public clearance tracking). */
.bg-brand {
    background-color: var(--mp-green-dark) !important;
    color: #fff !important;
}

.btn-brand {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--mp-green-dark);
    --bs-btn-border-color: var(--mp-green-dark);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--mp-green-darker);
    --bs-btn-hover-border-color: var(--mp-green-darker);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--mp-green-darker);
    --bs-btn-active-border-color: var(--mp-green-darker);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--mp-green-dark);
    --bs-btn-disabled-border-color: var(--mp-green-dark);
    --bs-btn-focus-shadow-rgb: 25, 135, 84;
}

/* Keep the focus ring on brand cards green rather than Bootstrap blue. */
.card:has(.bg-brand) .form-control:focus,
.card:has(.bg-brand) .form-select:focus {
    border-color: #8fc9ad;
    box-shadow: 0 0 0 0.25rem rgba(25, 135, 84, 0.25);
}

.btn-outline-brand {
    --bs-btn-color: var(--mp-green-dark);
    --bs-btn-border-color: var(--mp-green-dark);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--mp-green-dark);
    --bs-btn-hover-border-color: var(--mp-green-dark);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--mp-green-dark);
    --bs-btn-active-border-color: var(--mp-green-dark);
    --bs-btn-disabled-color: var(--mp-green-dark);
    --bs-btn-disabled-border-color: var(--mp-green-dark);
    --bs-btn-focus-shadow-rgb: 25, 135, 84;
}

/* Body and Layout */
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

/* Navbar */
.navbar-brand {
    font-weight: 600;
}

/* Nav items that POST (Sync Database) must read as links, not buttons. */
.navbar-nav .nav-link.btn-link {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    border: 0;
    padding: 0.5rem;
}

.navbar-nav .nav-link.btn-link:hover,
.navbar-nav .nav-link.btn-link:focus {
    color: #fff;
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.card-header {
    font-weight: 600;
}

/* Stats Cards */
.card.bg-primary,
.card.bg-success,
.card.bg-warning,
.card.bg-info,
.card.bg-danger {
    border: none;
}

/* Buttons */
.btn {
    font-weight: 500;
}

/* Login Page */
.card.shadow {
    border: none;
}

/* Alerts */
.alert {
    border: none;
}

/* Footer */
.footer {
    border-top: 3px solid var(--mp-gold);
}

/* Corporate green navbar with a gold accent */
.navbar.bg-primary {
    background-color: var(--mp-green-dark) !important;
    border-bottom: 3px solid var(--mp-gold);
}

/* Tables */
.table th {
    font-weight: 600;
    background-color: #f8f9fa;
}

/* Status Badges */
.badge.bg-pending {
    background-color: #ffc107 !important;
    color: #212529 !important;
}

.badge.bg-cleared {
    background-color: #198754 !important;
}

.badge.bg-blocked {
    background-color: #dc3545 !important;
}

/* Stats cards that filter the list below them when clicked. */
a.stat-card {
    display: block;
    text-decoration: none;
    color: inherit;
}

a.stat-card .card {
    transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out;
}

a.stat-card:hover .card,
a.stat-card:focus-visible .card {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* Badges that carry a reason on hover. The help cursor and the dotted
   underline are the only hint that there is something to read, so a badge
   with no reason recorded must not get this class. */
.badge.has-reason {
    cursor: help;
    text-decoration: underline dotted currentColor;
    text-underline-offset: 2px;
}

.badge.has-reason:hover,
.badge.has-reason:focus {
    filter: brightness(1.15);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .card-body dl.row dt,
    .card-body dl.row dd {
        text-align: left;
    }
}

/* Collapsible card panels.

   The toggle is a button wrapping only the panel title, so buttons and badges
   that sit in the same header (Refresh, status pills) stay clickable instead
   of being swallowed by the toggle's hit area. */
.panel-toggle {
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    text-align: left;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.panel-toggle:hover,
.panel-toggle:focus {
    color: inherit;
    text-decoration: none;
}

.panel-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    border-radius: 2px;
}

.panel-chevron {
    transition: transform .2s ease;
    flex-shrink: 0;
}

/* Bootstrap puts .collapsed on the toggle while its target is hidden. */
.panel-toggle.collapsed .panel-chevron {
    transform: rotate(-90deg);
}

/* Stacked tables on small screens.

   A wide financial table inside .table-responsive technically works on a phone,
   but the amounts sit off the right edge and the reader has to scroll sideways
   to answer "how much was this?". Below the md breakpoint each row becomes a
   labelled block instead, so a row reads top to bottom with no scrolling.

   Every cell needs a data-label; the label is drawn from it via ::before. */
@media (max-width: 767.98px) {
    .table-stack thead {
        display: none;
    }

    .table-stack,
    .table-stack tbody,
    .table-stack tfoot,
    .table-stack tr,
    .table-stack td {
        display: block;
        width: 100%;
    }

    .table-stack tr {
        border: 1px solid var(--bs-border-color, #dee2e6);
        border-radius: .375rem;
        margin-bottom: .5rem;
        padding: .5rem .75rem;
    }

    /* Striping relies on table rows, so restate it for the block layout. */
    .table-stack.table-striped > tbody > tr:nth-of-type(odd) {
        background-color: rgba(0, 0, 0, .03);
    }

    .table-stack td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        border: 0;
        padding: .2rem 0;
        text-align: right;
    }

    .table-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        text-align: left;
        white-space: nowrap;
        color: var(--bs-secondary-color, #6c757d);
    }

    /* A cell holding only a placeholder dash is noise once stacked - the row
       already shows the figures that do exist. */
    .table-stack td.is-empty {
        display: none;
    }

    /* The totals row is a summary, not another record: no label column, and
       it should not look like one more transaction. */
    .table-stack tfoot tr {
        border-width: 2px;
        font-weight: 600;
    }

    .table-stack tfoot td[colspan] {
        display: none;
    }
}

/* Contextual row colours in the stacked layout.

   Bootstrap paints .table-danger and friends through the table cell box-shadow,
   which does nothing once the row is display:block - an overdue loan would lose
   its red tint on exactly the screen where it matters most. Restated here, and
   written to out-specify the striping rule above so a highlighted row in an odd
   position still reads as highlighted. */
@media (max-width: 767.98px) {
    .table-stack > tbody > tr.table-danger,
    .table-stack.table-striped > tbody > tr.table-danger:nth-of-type(odd) {
        background-color: var(--bs-danger-bg-subtle, #f8d7da);
        border-color: var(--bs-danger-border-subtle, #f1aeb5);
    }

    .table-stack > tbody > tr.table-warning,
    .table-stack.table-striped > tbody > tr.table-warning:nth-of-type(odd) {
        background-color: var(--bs-warning-bg-subtle, #fff3cd);
        border-color: var(--bs-warning-border-subtle, #ffe69c);
    }
}

/* Card headers that stack on small screens.

   A header with a long title and one or two action buttons has nowhere to go on
   a phone: the title wraps to two lines and the buttons get squeezed against it.
   Below the md breakpoint the header becomes a column - title first, actions on
   their own full-width row underneath, where they are also a comfortable tap
   target. Unchanged from md up. */
@media (max-width: 767.98px) {
    .card-header.header-stack-sm {
        flex-direction: column;
        align-items: stretch !important;
        gap: .5rem;
    }

    .card-header.header-stack-sm .card-header-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: .5rem;
    }

    /* Buttons share the row evenly; a status badge keeps its natural width so
       it does not stretch into looking like a button. */
    .card-header.header-stack-sm .card-header-actions > .btn {
        flex: 1 1 0;
        margin: 0 !important;
    }

    .card-header.header-stack-sm .card-header-actions > .badge {
        flex: 0 0 auto;
        margin: 0 !important;
    }
}

/* Compact stat cards on small screens.

   The queue and manage pages open with four to six stat cards. At col-md-3 they
   go full width on a phone, so the counts alone push the actual work - the
   filters and the queue table - two or three screens down. Two per row with
   tighter padding keeps the same information above the fold.

   .stat-icon replaces Bootstrap's .fs-1 here because that utility carries
   !important and cannot be scaled down per breakpoint. */
.stat-icon {
    font-size: 2.5rem;
    line-height: 1;
}

@media (max-width: 767.98px) {
    .stat-icon {
        font-size: 1.5rem;
    }

    .stat-grid .card-body {
        padding: .6rem .75rem;
    }

    .stat-grid .card-title {
        font-size: .8rem;
    }

    .stat-grid .card-body h2 {
        font-size: 1.4rem;
    }
}

/* Stacked rows that lead with a checkbox.

   The queue and manage tables put a select box in the first column. Stacked, a
   labelled row reading "(blank) [x]" is meaningless, so the checkbox is pulled
   out of the label/value flow and floated at the top-right of the block where
   it stays an easy tap target. */
@media (max-width: 767.98px) {
    .table-stack tr.stack-row {
        position: relative;
        padding-right: 2.75rem;
    }

    .table-stack td.stack-check {
        position: absolute;
        top: .5rem;
        right: .75rem;
        width: auto;
        padding: 0;
        display: block;
    }

    .table-stack td.stack-check::before {
        content: none;
    }

    /* The candidate number is the row's identity - give it a little more
       weight than the fields under it. */
    .table-stack td.stack-title {
        font-size: 1.05rem;
    }
}

/* Bulk action bars.

   Clear / Block / Upload sit beside a "n selected of m" count. On a phone the
   three buttons wrap into a ragged stack of different widths; below md they
   become one full-width column so they line up and stay tappable. */
@media (max-width: 767.98px) {
    .bulk-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch !important;
    }

    .bulk-actions > .btn {
        width: 100%;
    }
}

/* Action cells in a stacked row.

   A cell holding Clear / Block buttons cannot use the label-left, value-right
   layout - at 375px the pair overflows the card. Below md the label sits on its
   own line and the buttons take the full width underneath, which also makes
   them a proper tap target for what are consequential actions. */
@media (max-width: 767.98px) {
    .table-stack td.stack-buttons {
        display: block;
        white-space: normal !important;
        text-align: left;
        padding-top: .4rem;
    }

    .table-stack td.stack-buttons::before {
        display: block;
        margin-bottom: .35rem;
    }

    .table-stack td.stack-buttons .btn {
        width: 100%;
    }

    .table-stack td.stack-buttons .btn + .btn {
        margin-top: .35rem;
    }
}

/* Page headings with action buttons beside them.

   A long title next to Refresh/Back leaves both squeezed on a phone: the
   heading wraps to three lines and the buttons stack into a narrow column
   against it. Below md the heading takes the full width and the actions sit on
   their own row underneath, sharing it evenly. */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
}

.page-header-actions {
    display: flex;
    gap: .5rem;
    flex-shrink: 0;
}

@media (max-width: 767.98px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header-actions {
        width: 100%;
    }

    /* Direct children so a button wrapped in its own <form> (the CSRF-posted
       Refresh) still shares the row rather than collapsing to its own width. */
    .page-header-actions > * {
        flex: 1 1 0;
    }

    .page-header-actions .btn {
        width: 100%;
    }
}
