/* ==========================================================================
   Fussspool Public — Mobile-First Responsive Styles
   ========================================================================== */

/* --- Base / Mobile First --- */

.fussspool-wrap,
.fussspool-coupon-form {
    max-width: 100%;
    padding: 0 4px;
    font-size: 14px;
}

/* Notices */
.fussspool-notice {
    padding: 10px 14px;
    margin: 10px 0;
    border-radius: 4px;
    border-left: 4px solid #ccc;
}
.fussspool-notice-success {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
}
.fussspool-notice-error {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}
.fussspool-notice-warning {
    background: #fff3cd;
    border-color: #856404;
    color: #533f03;
}
.fussspool-notice p {
    margin: 0;
}

/* Forms */
.fussspool-form {
    margin: 12px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.fussspool-inline-form {
    display: inline-block;
    margin: 0;
}
.fussspool-form label {
    font-weight: 600;
    white-space: nowrap;
}

/* Inputs */
.fussspool-select,
.fussspool-input {
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    min-height: 44px; /* Touch target */
    max-width: 100%;
    box-sizing: border-box;
}
.fussspool-select {
    background: #fff;
    appearance: auto;
}
.fussspool-select-sm,
.fussspool-input-sm {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    min-height: 40px;
    max-width: 100%;
    box-sizing: border-box;
}
.fussspool-score-input {
    width: 56px;
    padding: 6px 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
    min-height: 40px;
    box-sizing: border-box;
}

/* Buttons */
.fussspool-btn {
    display: inline-block;
    padding: 10px 18px;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    min-height: 44px;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.4;
}
.fussspool-btn:hover {
    background: #005a87;
    color: #fff;
}
.fussspool-btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    min-height: 40px;
}
.fussspool-btn-secondary {
    background: #6c757d;
}
.fussspool-btn-secondary:hover {
    background: #545b62;
}
.fussspool-btn-danger {
    background: #dc3545;
}
.fussspool-btn-danger:hover {
    background: #c82333;
}

/* Tables — scrollable wrapper */
.fussspool-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 12px 0;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}
.fussspool-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}
.fussspool-table thead {
    background: #f5f5f5;
}
.fussspool-table th,
.fussspool-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #e0e0e0;
    text-align: left;
    vertical-align: middle;
}
.fussspool-table th {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #555;
}
.fussspool-table tbody tr:last-child td {
    border-bottom: none;
}
.fussspool-table tbody tr:hover {
    background: #fafafa;
}

/* Situation Analysis — inline edit rows */
.fussspool-wi-edit-row {
    background: #f0f7ff !important;
}
.fussspool-wi-edit-row td {
    padding: 10px 10px;
    vertical-align: middle;
}
.fussspool-wi-save-row {
    background: #46b450;
}
.fussspool-wi-save-row:hover {
    background: #388e3c;
}

/* Standings highlights */
.fussspool-current-user {
    background-color: #d9edf7 !important;
}
.fussspool-leader {
    background-color: #1a7431 !important;
    color: #fff !important;
}
.fussspool-leader td {
    color: #fff !important;
}
.fussspool-top-winner {
    background-color: #d4edda !important;
}

/* Sticky name column — stays visible when scrolling horizontally */
.fussspool-standings .fussspool-col-arrow {
    position: sticky;
    left: 0;
    background: inherit;
    background-color: #fff;
    z-index: 1;
    min-width: 28px;
    max-width: 36px;
}
.fussspool-standings .fussspool-col-pos {
    position: sticky;
    left: 28px; /* offset past ↕ column */
    background: inherit;
    background-color: #fff;
    z-index: 1;
    min-width: 28px;
    max-width: 36px;
}
.fussspool-standings .fussspool-col-user {
    position: sticky;
    left: 56px; /* offset past ↕ and # columns */
    background: inherit;
    background-color: #fff; /* opaque fallback */
    z-index: 1;
    min-width: 100px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Ensure sticky columns get correct bg for highlighted rows */
.fussspool-standings tr.fussspool-leader .fussspool-col-arrow,
.fussspool-standings tr.fussspool-leader .fussspool-col-pos,
.fussspool-standings tr.fussspool-leader .fussspool-col-user {
    background-color: #1a7431 !important;
    color: #fff !important;
}
.fussspool-standings tr.fussspool-top-winner .fussspool-col-arrow,
.fussspool-standings tr.fussspool-top-winner .fussspool-col-pos,
.fussspool-standings tr.fussspool-top-winner .fussspool-col-user {
    background-color: #d4edda !important;
}
.fussspool-standings tr.fussspool-current-user .fussspool-col-arrow,
.fussspool-standings tr.fussspool-current-user .fussspool-col-pos,
.fussspool-standings tr.fussspool-current-user .fussspool-col-user {
    background-color: #d9edf7 !important;
}
thead .fussspool-col-arrow,
thead .fussspool-col-pos,
thead .fussspool-col-user {
    background-color: #fff;
    z-index: 3;
    position: sticky;
}

.fussspool-standings-title {
    margin-bottom: 8px;
    font-size: 16px;
}
.fussspool-actual-row {
    background-color: #f0fff0 !important;
}
.fussspool-wi-changed {
    background-color: #fff !important; /* white to stand out from green actual rows */
}
.fussspool-actual-score {
    background-color: #d4edda;
    font-weight: 600;
}

/* Total row */
.fussspool-total-row td {
    font-weight: 700;
    border-top: 2px solid #333;
    background: #f9f9f9;
}

/* Flags */
.fussspool-flag {
    height: 14px;
    vertical-align: middle;
    margin-right: 4px;
}

/* Icons */
.fussspool-icon {
    height: 16px;
    vertical-align: middle;
    margin-right: 2px;
}

/* Achievement badges — compact coloured chips that don't overflow */
.fussspool-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    margin-right: 2px;
    vertical-align: middle;
}
.fussspool-badge-score  { background: #0073aa; color: #fff; }
.fussspool-badge-result { background: #46b450; color: #fff; }
.fussspool-badge-goals  { background: #f0ad00; color: #fff; }
.fussspool-badge-winner { background: #9b59b6; color: #fff; }
.fussspool-badge img    { height: 14px; vertical-align: middle; }

/* Points cell (used by JS) */
.fussspool-points-cell {
    font-weight: 600;
}

/* --- Tablet and up (≥768px) --- */

@media (min-width: 768px) {
    .fussspool-wrap,
    .fussspool-coupon-form {
        padding: 0;
        font-size: 15px;
    }

    .fussspool-table {
        font-size: 14px;
    }

    .fussspool-table th,
    .fussspool-table td {
        padding: 10px 14px;
    }

    .fussspool-score-input {
        width: 64px;
    }
}

/* --- Desktop (≥1024px) --- */

@media (min-width: 1024px) {
    .fussspool-table {
        white-space: normal;
    }

    .fussspool-table th,
    .fussspool-table td {
        padding: 10px 16px;
    }
}

/* --- Very small screens: card-like fallback for narrow tables --- */

@media (max-width: 480px) {
    .fussspool-form {
        flex-direction: column;
        align-items: stretch;
    }

    .fussspool-select,
    .fussspool-input,
    .fussspool-btn {
        width: 100%;
    }

    .fussspool-table th,
    .fussspool-table td {
        padding: 6px 8px;
        font-size: 12px;
    }

    .fussspool-score-input {
        width: 48px;
        font-size: 13px;
    }
}

/* ==========================================================================
   Mobile card layout — Previous Coupon & Compare Predictions
   Stacks each row as a card, with points-priority columns shown first.
   Applied below 640px where horizontal scrolling becomes painful.
   ========================================================================== */

@media (max-width: 640px) {

    /* Hide the real thead — labels come from data-label attributes instead */
    .fussspool-table-mobile-cards thead {
        display: none;
    }

    .fussspool-table-mobile-cards,
    .fussspool-table-mobile-cards tbody {
        display: block;
        width: 100%;
    }

    /* Each row becomes a card */
    .fussspool-table-mobile-cards tbody tr {
        display: flex;
        flex-wrap: wrap;
        border: 1px solid #ddd;
        border-radius: 6px;
        margin-bottom: 10px;
        padding: 8px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
        position: relative;
    }

    .fussspool-table-mobile-cards tbody tr.fussspool-current-user {
        background: #d9edf7 !important;
    }
    .fussspool-table-mobile-cards tbody tr.fussspool-top-winner {
        background: #d4edda !important;
    }
    .fussspool-table-mobile-cards tbody tr.fussspool-actual-row {
        background: #f0fff0 !important;
    }
    .fussspool-table-mobile-cards tbody tr.fussspool-total-row {
        background: #f9f9f9 !important;
        font-weight: 700;
        border-top: 2px solid #333;
        border-radius: 0;
        margin-top: 0;
    }

    /* Each cell is a labelled field */
    .fussspool-table-mobile-cards td {
        display: flex;
        flex-direction: column;
        padding: 4px 8px;
        border: none;
        font-size: 13px;
        min-width: 50%;
        box-sizing: border-box;
    }

    /* Label above the value */
    .fussspool-table-mobile-cards td::before {
        content: attr(data-label);
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        color: #888;
        margin-bottom: 2px;
    }

    /* Cells with no label (icon column) take less space */
    .fussspool-table-mobile-cards td[data-label=""] {
        min-width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 4px;
    }

    /* ---- Column ordering for Previous Coupon & Compare ----
       Layout goal: Time | Home | Away | Earned/Points — visible at a glance.
       Predicted, actual, winner cols come next. Odds and detail cols last.      */

    /* Row 1 — Time spans full width, gives context */
    .fussspool-table-mobile-cards td[data-label="Time"] {
        order: 1;
        min-width: 100%;
        font-size: 11px;
        color: #666;
        padding-bottom: 2px;
    }

    /* Row 2 — Home and Away side by side (50% each) */
    .fussspool-table-mobile-cards td[data-label="Home"],
    .fussspool-table-mobile-cards td[data-label="Away"] {
        order: 2;
        min-width: 50%;
        font-weight: 600;
    }

    /* Row 3 — User label (compare table) */
    .fussspool-table-mobile-cards td[data-label="User"] {
        order: 2;
        min-width: 100%;
        font-weight: 600;
    }

    /* Row 3 — Earned + badges on same line, highlighted */
    .fussspool-table-mobile-cards td[data-label="Earned"],
    .fussspool-table-mobile-cards td[data-label="Points"] {
        order: 3;
        min-width: 100%;
        font-size: 18px;
        font-weight: 700;
        color: #0073aa;
        border-bottom: 1px solid #eee;
        padding-bottom: 6px;
        margin-bottom: 4px;
        flex-direction: row;
        align-items: center;
        gap: 6px;
        flex-wrap: wrap;
    }

    /* Suppress the pseudo-label for Earned in flex-row mode */
    .fussspool-table-mobile-cards td[data-label="Earned"]::before,
    .fussspool-table-mobile-cards td[data-label="Points"]::before {
        min-width: 3em;
        flex-shrink: 0;
    }

    /* Badges sit inline with Earned — pull them to order 3 and hide their own cell label */
    .fussspool-table-mobile-cards td[data-label=""] {
        order: 3;
        min-width: auto;
        flex-direction: row;
        align-items: center;
        gap: 3px;
        padding-left: 0;
        border-bottom: 1px solid #eee;
        padding-bottom: 6px;
        margin-bottom: 4px;
    }

    .fussspool-table-mobile-cards td[data-label=""]::before {
        content: none;
    }

    /* Fix flag stretch — in flex column cells, img inherits stretch */
    .fussspool-table-mobile-cards td img.fussspool-flag {
        height: 14px;
        width: auto;
        align-self: center;
        flex-shrink: 0;
    }

    /* Row 4 — Predicted score and winner */
    .fussspool-table-mobile-cards td[data-label="Predicted"],
    .fussspool-table-mobile-cards td[data-label="Pred. Winner"] {
        order: 4;
        min-width: 50%;
    }

    /* Row 5 — Actual result and winner */
    .fussspool-table-mobile-cards td[data-label="Actual"],
    .fussspool-table-mobile-cards td[data-label="Act. Winner"] {
        order: 5;
        min-width: 50%;
    }

    /* Row 6 — Max points */
    .fussspool-table-mobile-cards td[data-label="Max"] {
        order: 6;
        min-width: 50%;
    }

    /* Row 7 — Odds and other detail cols (requires scroll) */
    .fussspool-table-mobile-cards td[data-label="1"],
    .fussspool-table-mobile-cards td[data-label="X"],
    .fussspool-table-mobile-cards td[data-label="2"],
    .fussspool-table-mobile-cards td[data-label="Home Score"],
    .fussspool-table-mobile-cards td[data-label="Away Score"] {
        order: 7;
        min-width: 33%;
    }

    /* Match fixture columns in compare (e.g. "ENG v MLT") */
    .fussspool-table-mobile-cards td:not([data-label="Time"]):not([data-label="Home"]):not([data-label="Away"]):not([data-label="User"]):not([data-label="Earned"]):not([data-label="Points"]):not([data-label="Predicted"]):not([data-label="Pred. Winner"]):not([data-label="Actual"]):not([data-label="Act. Winner"]):not([data-label="Max"]):not([data-label="1"]):not([data-label="X"]):not([data-label="2"]):not([data-label="Home Score"]):not([data-label="Away Score"]):not([data-label=""]) {
        order: 8;
        min-width: 50%;
    }

    /* Actual score highlight still works in card mode */
    .fussspool-table-mobile-cards td.fussspool-actual-score {
        background: transparent;
        font-weight: 600;
    }

    /* ---- Coupon form card layout ----
       Priority: Home/Away fixture → Score inputs + Qualifying → Pts → Time → Odds */

    /* Row 1 — Fixture: Home and Away side by side */
    /* (already covered by [data-label="Home"] and [data-label="Away"] at order:2) */

    /* Row 2 — Score inputs + Qualifying on same line */
    .fussspool-table-mobile-cards td[data-label="Home Score"],
    .fussspool-table-mobile-cards td[data-label="Away Score"] {
        order: 3;
        min-width: 40%;
        flex-direction: row;
        align-items: center;
        gap: 4px;
    }

    .fussspool-table-mobile-cards td[data-label="Qualifying"] {
        order: 3;
        min-width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }

    .fussspool-table-mobile-cards td[data-label="Qualifying"]::before {
        min-width: 6em;
        flex-shrink: 0;
    }

    /* Row 3 — Pts: estimated points, highlighted */
    .fussspool-table-mobile-cards td[data-label="Pts"] {
        order: 4;
        min-width: 100%;
        font-size: 18px;
        font-weight: 700;
        color: #0073aa;
        border-bottom: 1px solid #eee;
        padding-bottom: 6px;
        margin-bottom: 4px;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }

    /* Row 4 — Time: context, smaller */
    .fussspool-table-mobile-cards td[data-label="Time"] {
        order: 5;
        min-width: 100%;
        font-size: 11px;
        color: #666;
    }

    /* Row 5 — Odds: detail */
    .fussspool-table-mobile-cards td[data-label="1"],
    .fussspool-table-mobile-cards td[data-label="X"],
    .fussspool-table-mobile-cards td[data-label="2"] {
        order: 6;
        min-width: 33%;
    }

    /* Score inputs fill their cell nicely in card mode */
    .fussspool-table-mobile-cards td[data-label="Home Score"] .fussspool-score-input,
    .fussspool-table-mobile-cards td[data-label="Away Score"] .fussspool-score-input {
        width: 100%;
        max-width: 80px;
    }
}
