/* ============================================
   Blue Chip Analytics - Rankings Page (Shared)
   Used by: power-ratings/index.php
            home-field-advantage/index.php
   
   Both pages share an identical layout: stat
   cards, controls bar, conference legend,
   chart/table toggle, and responsive rules.
   Extends base.css
   ============================================ */

/* Page title styled globally via base.css h1.page-title */

/* ---- Controls Bar (Search / Filter / View toggle) ---- */
.controls {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.control-group {
    flex: 1;
    min-width: 200px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input,
select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

/* ---- Summary Stat Cards ---- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 14px;
}

.stat-card {
    background: var(--color-brand-gradient);
    color: white;
    padding: 14px 16px;
    border-radius: 8px;
    text-align: center;
}

.stat-card h3 {
    margin: 0 0 6px 0;
    font-size: 14px;
}

.stat-card .number {
    font-size: 20px;
    font-weight: bold;
}

/* ---- Chart Container ---- */
.chart-container {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    border: 1px solid #eee;
}

.chart {
    width: 100%;
    height: 400px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* ---- Rankings Table ---- */
.table-container {
    background: white;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid #eee;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background: #f8f9fa;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
}

th:hover {
    background: var(--color-border-mid);
}

tr:hover {
    background: #f8f9fa;
}

/* Numeric/measure columns right-aligned; label columns stay left */
th.num,
td.num {
    text-align: right;
}

/* ---- Conference Tags ---- */
.conference-tag {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    color: white;
}

/* One class per conference — mirrors the conferenceColors object in JS.
   Space replaced with hyphen via: team.conference.replace(/\s+/g, '-') */
.SEC         { background: #FF6B35; }
.Big-Ten     { background: #0066CC; }
.ACC         { background: #8B0000; }
.Big-12      { background: #FFD700; }
.Pac-12      { background: #8A2BE2; }
.American    { background: #FF1744; }
.MW          { background: #2E8B57; }
.Sun-Belt    { background: #FF8C00; }
.CUSA        { background: #800080; }
.MAC         { background: #228B22; }
.Independent { background: #708090; }

/* ---- Conference Legend ---- */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

.legend-color {
    width: 15px;
    height: 15px;
    border-radius: 3px;
}

/* ============================================
   Responsive Overrides
   ============================================ */

/* Tablet & below (≤768px) */
@media (max-width: 768px) {
    /* Tighten the raised card and the table-section card so tables use more of
       the screen width — removes the extra inset between page edge and table. */
    body.page-raised .container {
        padding: 12px 6px;
    }
    .top10-summary {
        padding: 12px 4px;
    }

    /* Controls */
    .controls {
        flex-direction: column;
        gap: 15px;
        margin-bottom: 20px;
    }

    .control-group {
        min-width: unset;
    }

    label {
        font-size: 14px;
    }

    input,
    select {
        padding: 12px;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 6px;
    }

    input:focus,
    select:focus {
        outline: 2px solid var(--color-brand-light);
        outline-offset: 2px;
    }

    /* Stat cards: tight 2×2 grid on tablet/mobile */
    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 14px;
    }

    .stat-card {
        padding: 10px 8px;
        border-radius: 6px;
    }

    .stat-card h3 {
        font-size: 11px;
        margin-bottom: 4px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        opacity: 0.9;
    }

    .stat-card .number {
        font-size: 20px;
        font-weight: 700;
        line-height: 1;
    }

    /* Reorder main content: table first, chart second */
    .main-content {
        display: flex;
        flex-direction: column;
    }

    .chart-container {
        order: 2;
        padding: 15px;
        margin-bottom: 0;
        margin-top: 20px;
    }

    .chart-container h3 {
        font-size: 16px;
        margin-bottom: 15px;
    }

    .chart {
        height: 300px;
    }

    .table-container {
        order: 1;
        margin-bottom: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    /* Horizontal scroll indicator */
    .table-container::-webkit-scrollbar {
        height: 6px;
    }

    .table-container::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    .table-container::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 3px;
    }

    .table-container::-webkit-scrollbar-thumb:hover {
        background: #a1a1a1;
    }

    /* Compact tables that fit the viewport — no horizontal scroll (both the
       Top-10 summary and the interactive table). */
    table {
        width: 100%;
        font-size: 13px;
    }

    th,
    td {
        padding: 6px 5px;
        white-space: normal;
    }

    th {
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* Hide sort-direction arrows on mobile — they break header alignment. */
    .sort-arrow {
        display: none;
    }

    /* Give the interactive table the same header look as the Top-10 summary. */
    .table-container th {
        background: var(--color-bg-subtle);
        color: var(--color-brand-dark);
        font-size: 0.85em;
        font-weight: 600;
        letter-spacing: 0.03em;
    }

    /* Rank column: compress to its content. */
    th:first-child,
    td:first-child {
        width: 1%;
        white-space: nowrap;
        padding-right: 4px;
    }

    /* Team name column: slightly larger, no forced min-width. */
    td:nth-child(2) {
        font-weight: 600;
        font-size: 1.08em;
    }

    /* Compact conference tags */
    .conference-tag {
        padding: 2px 6px;
        font-size: 10px;
        border-radius: 8px;
    }

    /* Compact legend */
    .legend {
        gap: 8px;
        margin-bottom: 15px;
    }

    .legend-item {
        font-size: 11px;
        gap: 4px;
    }

    .legend-color {
        width: 12px;
        height: 12px;
    }

    /* Touch-friendly tap targets */
    th,
    tr {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

/* Extra small screens (≤480px) */
@media (max-width: 480px) {
    /* Stat cards: keep the 2×2 grid at all mobile widths */
    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .stat-card {
        padding: 8px 6px;
    }

    .stat-card h3 {
        font-size: 10px;
    }

    .stat-card .number {
        font-size: 18px;
    }

    /* Left-align legend when space is tight */
    .legend {
        justify-content: flex-start;
    }

    table {
        font-size: 12px;
    }

    th,
    td {
        padding: 6px 4px;
    }
}
