/* ============================================
   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-level overrides ----
   base.css sets background: #f7f7f7 on body.
   These pages use a white background with
   padded body instead. */
body {
    background: white;
    padding: 20px;
    min-height: 100vh;
}

/* ---- Container ----
   base.css defines .container without a shadow.
   These pages use a heavier card shadow. */
.container {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* ---- Page Title ---- */
h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
}

/* ---- 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: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #1a365d 0%, #2c5282 50%, #3182ce 100%);
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
}

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

.stat-card .number {
    font-size: 24px;
    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: hidden;
    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: #e9ecef;
}

tr:hover {
    background: #f8f9fa;
}

/* ---- 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) {
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    }

    h1 {
        font-size: 24px;
        margin-bottom: 20px;
    }

    /* 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 #3182ce;
        outline-offset: 2px;
    }

    /* Stat cards: 2-column grid on tablet */
    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-card h3 {
        font-size: 14px;
        margin-bottom: 8px;
    }

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

    /* 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 table — horizontal scroll rather than wrapping */
    table {
        min-width: 600px;
        font-size: 14px;
    }

    th,
    td {
        padding: 8px 6px;
        white-space: nowrap;
    }

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

    /* Team name column: readable minimum width */
    td:nth-child(2) {
        font-weight: 500;
        min-width: 180px;
    }

    /* 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: single column */
    .stats {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 12px;
    }

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

    table {
        min-width: 550px;
        font-size: 13px;
    }

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