/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-row-hover: #1e2a4a;
    --bg-input: #1a1a2e;
    --border: #2a2a4a;
    --text-primary: #e0e0e0;
    --text-secondary: #8888aa;
    --text-muted: #555577;
    --accent: #6c5ce7;
    --accent-hover: #7f70f0;
    --green: #00e676;
    --green-dim: #00a854;
    --red: #ff5252;
    --red-dim: #c62828;
    --yellow: #ffd740;
    --orange: #ff9100;
    --header-bg: #12122a;
    --tab-active: #6c5ce7;
    --tab-inactive: transparent;
    --scrollbar-track: #1a1a2e;
    --scrollbar-thumb: #2a2a4a;
}

html { font-size: 14px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a5a; }

/* ── Header ───────────────────────────────────────────────────────────── */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.header h1 span {
    color: var(--accent);
}

/* ── Controls Bar ─────────────────────────────────────────────────────── */
.controls {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.position-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
}

.position-tab {
    padding: 0.4rem 0.75rem;
    border: none;
    background: var(--tab-inactive);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.position-tab:hover {
    color: var(--text-primary);
    background: rgba(108, 92, 231, 0.15);
}

.position-tab.active {
    background: var(--tab-active);
    color: #fff;
}

/* ── Search & Filters ─────────────────────────────────────────────────── */
.search-box {
    position: relative;
    flex: 0 1 220px;
}

.search-box input {
    width: 100%;
    padding: 0.45rem 0.75rem 0.45rem 2rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.15s;
}

.search-box input:focus {
    border-color: var(--accent);
}

.search-box::before {
    content: '\1F50D';
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    opacity: 0.5;
}

.filter-select {
    padding: 0.45rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    min-width: 120px;
}

.filter-select:focus {
    border-color: var(--accent);
}

.filter-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.controls-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.player-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.btn {
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.1);
}

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-accent:hover {
    background: var(--accent-hover);
}

/* ── Table ────────────────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 120px);
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 1100px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

thead th {
    background: var(--header-bg);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.55rem 0.5rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color 0.15s;
    position: relative;
}

thead th:hover {
    color: var(--text-primary);
}

thead th.sorted {
    color: var(--accent);
}

thead th .sort-arrow {
    font-size: 0.6rem;
    margin-left: 3px;
    opacity: 0;
    transition: opacity 0.15s;
}

thead th.sorted .sort-arrow {
    opacity: 1;
}

/* Column widths */
.col-name { width: 180px; }
.col-team { width: 55px; }
.col-pos { width: 55px; }
.col-price { width: 80px; }
.col-avg { width: 55px; }
.col-3ra { width: 50px; }
.col-5ra { width: 50px; }
.col-be { width: 50px; }
.col-own { width: 60px; }
.col-round { width: 48px; }
.col-prev-avg { width: 60px; }
.col-prev-gms { width: 50px; }
.col-injury { width: 30px; }

tbody tr {
    border-bottom: 1px solid rgba(42, 42, 74, 0.5);
    transition: background 0.1s;
}

tbody tr:hover {
    background: var(--bg-row-hover);
}

tbody td {
    padding: 0.5rem 0.5rem;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Name Cell ────────────────────────────────────────────────────────── */
.player-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.player-name .name-text {
    font-weight: 600;
    color: var(--text-primary);
}

.player-name .first-name {
    font-weight: 400;
    color: var(--text-secondary);
}

/* ── Team Badge ───────────────────────────────────────────────────────── */
.team-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #fff;
    text-align: center;
}

/* ── Position Badge ───────────────────────────────────────────────────── */
.pos-badge {
    display: inline-block;
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(108, 92, 231, 0.15);
    color: var(--accent);
}

/* ── Score Cells ──────────────────────────────────────────────────────── */
.score-cell {
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.score-high { color: var(--green); }
.score-mid { color: var(--text-primary); }
.score-low { color: var(--red); }
.score-dnp { color: var(--text-muted); font-weight: 400; font-style: italic; }

/* ── Price ────────────────────────────────────────────────────────────── */
.price-cell {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* ── Ownership Bar ────────────────────────────────────────────────────── */
.own-cell {
    position: relative;
}

.own-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: rgba(108, 92, 231, 0.12);
    border-radius: 0 3px 3px 0;
    transition: width 0.3s;
}

.own-text {
    position: relative;
    z-index: 1;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-size: 0.8rem;
}

/* ── BE Cell ──────────────────────────────────────────────────────────── */
.be-positive { color: var(--red); }
.be-negative { color: var(--green); }
.be-neutral { color: var(--text-secondary); }

/* ── Status Icons (Injury / Suspended / Bye) ─────────────────────────── */
.status-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    cursor: help;
    flex-shrink: 0;
    line-height: 1;
}

.status-injury {
    background: rgba(255, 82, 82, 0.15);
    color: var(--red);
    border: 1px solid rgba(255, 82, 82, 0.3);
    font-size: 0.7rem;
}

.status-suspended {
    background: rgba(255, 145, 0, 0.15);
    color: var(--orange);
    border: 1px solid rgba(255, 145, 0, 0.3);
    font-size: 0.7rem;
}

.status-bye {
    background: rgba(136, 136, 170, 0.15);
    color: var(--text-secondary);
    border: 1px solid rgba(136, 136, 170, 0.3);
    font-size: 0.65rem;
}

/* ── Sticky columns ───────────────────────────────────────────────────── */
thead th:first-child,
tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
}

thead th:first-child {
    z-index: 15;
    background: var(--header-bg);
}

tbody td:first-child {
    background: var(--bg-primary);
}

tbody tr:hover td:first-child {
    background: var(--bg-row-hover);
}

/* ── Upload Panel ─────────────────────────────────────────────────────── */
.upload-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.upload-overlay.active {
    display: flex;
}

.upload-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 560px;
    width: 90%;
}

.upload-panel h2 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.upload-panel p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 1rem;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.05);
}

.upload-zone p {
    margin: 0;
    color: var(--text-secondary);
}

.upload-zone .upload-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

.upload-file-input {
    display: none;
}

.upload-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-height: 1.5rem;
}

.upload-status.success { color: var(--green); }
.upload-status.error { color: var(--red); }

.upload-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ── Year Tabs (for stats history) ────────────────────────────────────── */
.year-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
}

.year-tab {
    padding: 0.35rem 0.6rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
}

.year-tab:hover { color: var(--text-primary); }
.year-tab.active { background: var(--accent); color: #fff; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .header { padding: 0.5rem 1rem; }
    .controls { padding: 0.5rem 1rem; }
    .search-box { flex: 1 1 180px; }
    .col-round { display: none; }
    .col-prev-avg { display: none; }
    .col-prev-gms { display: none; }
    table { min-width: 700px; }
}

/* ── Loading ──────────────────────────────────────────────────────────── */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--text-secondary);
    gap: 1rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Empty State ──────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

/* ── Tooltip ──────────────────────────────────────────────────────────── */
.tooltip {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    color: var(--text-primary);
    z-index: 300;
    pointer-events: none;
    max-width: 280px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    line-height: 1.4;
}

/* ── Price format ─────────────────────────────────────────────────────── */
.price-k {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ── Hot/Cold indicator ───────────────────────────────────────────────── */
.hot-indicator { color: var(--orange); margin-left: 4px; font-size: 0.7rem; }
.cold-indicator { color: #4fc3f7; margin-left: 4px; font-size: 0.7rem; }
