* {
    box-sizing: border-box;
}

/* =========================
   PODSTAWOWY LAYOUT
========================= */

body {
    font-family: Arial, sans-serif;
    background: #f4f6f8;
    margin: 0;
    padding: 30px;
    color: #222;
}

.liga-wrapper {
    max-width: 1350px;
    margin: 0 auto;
    background: #ffffff;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.page-header {
    text-align: center;
    margin-bottom: 30px;
}

.page-header h1 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 32px;
}

.page-header p {
    margin: 0;
    color: #555;
}

.section-block {
    margin-top: 35px;
}

.section-block h2 {
    text-align: center;
    margin-bottom: 18px;
}

/* =========================
   TABELE - USTAWIENIA WSPOLNE
========================= */

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    border: 1px solid #cccccc;
    padding: 10px;
    text-align: center;
    vertical-align: middle;
}

th {
    background: #1f4e79;
    color: #ffffff;
}

/* =========================
   RANKING
========================= */

.ranking-team-name {
    text-align: center;
}

.ranking-team-name span {
    display: block;
    line-height: 1.35;
}

/* =========================
   TABELA WYNIKOW - MATRIX
========================= */

.table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #cfd6dc;
}

.matrix-table {
    border-collapse: separate;
    border-spacing: 0;
    min-width: 980px;
    width: max-content;
    font-size: 13px;
}

.matrix-table th,
.matrix-table td {
    border-right: 1px solid #cfd6dc;
    border-bottom: 1px solid #cfd6dc;
    padding: 8px 10px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.matrix-table thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #17486f;
    color: #ffffff;
    font-weight: 700;
}

/* Kolumna 1 - Nr */
.matrix-table th:nth-child(1),
.matrix-table td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 10;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    background: #e9eef3;
}

/* Kolumna 2 - Druzyna */
.matrix-table th:nth-child(2),
.matrix-table td:nth-child(2) {
    position: sticky;
    left: 44px;
    z-index: 10;
    text-align: left;
    background: #e9eef3;
    box-shadow: 4px 0 6px rgba(0, 0, 0, 0.08);
}

.matrix-table thead th:nth-child(1),
.matrix-table thead th:nth-child(2) {
    z-index: 30;
    background: #17486f;
    color: #ffffff;
}

.team-number {
    width: 40px;
    font-weight: bold;
    background: #eef3f8;
}

.team-name {
    text-align: left;
    font-weight: bold;
    background: #eef3f8;
    line-height: 1.35;
}

.team-name span {
    display: block;
    font-weight: 700;
    line-height: 1.35;
}

.match-cell {
    width: 105px;
    min-width: 92px;
    height: 62px;
    font-size: 13px;
    line-height: 1.25;
}

.match-cell strong {
    display: block;
    font-size: 12px;
    margin-bottom: 5px;
}

.match-cell span {
    display: block;
    font-size: 12px;
    line-height: 1.3;
}

.match-cell.played {
    background: #ffffff;
}

.self-match {
    background: #dddddd !important;
    color: #555555;
    font-weight: bold;
    font-size: 18px;
}

.summary-cell {
    width: 70px;
    min-width: 58px;
    background: #ffffff;
}

td.summary-cell.points-cell,
td.summary-cell.sets-cell,
td.summary-cell.games-cell,
td.summary-cell.place-cell {
    background: #ffffff;
}

.score {
    margin-top: 6px;
    padding: 4px 6px;
    display: inline-block;
    color: #17486f;
    font-weight: 700;
    border-radius: 4px;
    line-height: 1.35;
}

.score .sets-result {
    display: block;
    font-size: 14px;
}

.score .games-result {
    display: block;
    font-size: 11px;
    font-weight: 400;
    margin-top: 2px;
}

/* =========================
   KALENDARZ
========================= */

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(130px, 1fr));
    gap: 14px;
}

.calendar-round {
    background: #f8fafc;
    border: 1px solid #dde3ea;
    border-radius: 10px;
    overflow: hidden;
}

.calendar-round-header {
    background: #1f4e79;
    color: #ffffff;
    padding: 12px;
    text-align: center;
}

.calendar-round-header strong {
    display: block;
    font-size: 16px;
    margin-bottom: 3px;
}

.calendar-round-header span {
    font-size: 13px;
}

.calendar-matches {
    list-style: none;
    margin: 0;
    padding: 0;
}

.calendar-matches li {
    padding: 10px 12px;
    border-top: 1px solid #dde3ea;
    background: #ffffff;
}

.calendar-matches li:nth-child(even) {
    background: #f8fafc;
}

.match-pair {
    display: block;
    font-weight: bold;
    font-size: 17px;
}

.match-time {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    color: #555555;
}

/* =========================
   NAWIGACJA RUND
========================= */

.league-nav {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 20px 0;
}

.league-btn {
    display: inline-block;
    padding: 10px 18px;
    background: #222222;
    color: #ffffff;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    transition: 0.2s;
}

.league-btn:hover {
    background: #444444;
}

.league-btn.active {
    background: #24577f;
    cursor: default;
}

/* =========================
   PRZYCISKI DRUKOWANIA
========================= */

.print-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin: 25px 0;
    flex-wrap: wrap;
}

.print-buttons button {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: #1f5fa8;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
}

.print-buttons button:hover {
    background: #174a82;
}

/* =========================
   WIDGET
========================= */

section#hlp {
    padding: 50px 0;
}

#hlp > div {
    margin: 0 auto;
}

/* =========================
   RESPONSYWNOSC
========================= */

@media (max-width: 1200px) {
    .calendar-grid {
        grid-template-columns: repeat(3, minmax(180px, 1fr));
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .liga-wrapper {
        padding: 15px;
    }

    .page-header h1 {
        font-size: 26px;
    }

    .calendar-grid {
        grid-template-columns: 1fr;
    }

    .calendar-round-header {
        text-align: left;
    }

    .matrix-table {
        min-width: 860px;
        font-size: 12px;
    }

    .matrix-table th,
    .matrix-table td {
        padding: 6px 7px;
    }

    .matrix-table th:nth-child(1),
    .matrix-table td:nth-child(1) {
        width: 36px;
        min-width: 36px;
        max-width: 36px;
    }

    .matrix-table th:nth-child(2),
    .matrix-table td:nth-child(2) {
        left: 36px;
    }

    .match-cell {
        min-width: 78px;
    }

    .match-cell strong,
    .match-cell span {
        font-size: 11px;
    }

    .team-name span {
        font-size: 11px;
        line-height: 1.3;
    }

    .summary-cell {
        min-width: 48px;
    }
}

/* =========================
   DRUKOWANIE
========================= */

@media print {
    @page {
        size: A4 landscape;
        margin: 6mm;
    }

    html,
    body {
        background: #ffffff !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    /* Elementy, ktorych nigdy nie drukujemy */
    .league-nav,
    .print-section,
    .print-buttons,
    .league-footer,
    #hlp,
    .page-header {
        display: none !important;
    }

    /* Czyszczenie layoutu dla wydruku */
    .liga-wrapper,
    .section-block,
    .table-scroll {
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
    }

    /* -------------------------
       DRUK - MATRIX
    ------------------------- */

    body.print-matrix #rankingSection {
        display: none !important;
    }

    body.print-matrix #leagueTableSection {
        display: block !important;
        width: 100% !important;
        background: #ffffff !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    body.print-matrix #leagueTableSection h2 {
        color: #000000 !important;
        text-align: center !important;
        font-size: 16px !important;
        margin: 0 0 8px 0 !important;
        padding: 0 !important;
    }

    body.print-matrix .matrix-table {
        width: 100% !important;
        min-width: 0 !important;
        border-collapse: collapse !important;
        border-spacing: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 9px !important;
        page-break-inside: auto !important;
    }

    body.print-matrix .matrix-table thead {
        display: table-header-group !important;
    }

    body.print-matrix .matrix-table tr {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    body.print-matrix .matrix-table th,
    body.print-matrix .matrix-table td {
        position: static !important;
        border: 1px solid #000000 !important;
        background: #ffffff !important;
        color: #000000 !important;
        padding: 3px 4px !important;
        text-align: center !important;
        vertical-align: middle !important;
        box-shadow: none !important;
    }

    body.print-matrix .matrix-table th {
        font-weight: 700 !important;
    }

    /* -------------------------
       DRUK - RANKING
    ------------------------- */

    body.print-ranking #leagueTableSection {
        display: none !important;
    }

    body.print-ranking #rankingSection {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body.print-ranking #rankingSection h2 {
        margin: 0 0 8px 0 !important;
        padding: 0 !important;
        text-align: center !important;
        font-size: 18px !important;
        color: #000000 !important;
    }

    body.print-ranking .ranking-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 11px !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    body.print-ranking .ranking-table thead {
        display: table-header-group !important;
    }

    body.print-ranking .ranking-table tr {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    body.print-ranking .ranking-table th,
    body.print-ranking .ranking-table td {
        border: 1px solid #000000 !important;
        background: #ffffff !important;
        color: #000000 !important;
        padding: 3px 5px !important;
        line-height: 1.15 !important;
        text-align: center !important;
        vertical-align: middle !important;
    }
}
