/* ═══════════════════════════════════════════════════════════════════════════
   UI polish — MCA look applied app-wide WITHOUT touching each page.
     1. Spinners   — every Bootstrap .spinner-border becomes the maroon/gold ring
     2. Alerts     — accent bar, soft shadow, slide-in
     3. Toasts     — a page's top-level SUCCESS message floats top-right and fades out
     4. Boot screen — the "Loading…" shown while the app starts
   Colours come from site.css (--mca-*).
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Spinners ─────────────────────────────────────────────────────────── */
.spinner-border {
    border-width: .28em;
    border-style: solid;
    border-color: var(--mca-border, #E8D5D5);
    border-top-color: var(--mca-maroon, #8B1A1A);
    border-right-color: var(--mca-gold, #C9A84C);
    animation-duration: .9s;
}
/* keep white spinners white (e.g. inside a maroon button) */
.btn .spinner-border, .spinner-border.text-light, .spinner-border.text-white {
    border-color: rgba(255,255,255,.35);
    border-top-color: #fff;
    border-right-color: var(--mca-gold-light, #F0D080);
}

/* ── 2. Alerts ───────────────────────────────────────────────────────────── */
.alert {
    border-radius: 10px;
    border-width: 1px;
    border-left-width: 5px;
    box-shadow: 0 2px 8px rgba(45, 21, 21, .06);
    animation: mca-alert-in .25s ease-out;
}
.alert-success { border-left-color: #16A34A; }
.alert-danger  { border-left-color: #DC2626; }
.alert-warning { border-left-color: #D97706; background-color: #FEF3C7; border-color: #FCD34D; color: var(--mca-warning, #92400E); }
.alert-info    { border-left-color: #2563EB; background-color: #DBEAFE; border-color: #93C5FD; color: var(--mca-info, #1E40AF); }
@keyframes mca-alert-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ── 3. Success messages as toasts ───────────────────────────────────────────
   Only a page's TOP-LEVEL success alert (directly inside the content area — the
   "✅ … saved!" message). Success boxes inside cards / modals stay where they are.
   Errors and warnings stay inline: they must not disappear on their own.
   Hover keeps it on screen.                                                    */
article.content > .alert-success {
    position: fixed;
    top: 72px; right: 20px;
    z-index: 1080;
    width: auto; max-width: min(420px, calc(100vw - 40px));
    margin: 0;
    padding: 12px 16px;
    background: #fff;
    color: var(--mca-success, #166534);
    border: 1px solid #BBF7D0;
    border-left: 5px solid #16A34A;
    box-shadow: 0 10px 30px rgba(45, 21, 21, .18);
    font-weight: 500;
    animation: mca-toast 5.5s ease forwards;
}
article.content > .alert-success:hover { animation-play-state: paused; }
@keyframes mca-toast {
    0%   { opacity: 0; transform: translateX(24px); visibility: visible; }
    6%   { opacity: 1; transform: none; }
    88%  { opacity: 1; transform: none; }
    100% { opacity: 0; transform: translateX(24px); visibility: hidden; pointer-events: none; }
}
@media (max-width: 640.98px) {
    article.content > .alert-success { top: 12px; right: 12px; left: 12px; max-width: none; }
}

/* ── 4. Boot screen ──────────────────────────────────────────────────────── */
.mca-boot {
    min-height: calc(100vh / var(--ui-zoom, 1));
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 35%, #fff 0%, var(--mca-cream, #FDF6F0) 70%);
    color: var(--mca-maroon, #8B1A1A);
}
.mca-boot .boot-ring { position: relative; width: 112px; height: 112px; }
.mca-boot .boot-ring::before {
    content: ""; position: absolute; inset: 0; border-radius: 50%;
    border: 5px solid var(--mca-border, #E8D5D5);
    border-top-color: var(--mca-maroon, #8B1A1A);
    border-right-color: var(--mca-gold, #C9A84C);
    animation: mca-spin 1s linear infinite;
}
.mca-boot .boot-ring img { position: absolute; inset: 14px; width: 84px; height: 84px; border-radius: 50%; }
.mca-boot .boot-name { margin-top: 18px; font-weight: 700; letter-spacing: 1.5px; font-size: 15px; }
.mca-boot .boot-sub { margin-top: 2px; font-size: 12px; color: var(--mca-gray, #6B7280); }
@keyframes mca-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .alert, article.content > .alert-success, .mca-boot .boot-ring::before { animation: none; }
}

/* ── 5. Mobile cards for list tables (tagged by js/mobile-cards.js) ─────────
   Phone width only. First cell = card title; cells with buttons = action row.  */
@media (max-width: 767.98px) {
    /* keep the wrapper's own sideways scroll: if a card is ever wider than the phone,
       it must not stretch the whole page (that cut off the header and the dashboard) */
    .table-responsive:has(> table.mca-cards) { overflow-x: auto; }
    table.mca-cards, table.mca-cards tbody, table.mca-cards tfoot,
    table.mca-cards tr, table.mca-cards td { display: block; width: 100%; }
    table.mca-cards thead { display: none; }
    table.mca-cards { border: 0; background: transparent; }

    table.mca-cards tr {
        background: #fff;
        border: 1px solid var(--mca-border, #E8D5D5);
        border-left: 4px solid var(--mca-maroon, #8B1A1A);
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(45, 21, 21, .06);
        margin-bottom: 12px;
        padding: 6px 12px;
    }
    table.mca-cards tr:hover { background: #fff; }
    table.mca-cards > :not(caption) > * > * { box-shadow: none; background: transparent; }   /* undo striped / hover bg */

    /* Label on the left (absolutely placed), value flows normally on the right — a cell
       can hold several pieces (dot + name + icon, name + student no.) and they stay together. */
    table.mca-cards td {
        position: relative;
        border: 0 !important;
        border-bottom: 1px dashed #F0E4E4 !important;
        padding: 7px 0 7px 42% !important;
        min-height: 2rem;
        text-align: right; white-space: normal; overflow-wrap: anywhere;
    }
    table.mca-cards td::before {
        content: attr(data-label);
        position: absolute; left: 0; top: 7px; width: 40%;
        text-align: left; white-space: normal;
        font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px;
        color: var(--mca-gray, #6B7280);
    }
    table.mca-cards td .badge { white-space: normal; }
    table.mca-cards td .progress { margin-top: 5px; }
    table.mca-cards td[data-label=""], table.mca-cards td[data-span] { padding-left: 0 !important; }
    table.mca-cards td[data-label=""]::before,
    table.mca-cards td[data-span]::before { content: none; }
    table.mca-cards td[data-span] { text-align: center; }
    table.mca-cards td:last-child { border-bottom: 0 !important; }

    /* first cell = title of the card */
    table.mca-cards tbody td:first-child {
        font-weight: 700; font-size: 15px; color: var(--mca-text, #2D1515);
        border-bottom: 1px solid #F0E4E4 !important;
    }
    /* a cell that holds buttons / links = action row, buttons right-aligned and wrapping */
    table.mca-cards td:has(.btn) .btn { margin: 2px 0 2px 4px; }

    /* totals row */
    table.mca-cards tfoot tr { border-left-color: var(--mca-gold, #C9A84C); background: #FFFBF0; }
}

/* ── 6. Dashboard stat cards on a phone ──────────────────────────────────────
   The summary cards (TOTAL STUDENTS / ENROLLED / …) sit two per row on a phone; the
   big emoji icon (inline font-size 2–2.5rem) squeezed the text and was cut off at
   the card edge. On a phone the icon becomes a small badge in the card's top-right
   corner and the text gets the full width.                                       */
@media (max-width: 767.98px) {
    .card > .card-body:has(> .d-flex > span[style*="font-size:2"]) { position: relative; padding-right: 2.6rem; }
    .card > .card-body > .d-flex > span[style*="font-size:2"] {
        position: absolute; top: 10px; right: 10px;
        font-size: 1.35rem !important; line-height: 1;
        width: 2.1rem; height: 2.1rem; border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        background: var(--mca-cream, #FDF6F0);
    }
    .card > .card-body:has(> .d-flex > span[style*="font-size:2"]) small { font-size: 11px; letter-spacing: .2px; display: block; line-height: 1.25; }
    .card > .card-body:has(> .d-flex > span[style*="font-size:2"]) small:first-child { margin-bottom: 4px; }
    .card > .card-body:has(> .d-flex > span[style*="font-size:2"]) h3 { font-size: 1.5rem; word-break: break-word; }
}

/* ── 7. Page header on a phone ───────────────────────────────────────────────
   Title on top, then the header buttons as a tidy wrap of equal pills — they
   were squeezed side by side, wrapping word by word and running off the screen. */
@media (max-width: 767.98px) {
    .page-header { flex-direction: column; align-items: stretch; gap: .6rem; }
    .page-header > div:first-child h3 { font-size: 1.15rem; }
    .page-header > .btn,
    .page-header > div:not(:first-child) { display: flex; flex-wrap: wrap; gap: .4rem; }
    .page-header > .btn { align-self: flex-start; }
    .page-header > div:not(:first-child) > .btn {
        flex: 1 1 calc(50% - .4rem);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        font-size: 13px; padding: .4rem .5rem;
    }
}

/* ── 8. Never let the page scroll sideways on a phone ────────────────────────
   Wide content keeps its own scroll box (.table-responsive); the page itself stays
   phone-wide so the header, menu button and Logout are always on screen.        */
@media (max-width: 767.98px) {
    html, body { overflow-x: hidden; }
    main, article.content { max-width: 100vw; min-width: 0; }
}

/* ── 9. Tabs on a phone ──────────────────────────────────────────────────────
   A row of tabs (e.g. ECR: Written Works · Performance Tasks · QA · Summary) stays
   ONE swipeable row instead of stacking into a tall block.                        */
@media (max-width: 767.98px) {
    .nav-tabs {
        flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-item { flex: 0 0 auto; }
    .nav-tabs .nav-link { white-space: nowrap; padding: .5rem .8rem !important; font-size: 14px; }
}

/* ── 10. ECR grid on a phone ─────────────────────────────────────────────────
   The score grid stays a grid (it scrolls sideways), but the STUDENT NAME column
   is pinned on the left so the teacher always sees whose score is being typed.
   The # column is hidden to give the scores room.                                 */
@media (max-width: 767.98px) {
    table.ecr-grid:not(.mca-cards) th:nth-child(1),
    table.ecr-grid:not(.mca-cards) td:nth-child(1):not([colspan]) { display: none; }
    table.ecr-grid:not(.mca-cards) th:nth-child(2),
    table.ecr-grid:not(.mca-cards) td:nth-child(2) {
        position: sticky; left: 0; z-index: 2;
        min-width: 130px !important; max-width: 150px;
        font-size: 13px; line-height: 1.2;
        background: #fff;
        box-shadow: 2px 0 4px rgba(0,0,0,.08);
    }
    table.ecr-grid:not(.mca-cards) thead th:nth-child(2) { background: var(--mca-maroon-dark, #6B0F0F); z-index: 3; }
    table.ecr-grid:not(.mca-cards) td input.form-control { min-width: 58px; padding: .25rem .35rem; font-size: 14px; }
}

/* ── 11. Filter bars on a phone ──────────────────────────────────────────────
   A card of filters (School Year · Grade · Semester · Section …) laid out as a
   flex row used to shrink each box to its text and hug the right edge. On a phone:
   two filters per row, full-width boxes, buttons full width underneath.          */
@media (max-width: 767.98px) {
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) {
        align-items: stretch !important; justify-content: flex-start !important; gap: .6rem !important;
    }
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) > div {
        flex: 1 1 calc(50% - .6rem); min-width: 0; text-align: left;
    }
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) > div > select,
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) > div > input.form-control { width: 100% !important; }
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) > div.form-check { flex-basis: 100%; }
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) > .btn,
    .card-body.d-flex.flex-wrap:has(> div > select, > div > input.form-control) > div:has(> .btn:only-child) { flex: 1 1 100%; }
}

/* ── 12. Breathing room at the bottom of every page ──────────────────────────
   The last thing on a page (Prev / Next pager, totals, Save buttons) sat flush
   against the bottom edge. Extra space under the content, more on a phone, plus
   the iPhone home-bar safe area.                                                 */
article.content { padding-bottom: 3rem !important; }
.pagination { margin-bottom: 1rem; }
@media (max-width: 767.98px) {
    article.content { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)) !important; }
}
