:root {
    --bg-primary: #f1f5f9;
    --bg-card: #f8fafc;
    --text-primary: #1e293b;
    --border-color: #e2e8f0;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-card: #1e293b;
    --text-primary: #e2e8f0;
    --border-color: #334155;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.container {
    margin: 0 auto;
    padding: 0 15px;
    box-sizing: border-box;
}


/* --- AD SLOT CENTERING --- */
#ad-top-slot {
    display: flex !important;
    justify-content: center !important;
    align-items: center;
    width: 100%;
    margin: 0 auto;
}


/* --- DESKTOP FIXED LAYOUT --- */

@media (min-width: 1025px) {
    html, body {
        overflow-x: clip !important;
    }
    body {
        min-width: 1280px !important; 
        padding-top: 50px !important; 
    }

    .container {
        width: 1280px;
        max-width: 1280px; 
        margin: 0 auto;
    }
}

.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 6px 0; 
    position: fixed; 
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
    box-sizing: border-box;
}




/* --- RESPONSIVE GRID LAYOUT --- */
.main-grid {
    display: grid;
    grid-template-columns: 950px 300px; 
    gap: 25px;
    margin-top: 20px;
    align-items: start;
    justify-content: center; 
}

@media (max-width: 1024px) {
    .container {
        width: 100%;
        max-width: 100%;
    }
    .main-grid { 
        grid-template-columns: 1fr; 
    }
    .right-sidebar { display: none; }
}

/* --- TABLE FOUNDATION --- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
}
.table th, .table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}





/* --- HEADER NAVIGATION --- */
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 36px; 
}

.brand-logo {
    font-size: 1.5rem;
    font-weight: 800;
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    padding-bottom: 2px;
}

@media (max-width: 1024px) {
    .header-container {
        min-height: 36px;
    }
    body {
        padding-top: 50px !important; 
    }
}





.main-nav {
    display: flex;
    gap: 20px;
    align-items: center;
}
.main-nav a {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
}
.theme-btn, .mobile-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-primary);
}
.mobile-toggle { display: none; }

/* Add breathing room to H1 page titles */
.league-header {
    padding-left: 15px !important;
    padding-right: 15px !important;
}

/* --- SEARCH & QUICK LINKS UI --- */
.search-wrapper {
    position: relative;
    width: 190px;
    display: flex;
    align-items: center;
}
.global-search-input {
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background-color: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}
.global-search-input:focus { border-color: #2563eb; }

.search-results-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    margin-top: 5px;
    max-height: 400px;
    overflow-y: auto;
}
.search-results-dropdown.is-active { display: block; }
.search-cat-header {
    background: var(--bg-primary);
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #64748b;
    text-transform: uppercase;
}
.search-result-item {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    border-bottom: 1px solid var(--bg-primary);
}
.search-result-item:hover { background-color: #eff6ff; }
.search-highlight {
    background-color: #fef08a;
    color: #854d0e;
    font-weight: bold;
    padding: 0 2px;
    border-radius: 2px;
}

.quick-links-dropdown {
    position: relative;
    display: flex;
    align-items: center;
    height: 100%;
}
.quick-links-btn {
    height: 32px;
    padding: 0 16px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: default;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}
.quick-links-content {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0 0 6px 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-height: 600px;
    overflow-y: auto;
}
.quick-links-dropdown:hover .quick-links-content { display: block; }
.quick-links-dropdown:hover .quick-links-btn { background-color: var(--bg-primary); }

.ql-cat-title {
    background: var(--bg-primary);
    padding: 4px 12px;
    font-size: 0.7rem;
    font-weight: bold;
    color: #64748b;
    text-transform: uppercase;
}
.ql-item {
    display: block;
    padding: 5px 12px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.75rem;
    border-bottom: 1px solid var(--bg-primary);
    font-weight: normal !important; 
}
.ql-item:hover { background-color: #eff6ff; color: #2563eb; }
.ql-item img {
    vertical-align: middle;
    margin-right: 8px;
    border: 1px solid #e2e8f0;
    width: 16px;
    height: 12px;
    border-radius: 2px;
}
.ql-action { 
    font-size: 0.8rem; 
    color: #3b82f6 !important; 
    font-weight: bold !important; 
}

/* --- DESKTOP SPECIFIC HEADER OVERRIDES --- */
@media (min-width: 769px) {
    .main-nav {
        margin-right: 180px !important; /* Pushes the entire block of links and search bar left */
    }
    .search-wrapper {
        margin-right: 0 !important; 
    }
}

/* --- MATCHES GRID & CONTAINERS --- */
.matches-grid-container {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 30px !important;
    align-items: flex-start !important;
    width: 100%;
}
.match-col-box, .matches-col {
    flex: 1 1 calc(50% - 15px);
    max-width: calc(50% - 15px);
    min-width: 320px;
    background-color: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px;
    padding: 15px; 
    box-sizing: border-box;
}

/* --- COMMON MATCH STYLES --- */
.match-time-green {
    color: #16a34a !important; 
    font-size: 0.85rem !important;
    font-weight: 500 !important;
}
.upcoming-match-block { border-bottom: 12px solid transparent !important; }
.upcoming-match-block tr:last-child { border-bottom: none !important; }
.played-row { border-bottom: none !important; }

/* --- PPG BARS --- */
.ppg-bar-bg {
    width: 100%;
    min-width: 50px;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}
.ppg-bar-fill {
    height: 100%;
    border-radius: 4px;
}
.ppg-bar-fill.home { background: #3b82f6; }
.ppg-bar-fill.away { background: #10b981; }

/* --- CUSTOM HOVER TOOLTIPS --- */
.custom-tooltip-wrapper {
    position: relative;
    display: inline-block;
    cursor: pointer;
}
.custom-tooltip-content {
    display: none;
    position: absolute;
    top: 100%;
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bg-card);
    color: var(--text-primary);
    text-align: center;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 100;
    min-width: 120px;
    white-space: nowrap;
}
.custom-tooltip-wrapper:hover .custom-tooltip-content { display: block; }
.tooltip-divider { border-top: 1px dashed var(--border-color); margin: 4px 0; }
.tooltip-ht { font-weight: bold; color: var(--text-primary); font-size: 0.85rem; }
.tooltip-event { font-size: 0.85rem; padding: 2px 0; }

/* --- STAT ICONS & BUTTONS --- */
.stat-icon-btn {
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    min-height: 46px !important;
    width: 46px !important; 
    margin-left: auto !important; 
    background-color: transparent !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 4px !important;
    padding: 4px !important;
    text-decoration: none !important;
    box-sizing: border-box !important;
}
.stat-caption {
    font-size: 0.55rem !important;
    color: var(--text-primary) !important;
    margin-top: 2px !important;
    text-transform: uppercase !important;
    opacity: 0.7 !important;
}
.team-stat-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    width: 24px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: transparent;
    text-decoration: none;
    font-size: 0.7rem;
}
.results-h2h-btn {
    display: inline-block;
    height: 16px !important;
    line-height: 14px !important;
    font-size: 0.65rem !important;
    padding: 0 6px !important;
    border-radius: 3px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    text-decoration: none;
    vertical-align: middle;
}
.upcoming-h2h-btn {
    display: flex; 
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 30px !important; 
    font-size: 0.7rem !important; 
    border-radius: 4px; 
    border: 1px solid var(--border-color);
    text-decoration: none;
    background-color: var(--bg-card);
}
.team-stat-btn:hover, .upcoming-h2h-btn:hover, .results-h2h-btn:hover {
    background-color: var(--bg-primary);
    border-color: var(--text-primary);
}
.info-tooltip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #94a3b8;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: help;
    text-decoration: none;
    transition: background-color 0.2s ease;
}
.info-tooltip-btn:hover { background-color: #64748b; }

/* --- BADGES & MUTED TEXT --- */
.placeholder-text, .muted-text, .live-countdown {
    font-size: 0.75rem !important;
    color: #64748b !important; 
    font-weight: normal !important;
}
.result-box-static {
    padding: 3px 8px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 4px !important;
    font-weight: bold !important;
}
.box-val {
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    display: inline-block;
    min-width: 20px;
    text-align: center;
}
.score-badge {
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: bold;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 1px 6px;
    border-radius: 4px;
    color: #2563eb;
    display: inline-block;
    cursor: pointer !important; 
}

/* --- GLOBAL HIGHLIGHT CLASSES --- */
.highlight-home { background-color: #e0f2fe; }
.highlight-away { background-color: #dcfce7; }
.highlight-team { background-color: #e2e8f0; } 

.win-bg { background-color: #dcfce7 !important; color: #166534 !important; border-color: #bbf7d0 !important; }
.draw-bg { background-color: #fef9c3 !important; color: #854d0e !important; border-color: #fef08a !important; }
.loss-bg { background-color: #fee2e2 !important; color: #991b1b !important; border-color: #fecaca !important; }
.neutral-bg { background-color: #f1f5f9; }
.alt-row-bg { background-color: #f8fafc; }
.streak-neutral { background-color: #e2e8f0; color: var(--text-primary); }
.win-row { background-color: #dcfce7 !important; }
.draw-row { background-color: #fef9c3 !important; }
.loss-row { background-color: #fee2e2 !important; }

/* --- TOP DASHBOARD (Divisions & Summary) --- */
.top-dashboard {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    align-items: stretch;
}
.divisions-col {
    flex: 1 1 250px;
    max-width: 320px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 15px; 
    box-sizing: border-box;
}
.summary-col {
    flex: 999 1 450px; 
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
}

.divisions-col h2 {
    font-size: 0.95rem;
    font-weight: bold;
    margin-top: 0;
    margin-bottom: 4px; 
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}
.division-item {
    display: block;
    padding: 1px 4px; 
    text-decoration: none;
    color: #3b82f6;
    border-radius: 4px;
    font-size: 0.8rem; 
    margin-bottom: 0;
    line-height: 1.4;
}
.division-item:hover { background-color: var(--border-color); }
.division-item.current {
    font-weight: bold;
    color: var(--text-primary);
    background-color: var(--bg-primary); 
    pointer-events: none;
}
.divisions-list.multi-column {
    display: grid;
    grid-template-rows: repeat(7, min-content);
    grid-auto-flow: column;
    column-gap: 10px; 
}
.divisions-list.multi-column .division-item {
    font-size: 0.72rem; 
    padding: 1px 2px;
}

.summary-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 10px; 
}
.season-progress { flex: 1; }
.progress-labels {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 0.8rem;
}
.progress-title { font-weight: bold; color: var(--text-primary); }
.progress-numbers { color: #64748b; }
.progress-bar-bg {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background-color: #3b82f6;
    border-radius: 4px;
}
.gpg-stat {
    text-align: center;
    min-width: 100px;
    padding-left: 15px;
    border-left: 1px solid var(--border-color);
}
.gpg-value {
    font-size: 1.8rem; 
    font-weight: bold;
    color: var(--text-primary);
    line-height: 1;
}
.gpg-label {
    font-size: 0.65rem;
    color: #64748b;
    margin-top: 4px;
}
.outcome-bar-container {
    display: flex;
    width: 100%;
    height: 18px; 
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 4px;
}
.outcome-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
}
.outcome-segment.hw { background-color: #3b82f6; }
.outcome-segment.d { background-color: #94a3b8; }
.outcome-segment.aw { background-color: #10b981; }
.outcome-counts { text-align: center; font-size: 0.7rem; }
.wdl-bar {
    display: flex;
    height: 8px;
    width: 100%;
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto;
}
.wdl-bar .win { background-color: #22c55e; }
.wdl-bar .draw { background-color: #eab308; }
.wdl-bar .loss { background-color: #ef4444; }

/* --- TEAM PAGE: 50/50 SPLIT --- */
.team-grid-container { width: 100%; }
.team-col-left { flex: 1 1 calc(55% - 10px); max-width: calc(55% - 10px); }
.team-col-right { flex: 1 1 calc(45% - 10px); max-width: calc(45% - 10px); }
@media (max-width: 1024px) {
    .team-col-left, .team-col-right { flex: 1 1 100%; max-width: 100%; }
}
.custom-stat-box {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 25px;
}
.custom-stat-box .box-title {
    text-align: center;
    font-weight: bold;
    font-size: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 12px;
}
.goal-stats-table.tight-rows td { padding: 5px 8px !important; vertical-align: middle; }
.results-matrix-table td { padding: 6px 4px !important; }

/* --- LEAGUE COMPARISON BARS & TABS --- */
.comp-tabs { 
    margin-bottom: 0 !important; 
    border-bottom: 1px solid var(--border-color); 
    padding-top: 10px;
}
.comp-tabs ul { display: flex; list-style: none; padding: 0; margin: 0; }
.comp-tabs li { margin: 0 5px 0 0; }
.comp-tabs a { 
    display: block;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color); 
    border-bottom: none; 
    border-radius: 6px 6px 0 0; 
    padding: 8px 16px; 
    cursor: pointer;
    color: var(--text-primary);
    font-weight: 500;
}
.comp-tabs li.is-active a { 
    background-color: var(--bg-card); 
    font-weight: bold;
    margin-bottom: -1px;
    padding-bottom: 9px;
}
.comp-badge {
    color: #ffffff;
    font-weight: bold;
    border-radius: 3px;
    padding: 2px 4px;
    display: inline-block;
    min-width: 38px;
}
.comp-badge.badge-green { background-color: #16a34a; }
.comp-badge.badge-red { background-color: #dc2626; }
.comp-badge.badge-gray { background-color: #94a3b8; }
.comp-dual-bar { display: flex; align-items: center; width: 100%; height: 10px; }
.comp-bar-left { flex: 1; display: flex; justify-content: flex-end; height: 100%; padding-right: 2px; }
.comp-bar-left .fill { height: 100%; border-radius: 2px 0 0 2px; }
.comp-bar-center { width: 2px; height: 12px; background-color: #94a3b8; }
.comp-bar-right { flex: 1; display: flex; justify-content: flex-start; height: 100%; padding-left: 2px; }
.comp-bar-right .fill { height: 100%; border-radius: 0 2px 2px 0; background-color: #cbd5e1; }
.sl-bar-wrapper { height: 6px; background-color: transparent; border-radius: 3px; width: 100%; overflow: hidden; }
.sl-bar-fill { height: 100%; background-color: #3b82f6; border-radius: 3px; }
.sl-score-box {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: bold;
    display: inline-block;
    min-width: 32px;
    text-align: center;
}

/* --- STANDALONE ADVERTISEMENT CLASSES --- */
.standalone-desktop {
    position: fixed;
    bottom: 0;
    left: 50%;
    right: 0;
    max-width: 100%;
    background-color: #FFFFFF;
    border: 1px solid rgb(204, 204, 204);
    padding: 3px 3px 0px 3px;
    box-sizing: content-box;
    text-align: center;
    width: fit-content;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    z-index: 999999999;
}

.standalone-mobile {
    position: fixed;
    bottom: 0;
    left: 50%;
    right: 0;
    max-width: 100%;
    background-color: #FFFFFF;
    border: 1px solid rgb(204, 204, 204);
    padding: 3px 3px 0px 3px;
    box-sizing: content-box;
    text-align: center;
    width: fit-content;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    z-index: 999999999;
}




/* --- MATCH PAGE: 60/40 SPLIT --- */
.match-col-left { flex: 0 0 calc(60% - 15px); max-width: calc(60% - 15px); box-sizing: border-box; }
.match-col-right { flex: 0 0 calc(40% - 15px); max-width: calc(40% - 15px); box-sizing: border-box; }

/* --- H2H PAGE: FORCE SINGLE COLUMN STACKING --- */
.force-single-column .matches-grid-container,
.force-single-column .team-grid-container {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
}
.force-single-column .matches-col,
.force-single-column .team-col-left,
.force-single-column .team-col-right {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
}
.force-single-column [style*="display: flex; gap: 15px"] {
    flex-direction: column !important;
}

/* --- DARK MODE EXPLICIT RULES --- */
[data-theme="dark"] .match-time-green { color: #22c55e !important; }
[data-theme="dark"] .placeholder-text { color: #94a3b8 !important; }
[data-theme="dark"] .muted-text,
[data-theme="dark"] .live-countdown { color: #64748b !important; }
[data-theme="dark"] .text-muted-date { color: #94a3b8 !important; }
[data-theme="dark"] .progress-bar-bg { background-color: #334155; }
[data-theme="dark"] .result-box-static { background-color: transparent !important; }
[data-theme="dark"] .comp-bar-right .fill { background-color: #475569; }
[data-theme="dark"] .sl-score-box { background-color: transparent; }
[data-theme="dark"] .info-tooltip-btn { background-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .info-tooltip-btn:hover { background-color: #64748b; }

[data-theme="dark"] .stat-icon-btn,
[data-theme="dark"] .team-stat-btn,
[data-theme="dark"] .upcoming-h2h-btn,
[data-theme="dark"] .results-h2h-btn {
    background-color: #0f172a !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
}

[data-theme="dark"] .highlight-home { background-color: rgba(59, 130, 246, 0.15) !important; color: #e2e8f0 !important; }
[data-theme="dark"] .highlight-away { background-color: rgba(16, 185, 129, 0.15) !important; color: #e2e8f0 !important; }
[data-theme="dark"] .highlight-team { background-color: rgba(255, 255, 255, 0.05) !important; color: #e2e8f0 !important; }

[data-theme="dark"] .win-row { background-color: rgba(34, 197, 94, 0.15) !important; }
[data-theme="dark"] .draw-row { background-color: rgba(234, 179, 8, 0.15) !important; }
[data-theme="dark"] .loss-row { background-color: rgba(239, 68, 68, 0.15) !important; }
[data-theme="dark"] .win-bg { background-color: rgba(34, 197, 94, 0.2) !important; color: #4ade80 !important; border-color: #166534 !important; }
[data-theme="dark"] .draw-bg { background-color: rgba(234, 179, 8, 0.2) !important; color: #facc15 !important; border-color: #854d0e !important; }
[data-theme="dark"] .loss-bg { background-color: rgba(239, 68, 68, 0.2) !important; color: #f87171 !important; border-color: #991b1b !important; }
[data-theme="dark"] .neutral-bg { background-color: rgba(255, 255, 255, 0.05) !important; }
[data-theme="dark"] .alt-row-bg { background-color: rgba(255, 255, 255, 0.02) !important; }
[data-theme="dark"] .streak-neutral { background-color: rgba(255, 255, 255, 0.05) !important; color: #e2e8f0 !important; }
[data-theme="dark"] .score-badge { background: #0f172a; color: #60a5fa; }
[data-theme="dark"] .goal-stats-table tr { border-color: #334155 !important; }
[data-theme="dark"] .goal-stats-table tr[style*="border-bottom: 1px solid #ffffff"] { border-bottom: 1px solid #334155 !important; }
[data-theme="dark"] .goal-stats-table tr[style*="border-top: 1px solid #ffffff"] { border-top: 1px solid #334155 !important; }

[data-theme="dark"] .custom-tooltip-content,
body.dark-mode .custom-tooltip-content {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
}

[data-theme="dark"] .search-result-item:hover { background-color: #1e293b; color: #60a5fa; }
[data-theme="dark"] .search-highlight { background-color: rgba(234, 179, 8, 0.3); color: #facc15; }
[data-theme="dark"] .ql-item:hover { background-color: #1e293b; color: #60a5fa; }

/* --- KEYBOARD NAVIGATION HIGHLIGHT --- */
.search-result-item.is-highlighted {
    background-color: #eff6ff;
    color: #2563eb;
}
[data-theme="dark"] .search-result-item.is-highlighted {
    background-color: #1e293b;
    color: #60a5fa;
}

/* --- SITEWIDE QUESTION MARK TOOLTIPS CONFIGURATION --- */
.help-tooltip {
    position: absolute !important;
    bottom: 6px !important;
    right: 12px !important;
    left: auto !important;
    top: auto !important;
    display: inline-block !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 50 !important;
}

.help-tooltip .custom-tooltip-content {
    position: absolute !important;
    top: 100% !important; 
    bottom: auto !important;
    right: 0 !important; 
    left: auto !important; 
    width: 300px !important; 
    max-width: 300px !important; 
    min-width: 0 !important; 
    transform: none !important;
    white-space: normal !important; 
    text-align: left !important;
    margin-top: 8px !important;
    box-sizing: border-box !important;
}





/* --- UNIFIED MOBILE HEADER & MENU CONTROLS (<768px) --- */
@media (max-width: 768px) {
    .mobile-toggle { 
        display: block; 
        padding: 0 4px;
        margin-top: 2px;
    }
    
    .main-nav {
        display: none;
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        position: absolute;
        top: 48px;
        left: 0;
        right: 0;



        background: var(--bg-primary); 
        padding: 15px;
        border-bottom: 1px solid var(--border-color);
        z-index: 9999;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
        box-sizing: border-box !important;
    }
    .main-nav.is-active { display: flex; }
    
    /* Force Search to the top, make it prominent */
    .search-wrapper { 
        order: 1; 
        width: 100% !important; 
        max-width: 100% !important; 
        margin: 0 0 10px 0 !important; 
        padding: 0 !important; 
        box-sizing: border-box !important;
    }
    .global-search-input { 
        border: 2px solid #94a3b8 !important;
        font-size: 1.05rem !important; 
        height: 44px !important; 
        padding: 0 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Push Quick Links directly below the Search Box */
    .quick-links-dropdown { 
        order: 2; 
        display: block !important; /* Strips desktop flex alignment */
        width: 100% !important; 
        max-width: 100% !important; 
        margin: 0 0 10px 0 !important; 
        padding: 0 !important; 
        height: auto !important; 
        box-sizing: border-box !important;
    }
    .quick-links-btn { 
        display: flex !important;
        width: 100% !important; 
        justify-content: space-between !important; 
        height: 44px !important; 
        font-size: 0.95rem !important; 
        box-sizing: border-box !important;
    }
    
    /* Style Quick Links dropdown menu inline natively */
    .quick-links-content { 
        position: static !important; 
        width: 100% !important; 
        max-width: 100% !important; 
        box-shadow: none !important; 
        border: 1px solid var(--border-color) !important; 
        margin-top: 5px !important; 
        transform: none !important; 
        left: 0 !important; 
        display: none; 
        box-sizing: border-box !important;
    }
    
    /* Disable CSS hover logic on mobile, lean entirely on Javascript */
    .quick-links-dropdown:hover .quick-links-content { display: none; }
    .quick-links-dropdown.is-open .quick-links-content { display: block !important; }

    /* Fix Search Panel Width */
    .search-results-dropdown { 
        position: absolute !important; 
        top: 100% !important; 
        left: 0 !important; 
        transform: none !important; 
        width: 100% !important; 
        z-index: 1001 !important; 
        box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1) !important; 
    }
    
    /* Format the standard navigation links below Quick Links */
    .main-nav > a { 
        order: 3; 
        padding: 6px 0 !important; /* Tighter padding to match spacing request */
        border-bottom: 1px dashed var(--border-color); 
        width: 100% !important; 
        box-sizing: border-box !important;
    }
    .main-nav > a:last-of-type { border-bottom: none; margin-bottom: 5px !important; }
    .theme-btn { order: 4; align-self: flex-start; margin-top: 5px !important; }
}


/* --- COMPREHENSIVE ANTI-BLOWOUT SYSTEM FOR MOBILE (<1023px) --- */
@media (max-width: 1023px) {
    /* 1. Lock the root viewport */
    html, body {
        overflow-x: clip !important; /* Prevents scroll bleed safely */
        width: 100% !important;
        max-width: 100vw !important;
        position: relative;
    }

    /* Restore comfortable padding specifically for the top navbar in mobile */
    .site-header .container {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }

    /* 2. Grid Column Minimums (The true fix for CSS Grid blowout) */
    .main-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        width: 100% !important;
    }

    /* 3. Eradicate rigid min-widths left over from desktop flex elements */
    .match-col-box, 
    .matches-col,
    .divisions-col,
    .summary-col,
    .team-col-left,
    .team-col-right,
    .custom-stat-box,
    .team-stat-summary {
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 4. Ensure core structural parents NEVER exceed boundaries */
    .container, .main-content {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 0 3px !important; 
    }

    /* 5. Minimize padding inside components */
    .custom-stat-box, .match-col-box, .team-stat-summary, .stats-container > div {
        padding: 3px !important;
    }

    /* Match Page Mobile Specific Overrides */
    .match-countdown-header {
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
    }
    .match-countdown-header > div {
        text-align: center !important;
        width: 100% !important;
    }
    
    .match-stats-val {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }
    
    .ppg-section, .ppg-section * {
        font-weight: normal !important;
    }

    .help-tooltip {
        position: relative !important;
        bottom: auto !important;
        right: auto !important;
        left: auto !important;
        top: auto !important;
        display: flex !important;
        justify-content: flex-end !important; 
        width: 100% !important;
        margin-top: 15px !important;
        margin-bottom: 6px !important;
        padding-right: 12px !important;
        box-sizing: border-box !important;
    }
    .help-tooltip .custom-tooltip-content {
        right: 12px !important;
        left: auto !important;
    }
    
    /* 60/40 Split Override for Mobile */
    .match-col-left, .match-col-right { flex: 0 0 100%; max-width: 100%; }
}



/* --- R89 HPA STICKY FIX --- */
/* Forces the dynamically generated 2nd HPA unit to stay below the sticky top nav */
.sidebar3, .sidebar3 > div {
    position: sticky !important;
    top: 60px !important; 
    margin-top: 10px !important; 
    align-self: flex-start !important; 
}
#ad-sidebar-slot {
    position: sticky !important;
    top: 60px !important; 
}

/* Restore breathing room for Info Pages in mobile mode */
    .custom-stat-box h1 {
        margin-top: 15px !important;
        padding-left: 12px !important;
    }
    .info-content {
        padding: 0 12px 15px 12px !important;
    }