/* ==========================================================================
   Cosmic BB Stats — Front-end Stats Tables
   Colors are controlled via CSS custom properties.
   Defaults can be overridden from BB Stats → Settings → Table Colors.
   ========================================================================== */

/* ── Default CSS Variables ───────────────────────────────────────────────── */
.cbs-stats-wrapper {
    --cbs-header-bg:      #333366;
    --cbs-header-text:    #ffffff;
    --cbs-border:         #f503f9;
    --cbs-table-bg:       #0a0a1a;
    --cbs-stats-text:     #ffffff;
    --cbs-player-name:    #5efb42;
    --cbs-accent:         #f503f9;
    --cbs-row-alt-bg:     #141428;
    --cbs-title-color:    #ffffff;
    --cbs-label-color:    #cccccc;
    /* Cosmic Stats */
    --cbs-cosmic:         #b44fff;
    /* Team name colors */
    --cbs-team-chili:     #ff4444;
    --cbs-team-glow:      #5efb42;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--cbs-stats-text);
    max-width: 100%;
}

/* ── Season Picker ───────────────────────────────────────────────────────── */
.cbs-season-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.cbs-season-picker label {
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cbs-label-color);
}

.cbs-season-select {
    padding: 6px 12px;
    border: 1px solid var(--cbs-border);
    border-radius: 3px;
    font-size: 14px;
    cursor: pointer;
    background: var(--cbs-table-bg);
    color: var(--cbs-accent);
    font-weight: 600;
    transition: all 0.2s;
}

.cbs-season-select:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--cbs-accent);
}

/* ── Tab Switcher (for [cbs_stats]) ─────────────────────────────────────── */
.cbs-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--cbs-border);
    margin-bottom: 0;
}

.cbs-tab {
    padding: 10px 28px;
    background: var(--cbs-row-alt-bg);
    border: 1px solid var(--cbs-border);
    border-bottom: none;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--cbs-label-color);
    transition: background 0.15s, color 0.15s;
    border-radius: 3px 3px 0 0;
}

.cbs-tab:hover {
    opacity: 0.85;
    color: var(--cbs-accent);
}

.cbs-tab--active {
    background: var(--cbs-accent);
    color: #ffffff;
    border-color: var(--cbs-accent);
}

.cbs-tab--active:hover {
    opacity: 0.9;
    color: #ffffff;
}

.cbs-tab-panel--hidden {
    display: none;
}

/* ── Table Title ─────────────────────────────────────────────────────────── */
.cbs-table-title {
    font-size: 1.4em;
    margin-bottom: 14px;
    color: var(--cbs-title-color);
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* ── Table Container (scrolls both axes; sticky needs a defined scroll ancestor) */
.cbs-table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 600px;
    -webkit-overflow-scrolling: touch;
    border-radius: 3px;
    border: 1px solid var(--cbs-border);
    box-shadow: 0 0 12px rgba(245, 3, 249, 0.2);
    margin-bottom: 24px;
}

/* ── Stats Table ─────────────────────────────────────────────────────────── */
.cbs-stats-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    background: var(--cbs-table-bg);
    font-size: 14px;
    border-spacing: 0;
    margin-block-end: 0;
    margin-bottom: 0;
    table-layout: auto;
}

/* Header */
.cbs-stats-table thead tr {
    background: var(--cbs-header-bg);
    color: var(--cbs-header-text);
}

.cbs-stats-table thead th {
    padding: 11px 10px;
    text-align: center;
    white-space: nowrap;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: default;
    user-select: none;
    color: var(--cbs-header-text);
    background: var(--cbs-header-bg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    position: sticky;
    top: 0;
    z-index: 2;
}

.cbs-stats-table thead th:last-child {
    border-right: none;
}

.cbs-stats-table thead th.cbs-col-player {
    text-align: left;
    padding-left: 14px;
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    white-space: normal;
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    position: sticky;
    left: 0;
    z-index: 3;
}

/* Sortable column affordance */
.cbs-stats-table thead th.cbs-sortable {
    cursor: pointer;
}

.cbs-stats-table thead th.cbs-sortable:hover {
    opacity: 0.85;
}

.cbs-stats-table thead th.cbs-sort-asc::after {
    content: ' ▲';
    font-size: 9px;
    opacity: 0.9;
}

.cbs-stats-table thead th.cbs-sort-desc::after {
    content: ' ▼';
    font-size: 9px;
    opacity: 0.9;
}

/* Body */
.cbs-stats-table tbody tr {
    border-bottom: 1px solid var(--cbs-border);
}

.cbs-stats-table tbody tr:last-child {
    border-bottom: none;
}

.cbs-stats-table tbody td {
    padding: 9px 10px;
    text-align: center;
    white-space: nowrap;
    color: var(--cbs-stats-text);
    border: 1px solid var(--cbs-border);
    vertical-align: middle;
    background: transparent;
}

.cbs-stats-table tbody td.cbs-col-player {
    text-align: left;
    padding-left: 14px;
    font-weight: 700;
    color: var(--cbs-player-name);
    letter-spacing: 0.01em;
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    white-space: normal;
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--cbs-table-bg);
}

.cbs-stats-table tbody tr:nth-child(even) td.cbs-col-player {
    background: var(--cbs-row-alt-bg);
}

/* Rate stats (AVG, OBP, SLG, ERA, etc.) */
.cbs-stats-table td.cbs-rate {
    font-weight: 700;
    color: var(--cbs-accent);
}

/* OPS highlight — same accent as other rate stats */
.cbs-stats-table td.cbs-ops {
    font-weight: 700;
    color: var(--cbs-accent);
}

/* Cosmic Stats (B4F, B4F%) */
.cbs-stats-table td.cbs-cosmic {
    font-weight: 700;
    color: var(--cbs-cosmic);
}

/* Cosmic column header tint */
.cbs-stats-table thead th.cbs-col-cosmic {
    color: var(--cbs-cosmic);
}

/* Team-based player name colors */
.cbs-stats-table td.cbs-col-player.cbs-player-chili {
    color: var(--cbs-team-chili);
}

.cbs-stats-table tbody tr:nth-child(even) td.cbs-col-player.cbs-player-chili {
    color: var(--cbs-team-chili);
}

.cbs-stats-table td.cbs-col-player.cbs-player-glow {
    color: var(--cbs-team-glow);
}

.cbs-stats-table tbody tr:nth-child(even) td.cbs-col-player.cbs-player-glow {
    color: var(--cbs-team-glow);
}

/* ── B4F Explainer Tooltip ───────────────────────────────────────────────── */
.cbs-stats-table thead th[data-cbs-tooltip] {
    cursor: help;
}

#cbs-tooltip {
    position: fixed;
    z-index: 99999;
    background: #1a0a2e;
    color: var(--cbs-stats-text, #ffffff);
    border: 1px solid var(--cbs-cosmic, #b44fff);
    border-radius: 5px;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    white-space: normal;
    width: 240px;
    pointer-events: none;
    line-height: 1.5;
    box-shadow: 0 2px 12px rgba(180, 79, 255, 0.5);
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* Zebra rows */
.cbs-stats-table tbody tr:nth-child(even) {
    background: var(--cbs-row-alt-bg);
}

/* ── Team Logo Column ────────────────────────────────────────────────────── */
.cbs-stats-table thead th.cbs-col-team,
.cbs-stats-table tbody td.cbs-col-team {
    width: 58px;
    min-width: 58px;
    text-align: center;
    padding: 4px 6px;
    vertical-align: middle;
}

.cbs-team-logo {
    max-width: 50px;
    max-height: 50px;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
    filter: drop-shadow( 0 0 4px rgba(0, 0, 0, 0.6) );
}

/* ── Demo Mode Banner ────────────────────────────────────────────────────── */
.cbs-demo-banner {
    padding: 10px 16px;
    margin-bottom: 12px;
    background: #fffbea;
    border: 2px solid #f0c040;
    border-radius: 4px;
    color: #5a4000;
    font-size: 13px;
}

.cbs-demo-banner a {
    color: #2271b1;
}

/* ── No Data Message ─────────────────────────────────────────────────────── */
.cbs-no-data {
    padding: 24px;
    text-align: center;
    color: var(--cbs-label-color);
    font-style: italic;
    background: var(--cbs-row-alt-bg);
    border: 1px solid var(--cbs-border);
    border-radius: 3px;
}

/* ── Responsive Adjustments ──────────────────────────────────────────────── */
@media screen and (max-width: 768px) {
    .cbs-table-container {
        overflow-x: auto;
        overflow-y: auto;
    }

    .cbs-stats-table {
        font-size: 12px;
        min-width: 880px; /* ⬅️ gives ALL columns more breathing room */
    }

    .cbs-stats-table thead th,
    .cbs-stats-table tbody td {
        padding: 7px 7px; /* ⬅️ slightly wider cells */
    }

    /* Player column */
    .cbs-stats-table thead th.cbs-col-player,
    .cbs-stats-table tbody td.cbs-col-player {
        width: 140px;
        min-width: 140px;
        max-width: 140px;
        padding-left: 10px;
        padding-right: 10px;
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: normal;
        hyphens: none;
        line-height: 1.25;
    }

    /* Stat columns */
    .cbs-stats-table thead th:not(.cbs-col-player),
    .cbs-stats-table tbody td:not(.cbs-col-player) {
        min-width: 60px; /* ⬅️ ensures stats don't collapse too tight */
    }

    .cbs-tab {
        padding: 8px 14px;
        font-size: 12px;
    }
}