/**
 * Series Ranking Specific Styles
 *
 * Extends /assets/css/style.css with tabs, matrix table, and ranking-specific styles.
 * Color scheme: Red (#C71F3C) to match Swiss Squash branding.
 */

/* ========== SERIES HEADER ========== */
.series-header {
    justify-content: center;
}

.series-header .logos-left,
.series-header .logos-right {
    flex: 0 0 auto;
    min-width: 150px;
    align-self: flex-start;
}

.series-header .logos-right {
    visibility: hidden;
}

.header-title {
    text-align: center;
    flex: 1;
}

.header-title h1 {
    margin-bottom: 0;
}

.header-title .subtitle {
    color: #666;
    font-size: 0.9em;
    margin: 2px 0 0 0;
}

/* ========== META SECTION ========== */
.meta {
    background: #f8f9fa;
    padding: 10px 15px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.meta p {
    margin: 3px 0;
    font-size: 0.9em;
}

.meta-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
}

.meta-inline span {
    font-size: 0.9em;
}

/* ========== RULES SECTION (Foldable) ========== */
.rules-section {
    margin-top: -15px;
    margin-bottom: 8px;
}

.rules-section summary {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    list-style: none;
    color: #888;
    font-size: 0.85em;
}

.rules-section summary::-webkit-details-marker {
    display: none;
}

.rules-section summary::before,
.rules-section summary::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #ddd;
}

.rules-section summary::before {
    margin-right: 12px;
}

.rules-section summary::after {
    margin-left: 12px;
}

.rules-section summary .summary-text::before {
    content: "▶ ";
    font-size: 0.7em;
    transition: transform 0.2s ease;
    display: inline-block;
}

.rules-section[open] summary .summary-text::before {
    content: "▼ ";
}

.rules-section summary:hover {
    color: #666;
}

.rules-list {
    padding: 10px 15px 15px 35px;
    margin: 0;
    background: #f8f9fa;
    border-radius: 5px;
    margin-top: 10px;
}

.rules-list li {
    margin-bottom: 5px;
    font-size: 0.8em;
    color: #666;
}

.rules-list li:last-child {
    margin-bottom: 0;
}

.rules-list .prize-eligibility-note {
    font-style: italic;
    opacity: 0.8;
}

.rules-list .points-table {
    margin-top: 5px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85em;
    color: #666;
    white-space: nowrap;
    overflow-x: auto;
}

/* ========== TABS SYSTEM ========== */
.tabs-container {
    margin-bottom: 30px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
    padding: 6px 16px;
    cursor: pointer;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    transition: all 0.3s ease;
    font-weight: 600;
    color: #666;
    font-size: 13px;
}

.tab-btn:hover {
    background: #e0e0e0;
}

.tab-btn.active {
    background: #C71F3C;
    color: white;
    border-color: #C71F3C;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.tab-content h2 {
    color: #C71F3C;
    font-size: 1.8em;
    margin-bottom: 5px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.category-info {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 20px;
}

/* ========== MATRIX TABLE ========== */
.table-wrapper {
    overflow-x: auto;
    margin-bottom: 30px;
}

.matrix-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9em;
}

.matrix-table thead {
    background: #C71F3C;
    color: white;
}

.matrix-table th {
    padding: 8px 6px;
    text-align: center;
    font-weight: 600;
    border-right: 1px solid rgba(255,255,255,0.2);
    white-space: nowrap;
}

.tournament-col .tournament-name {
    display: block;
}

.tournament-col .tournament-date {
    display: block;
    font-size: 0.75em;
    font-weight: 400;
    opacity: 0.85;
}

.matrix-table th:last-child {
    border-right: none;
}

/* Sticky columns (rank + player name) */
.sticky-col {
    position: sticky;
    background: white;
    z-index: 10;
}

.rank-col {
    left: 0;
    width: 50px;
    text-align: center;
}

.player-col {
    left: 50px;
    min-width: 150px;
    text-align: left;
}

.matrix-table thead .sticky-col {
    background: #C71F3C;
    z-index: 20;
}

.tournament-col {
    width: 70px;
    min-width: 70px;
    text-align: center;
}

.total-col {
    width: 70px;
    text-align: center;
    font-weight: 600;
    background: #f8f9fa;
}

.matrix-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
}

.matrix-table tbody tr:nth-child(odd) {
    background: #fafafa;
}

.matrix-table tbody tr:nth-child(odd) .sticky-col {
    background: #fafafa;
}

.matrix-table tbody tr:hover {
    background: #fce8eb;
}

.matrix-table tbody tr:hover .sticky-col {
    background: #fce8eb;
}

.matrix-table td {
    padding: 8px;
    border-right: 1px solid #e0e0e0;
}

.matrix-table td:last-child {
    border-right: none;
}

.center {
    text-align: center;
}

/* ========== RANK STYLES ========== */
.rank {
    font-weight: bold;
    font-size: 1.1em;
    color: #C71F3C;
}

.rank-1 { color: #FFD700; } /* Gold */
.rank-2 { color: #C0C0C0; } /* Silver */
.rank-3 { color: #CD7F32; } /* Bronze */

.player-name {
    font-weight: 600;
    padding-left: 12px !important;
}

/* ========== POINTS BADGES ========== */
.points-badge {
    display: inline-block;
    padding: 4px 8px;
    background: #fce8eb;
    border-radius: 3px;
    color: #C71F3C;
    font-weight: 600;
    min-width: 30px;
}

.no-participation {
    color: #ccc;
    font-size: 1.2em;
}

/* Ineligible for prize (insufficient participations) */
.matrix-table tbody tr.ineligible-for-prize {
    opacity: 0.35;
}

.matrix-table tbody tr.ineligible-for-prize:hover {
    opacity: 0.6;
}

.participation-count {
    color: #666;
    font-weight: 600;
}

.total-points {
    color: #C71F3C;
    font-size: 1.1em;
}

/* ========== FOOTER ========== */
.ranking-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
    color: #666;
    font-size: 0.9em;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .tab-btn {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    .matrix-table {
        font-size: 0.8em;
    }

    .player-col {
        min-width: 120px;
    }

    .meta {
        padding: 10px;
        font-size: 0.85em;
    }
}

/* Shown only when printing (hidden on screen — tabs act as titles there) */
.print-only {
    display: none;
}

@media print {
    /* Landscape: the matrix table (Rank + Player + N tournaments + totals) is wide */
    @page {
        size: landscape;
        margin: 12mm 10mm;
    }

    /* Keep background colours: points badges, grayed-out ineligible rows */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body {
        background: #fff;
    }

    /* Hide screen-only chrome. NOTE: .header-fixed is intentionally kept —
       the base stylesheet (assets/css/style.css) already un-fixes it and
       resizes the logo for print, giving us the title/season/logo header. */
    .tabs,
    .rules-section > summary {
        display: none !important;
    }

    /* Print the header once, at the very top, then move on to the rules */
    .header-fixed {
        page-break-after: avoid;
        break-after: avoid;
    }

    /* Reveal print-only elements (category titles) */
    .print-only {
        display: block;
    }

    /* Force the rules section open and printed at the top */
    .rules-section[open],
    .rules-section {
        page-break-inside: avoid;
        page-break-after: always;
    }
    .rules-section .rules-list {
        display: block !important;
    }

    /* Show every category, one per page.
       Override the fadeIn animation: when not animated, inactive tabs keep
       opacity:0 (the keyframe's `from` state) and print as blank pages. */
    .tab-content {
        display: block !important;
        opacity: 1 !important;
        animation: none !important;
        page-break-before: always;
    }
    .tab-content:first-of-type {
        page-break-before: avoid;
    }

    /* Keep the category title (and its count line) glued to the table:
       otherwise a too-tall table gets pushed to the next page, leaving the
       title alone with a blank gap below it. */
    .category-title {
        color: #C71F3C;
        margin: 0 0 4px;
        page-break-after: avoid;
        break-after: avoid;
    }
    .category-info {
        page-break-after: avoid;
        break-after: avoid;
    }

    /* Repeat column headers on every printed page; let a long table start
       right after its title and split in place rather than be pushed away. */
    .table-wrapper {
        overflow: visible !important;
        page-break-before: avoid;
        break-before: avoid;
        page-break-inside: auto;
        break-inside: auto;
    }
    .matrix-table thead {
        display: table-header-group;
    }
    .matrix-table tbody tr {
        page-break-inside: avoid;
    }

    /* Sticky columns are meaningless on paper and can clip cells */
    .matrix-table .sticky-col {
        position: static !important;
    }

    .ranking-footer {
        page-break-before: avoid;
    }
}

/* Empty ranking notice: shown when no player is ranked yet, so the page
   states where the season stands instead of looking like a failed load. */
.empty-ranking {
    margin: 40px auto;
    padding: 32px 24px;
    max-width: 560px;
    text-align: center;
    background: #fafafa;
    border: 1px solid #e4e4e4;
    border-radius: 8px;
}

.empty-ranking h2 {
    margin: 0 0 12px;
    font-size: 1.15em;
    font-weight: 600;
    color: #333;
}

.empty-ranking p {
    margin: 0;
    color: #666;
    font-size: 0.92em;
    line-height: 1.5;
}

.empty-ranking .empty-ranking-detail {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #e9e9e9;
    color: #555;
}

/* Season picker: lets the header switch between the seasons that have data.
   .logos-right is a hidden spacer that keeps the title centred, so the picker
   has to opt back into visibility. */
.season-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    visibility: visible;
}

.season-picker-label {
    font-size: 0.78em;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.season-picker select {
    padding: 4px 8px;
    font-size: 0.85em;
    font-family: inherit;
    color: #333;
    background: #fff;
    border: 1px solid #d4d4d4;
    border-radius: 4px;
    cursor: pointer;
}

.season-picker select:hover {
    border-color: #b4b4b4;
}

@media print {
    /* The picker is a navigation control, useless on paper */
    .season-picker {
        display: none;
    }
}
