/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: 'Roboto', sans-serif;
    background: #f5f5f5;
    color: #212121;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Trackunit Brand Colors === */
:root {
    --primary: #1B1F3B;
    --primary-dark: #0F1229;
    --primary-light: rgba(27, 31, 59, 0.12);
    --accent: #FFD100;
    --accent-dark: #E6BC00;
    --success: #2e7d32;
    --error: #c62828;
    --surface: #ffffff;
    --on-surface: #212121;
    --on-surface-light: #757575;
    --divider: #e0e0e0;
    --shadow: 0 2px 4px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.08);
    --radius: 8px;
}

/* === Navbar === */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: white;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
}
.nav-brand img {
    height: 68px;
    filter: brightness(0) invert(1);
}
.nav-links {
    display: flex;
    align-items: center;
    gap: .25rem;
    flex-wrap: wrap;
}
.nav-link {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .875rem;
    transition: background .2s;
}
.nav-link:hover { background: rgba(255,255,255,.15); color: white; }
.nav-link-accent {
    margin-left: auto;
    background: var(--accent);
    color: #1B1F3B;
    font-weight: 700;
    border-radius: var(--radius);
}
.nav-link-accent:hover {
    background: var(--accent-dark);
    color: #1B1F3B;
}
.nav-user {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    color: rgba(255,255,255,.9);
    padding: .5rem .75rem;
    font-size: .875rem;
}

/* === Container === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    flex: 1;
}

/* === Cards === */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-title {
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--primary-dark);
}
.card-title .material-icons { font-size: 1.5rem; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    padding: .625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .2s, box-shadow .2s;
    line-height: 1.5;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); color: #1B1F3B; font-weight: 700; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #1b5e20; }
.btn-outline {
    background: transparent;
    color: white;
    border: 1px solid rgba(255,255,255,.5);
}
.btn-outline:hover { background: rgba(255,255,255,.15); }
.btn-sm { padding: .375rem .75rem; font-size: .8125rem; }
.btn-block { width: 100%; justify-content: center; }

/* === Forms === */
.form-group { margin-bottom: 1.25rem; }
.form-label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    color: var(--on-surface);
    margin-bottom: .375rem;
}
.form-control {
    width: 100%;
    padding: .625rem .75rem;
    border: 1px solid var(--divider);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: .9375rem;
    transition: border-color .2s, box-shadow .2s;
    background: var(--surface);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
select.form-control { appearance: auto; }

/* === Tables === */
.table-wrapper { overflow-x: auto; overflow-y: visible; }
.table-wrapper:has(.tooltip-trigger) { overflow: visible; }
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--divider);
}
th {
    font-size: .75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--on-surface-light);
    background: #fafafa;
}
tr:hover td { background: #f5f5f5; }

/* === Alerts === */
.alert {
    padding: .875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9375rem;
}
.alert-success { background: #e8f5e9; color: var(--success); border: 1px solid #c8e6c9; }
.alert-error { background: #ffebee; color: var(--error); border: 1px solid #ffcdd2; }

/* === Badge / Chip === */
.badge {
    display: inline-block;
    padding: .25rem .625rem;
    border-radius: 1rem;
    font-size: .75rem;
    font-weight: 500;
}
.badge-active { background: #e8f5e9; color: var(--success); }
.badge-inactive { background: #f5f5f5; color: var(--on-surface-light); }

/* === Rank number === */
.rank-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    font-weight: 700;
    font-size: .875rem;
}
.rank-1 { background: #FFF8E1; color: #C69500; }
.rank-2 { background: #f5f5f5; color: #616161; }
.rank-3 { background: #fff3e0; color: #e65100; }

/* === Rating display === */
.rating-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* === Tabs === */
.tabs {
    display: flex;
    gap: .25rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--divider);
}
.tab {
    padding: .75rem 1.25rem;
    text-decoration: none;
    color: var(--on-surface-light);
    font-weight: 500;
    font-size: .9375rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .2s, border-color .2s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === Grid === */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

/* === Hero === */
.hero {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 3rem 1.5rem;
    text-align: center;
    border-radius: var(--radius);
    margin-bottom: 2rem;
}
.hero h1 { font-size: 2rem; font-weight: 700; margin-bottom: .5rem; }
.hero p { font-size: 1.125rem; opacity: .9; }
.hero-logo { height: 80px; margin-bottom: 1rem; filter: brightness(0) invert(1); }

/* === Footer === */
.footer {
    background: var(--primary-dark);
    color: rgba(255,255,255,.7);
    text-align: center;
    padding: 1.5rem;
    margin-top: auto;
    font-size: .875rem;
}

/* === Helpers === */
.text-center { text-align: center; }
.text-muted { color: var(--on-surface-light); }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--on-surface-light);
}
.empty-state .material-icons { font-size: 3rem; margin-bottom: .5rem; display: block; }

/* === Auth pages === */
.auth-wrapper {
    max-width: 440px;
    margin: 2rem auto;
}

/* === Score display === */
.score { font-weight: 700; font-size: 1rem; }
.winner { color: var(--success); }
.loser { color: var(--error); }

/* === Rating change badges === */
.rating-change {
    display: inline-block;
    font-size: .6875rem;
    font-weight: 700;
    padding: .125rem .375rem;
    border-radius: .75rem;
    margin-left: .25rem;
    vertical-align: middle;
}
.rating-up { background: #e8f5e9; color: var(--success); }
.rating-down { background: #ffebee; color: var(--error); }

/* === Nerd mode toggle === */
.nerd-toggle {
    background: #f5f5f5;
    color: var(--on-surface-light);
    border: 1px solid var(--divider);
}
.nerd-toggle:hover {
    background: #eeeeee;
}
.nerd-toggle.nerd-active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* === Tooltip for nerd columns === */
.tooltip-trigger {
    position: relative;
    cursor: help;
    border-bottom: 1px dashed var(--on-surface-light);
}
.tooltip-trigger .tooltip-box {
    display: none;
    position: fixed;
    background: var(--primary-dark);
    color: white;
    font-size: .75rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1.4;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    width: 220px;
    white-space: normal;
    z-index: 10000;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}
.tooltip-trigger .tooltip-box::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--primary-dark);
}

/* === Home two-column layout === */
.home-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}
.home-col-left, .home-col-right {
    min-width: 0;
}

/* === Profile links === */
.profile-link {
    text-decoration: none;
    font-weight: 500;
    transition: opacity .2s;
}
.profile-link:hover {
    opacity: .8;
    text-decoration: underline;
}
.profile-link:not(.winner):not(.loser) {
    color: var(--primary);
}

/* === Responsive === */
@media (max-width: 768px) {
    .nav-container { flex-direction: column; }
    .nav-links { width: 100%; justify-content: center; }
    .hero h1 { font-size: 1.5rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .home-columns { grid-template-columns: 1fr; }
}
