/* ═══════════════════════════════════════════════════════
   VELO Dashboard – Theme
   ═══════════════════════════════════════════════════════ */

/* ─── Variables (Dark – default) ─── */
:root,
[data-theme="dark"] {
    --bg-0: #07090f;
    --bg-1: #0d1117;
    --bg-2: #161b22;
    --bg-3: #1c2333;
    --bg-hover: #1f2d3d;
    --bg-active: #253347;

    --border: #30363d;
    --border-light: #3d444d;

    --text-0: #f0f6fc;
    --text-1: #e6edf3;
    --text-2: #8b949e;
    --text-3: #6e7681;

    --green: #3fb950;
    --green-dim: #238636;
    --red: #f85149;
    --red-dim: #da3633;
    --blue: #58a6ff;
    --cyan: #39d2c0;
    --amber: #d29922;
    --purple: #bc8cff;
    --orange: #f0883e;

    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 8px 24px rgba(0, 0, 0, .4);
    --transition: 150ms ease;

    --bg-even-row: #111520;
    --header-bg: rgba(13,17,23,.85);
}

/* ─── Variables (Light) ─── */
[data-theme="light"] {
    --bg-0: #f0f2f5;
    --bg-1: #ffffff;
    --bg-2: #f6f8fa;
    --bg-3: #eaeef2;
    --bg-hover: #e2e8f0;
    --bg-active: #d0d7de;

    --border: #d0d7de;
    --border-light: #bbc0c7;

    --text-0: #1b1f24;
    --text-1: #24292f;
    --text-2: #57606a;
    --text-3: #8b949e;

    --green: #1a7f37;
    --green-dim: #2da44e;
    --red: #cf222e;
    --red-dim: #d1242f;
    --blue: #0969da;
    --cyan: #1b9e8c;
    --amber: #9a6700;
    --purple: #8250df;
    --orange: #bc4c00;

    --shadow: 0 8px 24px rgba(140,149,159,.2);

    --bg-even-row: #f6f8fa;
    --header-bg: rgba(255,255,255,.85);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background: var(--bg-0);
    color: var(--text-1);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

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

/* ═══════════════════ AUTH GATE ═══════════════════ */
#auth-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(59,130,246,.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(16,185,129,.06) 0%, transparent 50%),
        var(--bg-0);
}

.auth-card {
    text-align: center;
    padding: 3rem 2.5rem;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    min-width: 360px;
}

.auth-logo {
    font-family: var(--font-mono);
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: .25rem;
    letter-spacing: .15em;
}

.logo-bracket { color: var(--text-3); }
.logo-text    { color: var(--cyan); }

.auth-subtitle {
    font-family: var(--font-mono);
    font-size: .75rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .2em;
    margin-bottom: 2rem;
}

.auth-fullname {
    font-family: var(--font-mono);
    font-size: .65rem;
    color: var(--text-2);
    letter-spacing: .12em;
    margin-bottom: .15rem;
}

.auth-input-wrap {
    display: flex;
    align-items: center;
    background: var(--bg-0);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 1rem;
    margin-bottom: 1.25rem;
    transition: border-color var(--transition);
}

.auth-input-wrap:focus-within {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(57,210,192,.1);
}

.prompt {
    font-family: var(--font-mono);
    color: var(--cyan);
    font-size: 1rem;
    margin-right: .5rem;
    user-select: none;
}

#auth-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-0);
    font-family: var(--font-mono);
    font-size: .95rem;
    padding: .75rem 0;
    letter-spacing: .05em;
}

#auth-input::placeholder { color: var(--text-3); }

#auth-submit {
    width: 100%;
    padding: .7rem;
    background: var(--cyan);
    color: var(--bg-1);
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .15em;
    cursor: pointer;
    transition: all var(--transition);
}

#auth-submit:hover {
    background: #4ae8d6;
    box-shadow: 0 0 20px rgba(57,210,192,.3);
}

.error {
    color: var(--red);
    font-family: var(--font-mono);
    font-size: .8rem;
    margin-top: 1rem;
    letter-spacing: .1em;
}

/* ═══════════════════ HEADER ═══════════════════ */
#header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 48px;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-small {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .1em;
    margin-right: 1rem;
    display: flex;
    align-items: baseline;
    gap: .5rem;
}

.logo-fullname {
    font-size: .55rem;
    font-weight: 400;
    color: var(--text-3);
    letter-spacing: .06em;
}

#widget-nav { display: flex; gap: .25rem; }

.nav-btn {
    font-family: var(--font-mono);
    font-size: .75rem;
    padding: .35rem .75rem;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-2);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: .05em;
}

.nav-btn:hover { color: var(--text-1); background: var(--bg-2); }

.nav-btn.active {
    color: var(--cyan);
    border-color: var(--cyan);
    background: rgba(57,210,192,.08);
}

.meta-text {
    font-family: var(--font-mono);
    font-size: .7rem;
    color: var(--text-3);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-3);
    font-size: 1.1rem;
    cursor: pointer;
    padding: .25rem;
    transition: color var(--transition);
}

.btn-icon:hover { color: var(--red); }

/* ─── Theme Toggle ─── */
#theme-toggle {
    font-size: 1rem;
    line-height: 1;
}

#theme-toggle:hover { color: var(--cyan); }

/* ═══════════════════ MAIN CONTENT ═══════════════════ */
#widget-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ─── Widget Card ─── */
.widget {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: .75rem;
    flex-wrap: wrap;
}

.widget-header-left {
    display: flex;
    align-items: center;
}

.widget-title {
    font-family: var(--font-mono);
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-0);
    display: flex;
    align-items: center;
    gap: .5rem;
}

.widget-title .icon { font-size: 1rem; }

.widget-badge {
    font-family: var(--font-mono);
    font-size: .65rem;
    padding: .15rem .5rem;
    border-radius: 999px;
    background: rgba(57,210,192,.1);
    color: var(--cyan);
    border: 1px solid rgba(57,210,192,.2);
    flex-shrink: 0;
}

/* ─── Widget Tabs ─── */
.widget-tabs {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
}

.widget-tab {
    font-family: var(--font-mono);
    font-size: .7rem;
    font-weight: 500;
    padding: .3rem .65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.widget-tab:hover {
    color: var(--text-1);
    border-color: var(--text-3);
}

.widget-tab.active {
    background: rgba(57,210,192,.12);
    color: var(--cyan);
    border-color: rgba(57,210,192,.35);
    font-weight: 600;
}

/* ─── Search Bar ─── */
.search-wrap {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
}

.search-icon { color: var(--text-3); font-size: .85rem; }

.search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-1);
    font-family: var(--font-mono);
    font-size: .8rem;
}

.search-input::placeholder { color: var(--text-3); }

.search-count {
    font-family: var(--font-mono);
    font-size: .7rem;
    color: var(--text-3);
}

/* ─── Table ─── */
.table-wrap { overflow-x: auto; overflow-y: auto; max-height: 75vh; }

table { width: 100%; border-collapse: collapse; font-size: .82rem; }

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

th {
    font-family: var(--font-mono);
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-3);
    padding: .6rem .75rem;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
    user-select: none;
    cursor: pointer;
    transition: color var(--transition);
}

th:hover { color: var(--text-1); }
th.sort-asc, th.sort-desc { color: var(--cyan); }

th .sort-arrow {
    display: inline-block;
    margin-left: .3rem;
    font-size: .6rem;
    opacity: .3;
}

th.sort-asc .sort-arrow,
th.sort-desc .sort-arrow { opacity: 1; color: var(--cyan); }

th.align-right { text-align: right; }
th.align-center { text-align: center; }

td {
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: .8rem;
}

td.align-right { text-align: right; }
td.align-center { text-align: center; }

tr { transition: background var(--transition); cursor: pointer; }

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

/* ─── Cell Formatting ─── */
.cell-positive  { color: var(--green); }
.cell-negative  { color: var(--red); }
.cell-neutral   { color: var(--text-2); }
.cell-highlight { color: var(--amber); }
.cell-muted     { color: var(--text-3); }

.cell-team { font-weight: 600; text-transform: capitalize; }

.cell-matchup {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.cell-matchup .at { color: var(--text-3); font-weight: 400; font-size: .7rem; }

/* ─── Frozen (sticky) columns ─── */
th.col-frozen,
td.col-frozen {
    position: sticky;
    z-index: 5;
}

thead th.col-frozen {
    z-index: 15;  /* Above sticky header (10) and frozen body cells (5) */
}

td.col-frozen {
    background: var(--bg-1);
}

tbody tr:nth-child(even) td.col-frozen {
    background: var(--bg-even-row);
}

tbody tr:hover td.col-frozen {
    background: var(--bg-hover);
}

tbody tr:nth-child(even):hover td.col-frozen {
    background: var(--bg-hover);
}

/* ─── Probability Bar ─── */
.prob-cell {
    display: flex;
    align-items: center;
    gap: .5rem;
    justify-content: center;
}

.prob-bar {
    width: 50px;
    height: 4px;
    background: var(--bg-3);
    border-radius: 2px;
    overflow: hidden;
}

.prob-fill {
    height: 100%;
    border-radius: 2px;
    transition: width .3s ease;
}

.prob-fill.high { background: var(--green); }
.prob-fill.mid  { background: var(--amber); }
.prob-fill.low  { background: var(--red); }

/* ═══════════════════ MODAL ═══════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 150ms ease;
}

.modal {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(0,0,0,.5);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 200ms ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-1);
}

.modal-header h2 {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-0);
}

.modal-header .btn-icon { font-size: 1.4rem; }

#modal-body { padding: 1.5rem; }

/* ─── Detail Grid ─── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.detail-section {
    padding: 1rem;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.detail-section h3 {
    font-family: var(--font-mono);
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .1em;
    margin-bottom: .75rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: .3rem 0;
    font-family: var(--font-mono);
    font-size: .8rem;
}

.detail-label { color: var(--text-3); }
.detail-value { color: var(--text-0); font-weight: 500; }

.detail-section.full-width { grid-column: 1 / -1; }

/* ═══════════════════ TOOLTIP ═══════════════════ */
.tooltip {
    position: fixed;
    z-index: 300;
    padding: .5rem .75rem;
    background: var(--bg-3);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
    font-family: var(--font-mono);
    font-size: .75rem;
    color: var(--text-1);
    pointer-events: none;
    max-width: 280px;
    white-space: pre-line;
}

/* ═══════════════════ ANIMATIONS ═══════════════════ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════ LOADING STATE ═══════════════════ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    font-family: var(--font-mono);
    font-size: .85rem;
    color: var(--text-3);
}

.loading::after {
    content: '';
    width: 16px; height: 16px;
    margin-left: .75rem;
    border: 2px solid var(--border);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

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

/* ═══════════════════ EMPTY STATE ═══════════════════ */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    font-family: var(--font-mono);
}

.empty-state .icon { font-size: 2rem; margin-bottom: 1rem; }
.empty-state p { color: var(--text-3); font-size: .85rem; }

/* ─── Game Status Indicators ─── */
tr.game-live td { opacity: 0.55; }
tr.game-live td.col-frozen { opacity: 0.55; }
tr.game-final td { opacity: 0.45; }
tr.game-final td.col-frozen { opacity: 0.45; }

tr.game-live td:first-child::before,
tr.game-final td:first-child::before {
    display: inline-block;
    margin-right: .3rem;
    font-size: .7em;
    vertical-align: middle;
}

.status-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: .6rem;
    font-weight: 600;
    letter-spacing: .06em;
    padding: .1rem .35rem;
    border-radius: 3px;
    text-transform: uppercase;
    margin-left: .4rem;
    vertical-align: middle;
}

.status-live {
    background: rgba(218,54,51,.18);
    color: var(--red);
    border: 1px solid rgba(218,54,51,.3);
}

.status-final {
    background: rgba(139,148,158,.15);
    color: var(--text-3);
    border: 1px solid rgba(139,148,158,.25);
}

.game-score {
    font-family: var(--font-mono);
    font-size: .75em;
    font-weight: 600;
    color: var(--text-2);
    margin-left: .3rem;
}

/* ─── Team Record (Season Outlook) ─── */
.team-record {
    display: block;
    font-size: .7em;
    font-weight: 400;
    color: var(--text-3);
    line-height: 1.2;
}

/* ═══════════════════ RESPONSIVE ═══════════════════ */

/* Fluid base font: scales from ~13px at 320px to 16px at 1200px */
html { font-size: clamp(0.8rem, 0.65rem + 0.5vw, 1rem); }

@media (max-width: 768px) {
    #header { padding: 0 .75rem; }
    #widget-container { padding: .75rem; }
    .detail-grid { grid-template-columns: 1fr; }
    .auth-card { min-width: auto; margin: 1rem; }
    .meta-text { display: none; }
    .logo-fullname { display: none; }

    /* Unfreeze sticky columns on mobile — they take too much horizontal space */
    th.col-frozen,
    td.col-frozen {
        position: static !important;
        left: auto !important;
        z-index: auto !important;
    }

    /* Compact table for narrow screens (px values avoid compounding with fluid root) */
    th  { padding: 5px 4px; font-size: 10px; letter-spacing: .02em; }
    td  { padding: 4px 4px;  font-size: 11px; }
    .val-heat { padding: 1px 2px; }
    .val-prob { font-size: 0.65em; }
    .team-record { font-size: .6em; }
}

/* Mid-size screens: slightly tighter table */
@media (max-width: 1200px) and (min-width: 769px) {
    th  { padding: .45rem .4rem; font-size: .65rem; }
    td  { padding: .4rem .4rem;  font-size: .74rem; }
    .val-heat { padding: 1px 3px; }
}
