/*
 * Mobile fixes - loaded LAST on every page (base.html and the standalone auth/error
 * templates), so it wins over page CSS without !important where possible.
 *
 * Everything here came out of rendering the site at 320-430px with Playwright and
 * measuring: page-wide horizontal scroll, off-centre content, tap targets under ~32px,
 * and form fields under 16px (iOS zooms the page when one of those is focused).
 */

/* Media never wider than its container. */
img, video, iframe {
    max-width: 100%;
}

/* Tables that do not fit scroll inside their own box, never the whole page. */
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    /* Safety net: a single stray wide element must not give the whole page a
       sideways scroll. `clip` (unlike `hidden`) keeps position: sticky working. */
    html, body {
        overflow-x: clip;
    }

    /* Long team names, e-mails and URLs wrap instead of pushing the layout out. */
    body {
        overflow-wrap: break-word;
    }

    /* iOS Safari zooms into any field whose text is under 16px and does not zoom
       back out. Login, register, contact and the footer newsletter were 12-14px. */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="button"]):not([type="hidden"]),
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Open mobile menu: fully opaque, otherwise the glowing hero headline shows
       through behind the menu items. */
    #menu.mobile-open {
        background-color: #08090d;
    }

    /* A field's intrinsic width grows with its font size, so the 16px rule above
       would widen the footer newsletter row past 320px. Let fields shrink instead. */
    .footer-columns > *,
    .newsletter-form > * {
        min-width: 0;
    }

    .newsletter-form input {
        width: 100%;
    }

    /* Home hero kept its desktop padding-right: 40px, so on a phone the text and both
       buttons sat 14px from the left edge and 54px from the right. */
    .hero-content {
        padding-right: 0 !important;
    }

    .hero-cta {
        justify-content: center;
    }

    /* Tap targets: enlarge the hit area without moving anything visually
       (padding grows the box, the equal negative margin cancels it in the layout). */
    .sp-crumbs a,
    .pg-hero .crumb a,
    .auth-forgot,
    .help-link,
    .back-link a,
    .sp-league-head a,
    #Footer .footer-column .nav-dropdown > .dropdown-toggle {
        display: inline-block;
        padding-top: 12px;
        padding-bottom: 12px;
        margin-top: -12px;
        margin-bottom: -12px;
    }

    /* Row links in the public fixture lists were 21px tall. */
    .sp-list li a {
        display: inline-block;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    /* Legal cookie table: 4 columns do not fit 320px - scroll inside .table-scroll. */
    .table-scroll > .cookie-table {
        min-width: 560px;
    }
}

/* ---------------------------------------------------------------------------
 * Dashboard match card
 *
 * Odds, headline pick and the BTTS / over-under chips shared ONE non-wrapping row.
 * On a phone the pick column was ~73px wide and the chips were pushed past the
 * card's right edge, where the card's overflow:hidden cut them off - the extra
 * markets were simply invisible on mobile. A legacy rule in dashboard.css also hid
 * .prediction-outcome on mobile, so a BTTS / O-U headline pick read as a bare "51%".
 * ------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .fc-card-bottom {
        flex-wrap: wrap;
        row-gap: 10px;
    }

    .fc-card-bottom .fc-card-odds {
        flex: 1 1 100%;
    }

    .fc-card-bottom .fc-card-odds .odds-row {
        justify-content: center;
    }

    .fc-card-bottom .fc-card-odds .odds-item {
        flex: 1 1 0;
        min-width: 0;
        padding: 6px 4px;
    }

    .fc-card-bottom .fc-card-prediction {
        flex: 1 1 100%;
    }

    .fc-card-bottom .match-card-prediction .prediction-result {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .fc-card-bottom .match-card-prediction .prediction-content {
        flex: 1 1 100%;
        min-width: 0;
    }

    .fc-card-bottom .match-card-prediction .prediction-outcome {
        display: inline;
        white-space: nowrap;
    }

    .fc-card-bottom .mkt-chip-row {
        flex: 1 1 100%;
        margin-top: 0;
    }
}

/* Team names: crest above the name and up to two lines, instead of
   "Słowa..." / "Kazac..." squeezed next to the crest. */
@media (max-width: 480px) {
    .fc-card-team,
    .fc-card-team.away {
        flex-direction: column;
        text-align: center;
        gap: 4px;
    }

    .fc-card-team-name {
        white-space: normal;
        overflow-wrap: anywhere;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-height: 1.25;
    }
}

/* ---------------------------------------------------------------------------
 * Logged-in pages (measured with a test account)
 * ------------------------------------------------------------------------- */
@media (max-width: 768px) {
    /* /agents: sections were width: min(96vw, ...) = 360px inside a 320px content
       box, so every section stuck out 20px on the right. */
    .agents-guide-section,
    .leaderboard-section,
    .todays-picks-section,
    .all-agents-section,
    .charts-section,
    .recent-predictions-section {
        width: auto;
        margin-left: 0;
        margin-right: 0;
    }

    /* /billing: a `1fr` track never shrinks below its content (~380px). */
    .billing-grid,
    .billing-stack {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    /* Invisible hit-area extension for controls that must stay visually small. */
    .bb-dot,
    .refresh-btn {
        position: relative;
    }

    .bb-dot::after,
    .refresh-btn::after {
        content: '';
        position: absolute;
        inset: -12px;
    }

    /* /playerbets date and sort buttons (29-30px). */
    .pb-date,
    .pb-sort button {
        min-height: 40px;
    }

    .pb-dates {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* /profile row buttons (32px). */
    .setting-row .btn-action {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Dashboard onboarding tour "Skip" (27px). */
    .rb-tour-skip {
        min-height: 40px;
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Inline text links that sit alone on a line. */
    .current-plan-note a,
    .player-name a {
        display: inline-block;
        padding-top: 10px;
        padding-bottom: 10px;
        margin-top: -10px;
        margin-bottom: -10px;
    }
}

/* ---------------------------------------------------------------------------
 * /history on a phone: one card per pick instead of an 800px-wide table.
 *
 * The table scrolled sideways inside its box, so a phone showed Date and Match
 * and nothing else - the pick, odds, result and hit/miss were all off to the right.
 * ------------------------------------------------------------------------- */
@media (max-width: 640px) {
    body.history-style-page #predictions-container .table-dark {
        min-width: 0 !important;
        width: 100%;
    }

    body.history-style-page #predictions-container .table-responsive,
    body.history-style-page #predictions-container {
        overflow-x: visible;
    }

    body.history-style-page #predictions-container thead {
        display: none;
    }

    body.history-style-page #predictions-container tbody,
    body.history-style-page #predictions-container table {
        display: block;
    }

    body.history-style-page #predictions-container tr.prediction-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "date   status"
            "match  match"
            "league league"
            "pick   odds"
            "conf   result";
        gap: 6px 12px;
        padding: 12px 14px;
        margin-bottom: 10px;
        border-bottom: 1px solid var(--rb-border-muted, rgba(255, 255, 255, 0.08));
    }

    body.history-style-page #predictions-container tr.prediction-row > td {
        display: block;
        width: auto !important;
        min-width: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        text-align: left;
        white-space: normal;
        background: transparent;
    }

    body.history-style-page #predictions-container .h-date   { grid-area: date; color: var(--rb-text-tertiary, #94a3b8); font-size: 0.8rem; }
    body.history-style-page #predictions-container .h-status { grid-area: status; }
    body.history-style-page #predictions-container .h-match  { grid-area: match; font-size: 0.95rem; }
    body.history-style-page #predictions-container .h-league { grid-area: league; color: var(--rb-text-tertiary, #94a3b8); font-size: 0.78rem; }
    body.history-style-page #predictions-container .h-pick   { grid-area: pick; }
    body.history-style-page #predictions-container .h-odds   { grid-area: odds; text-align: right; }
    body.history-style-page #predictions-container .h-conf   { grid-area: conf; }
    body.history-style-page #predictions-container .h-result { grid-area: result; text-align: right; }

    /* Small caption above the value, so the columns keep their meaning without a header. */
    body.history-style-page #predictions-container td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.65rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--rb-text-tertiary, #94a3b8);
        margin-bottom: 2px;
    }

    body.history-style-page #predictions-container .status-cell {
        flex-direction: row;
        justify-content: flex-end;
        min-width: 0;
    }

    body.history-style-page #predictions-container .prediction-badge {
        min-width: 0;
    }

    body.history-style-page #predictions-container .h-conf .confidence-bar {
        display: inline-block;
        vertical-align: middle;
        width: 60px;
        margin-right: 6px;
    }
}

@media (max-width: 640px) {
    /* Bootstrap's striped table paints every cell of odd rows (inset box-shadow),
       which turned each field of every other card into a grey tile. */
    body.history-style-page #predictions-container tr.prediction-row > td {
        box-shadow: none !important;
        --bs-table-accent-bg: transparent;
        --bs-table-bg-type: transparent;
    }

    /* "Home vs Away" on one line instead of a tall centred block. */
    /* dashboard.css forces .match-teams into a centred column with !important. */
    body.history-style-page #predictions-container .h-match .match-teams {
        display: block !important;
        text-align: left;
        min-height: 0 !important;
        height: auto !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    body.history-style-page #predictions-container .h-match .match-teams strong {
        display: inline;
    }
}

@media (max-width: 900px) {
    /* /playerbets: the player column stretched to ~300px (its sub-line is nowrap and an
       auto-layout table sizes to that), pushing "Nasze %" and the odds column off the
       card on a phone. Fixed layout: numbers get fixed tracks, the name column the rest. */
    .pb-table {
        table-layout: fixed;
    }

    .pb-table th:not(:first-child),
    .pb-table td:not(:first-child) {
        width: 58px;
        padding-left: 4px;
        padding-right: 6px;
    }
}

@media (max-width: 480px) {
    /* /bet-builder header: team names were cut to "Be..." / "M..." next to their crests. */
    .bb-versus .bb-team {
        flex: 1 1 0;
        min-width: 0;
        flex-direction: column;
        text-align: center;
        gap: 4px;
    }

    .bb-versus .bb-team-away {
        flex-direction: column-reverse;
    }

    .bb-card-top {
        padding: 18px 14px 16px;
    }

    .bb-versus {
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 8px;
    }

    .bb-versus .bb-ai-ring {
        width: 60px;
        height: 60px;
    }

    /* League tag + kickoff: the tag no longer pushes the kickoff off the card. */
    .bb-match-strip {
        gap: 8px;
    }

    .bb-match-strip .bb-league-tag {
        flex: 1 1 auto;
        min-width: 0;
        padding: 6px 10px;
    }

    .bb-match-strip .bb-league-name {
        max-width: 100%;
    }

    .bb-match-strip .bb-kickoff {
        flex-shrink: 0;
    }

    .bb-versus .bb-team-name {
        font-size: 0.92rem;
        white-space: normal;
        overflow-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        line-height: 1.25;
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    /* /agents refresh icon was squeezed to 13px wide by its flex row. */
    .predictions-filters .refresh-btn {
        flex-shrink: 0;
        min-width: 40px;
    }
}

@media (max-width: 640px) {
    /* /results/predictions: League and Confidence are hidden on phones (template);
       the rest wraps so pick, result and status fit without sideways scrolling. */
    .table-responsive > .table td,
    .table-responsive > .table th {
        white-space: normal;
        padding-left: 6px;
        padding-right: 6px;
        font-size: 0.85rem;
    }

    .table-responsive > .table .badge {
        white-space: normal;
        text-align: left;
    }
}

@media (max-width: 640px) {
    .results-table {
        table-layout: fixed;
        width: 100%;
    }

    .results-table th:last-child,
    .results-table td:last-child {
        width: 34px;
        text-align: center;
    }

    .results-table .badge {
        white-space: normal !important;
        display: inline-block;
        max-width: 100%;
    }

    /* Visible columns on a phone: Date, Match, Prediction, Status (League, Confidence
       and Result are md+ only - the score is already under the match). */
    .results-table th:nth-child(1),
    .results-table td:nth-child(1) { width: 58px; }
    .results-table th:nth-child(4),
    .results-table td:nth-child(4) { width: 72px; }

    .results-table td,
    .results-table th {
        overflow-wrap: break-word;
    }
}

/* ---------------------------------------------------------------------------
 * /player-stats on a phone. Each tab's table is 5-9 columns (~820px), so the
 * numbers people come for were all off to the right. The player column now
 * sticks to the left while the stat columns scroll inside the table box.
 * ------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .stats-table th:nth-child(1),
    .stats-table td:nth-child(1) {
        display: none;
    }

    .stats-table th:nth-child(2),
    .stats-table td:nth-child(2) {
        position: sticky;
        left: 0;
        z-index: 1;
        background: rgb(19, 23, 34);
        max-width: 150px;
        box-shadow: 1px 0 0 rgba(255, 255, 255, 0.08);
    }

    .stats-table th,
    .stats-table td {
        padding: 8px 8px;
        font-size: 0.85rem;
    }

    .stats-table td:not(:nth-child(2)) {
        white-space: nowrap;
        text-align: center;
    }

    .stats-table .player-photo,
    .stats-table .player-avatar {
        width: 32px;
        height: 32px;
    }

    .stats-table .player-cell {
        gap: 8px;
    }

    .stats-table .player-name {
        white-space: normal;
        line-height: 1.2;
    }

    /* Team: crest only; the name is in the crest's alt/title. */
    .stats-table .team-cell span {
        display: none;
    }
}

@media (max-width: 640px) {
    /* Team column = crest only, so it can be narrow. */
    .stats-table th:nth-child(3),
    .stats-table td:nth-child(3) {
        width: 44px;
        min-width: 0 !important;
        max-width: 44px;
        padding-left: 4px;
        padding-right: 4px;
    }

    .stats-table thead th:nth-child(3) {
        font-size: 0;            /* "DRUŻYNA" header would force the width back */
    }

    .stats-table .team-cell {
        justify-content: center;
        min-width: 0;
    }

    /* Overview: the position badge ("ATTACKER") is the widest cell and says the
       least - the numbers matter more on a phone. */
    .tab-content[data-tab="overview"] .stats-table th:nth-child(4),
    .tab-content[data-tab="overview"] .stats-table td:nth-child(4) {
        display: none;
    }

    .stats-table thead th {
        white-space: nowrap;
        font-size: 0.7rem;
    }
}

@media (max-width: 640px) {
    /* player-stats.css pins the table at min-width 620-760px; let it size to its
       columns - the wide tabs still scroll inside .table-container. */
    .stats-table {
        min-width: 0 !important;
    }

    .stats-table thead th {
        padding: 8px 6px !important;
        white-space: normal !important;
        letter-spacing: 0 !important;
        line-height: 1.15;
        vertical-align: bottom;
    }

    .stats-table th:nth-child(2),
    .stats-table td:nth-child(2) {
        max-width: 124px;
        width: 124px;
    }

    .stats-table .player-number {
        font-size: 0.72rem;
    }
}

@media (max-width: 640px) {
    /* The photo cost ~40px of the sticky column and names broke mid-word
       ("Fernánd-ez"); on a phone the name matters more. */
    .stats-table .player-photo,
    .stats-table .player-avatar {
        display: none;
    }

    .stats-table .player-name {
        overflow-wrap: normal;
        word-break: normal;
        hyphens: auto;
    }
}

/* ---------------------------------------------------------------------------
 * Landing "Co nas wyróżnia?" comparison on a phone: one card per criterion.
 * As a 4-column table the RobotBets column - the one with the live numbers -
 * sat off-screen to the right behind the two competitor columns.
 * ------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .comparison-section {
        padding-left: 16px;
        padding-right: 16px;
    }

    .comparison-table-wrapper {
        overflow-x: visible;
        background: transparent;
        padding: 0;
    }

    .comparison-table thead {
        display: none;
    }

    .comparison-table,
    .comparison-table tbody,
    .comparison-table tr,
    .comparison-table td {
        display: block;
        width: 100%;
        background: transparent;
    }

    .comparison-table tr {
        margin-bottom: 12px;
        padding: 14px 16px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 10px;
        background: rgba(15, 23, 42, 0.6);
    }

    .comparison-table td {
        padding: 0 !important;
        border: 0 !important;
        text-align: left;
    }

    .comparison-table td.criteria-cell {
        font-weight: 700;
        font-size: 1rem;
        margin-bottom: 8px;
    }

    .comparison-table td[data-label] {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 12px;
        padding: 5px 0 !important;
        font-size: 0.9rem;
        text-align: right;
    }

    .comparison-table td[data-label]::before {
        content: attr(data-label);
        flex-shrink: 0;
        text-align: left;
        font-size: 0.78rem;
        opacity: 0.6;
    }

    .comparison-table td.highlight-column {
        margin-top: 6px;
        padding-top: 10px !important;
        border-top: 1px solid rgba(45, 212, 191, 0.3) !important;
        color: #2dd4bf;
        font-weight: 600;
    }

    .comparison-table td.highlight-column::before {
        color: #2dd4bf;
        opacity: 1;
        font-weight: 700;
    }

    .comparison-table td.highlight-column .comparison-note {
        display: block;
        font-weight: 400;
    }

    .comparison-table .checkmark-wrapper {
        justify-content: flex-end;
    }
}

@media (max-width: 640px) {
    /* The RobotBets cell mixes text and spans ("108 aktywnych", "Śr. 51,5 %"); as a
       flex row each piece was spread apart. Plain block, label floated left. */
    .comparison-table td.highlight-column[data-label] {
        display: block;
        text-align: right;
    }

    .comparison-table td.highlight-column[data-label]::before {
        float: left;
        margin-right: 12px;
    }

    .comparison-table td.highlight-column .comparison-note {
        clear: both;
        text-align: right;
        margin-top: 2px;
    }

    .comparison-table td,
    .comparison-table td.criteria-cell,
    .comparison-table td.highlight-column {
        background: transparent !important;
    }
}
