:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --bg: #ffffff;
  --bg-alt: #f4f6f9;
  --muted: #5a5a5a;
  --accent: #1d5c9e;
  --accent-dark: #164a80;
  --border: #e2e2e2;
  --ok: #1e8e3e;
  --bad: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f0f0f0;
    --bg: #14161a;
    --bg-alt: #1b1e24;
    --muted: #a3a3a3;
    --accent: #6ea8e8;
    --accent-dark: #8fbdf0;
    --border: #2a2d33;
    --ok: #4caf50;
    --bad: #e57373;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg-alt);
  line-height: 1.5;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login-card h1 { margin: 0; }
.login-card .subtitle { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }
.login-card input {
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-alt);
  color: var(--fg);
  font-size: 1rem;
}
.login-card button {
  margin-top: 0.4rem;
  padding: 0.6rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }

/* ---------- Header ---------- */
header.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
header.site-header a.brand { font-weight: 700; text-decoration: none; color: var(--fg); }
#who { font-size: 0.85rem; color: var(--muted); flex: 1; text-align: right; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 0.85rem; text-decoration: underline; padding: 0;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  max-width: 1200px;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
  align-items: start;
}
.layout > * { min-width: 0; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}
.panel h2 { margin-top: 0; }
.muted { color: var(--muted); }

.col-list { list-style: none; padding: 0; margin: 0 0 1rem; font-size: 0.9rem; }
.col-list li { padding: 0.15rem 0; }
.col-list code { color: var(--accent); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab-button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
}
.tab-button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- SQL editor ---------- */
.sql-input {
  width: 100%;
  min-height: 90px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-alt);
  color: var(--fg);
  resize: vertical;
}
.sql-input.small { min-height: 60px; }

.controls { display: flex; gap: 0.5rem; margin: 0.6rem 0; }
.controls button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.controls button:hover { background: var(--accent-dark); }
.controls button.reset,
.controls button.reveal { background: var(--bg-alt); color: var(--fg); }

.error-text { color: var(--bad); font-weight: 600; }
.success-text { color: var(--ok); font-weight: 600; }

/* ---------- Result tables ---------- */
.result-table-wrap { overflow-x: auto; }
table.result-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}
table.result-table th, table.result-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
  white-space: nowrap;
}
table.result-table th { background: var(--bg-alt); }

/* ---------- Exercises ---------- */
.exercise-list { display: flex; flex-direction: column; gap: 1.25rem; }
.exercise {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}
.exercise-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge-ocr { background: var(--ok); color: #fff; }
.badge-enrichment { background: var(--muted); color: #fff; }
.answer-box {
  margin-top: 0.5rem;
  background: var(--bg-alt);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Admin ---------- */
.stat-list { list-style: none; padding: 0; display: flex; gap: 1.5rem; flex-wrap: wrap; }
.stat-list li {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
}

/* ---------- Footer ---------- */
.site-footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.5rem; }

.bug-report-btn {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  color: var(--fg);
  font-size: 0.85rem;
}
