/* ── Variables ─────────────────────────────────────────── */
:root {
    --purple: #2b0171;
    --purple-light: #3d0299;
    --red: #cc0022;
    --blue: #0c67b2;
    --pink: #cc0066;
    --white: #ffffff;
    --off-white: #f7f7f7;
    --light-gray: #e8e8e8;
    --mid-gray: #999;
    --dark: #1a1a1a;
    --text: #333;
    --font-heading: 'Merriweather', serif;
    --font-body: 'Open Sans', sans-serif;
    --radius: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.10);
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-body); color: var(--text); background: var(--off-white); font-size: 16px; line-height: 1.6; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ────────────────────────────────────────────── */
.site-header {
    display: flex;
    align-items: stretch;
    background: var(--white);
    border-bottom: 3px solid var(--purple);
}
.header-logo-section {
    background: var(--white);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.header-logo {
    height: 80px;
    width: auto;
}
.header-title-section {
    background: var(--purple);
    padding: 16px 28px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
}
.header-title {
    font-family: var(--font-heading);
    color: var(--white);
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}
.header-date {
    color: rgba(255,255,255,0.85);
    font-size: 1rem;
    margin-top: 4px;
}

/* ── Main ──────────────────────────────────────────────── */
.main-content { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Flash Messages ────────────────────────────────────── */
.flash-messages { margin-bottom: 1.5rem; }
.flash {
    background: #e8f4e8;
    border-left: 4px solid #2a7a2a;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-weight: 600;
}
.flash.error { background: #fdecea; border-left-color: var(--red); }

/* ── Section Titles ────────────────────────────────────── */
.section-title {
    font-family: var(--font-heading);
    color: var(--purple);
    font-size: 1.4rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--light-gray);
}

/* ── Stats Section ─────────────────────────────────────── */
.stats-section { margin-bottom: 2.5rem; }
.stats-header-row { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.timestamp { font-size: 0.85rem; color: var(--mid-gray); }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem 1rem;
    text-align: center;
    border-top: 4px solid var(--purple);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.stat-value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    color: var(--purple);
    line-height: 1;
}
.stat-label {
    font-size: 0.85rem;
    color: var(--mid-gray);
    margin-top: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Tier Columns ──────────────────────────────────────── */
.tiers-section { margin-bottom: 2.5rem; }
.tier-columns {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}
.tier-col {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.tier-col-header {
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    color: var(--white);
}
.tier-cheetah    { background: var(--purple); }
.tier-roadrunner { background: var(--blue); }
.tier-rabbit     { background: var(--pink); }
.tier-turtle     { background: #2a7a2a; }

.tier-label { font-family: var(--font-heading); font-size: 1.1rem; font-weight: 700; }
.tier-range { font-size: 0.8rem; opacity: 0.85; margin-top: 2px; }

.tier-list {
    list-style: none;
    padding: 0.5rem 0;
    flex-grow: 1;
}
.tier-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 1rem;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--light-gray);
}
.tier-item:last-child { border-bottom: none; }
.avatar-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 65%; }
.avatar-laps { color: var(--mid-gray); font-size: 0.82rem; white-space: nowrap; }
.tier-empty { padding: 1rem; color: var(--mid-gray); font-style: italic; font-size: 0.88rem; text-align: center; }

.view-more {
    display: block;
    text-align: center;
    padding: 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--blue);
    border-top: 1px solid var(--light-gray);
}
.view-more:hover { background: var(--off-white); text-decoration: none; }

/* ── Historical Table ──────────────────────────────────── */
.historical-section { margin-bottom: 2.5rem; }
.historical-table-wrap { overflow-x: auto; }
.historical-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.historical-table th {
    background: var(--purple);
    color: var(--white);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.historical-table td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--light-gray);
    font-size: 0.9rem;
}
.historical-table tr:last-child td { border-bottom: none; }
.historical-table tr:nth-child(even) td { background: var(--off-white); }

/* ── Tier Full Page ────────────────────────────────────── */
.tier-page-wrap { max-width: 800px; }
.tier-range-badge {
    display: inline-block;
    background: var(--light-gray);
    color: var(--mid-gray);
    font-size: 0.85rem;
    padding: 2px 10px;
    border-radius: 20px;
    font-family: var(--font-body);
    font-weight: normal;
    margin-left: 0.5rem;
    vertical-align: middle;
}
.tier-count { color: var(--mid-gray); margin-bottom: 1rem; font-size: 0.9rem; }
.tier-full-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.tier-full-table th {
    background: var(--purple);
    color: var(--white);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.9rem;
}
.tier-full-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--light-gray);
    font-size: 0.9rem;
}
.tier-full-table tr:last-child td { border-bottom: none; }
.tier-full-table tr:nth-child(even) td { background: var(--off-white); }
.tier-empty-full { color: var(--mid-gray); font-style: italic; margin-top: 1rem; }

/* ── Admin ─────────────────────────────────────────────── */
.admin-wrap { max-width: 960px; }
.admin-header-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.admin-nav { display: flex; gap: 0.75rem; }
.admin-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.admin-card h3 {
    font-family: var(--font-heading);
    color: var(--purple);
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}
.active-event-card { border-left: 5px solid var(--purple); }
.danger-card { border-left: 5px solid var(--red); }
.mini-stats { display: flex; gap: 1.5rem; margin: 0.75rem 0; font-size: 0.9rem; color: var(--mid-gray); }
.badge-active {
    display: inline-block;
    background: #e8f4e8;
    color: #2a7a2a;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid #2a7a2a;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--light-gray);
    color: var(--mid-gray);
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}
.admin-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--light-gray);
}
.admin-table tr:last-child td { border-bottom: none; }

/* ── Forms ─────────────────────────────────────────────── */
.event-form, .login-form, .historical-form { display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.85rem; font-weight: 700; color: var(--dark); text-transform: uppercase; letter-spacing: 0.04em; }
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.form-inline { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.form-note { font-size: 0.85rem; color: var(--mid-gray); font-style: italic; }
input[type="text"], input[type="number"], input[type="password"], input[type="datetime-local"] {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--light-gray);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font-body);
    width: 100%;
    transition: border-color 0.2s;
}
input:focus { outline: none; border-color: var(--purple); }
.add-region-form { margin-top: 1rem; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 0.55rem 1.2rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: var(--font-body);
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    text-align: center;
}
.btn-primary { background: var(--purple); color: var(--white); border-color: var(--purple); }
.btn-primary:hover { background: var(--purple-light); border-color: var(--purple-light); text-decoration: none; }
.btn-secondary { background: var(--blue); color: var(--white); border-color: var(--blue); }
.btn-secondary:hover { opacity: 0.85; text-decoration: none; }
.btn-outline { background: transparent; color: var(--purple); border-color: var(--purple); }
.btn-outline:hover { background: var(--purple); color: var(--white); text-decoration: none; }
.btn-danger { background: var(--red); color: var(--white); border-color: var(--red); }
.btn-danger:hover { opacity: 0.85; text-decoration: none; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ── Misc ──────────────────────────────────────────────── */
.back-link { display: inline-block; margin-bottom: 1.25rem; color: var(--blue); font-weight: 600; font-size: 0.9rem; }
.no-event { text-align: center; padding: 3rem; color: var(--mid-gray); font-style: italic; }
.login-wrap { max-width: 400px; margin: 3rem auto; background: var(--white); padding: 2rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.login-wrap .section-title { text-align: center; border: none; }

/* ── Footer ────────────────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.85rem;
    color: var(--mid-gray);
    border-top: 1px solid var(--light-gray);
    margin-top: 2rem;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .tier-columns { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .header-logo { height: 55px; }
    .header-title { font-size: 1.1rem; }
    .header-date { font-size: 0.85rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .tier-columns { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.5rem; }
    .main-content { padding: 1rem; }
    .form-row { grid-template-columns: 1fr; }
    .admin-header-row { flex-direction: column; align-items: flex-start; }
}
