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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --accent: #5b8dee;
  --accent-dark: #3a6ac8;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --text: #e2e8f0;
  --muted: #8892a4;
  --radius: 8px;
  --sidebar-w: 220px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

#app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

header { margin-bottom: 24px; }
header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; color: var(--accent); }
.subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* --- Library section --- */
#library-section { margin-bottom: 28px; }
.library-header-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-title { font-size: 18px; font-weight: 700; color: var(--text); }

.add-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
#event-url {
  flex: 1; min-width: 280px;
  padding: 9px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; outline: none; transition: border-color 0.15s;
}
#event-url:focus { border-color: var(--accent); }

/* Library table */
#library-table-wrap { margin-top: 4px; }
#library-table { font-size: 13px; }
#library-table thead tr { background: var(--surface2); }
#library-table th { font-weight: 600; color: var(--muted); padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: default; }
.library-row { border-bottom: 1px solid var(--border); transition: background 0.1s; }
.library-row:hover { background: var(--surface2); }
.library-row td { padding: 8px 12px; vertical-align: middle; }
.lib-name { font-weight: 500; }
.lib-actions { white-space: nowrap; display: flex; gap: 6px; }
.muted-hint { color: var(--muted); font-size: 13px; padding: 12px 0; }
.muted { color: var(--muted); font-size: 12px; }

button {
  padding: 10px 20px; border: none; border-radius: var(--radius);
  cursor: pointer; font-size: 14px; font-weight: 600; transition: background 0.15s;
}
button:not(.secondary):not(.danger) { background: var(--accent); color: #fff; }
button:not(.secondary):not(.danger):hover { background: var(--accent-dark); }
button.secondary { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
button.secondary:hover { color: var(--text); border-color: var(--accent); }
button.danger { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
button.danger:hover { background: rgba(248,113,113,0.25); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  margin-top: 10px; padding: 10px 14px;
  background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius); color: var(--red); font-size: 13px;
}

/* --- Event heading (shown above results) --- */
.event-heading {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 20px;
}
.event-heading-main {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
#event-title {
  font-size: 22px; font-weight: 700; color: var(--text);
}
.event-meta {
  color: var(--muted); font-size: 14px; margin-top: 4px;
}

/* --- Progress --- */
#progress-section { margin-bottom: 12px; }
.progress-bar-wrap { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s ease; }
#progress-msg { color: var(--muted); font-size: 13px; }

/* --- Results layout: sidebar + main --- */
.results-layout { display: flex; gap: 20px; align-items: flex-start; }

/* --- Sidebar --- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}
.sidebar-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); margin-bottom: 10px;
}
.disc-master {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; color: var(--text);
  padding: 5px 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}
.disc-master input { accent-color: var(--accent); }
#cat-checkboxes,
#disc-checkboxes { display: flex; flex-direction: column; gap: 4px; }
#cat-checkboxes label,
#disc-checkboxes label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; cursor: pointer; color: var(--text); font-size: 13px;
  padding: 4px 6px; border-radius: 5px; transition: background 0.1s;
}
#cat-checkboxes label:hover,
#disc-checkboxes label:hover { background: var(--surface2); }
#cat-checkboxes input[type=checkbox],
#disc-checkboxes input[type=checkbox] { accent-color: var(--accent); flex-shrink: 0; }
.disc-name { flex: 1; }
.disc-count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.sidebar-divider { border-top: 1px solid var(--border); margin: 12px 0; }

/* --- Main categories area --- */
#categories-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 32px; }

/* --- Per-category section --- */
.cat-section { display: flex; flex-direction: column; gap: 12px; }
.cat-header {
  display: flex; align-items: baseline; gap: 10px;
  padding-bottom: 8px; border-bottom: 2px solid var(--accent);
}
.cat-title { font-size: 18px; font-weight: 700; }
.cat-count { color: var(--muted); font-size: 13px; }

/* --- Chart --- */
.chart-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; overflow: hidden;
}
.chart-wrap canvas { display: block; }

/* --- Table --- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: var(--surface2); }
th {
  padding: 10px 12px; text-align: left; color: var(--muted); font-weight: 600;
  white-space: nowrap; cursor: pointer; user-select: none; border-bottom: 1px solid var(--border);
}
th:hover { color: var(--text); }
th .sort-icon::after { content: ''; margin-left: 4px; }
th.asc .sort-icon::after { content: '▲'; }
th.desc .sort-icon::after { content: '▼'; }

tbody tr.athlete-row { border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
tbody tr.athlete-row:hover { background: var(--surface2); }
tbody tr.detail-row td { padding: 0; background: var(--surface); }
tbody tr.detail-row.hidden { display: none; }

td { padding: 9px 12px; vertical-align: middle; }

.conf-high { color: var(--green); }
.conf-medium { color: var(--yellow); }
.conf-low, .conf-none { color: var(--red); }

.badge-warn {
  display: inline-block;
  background: rgba(251,191,36,0.15); color: var(--yellow);
  border: 1px solid rgba(251,191,36,0.3); border-radius: 4px;
  padding: 1px 5px; font-size: 11px; margin-left: 4px;
}

.pct-pill { display: inline-block; min-width: 50px; text-align: right; font-variant-numeric: tabular-nums; }

/* detail sub-table */
.detail-panel { padding: 12px 20px; }
.detail-panel table { font-size: 12px; margin-top: 8px; }
.detail-panel th { font-size: 11px; padding: 6px 10px; }
.detail-panel td { padding: 6px 10px; }
.detail-panel tr.dns-row td { color: var(--muted); }

.hidden { display: none !important; }
