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

:root {
    --primary: #1a5f2a;
    --primary-hover: #14491f;
    --danger: #c0392b;
    --success: #27ae60;
    --bg: #f5f5f5;
    --card-bg: #fff;
    --text: #333;
    --text-muted: #777;
    --border: #ddd;
    --gold: #f1c40f;
    --silver: #bdc3c7;
    --bronze: #cd7f32;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
    background: var(--primary);
    color: #fff;
    padding: 0.75rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.nav-brand {
    color: #fff;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.nav-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.nav-links a { color: rgba(255,255,255,0.9); text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; text-decoration: underline; }

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

body.wide-layout .container,
body.wide-layout .nav-container { max-width: 1800px; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger  { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #5a6268; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #219a52; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}
.card h2 { margin-bottom: 0.5rem; font-size: 1.2rem; }
.card-meta { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

/* Duplicate scrollbar rendered above a table that is wider than the page,
   added by table-scroll.js and kept in sync with the table below it. */
.table-scroll-top {
    display: none;
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 0.4rem;
    scrollbar-width: auto;
    scrollbar-color: #adb5bd #e9ecef;
}
.table-scroll-top.is-visible { display: block; }
.table-scroll-top__spacer { height: 1px; }
.table-scroll-top::-webkit-scrollbar { height: 12px; }
.table-scroll-top::-webkit-scrollbar-track { background: #e9ecef; border-radius: 6px; }
.table-scroll-top::-webkit-scrollbar-thumb { background: #adb5bd; border-radius: 6px; }
.table-scroll-top::-webkit-scrollbar-thumb:hover { background: #868e96; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.data-table th, .data-table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
}
.data-table tbody tr:hover { background: #f8f9fa; }

.podium-1 td:first-child { border-left: 4px solid var(--gold); }
.podium-2 td:first-child { border-left: 4px solid var(--silver); }
.podium-3 td:first-child { border-left: 4px solid var(--bronze); }

.dq-row { background: #fce4e4; }
.dnf-row { background: #fff8e1; }
.success-row { background: #d4edda; }
.round-group-header td { background: #eef2f7; font-size: 0.85rem; padding: 0.4rem 0.8rem; border-top: 2px solid var(--border); }
.class-group-header td { background: #f5f7fa; font-size: 0.82rem; padding: 0.35rem 0.8rem 0.35rem 1.4rem; border-top: 1px dashed var(--border); font-style: italic; color: var(--text-muted); }

.actions { display: flex; gap: 0.25rem; align-items: center; }
.actions form { display: inline; }

/* ── Upload ─────────────────────────────────────────────────────────────────── */
.upload-info {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}
.upload-info h3 { margin-bottom: 0.75rem; font-size: 1rem; }
.example-csv {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.82rem;
    overflow-x: auto;
    white-space: pre;
    margin-top: 0.5rem;
}
.hint-text {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.2rem;
}
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.form-group input[type="file"] {
    padding: 0.4rem 0;
    border: none;
    font-size: 0.9rem;
}

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-container {
    max-width: 600px;
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
}
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.9rem; }
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26, 95, 42, 0.2);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-actions { display: flex; gap: 0.5rem; margin-top: 1.5rem; }

/* ── Section Headers ───────────────────────────────────────────────────────── */
.section { margin-bottom: 2rem; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ── Class Tabs ────────────────────────────────────────────────────────────── */
.class-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.tab {
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 0.9rem;
    transition: all 0.2s;
}
.tab:hover { background: #e9ecef; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Filter Bar ────────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    flex-wrap: wrap;
}
.filter-bar select,
.filter-input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    min-width: 130px;
}
.filter-input-sm { min-width: 80px; }
.filter-input:focus,
.filter-bar select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26, 95, 42, 0.15);
}

/* ── Sortable table headers ────────────────────────────────────────────────── */
.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.sortable:hover { background: #e9ecef; }
.sort-icon {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 0.2rem;
    opacity: 0.6;
}
.sort-asc .sort-icon,
.sort-desc .sort-icon {
    color: var(--primary);
    opacity: 1;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #e9ecef;
    text-transform: uppercase;
}
.badge-admin { background: #d4edda; color: #155724; }
.badge-processor { background: #cce5ff; color: #004085; }
.badge-visitor { background: #e9ecef; color: #495057; }

/* ── Misc ──────────────────────────────────────────────────────────────────── */
.standings-info { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1rem; font-style: italic; }
.standings-links { margin-top: 1.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.empty-state { color: var(--text-muted); text-align: center; padding: 3rem 1rem; font-size: 1.1rem; }

/* ── Teams round breakdown ──────────────────────────────────────────────────── */
.round-breakdown summary { cursor: pointer; list-style: none; display: inline; text-decoration: underline dotted; text-underline-offset: 2px; }
.round-breakdown summary::-webkit-details-marker { display: none; }
.round-breakdown__detail { margin-top: 0.25rem; font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }

h1 { margin-bottom: 1rem; }

/* ── RC Agent Banner ───────────────────────────────────────────────────────── */
.rc-agent-banner {
    margin-top: 2rem;
    background: linear-gradient(135deg, #0f2027 0%, #1a3a2a 60%, #1a5f2a 100%);
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    overflow: hidden;
}
.rc-agent-banner__body {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    flex-wrap: wrap;
}
.rc-agent-banner__icon {
    font-size: 2rem;
    flex-shrink: 0;
}
.rc-agent-banner__text {
    flex: 1;
    min-width: 200px;
}
.rc-agent-banner__headline {
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.rc-agent-banner__sub {
    color: rgba(255,255,255,0.75);
    font-size: 0.85rem;
    line-height: 1.5;
}
.rc-agent-banner__sub strong {
    color: #fff;
}
.rc-agent-banner__cta {
    flex-shrink: 0;
    display: inline-block;
    padding: 0.6rem 1.25rem;
    background: var(--gold);
    color: #1a1a1a;
    font-weight: 700;
    font-size: 0.9rem;
    border-radius: var(--radius);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s, transform 0.1s;
}
.rc-agent-banner__cta:hover {
    background: #f4d03f;
    transform: translateY(-1px);
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
.footer {
    background: #333;
    color: rgba(255,255,255,0.7);
    padding: 1rem 0;
    text-align: center;
    font-size: 0.85rem;
    margin-top: auto;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .section-header { flex-direction: column; align-items: flex-start; }
    .nav-container { flex-direction: column; align-items: flex-start; }
}
