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

:root {
  --yellow:   #f5c400;
  --yellow-d: #d4a900;
  --red:      #e03030;
  --dark:     #0f1117;
  --dark2:    #1c1f28;
  --gray-100: #f4f5f7;
  --gray-200: #e8eaed;
  --gray-400: #9aa0ad;
  --gray-600: #5a6170;
  --gray-800: #2d3240;
  --white:    #ffffff;
  --radius:   6px;
  --shadow:   0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:0 8px 32px rgba(0,0,0,.14);
  --font:     'Inter', system-ui, sans-serif;
}

html { font-size: 15px; }
body { font-family: var(--font); background: var(--gray-100); color: var(--gray-800); line-height: 1.6; }
a { color: var(--yellow-d); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'Menlo', 'Consolas', monospace; font-size: .88em; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--dark);
  border-bottom: 3px solid var(--yellow);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: .5rem; color: var(--white); font-size: 1.3rem; font-weight: 800; }
.logo:hover { text-decoration: none; }
.logo-icon { font-size: 1.5rem; }
.logo-text em { color: var(--yellow); font-style: normal; }
.header-nav { display: flex; gap: 1rem; }
.nav-link { color: var(--gray-400); font-size: .9rem; font-weight: 500; }
.nav-link:hover { color: var(--white); text-decoration: none; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  text-align: center; padding: 1.5rem; font-size: .8rem; color: var(--gray-400);
  border-top: 1px solid var(--gray-200); margin-top: 3rem;
}

/* ── Hero ────────────────────────────────────────────────────────────────── */
.page-hero {
  background: linear-gradient(135deg, var(--dark2) 0%, #1a2235 100%);
  color: var(--white); padding: 2.5rem 1.5rem; text-align: center;
  border-bottom: 4px solid var(--yellow);
}
.page-hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: .4rem; }
.page-hero p  { color: var(--gray-400); font-size: 1rem; }

/* ── Page body ───────────────────────────────────────────────────────────── */
.page-body { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ── Excluded bubbles ────────────────────────────────────────────────────── */
.excluded-section {
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: var(--radius); padding: .75rem 1rem;
  margin-bottom: 1rem; display: flex; align-items: flex-start; gap: .75rem; flex-wrap: wrap;
}
.excluded-label { font-size: .8rem; font-weight: 600; color: var(--gray-600); white-space: nowrap; padding-top: .15rem; }
.bubbles { display: flex; flex-wrap: wrap; gap: .4rem; }
.bubble {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--yellow); color: var(--dark); border-radius: 999px;
  padding: .2rem .65rem .2rem .75rem; font-size: .8rem; font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.bubble em { font-style: normal; font-weight: 400; color: var(--gray-800); }
.bubble-remove {
  background: none; border: none; cursor: pointer; line-height: 1;
  font-size: 1.1rem; color: var(--gray-800); padding: 0 0 0 .1rem;
  opacity: .6; transition: opacity .15s;
}
.bubble-remove:hover { opacity: 1; }

/* ── Controls bar ────────────────────────────────────────────────────────── */
.controls-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; flex-wrap: wrap; gap: .75rem;
}
.controls-right { display: flex; align-items: center; gap: .5rem; }
.generate-group { display: flex; align-items: center; gap: .4rem; }
.cal-name-input {
  padding: .48rem .75rem; border: 1px solid var(--gray-200); border-radius: var(--radius);
  font-size: .88rem; font-family: var(--font); outline: none; width: 200px;
  transition: border-color .15s;
}
.cal-name-input:focus { border-color: var(--yellow); box-shadow: 0 0 0 2px rgba(245,196,0,.2); }
.race-count { font-size: .88rem; color: var(--gray-600); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1.1rem; border-radius: var(--radius);
  font-weight: 600; font-size: .9rem; cursor: pointer; border: none;
  transition: background .15s, transform .1s; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary  { background: var(--yellow); color: var(--dark); }
.btn-primary:hover { background: var(--yellow-d); }
.btn-ghost { background: var(--white); color: var(--gray-600); border: 1px solid var(--gray-200); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-full { width: 100%; justify-content: center; }
.btn-danger-sm { padding: .25rem .6rem; font-size: .78rem; background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; border-radius: 4px; cursor: pointer; }
.btn-danger-sm:hover { background: #fca5a5; }

/* ── Table wrapper ───────────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: auto;
}

/* ── Races table ─────────────────────────────────────────────────────────── */
#races-table {
  width: 100%; border-collapse: collapse; font-size: .87rem;
}
#races-table thead .col-headers th {
  background: var(--dark2); color: var(--white);
  padding: .7rem .9rem; text-align: left; font-weight: 700;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
#races-table thead .filter-row td {
  background: var(--gray-100); padding: .3rem .4rem;
  border-bottom: 2px solid var(--gray-200);
}
/* ── Column dropdown filters ─────────────────────────────────────────────── */
.col-filter { position: relative; }

.filter-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: .28rem .5rem;
  background: var(--white); border: 1px solid var(--gray-200); border-radius: 4px;
  font-size: .8rem; font-family: var(--font); cursor: pointer;
  white-space: nowrap; overflow: hidden; gap: .3rem;
  transition: border-color .15s;
}
.filter-btn:hover { border-color: var(--gray-400); }
.filter-btn.filter-active { border-color: var(--yellow-d); background: #fffbeb; font-weight: 600; }
.filter-btn-label { overflow: hidden; text-overflow: ellipsis; flex: 1; text-align: left; }
.dd-arrow { font-size: .7rem; flex-shrink: 0; color: var(--gray-400); }

.dd-panel {
  display: none; position: fixed;
  min-width: 180px; max-width: 280px; z-index: 1000;
  background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.dd-panel.open { display: block; }

.dd-search-wrap { padding: .4rem .5rem; border-bottom: 1px solid var(--gray-200); }
.dd-search {
  width: 100%; padding: .3rem .5rem; border: 1px solid var(--gray-200);
  border-radius: 4px; font-size: .82rem; font-family: var(--font); outline: none;
}
.dd-search:focus { border-color: var(--yellow); }

.dd-options { max-height: 240px; overflow-y: auto; padding: .3rem 0; }

.dd-option {
  display: flex; align-items: center; gap: .45rem;
  padding: .25rem .75rem; cursor: pointer; font-size: .84rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dd-option:hover { background: var(--gray-100); }
.dd-option input[type=checkbox] { accent-color: var(--yellow-d); flex-shrink: 0; cursor: pointer; }
.dd-option.dd-select-all { border-bottom: 1px solid var(--gray-200); padding-bottom: .4rem; margin-bottom: .2rem; }
.dd-option.dd-select-all span { font-weight: 600; }
.dd-option.dd-hidden { display: none; }

#races-table tbody tr.race-row {
  cursor: pointer; transition: background .1s;
  border-bottom: 1px solid var(--gray-200);
}
#races-table tbody tr.race-row:nth-child(even) { background: #fafbfc; }
#races-table tbody tr.race-row:hover { background: #fffbeb; }
#races-table tbody td { padding: .55rem .9rem; }
.race-name-cell { font-weight: 500; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 4rem 2rem; background: var(--white);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.4rem; margin-bottom: .5rem; }
.empty-state p { color: var(--gray-600); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 1rem;
}
.modal {
  background: var(--white); border-radius: 10px;
  padding: 2rem; max-width: 560px; width: 100%;
  box-shadow: var(--shadow-lg); position: relative;
}
.modal-close {
  position: absolute; top: .8rem; right: 1rem;
  background: none; border: none; font-size: 1.5rem;
  cursor: pointer; color: var(--gray-400); line-height: 1;
}
.modal h2 { margin-bottom: .5rem; font-size: 1.3rem; }
.modal p  { color: var(--gray-600); margin-bottom: 1rem; font-size: .9rem; }
.feed-url-box { display: flex; gap: .5rem; margin-bottom: .5rem; }
.feed-url-input {
  flex: 1; padding: .5rem .75rem; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-size: .85rem; font-family: 'Menlo', monospace;
  background: var(--gray-100); outline: none;
}
.copy-confirm { color: #16a34a; font-size: .88rem; font-weight: 600; }
.feed-instructions { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--gray-200); font-size: .85rem; }
.feed-instructions ul { margin-top: .4rem; padding-left: 1.2rem; }
.feed-instructions li { margin-bottom: .25rem; }

/* ── Admin pages ─────────────────────────────────────────────────────────── */
.admin-page { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
.admin-title { font-size: 1.8rem; font-weight: 800; margin-bottom: .25rem; }
.admin-subtitle { color: var(--gray-600); margin-bottom: 1.5rem; }
.admin-section { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; }
.admin-section h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--gray-200); }

.admin-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.admin-table th { background: var(--gray-100); padding: .6rem .9rem; text-align: left; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-600); border-bottom: 2px solid var(--gray-200); }
.admin-table td { padding: .6rem .9rem; border-bottom: 1px solid var(--gray-200); }
.admin-table tr:last-child td { border-bottom: none; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-400); font-size: .9rem; }

/* ── Stats grid ──────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem 1.5rem; border-left: 4px solid var(--yellow); }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-label { color: var(--gray-600); font-size: .85rem; margin-top: .25rem; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .35rem; color: var(--gray-800); }
.form-group small { color: var(--gray-400); font-size: .8rem; margin-top: .25rem; display: block; }
.form-input {
  width: 100%; padding: .55rem .8rem; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-size: .9rem; font-family: var(--font);
  outline: none; transition: border-color .15s;
}
.form-input:focus { border-color: var(--yellow); box-shadow: 0 0 0 2px rgba(245,196,0,.2); }
.form-select { appearance: auto; }
.form-row { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.form-group-action { padding-bottom: .05rem; }
.settings-form { max-width: 480px; }

/* ── Radio group ─────────────────────────────────────────────────────────── */
.radio-group { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1.25rem; }
.radio-label { display: flex; align-items: flex-start; gap: .6rem; font-size: .9rem; cursor: pointer; }
.radio-label input { margin-top: .2rem; accent-color: var(--yellow-d); }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error   { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page { min-height: 80vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.login-card { background: var(--white); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 2.5rem; width: 100%; max-width: 380px; }
.login-logo { font-size: 1.4rem; font-weight: 800; text-align: center; margin-bottom: 1.25rem; color: var(--dark); }
.login-card h1 { font-size: 1.2rem; text-align: center; margin-bottom: 1.5rem; font-weight: 700; }

/* ── Loading state ───────────────────────────────────────────────────────── */
.loading-state { display: flex; align-items: center; gap: 1rem; padding: 1rem; color: var(--gray-600); }
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--gray-200);
  border-top-color: var(--yellow-d); border-radius: 50%;
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.alert-error { padding: .75rem 1rem; background: #fef2f2; border: 1px solid #fca5a5; border-radius: 6px; color: #b91c1c; margin-top: 1rem; }

.staging-info { margin-bottom: 1rem; padding: .75rem 1rem; background: var(--gray-100); border-radius: var(--radius); font-size: .9rem; }

/* ── About page ──────────────────────────────────────────────────────────── */
.about-card {
  max-width: 720px; margin: 0 auto;
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 2.5rem;
}
.about-lead {
  font-size: 1.15rem; font-weight: 600; color: var(--gray-800);
  border-left: 4px solid var(--yellow); padding-left: 1rem;
  margin-bottom: 1.5rem; line-height: 1.5;
}
.about-card p { margin-bottom: 1.1rem; line-height: 1.75; color: var(--gray-800); }
.about-cta { margin-top: 2rem; }

/* ── Log pages ───────────────────────────────────────────────────────────── */
.filter-cell { max-width: 260px; }
.filter-tag { display: inline-block; background: var(--gray-200); border-radius: 4px; padding: .1rem .4rem; font-size: .78rem; margin: .1rem .15rem .1rem 0; }
.filter-tag.muted { background: #fee2e2; color: var(--red); }
.ua-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; color: var(--gray-600); }
.btn-link { font-size: .82rem; font-weight: 600; color: var(--yellow-d); margin-right: .4rem; }
.pagination { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: 1rem; }
.page-link { padding: .3rem .65rem; border-radius: 4px; border: 1px solid var(--gray-200); font-size: .85rem; color: var(--gray-800); }
.page-link.active { background: var(--yellow); border-color: var(--yellow-d); font-weight: 700; }
.page-link:hover { background: var(--gray-100); text-decoration: none; }
