/* ==========================================================================
   SEM'S SWIMS: RESULT CHECKER AND OFFICIAL RESULT CARD STYLES

   Contents
    1. Result checker: page wrapper
    2. Card header
    3. Form: card body, inputs and buttons
    4. Student results panel
    5. Term and session selection
    6. Responsive: selection grid
    7. Responsive: official result card on phones and tablets (<= 1000px)
    8. Large screens (>= 1440px)
    9. Official result card: container, watermark, letterhead and title
   10. Official result card: results table, summary, remarks, footer, buttons
   11. Print styling (A4)
   12. Loading spinners
   13. Bio section

   Order matters: later rules override earlier ones with equal specificity.
   Do not reorder sections without checking the cascade.
   ========================================================================== */

/* ==========================================================================
   1. RESULT CHECKER: PAGE WRAPPER
   ========================================================================== */

.swims-result-checker {
    max-width: 600px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.result-checker-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1);
    overflow: hidden;
}

/* ==========================================================================
   2. CARD HEADER
   Gradient heading at the top of the checker card.
   ========================================================================== */

.card-header {
    background: linear-gradient(135deg, #667eea 0%, #7c3aed 100%);
    color: #fff;
    padding: 2rem;
    text-align: center;
}

.card-header h1,
.card-header h2,
.card-header h3 {
    color: #fff !important;
    font-size: 1.8rem !important;
    font-weight: 600 !important;
    margin-bottom: 0.5rem !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.card-header p {
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 1rem !important;
    margin-top: 0.5rem !important;
}

/* ==========================================================================
   3. FORM: CARD BODY, INPUTS AND BUTTONS
   ========================================================================== */

.card-body {
    padding: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: .5rem;
    font-weight: 600;
}

.form-group input {
    width: 100%;
    padding: .75rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.submit-btn {
    width: 100%;
    padding: .75rem;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

.submit-btn:hover {
    background: #5a6fd8;
}

.submit-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.error-message {
    background: #fee2e2;
    color: #dc2626;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
}

/* ==========================================================================
   4. STUDENT RESULTS PANEL
   On-screen panel that holds the welcome line and the result card.
   ========================================================================== */

.student-results {
    margin-top: 2rem;
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 8px;
}

.student-info {
    margin-bottom: 1.5rem;
}

.student-info p {
    margin: .5rem 0;
}

.grades-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.grades-table th,
.grades-table td {
    padding: .75rem;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.grades-table th {
    background: #f1f5f9;
    font-weight: 600;
}

.no-results {
    text-align: center;
    color: #6b7280;
    font-style: italic;
}

/* ==========================================================================
   5. TERM AND SESSION SELECTION
   Dropdowns and the "view result" button.
   ========================================================================== */

.term-selection {
    margin: 20px 0;
    width: 100%;
}

.selection-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.selection-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.selection-group label {
    font-weight: 600;
    color: #2d3748;
    font-size: 14px;
}

.term-select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
    white-space: normal !important;
    overflow: visible !important;
    height: auto !important;
    min-height: 48px;
}

.term-select:focus {
    outline: none;
    border-color: #667eea;
}

.term-btn {
    width: 100%;
    padding: 14px 20px;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background .3s;
    margin-top: 10px;
}

.term-btn:hover {
    background: #5a6fd8;
}

.term-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #666;
}

/* ==========================================================================
   6. RESPONSIVE: SELECTION GRID
   Tablet, desktop and wide-desktop layouts for the selection row.
   ========================================================================== */

@media (min-width:768px) {
    .selection-grid {
        display: grid;
        grid-template-columns: 1fr 1fr 200px;
        gap: 15px;
        align-items: end;
    }

    .term-btn {
        width: 100%;
        margin-top: 0;
        min-width: auto;
        white-space: nowrap;
        padding: 14px 15px;
    }
}

@media (min-width:1024px) {
    .selection-grid {
        grid-template-columns: 1fr 1fr 220px;
        gap: 25px;
    }

    .swims-result-checker {
        max-width: 1000px;
        margin: 3rem auto;
        padding: 0 2rem;
    }

    .result-checker-card {
        margin: 0 auto;
        max-width: 900px;
    }

    .card-body {
        padding: 3rem;
    }

    .form-group input {
        padding: 1rem;
        font-size: 1.1rem;
    }

    .submit-btn {
        padding: 1rem;
        font-size: 1.1rem;
        font-weight: 600;
    }

    .student-results {
        padding: 2.5rem;
        margin-top: 2.5rem;
    }

    .selection-grid {
        grid-template-columns: 1fr 1fr 200px;
        gap: 25px;
    }

    .term-select {
        padding: 12px 18px;
        font-size: 16px;
    }

    .term-btn {
        padding: 14px 25px;
        font-size: 16px;
        font-weight: 600;
    }
}

@media (min-width:768px) and (max-width:1023px) {
    .selection-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .term-btn {
        margin-top: 10px;
    }
}

/* ==========================================================================
   7. RESPONSIVE: OFFICIAL RESULT CARD ON PHONES AND TABLETS
   Screen only, widths up to 1000px. !important is used to beat the desktop rules further down.
   ========================================================================== */

@media screen and (max-width:1000px) {
    /* Results table: fixed layout with narrow columns so every column fits on a phone */

    .results-table {
        width: 100% !important;
        table-layout: fixed !important;
        font-size: 8px !important;
    }

    .results-table th {
        font-size: 7px !important;
        padding: 2px 1px !important;
        line-height: 1 !important;
        height: 20px !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    .results-table td {
        font-size: 8px !important;
        padding: 3px 1px !important;
    }

    .subject-column {
        width: 25% !important;
        min-width: 25% !important;
        max-width: 25% !important;
    }

    .results-table td:not(.subject-column),
    .results-table th:not(:first-child) {
        width: 9.375% !important;
        min-width: 9.375% !important;
        max-width: 9.375% !important;
        text-align: center !important;
    }

    /* Results section padding */

    .results-section {
        padding-left: 5px !important;
        padding-right: 5px !important;
    }

    /* Summary boxes: scaled down so all four fit in one row */

    .summary-section {
        transform: scale(.85);
        transform-origin: top left;
        width: 117.65%;
        padding: 5px !important;
        margin: 0 !important;
    }

    .summary-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 4px !important;
        padding: 0 !important;
    }

    .summary-card {
        padding: 4px !important;
        min-height: 40px !important;
    }

    .summary-value {
        font-size: 11px !important;
        line-height: 1 !important;
        margin: 0 !important;
    }

    .summary-label {
        font-size: 6px !important;
        line-height: 1 !important;
        margin: 0 !important;
        word-break: break-word !important;
    }

    .summary-card:last-child .summary-value {
        font-size: 9px !important;
        letter-spacing: -.5px !important;
    }

    /* School letterhead, document title, remarks and footer: shrunk to fit small screens */

    .school-letterhead {
        padding: 3px 5px !important;
        gap: 5px !important;
        align-items: center !important;
    }

    .school-logo img {
        width: 30px !important;
        height: 30px !important;
    }

    .school-info h1 {
        font-size: 8px !important;
        line-height: 1 !important;
    }

    .motto {
        font-size: 6px !important;
        margin: 0 !important;
    }

    .address {
        font-size: 5px !important;
        display: none;
    }

    .document-title {
        font-size: 9px !important;
        padding: 3px !important;
    }

    /* Action buttons: original compact sizing */

    .action-buttons {
        padding: 1px 0 !important;
        margin-top: 1px !important;
        gap: 1px !important;
    }

    .btn {
        width: 95% !important;
        font-size: 8px !important;
        padding: 2px 1px !important;
        min-height: 20px !important;
        line-height: 1 !important;
    }

    .remarks-section {
        padding: 5px 8px !important;
        margin: 5px 8px !important;
    }

    .remarks-title {
        font-size: 9px !important;
        margin-bottom: 2px !important;
    }

    .remarks-section div {
        font-size: 8px !important;
        line-height: 1.2 !important;
    }

    .official-footer {
        font-size: 6px !important;
        padding: 4px !important;
        line-height: 1 !important;
    }

    .official-footer div {
        margin: 1px 0 !important;
    }

    /* Action buttons (Print / Check another): side by side on phones. Overrides the .btn width above */

    .action-buttons {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: center;
        gap: 8px !important;
        padding: 12px 10px !important;
    }

    .action-buttons .btn {
        flex: 1 1 0 !important;
        width: auto !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 12px 6px !important;
        min-height: 44px !important;
        font-size: 11px !important;
        line-height: 1.2 !important;
    }
}

/* ==========================================================================
   8. LARGE SCREENS (1440px AND UP)
   ========================================================================== */

@media (min-width:1440px) {
    .swims-result-checker {
        max-width: 1200px;
    }

    .result-checker-card {
        max-width: 1100px;
    }
}

/* ==========================================================================
   9. OFFICIAL RESULT CARD: CONTAINER, WATERMARK, LETTERHEAD AND TITLE
   ========================================================================== */

.official-result-card {
    width: 100%;
    max-width: 1000px;
    margin: 20px auto;
    background: #fff;
    border: 2px solid #1e3a8a;
    border-radius: 8px;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, .1);
    position: relative;
}

.watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
    opacity: .15;
}

.watermark img {
    width: 50%;
    max-width: 400px;
    filter: blur(.8px);
}

.content-layer {
    position: relative;
    z-index: 10;
}

.school-letterhead {
    padding: 12px 25px;
    background: #fff;
    border-bottom: 2px solid #1e3a8a;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 25px;
}

.school-logo img {
    width: 80px;
    border: 2px solid #1e3a8a;
    border-radius: 4px;
}

.school-info {
    text-align: left;
}

.school-info h1 {
    margin: 0;
    font-size: 20px;
    color: #1e3a8a;
    text-transform: uppercase;
    font-weight: bold;
    line-height: 1.2;
    font-family: Arial, Helvetica, sans-serif !important;
}

.motto {
    margin: 3px 0 0 0;
    font-size: 13px;
    color: #1e3a8a;
    font-weight: bold;
    font-style: italic;
}

.address {
    margin: 2px 0 0 0;
    font-size: 11px;
    color: #333;
    line-height: 1.2;
    font-family: Arial, Helvetica, sans-serif !important;
}

.document-title {
    background: #1e3a8a;
    color: #fff;
    padding: 6px;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    font-family: Arial, Helvetica, sans-serif !important;
}

/* ==========================================================================
   10. OFFICIAL RESULT CARD: RESULTS TABLE, SUMMARY, REMARKS, FOOTER AND BUTTONS
   Desktop defaults. The phone overrides above use !important.
   ========================================================================== */

.results-section {
    padding: 8px 25px;
    font-family: Arial, Helvetica, sans-serif !important;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    margin: 5px 0;
    font-family: Arial, Helvetica, sans-serif !important;
}

.results-table th {
    background: #1e3a8a;
    color: #fff;
    padding: 6px 3px;
    font-size: 9px;
    text-transform: uppercase;
    border: 1px solid #1e3a8a;
    font-family: Arial, Helvetica, sans-serif !important;
}

.results-table td {
    padding: 4px 3px;
    text-align: center;
    border: 1px solid #94a3b8;
    font-family: Arial, Helvetica, sans-serif !important;
}

.subject-column {
    text-align: left !important;
    padding-left: 6px;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif !important;
}

.total-score {
    background: #dbeafe !important;
    font-weight: bold;
    color: #1e3a8a;
}

.grade-A {
    background: #d1fae5;
    color: #065f46;
    font-weight: bold;
}

.grade-B {
    background: #bfdbfe;
    color: #1e40af;
    font-weight: bold;
}

.grade-C {
    background: #fef08a;
    color: #854d0e;
    font-weight: bold;
}

.grade-D {
    background: #fed7aa;
    color: #9a3412;
    font-weight: bold;
}

.grade-E {
    background: #d1d5db;
    color: #374151;
    font-weight: bold;
}

.grade-F {
    background: #fda4af;
    color: #991b1b;
    font-weight: bold;
}

.summary-section {
    padding: 10px 25px;
    font-family: Arial, Helvetica, sans-serif !important;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.summary-card {
    background: #fff;
    padding: 8px;
    border-radius: 4px;
    text-align: center;
    border: 1px solid #e2e8f0;
}

.summary-value {
    font-size: 16px;
    font-weight: bold;
    color: #1e3a8a;
}

.summary-label {
    font-size: 9px;
    color: #64748b;
    text-transform: uppercase;
}

.remarks-section {
    padding: 10px 25px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    margin: 0 25px 10px;
    font-family: Arial, Helvetica, sans-serif !important;
}

.remarks-title {
    font-weight: bold;
    color: #1e3a8a;
    font-size: 12px;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.official-footer {
    background: #1e3a8a;
    color: #fff;
    text-align: center;
    padding: 10px;
    font-size: 9px;
    line-height: 1.3;
    font-family: Arial, Helvetica, sans-serif !important;
}

.action-buttons {
    padding: 15px;
    text-align: center;
    background: #f1f5f9;
}

.btn {
    padding: 10px 20px;
    margin: 0 8px;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 12px;
}

/* ==========================================================================
   11. PRINT STYLING (A4)
   Applied when printing the official result card.
   Only the card (and the welcome line) is printed, and it fits on one A4 page.
   ========================================================================== */

@media print {
    /* A4 portrait page with 5mm margins */

    @page {
        size: A4 portrait;
        margin: 5mm;
    }

    /* Remove everything that isn't the card or a parent of it */

    body *:not(:has(.official-result-card)):not(.official-result-card):not(.official-result-card *):not(.student-info):not(.student-info *) {
        display: none !important;
    }

    html,
    body,
    body *:has(.official-result-card):not(.official-result-card) {
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        height: auto !important;
        min-height: 0 !important;
        position: static !important;
        width: auto !important;
        max-width: none !important;
        overflow: visible !important;
    }

    /* FIT: fixed 200mm printable width (A4 minus the 5mm margins). Divided by the zoom (0.85) because zoom scales lengths. If you change the zoom, change both numbers */

    .official-result-card {
        position: relative !important;
        width: calc(200mm / 0.85) !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 2px solid #1e3a8a !important;
        border-radius: 8px !important;
        box-shadow: none !important;
        zoom: 0.85;
    }

    /* COLOURS: force backgrounds to print, including pseudo-elements */

    *,
    *::before,
    *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Dark blue areas: the box-shadow still prints if the background is stripped */

    .document-title,
    .results-table th,
    .official-footer {
        background-color: #1e3a8a !important;
        box-shadow: inset 0 0 0 100vmax #1e3a8a !important;
        color: #fff !important;
    }

    /* FORCE GRADE COLORS TO PRINT */

    .grade-A,
    .grade-a {
        background-color: #d1fae5 !important;
        color: #065f46 !important;
    }

    .grade-B,
    .grade-b {
        background-color: #bfdbfe !important;
        color: #1e40af !important;
    }

    .grade-C,
    .grade-c {
        background-color: #fef08a !important;
        color: #854d0e !important;
    }

    .grade-D,
    .grade-d {
        background-color: #fed7aa !important;
        color: #9a3412 !important;
    }

    .grade-E,
    .grade-e {
        background-color: #d1d5db !important;
        color: #374151 !important;
    }

    .grade-F,
    .grade-f {
        background-color: #fda4af !important;
        color: #991b1b !important;
    }

    /* Ensure the colors cover the whole cell */

    .results-table td[class^="grade-"] {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        background-clip: padding-box !important;
    }

    /* Never split a table row, the summary or the footer across pages */

    tr,
    td,
    th,
    .official-footer,
    .summary-section {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Interface elements that must not appear on paper */

    .action-buttons,
    #swims-result-form,
    .card-header,
    .term-selection {
        display: none !important;
    }

    /* The "Welcome" line above the card is kept on the printout */

    .student-info {
        margin: 0 0 3mm 0 !important;
        padding: 0 !important;
        font-size: 12px !important;
    }
}

/* ==========================================================================
   12. LOADING SPINNERS
   ========================================================================== */

.circular-arrow-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: circular-spin .8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

.circular-arrow-spinner:after {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #fff;
}

@keyframes circular-spin {
    to {
        transform: rotate(360deg);
    }
}

.circular-arrow-spinner-sm {
    width: 16px;
    height: 16px;
    margin-right: 6px;
}

.circular-arrow-spinner-sm:after {
    border-left: 3px solid transparent;
    border-right: 3px transparent;
    border-bottom: 5px solid #fff;
}

.svg-arrow-spinner {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    vertical-align: middle;
    animation: circular-spin .8s linear infinite;
}

.unicode-spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    font-size: 16px;
    line-height: 1;
}

.unicode-spinner-sm {
    font-size: 14px;
    margin-right: 6px;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

.dropdown-loading-indicator .circular-arrow-spinner {
    border: 2px solid rgba(102, 126, 234, .3);
    border-top-color: #667eea;
}

.dropdown-loading-indicator .circular-arrow-spinner:after {
    border-bottom: 4px solid #667eea;
}

.dropdown-loading-indicator {
    color: #667eea;
}

/* ==========================================================================
   13. BIO SECTION
   Name, reg no, term, class and session grid inside the official card.
   ========================================================================== */

.bio-grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    margin-bottom: 20px;
    border: 1px solid #1e3a8a;
    font-family: Georgia, 'Times New Roman', Times, serif;
}

.bio-grid-row {
    display: flex;
    border-bottom: 1px solid #1e3a8a;
}

.bio-grid-row:last-child {
    border-bottom: none;
}

.bio-grid-label {
    width: 30%;
    background: #f8fafc;
    padding: 10px;
    font-size: 11px;
    font-weight: bold;
    color: #1e3a8a;
    text-transform: uppercase;
    border-right: 1px solid #1e3a8a;
    display: flex;
    align-items: center;
}

.bio-grid-value {
    width: 70%;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
}

/* Mobile layout: Compact side-by-side */

@media screen and (max-width: 768px) {
    .bio-grid-container {
        display: block;
    }

    .bio-grid-row {
        display: flex;
        flex-direction: row;
        border-bottom: 1px solid #1e3a8a;
    }

    .bio-grid-label {
        width: 36% !important;
        background: #f8fafc !important;
        padding: 8px !important;
        font-size: 10px !important;
        letter-spacing: 0.5px;
        border-right: 1px solid #1e3a8a !important;
        border-bottom: none !important;
    }

    .bio-grid-value {
        width: 64% !important;
        padding: 8px !important;
        font-size: 13px !important;
        overflow-wrap: anywhere;
    }
}