:root {
    --bg: #eef0f6;
    --card-bg: #ffffff;
    --text: #1e2130;
    --muted: #6b7280;
    --border: #e5e7eb;
    --header-from: #4338ca;
    --header-to: #5b21b6;
    --accent: #4338ca;
    --accent-soft: rgba(67, 56, 202, .1);
    --win: #16a34a;
    --win-soft: #dcfce7;
    --loss: #dc2626;
    --loss-soft: #fee2e2;
    --draw: #9ca3af;
    --draw-soft: #f3f4f6;
    --row-stripe: #f7f7fb;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

:root[data-theme="dark"] {
    --bg: #0f1117;
    --card-bg: #1a1d29;
    --text: #e8e9ee;
    --muted: #9aa0ae;
    --border: #2b2f3d;
    --header-from: #312878;
    --header-to: #452e8f;
    --accent: #8b7bf7;
    --accent-soft: rgba(139, 123, 247, .16);
    --win: #34d399;
    --win-soft: rgba(52, 211, 153, .15);
    --loss: #f87171;
    --loss-soft: rgba(248, 113, 113, .15);
    --draw: #9aa0ae;
    --draw-soft: rgba(154, 160, 174, .12);
    --row-stripe: #20232f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box;
}

html,
body {
    background: var(--bg);
    color: var(--text);
}

body {
    font-family: 'Manrope', 'Inter', sans-serif !important;
    min-height: 100vh;
}

a {
    color: var(--accent);
}

/* ---------- Header ---------- */
.site-header {
    background: linear-gradient(90deg, var(--header-from), var(--header-to));
    color: #fff;
    padding: 16px 0;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 14px;
}

.site-header .logo {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 10px;
}

.header-titles {
    flex: 1 1 auto;
    min-width: 0;
}

.header-titles h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.header-subtitle {
    font-size: .85rem;
    opacity: .85;
}

.theme-toggle {
    border: none;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, .28);
}

/* ---------- Layout ---------- */
.page-wrap {
    padding-top: 18px;
    padding-bottom: 60px;
}

/* ---------- Panels / cards ---------- */
.panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 14px;
    height: 100%;
}

.panel-title {
    font-weight: 700;
    font-size: .95rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-icon {
    opacity: .8;
}

/* ---------- Chip scrollers (this week / recent results) ---------- */
.chip-scroller {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.chip-scroller::-webkit-scrollbar {
    height: 3px;
}

.chip-scroller::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 3px;
}

.chip-scroller::-webkit-scrollbar-track {
    background: transparent;
}

.chip-scroller:hover {
    scrollbar-color: #d1d5db transparent;
}

.chip-scroller:hover::-webkit-scrollbar-thumb {
    background: #d1d5db;
}

.fixture-chip {
    flex: 0 0 auto;
    min-width: 170px;
    height: 106px;
    background: var(--row-stripe);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
}

.fixture-chip .chip-date {
    font-size: .7rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: 6px;
}

.fixture-chip .chip-team {
    font-size: .82rem;
    font-weight: 600;
    text-align: center;
}

.fixture-chip .chip-vs {
    text-align: center;
    font-size: .72rem;
    color: var(--muted);
    margin: 2px 0;
}

.fixture-chip .chip-score {
    text-align: center;
    font-weight: 700;
    color: var(--accent);
    margin: 2px 0;
}

.chip-empty {
    color: var(--muted);
    font-size: .85rem;
    padding: 8px 2px;
}

/* ---------- View toggle ---------- */
.view-toggle {
    display: flex;
    gap: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    width: fit-content;
    box-shadow: var(--shadow);
}

.view-toggle-btn {
    border: none;
    background: transparent;
    color: var(--text);
    font-weight: 600;
    border-radius: 8px;
    padding: 8px 16px;
}

.view-toggle-selected {
    background: var(--accent);
    color: #fff;
}

.view-toggle-btn:hover {
    color: var(--text);
}

.view-toggle-selected:hover {
    color: #fff;
}

/* ---------- Category filter pills ---------- */
.category-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.category-pill {
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    border-radius: 999px;
    padding: 6px 16px;
    font-weight: 600;
    font-size: .85rem;
}

.category-pill-selected {
    background: var(--win);
    border-color: var(--win);
    color: #fff;
}

/* ---------- Fluid layout ----------
   Bootstrap's .container snaps to fixed widths at each breakpoint, so the page
   jumps while resizing. Track the viewport continuously up to the same maximum. */
.container {
    width: 100%;
    max-width: 1320px;
    padding-left: clamp(0.75rem, 2vw, 1.5rem);
    padding-right: clamp(0.75rem, 2vw, 1.5rem);
}

/* ---------- League tables ---------- */
/* columns reflow by available width rather than flipping 1 -> 2 at a breakpoint */
.tables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 34rem), 1fr));
    gap: 1.5rem;
    align-items: start;
}

.tables-grid > * {
    min-width: 0;
}

/* Filters: fields share the row evenly and wrap as space runs out */
#divFiltersCollapse > .row.gx-2 {
    --bs-gutter-x: 0;
    --bs-gutter-y: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
    gap: .5rem 1rem;
    margin: 0;
}

#divFiltersCollapse > .row.gx-2 > * {
    width: auto;
    max-width: none;
    margin: 0;
    padding: 0;
    min-width: 0;
}

.division-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.division-card-header {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    padding: 10px 14px;
    font-size: .95rem;
}

.division-table {
    margin-bottom: 0 !important;
    color: var(--text);
}

.division-table {
    table-layout: fixed;
    width: 100%;
}

/* Stat columns (P W D L F A PTS) share one fixed width; Team takes the remainder */
.division-table th:nth-child(n+2):nth-child(-n+8),
.division-table td:nth-child(n+2):nth-child(-n+8) {
    width: 38px;
}

.division-table th:nth-child(9),
.division-table td:nth-child(9) {
    width: 104px;
}

.division-table .team-col {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.division-table thead th {
    border-bottom: 1px solid var(--border);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 700;
    padding: 8px 6px;
    background: var(--row-stripe);
}

.division-table tbody td {
    padding: 8px 6px;
    font-size: 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.division-table tbody tr:last-child td {
    border-bottom: none;
}

.division-table tbody tr:nth-child(odd) {
    background: var(--row-stripe);
}

.division-table a {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

.division-table a:hover {
    color: var(--accent);
}

.team-icon-link {
    display: inline-flex;
    align-items: center;
    color: var(--muted);
}

.team-icon-link:hover {
    color: var(--accent);
}

.team-icon {
    flex: 0 0 auto;
}

.team-col {
    min-width: 150px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-col {
    white-space: nowrap;
}

@media (max-width: 767.98px) {
    .form-col {
        display: none;
    }
}

.form-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: .68rem;
    font-weight: 700;
    color: #fff;
    margin: 0 1px;
}

.form-w {
    background: var(--win);
}

.form-l {
    background: var(--loss);
}

.form-d {
    background: var(--draw);
}

/* ---------- Category badge colours ---------- */
.cat-ladies {
    background: #db2777;
}

.cat-mens {
    background: #2563eb;
}

.cat-mixed {
    background: #0d9488;
}

.cat-other {
    background: var(--accent);
}

.badge-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
}

/* ---------- Fixtures stats row ---------- */
.stats-row {
    display: flex;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.stat-tile {
    flex: 1 1 0;
    text-align: center;
    padding: 14px 4px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
}

.stat-tile:last-child {
    border-right: none;
}

.stat-tile .stat-value {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--accent);
}

.stat-tile .stat-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
}

/* ---------- Filters ---------- */
.filter-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
}

.form-select,
.form-select:focus {
    background-color: var(--card-bg);
    color: var(--text);
    border-color: var(--border);
}

.status-pills {
    display: flex;
    width: 100%;
    min-width: 0;
}

.status-pill {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    height: 30px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    border-radius: 0;
    padding: 6px 8px;
    font-size: .8rem;
    font-weight: 600;
}

.status-pills>.status-pill:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.status-pills>.status-pill:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

.status-pills>.status-pill:hover,
.status-pills>.status-pill:focus {
    z-index: 1;
}

.status-pill-selected {
    background: var(--win);
    border-color: var(--win);
    color: #fff;
}

/* ---------- Data status ---------- */
.data-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.data-status-badge {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: #fff;
}

.data-status-badge.status-live {
    background: var(--win);
}

.data-status-badge.status-cached {
    background: var(--muted);
}

.data-status-refresh {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: .85rem;
    color: var(--muted);
    text-decoration: none;
}

.data-status-refresh:hover {
    color: var(--accent);
}

.data-status-refresh-icon {
    font-size: 1rem;
    line-height: 1;
}

/* ---------- Fixtures list ---------- */
.fixture-date-heading {
    color: var(--accent);
    font-weight: 700;
    font-size: 1rem;
    border-bottom: 2px solid var(--accent-soft);
    padding-bottom: 6px;
    margin: 18px 0 8px;
}

.fixtures-table {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 4px;
}

.fixtures-table-grouped {
    table-layout: fixed;
}

.fixtures-table-grouped th:nth-child(1),
.fixtures-table-grouped td:nth-child(1) {
    width: 8%;
}

.fixtures-table-grouped th:nth-child(2),
.fixtures-table-grouped td:nth-child(2) {
    width: 14%;
}

.fixtures-table-grouped th:nth-child(3),
.fixtures-table-grouped td:nth-child(3) {
    width: 18%;
}

.fixtures-table-grouped th:nth-child(4),
.fixtures-table-grouped td:nth-child(4) {
    width: 16%;
}

.fixtures-table-grouped th:nth-child(5),
.fixtures-table-grouped td:nth-child(5) {
    width: 18%;
}

.fixtures-table-grouped th:nth-child(6),
.fixtures-table-grouped td:nth-child(6) {
    width: 26%;
}

.fixtures-table-grouped th,
.fixtures-table-grouped td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fixtures-table th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    background: var(--row-stripe);
    padding: 8px 10px;
    font-weight: 700;
}

.fixtures-table td {
    padding: 10px;
    font-size: 16px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

.fixtures-table td .venue-link,
.fixtures-table td .result-link,
.fixtures-table td .postponed-tag {
    font-size: 16px;
}

.fixtures-table td .fixture-winner {
    color: #1c9a6c;
}

.fixtures-table td .fixture-team-link {
    font-weight: 700;
}

.fixtures-table td a {
    color: inherit;
    text-decoration: none;
}

.score-pill,
.score-pill:link,
.score-pill:visited,
.score-pill:hover,
.score-pill:active {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    padding: 2px 10px;
    font-weight: 700;
}

/* Score cell: pill is centred on the row like the team names; the Result link
   hangs below it out of flow so it doesn't push the pill off-centre */
.fixtures-table td.text-center {
    position: relative;
}

.fixtures-table-grouped td.text-center {
    overflow: visible;
}

.fixtures-table tr:has(.result-link) td {
    padding-top: 22px;
    padding-bottom: 22px;
}

.result-link {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(50% + 14px);
    display: block;
    font-size: 12px !important;
    font-weight: 700 !important;
    line-height: 1;
    text-decoration: none;
}

.result-text {
    display: inline-block;
    margin: 3px 0;
}

.result-link:hover .result-text {
    text-decoration: underline;
}

.postponed-tag {
    color: var(--loss);
    font-weight: 700;
    font-size: .8rem;
}

.venue-link {
    font-size: .78rem;
    color: var(--muted);
    text-decoration: none;
}

.venue-link:hover {
    color: var(--accent);
}

.empty-message {
    color: var(--muted);
    padding: 20px;
    text-align: center;
}

/* ---------- Team modal ---------- */
.team-modal-content {
    overflow: hidden;
    border: none;
}

.team-modal-header {
    background: linear-gradient(90deg, var(--header-from), var(--header-to));
    color: #fff;
    border-bottom: none;
}

.team-modal-header .modal-title {
    color: #fff;
    font-weight: 700;
}

.team-badge-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.team-badge {
    background: var(--header-from);
    color: #fff;
    border-radius: 8px;
    padding: 6px 12px;
    font-weight: 700;
    font-size: .9rem;
}

.team-division {
    color: var(--muted);
    font-size: .85rem;
}

.team-position {
    color: var(--accent);
    font-weight: 700;
    font-size: .95rem;
}

.team-stats-row {
    display: flex;
    background: var(--row-stripe);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.team-stat {
    flex: 1 1 0;
    text-align: center;
    padding: 10px 4px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 4px;
}

.team-stat:last-child {
    border-right: none;
}

.team-stat .stat-value {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--accent);
}

.team-stat .stat-label {
    font-size: .7rem;
    text-transform: uppercase;
    color: var(--muted);
}

.team-form-row .form-badge {
    width: 32px;
    height: 32px;
    font-size: .8rem;
}

.team-venue {
    font-size: .85rem;
    color: var(--muted);
}

.team-venue-link {
    margin-bottom: 2px;
}

.team-venue-postcode {
    font-size: .8rem;
    color: var(--muted);
}

.team-section-title {
    font-weight: 700;
    color: var(--accent);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    margin: 10px 0 6px;
}

.team-fixture-table {
    color: var(--text);
}

.team-fixture-table th {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 700;
    border-bottom: 1px solid var(--border);
}

.team-fixture-table td {
    font-size: .85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.team-fixture-table tr:last-child td {
    border-bottom: none;
}

.team-ha {
    color: var(--muted);
    font-size: .78rem;
}

.team-fixture-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
}

.team-fixture-row:last-child {
    border-bottom: none;
}

.team-fixture-list {
    background: var(--row-stripe);
    border: 1px solid var(--border);
    border-radius: 10px;
    max-height: 220px;
    overflow-y: auto;
}

/* ---------- Modal theming ---------- */
.modal-content {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.modal-header,
.modal-footer {
    border-color: var(--border);
}

.modal-header,
.match-modal-header {
    cursor: grab;
    touch-action: none;
}

.modal-header.modal-dragging,
.match-modal-header.modal-dragging {
    cursor: grabbing;
}

/* ---------- General table/legacy tweaks ---------- */
tbody,
td,
tfoot,
th,
thead,
tr {
    border-style: none;
    margin-bottom: 0;
}

th {
    font-weight: normal;
}

.modal-xxl {
    width: 95%;
    max-width: 1200px;
    margin: auto;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

/* ---------- Match modal ---------- */
.match-modal-dialog {
    max-width: 960px;
}

.match-modal-content {
    overflow: hidden;
    border: none;
}

.match-modal-header {
    background: linear-gradient(90deg, var(--header-from), var(--header-to));
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.match-modal-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.match-scoreline {
    background: var(--accent-soft);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.match-scoreline-team {
    font-weight: 700;
    font-size: 1rem;
    min-width: 0;
}

.match-score-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: 8px;
    background: var(--text);
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
}

.match-modal-body {
    padding: 16px;
}

.rubber-grid {
    display: grid;
    grid-template-columns: minmax(70px, 0.85fr) repeat(3, minmax(90px, 1fr));
    gap: 10px;
}

.rubber-grid-corner {
    background: transparent;
}

.pair-header {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 2px;
    font-weight: 700;
    font-size: .85rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 6px;
    min-width: 0;
}

.pair-header div {
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rubber-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
    min-width: 0;
}

.rubber-card-header {
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    text-align: center;
    padding: 4px;
    font-size: .85rem;
}

.rubber-card-body {
    padding: 6px 8px 8px;
}

.rubber-score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.rubber-score {
    flex: 1 1 0;
    text-align: center;
    background: var(--row-stripe);
    border-radius: 6px;
    margin: 2px 0;
    padding: 2px 0;
    font-size: .85rem;
    font-weight: 600;
    height: 25px;
}

.rubber-win-badge {
    display: block;
    width: fit-content;
    margin: 6px auto 0;
    text-align: center;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    padding: 2px 8px;
    border: 1px solid var(--accent);
    color: var(--accent);
}

.rubber-win-badge.rubber-win-home {
    border-color: var(--win);
    color: var(--win);
}

.rubber-win-badge.rubber-win-away {
    border-color: var(--accent);
    color: var(--accent);
}

@media (min-width: 768px) {
    #divFiltersCollapse {
        display: block !important;
        height: auto !important;
    }

    .filters-toggle {
        display: none !important;
    }
}

@media (max-width: 767px) {

    .summary-cards-row,
    #divFixtureStats,
    #btnSummaryView {
        display: none;
    }

    .filters-toggle {
        margin-bottom: 10px;
    }
}

@media (max-width: 575px) {
    .rubber-grid {
        grid-template-columns: minmax(60px, 0.8fr) repeat(3, minmax(78px, 1fr));
        gap: 6px;
    }

    .match-modal-body {
        padding: 10px;
    }

    .pair-header {
        font-size: .72rem;
        padding: 6px 3px;
    }

    .rubber-card-body {
        padding: 4px 5px 5px;
    }

    .rubber-score {
        font-size: .72rem;
    }

    .rubber-win-badge {
        font-size: .6rem;
        padding: 2px 6px;
    }

    .match-scoreline {
        gap: 8px;
        padding: 10px 12px;
    }

    .match-scoreline-team {
        font-size: .85rem;
    }

    .header-titles h1 {
        font-size: 1.1rem;
    }

    .team-stats-row {
        grid-template-columns: repeat(3, 1fr);
    }
}