:root {
    --a4-width: 210mm;
    --a4-height: 297mm;
    --paper-white: #ffffff;
    --border-color: #e2e8f0;
}

/* Base Styles */
* {
    box-sizing: border-box;
}

.engages-page {
    background-color: var(--white);
    margin: 0;
    padding: 0;
    font-family: 'Advent Pro', sans-serif;
    color: var(--black);
}

.document-container {
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f1f5f9;
    min-height: 80vh;
}

.a4-sheet {
    width: var(--a4-width);
    height: var(--a4-height);
    background: var(--paper-white);
    padding: 5mm;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

@media (max-width: 210mm) {
    .document-container {
        padding: 20px 10px;
        overflow-x: hidden;
    }
    .a4-sheet {
        width: 100%;
        height: auto;
        min-height: auto;
        padding: 5mm;
    }
}

/* Header Compact */
.doc-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 3px;
    margin-bottom: 4px;
}

.header-left {
    display: flex;
    justify-content: flex-start;
}

.doc-logo {
    height: 30px;
    width: auto;
}

.header-center {
    text-align: center;
}

.header-right {
    text-align: right;
}

.doc-main-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: #000;
    margin: 0;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.doc-edition-mention {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary-color);
    text-transform: uppercase;
}

.doc-subtitle {
    font-size: 0.7rem;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
}

/* Grid Layout */
.teams-grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(6, auto);
    gap: 5px;
    flex-grow: 1;
}

@media (max-width: 768px) {
    .teams-grid-container {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto;
    }
}

@media (max-width: 480px) {
    .teams-grid-container {
        grid-template-columns: 1fr;
    }
}

/* Team Mini Card */
.team-mini-card {
    border: 1px solid #f1f5f9;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
}

.team-mini-header {
    background-color: var(--charcoal);
    padding: 4px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 7px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.team-mini-jersey {
    height: 18px;
    width: 18px;
    object-fit: contain;
    background-color: white;
    border-radius: 50%;
    padding: 2px;
    border: 0.5px solid rgba(0,0,0,0.1);
}

.team-mini-name {
    font-size: 0.7rem;
    font-weight: 900;
    text-transform: uppercase;
    color: var(--white);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mini-table {
    width: 100%;
    border-collapse: collapse;
}

.mini-table td {
    padding: 4.2px 5px;
    font-size: 0.62rem;
    line-height: 1.15;
    border-bottom: 0.5px solid #f1f5f9;
}

.mini-dos {
    font-weight: 900;
    color: var(--primary-color);
    width: 15px;
}

.mini-name {
    font-weight: 800;
    text-transform: uppercase;
}

.mini-cat {
    font-size: 0.5rem;
    color: #64748b;
    text-align: right;
}

/* Footer Logos Compact */
.doc-footer {
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.partner-logos-row {
    display: flex;
    gap: 15px;
    align-items: center;
}

.partner-logos-row img {
    height: 28px;
}

.footer-info {
    font-size: 0.7rem;
    color: #94a3b8;
    text-align: right;
    text-transform: uppercase;
    font-weight: 700;
}

.footer-center {
    font-size: 0.7rem;
    font-weight: 700;
    color: #0B1F50;
    text-transform: uppercase;
    text-align: center;
}

/* PRINT RULES */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    html, body {
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body, .engages-page, .document-container {
        background: white !important;
    }

    .no-print, 
    .navbar, 
    .footer, 
    .page-header-light, 
    .viewer-actions,
    .partners-section,
    #preloader {
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    .document-container {
        display: block !important;
        min-height: auto !important;
        height: auto !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .a4-sheet {
        box-shadow: none !important;
        margin: 0 auto !important;
        width: 210mm !important;
        height: 292mm !important; /* Safe height to prevent Safari 2nd page without cropping */
        max-height: 292mm !important;
        padding: 5mm !important;
        border: none !important;
        background: white !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
    }

    .team-mini-header {
        background-color: #0B1F50 !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
    }

    .mini-dos {
        color: #C2945D !important;
    }

    .teams-grid-container {
        grid-template-columns: repeat(3, 1fr) !important;
        grid-template-rows: repeat(6, auto) !important;
        gap: 5px !important;
    }
}
