:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --bar-color: #2a78d6;
  --accent: #5865f2;
  --accent-ink: #ffffff;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --status-duplicate: #e67e22;
  --status-good-bg: rgba(12, 163, 12, 0.12);
  --status-warning-bg: rgba(250, 178, 25, 0.16);
  --status-critical-bg: rgba(208, 59, 59, 0.12);
  --status-duplicate-bg: rgba(230, 126, 34, 0.14);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 14px;
  --space-4: 20px;
  --space-5: 28px;
  --space-6: 40px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 3px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 4px 10px rgba(11, 11, 11, 0.08), 0 2px 4px rgba(11, 11, 11, 0.06);
  --btn-hover-filter: brightness(0.96);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --bar-color: #3987e5;
    --status-good-bg: rgba(12, 163, 12, 0.2);
    --status-warning-bg: rgba(250, 178, 25, 0.2);
    --status-critical-bg: rgba(208, 59, 59, 0.2);
    --status-duplicate-bg: rgba(230, 126, 34, 0.22);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --btn-hover-filter: brightness(1.15);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --bar-color: #3987e5;
  --status-good-bg: rgba(12, 163, 12, 0.2);
  --status-warning-bg: rgba(250, 178, 25, 0.2);
  --status-critical-bg: rgba(208, 59, 59, 0.2);
  --status-duplicate-bg: rgba(230, 126, 34, 0.22);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --btn-hover-filter: brightness(1.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

a { color: var(--accent); }

h1 { font-size: 1.6rem; margin: var(--space-5) 0 var(--space-4); display: flex; align-items: center; gap: var(--space-2); }
h2 { font-size: 1.1rem; margin: 0 0 var(--space-1); color: var(--text-primary); }
.section-hint { margin: 0 0 var(--space-3); color: var(--text-muted); font-size: 0.85rem; }

.muted { color: var(--text-muted); }

/* Top navigation */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 20px;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text-primary); display: flex; align-items: center; gap: 6px; }
.nav-links { display: flex; gap: 6px; flex: 1; }
.nav-links a {
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-links a:hover { color: var(--text-primary); background: var(--page); }
.nav-links a.active { color: var(--accent); background: var(--status-good-bg); font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 0.9rem; }
.avatar { width: 24px; height: 24px; border-radius: 50%; }
.logout { margin-left: 6px; color: var(--text-muted); text-decoration: none; }

main.container { padding-bottom: 60px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

/* Stat tiles -- color pairs with the label text, never color alone */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--baseline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.stat-icon { font-size: 1.5rem; line-height: 1; }
.stat-body { display: flex; flex-direction: column; gap: 4px; }
.stat-value {
  font-size: 1.9rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}
.stat-label { color: var(--text-secondary); font-size: 0.85rem; }
.stat-pending { border-left-color: var(--status-warning); }
.stat-approved { border-left-color: var(--status-good); }
.stat-rejected { border-left-color: var(--status-critical); }

/* Bar chart -- single series, sequential blue, no legend needed (title names it) */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 140px;
  padding: 8px 4px 0;
  border-bottom: 1px solid var(--baseline);
}
.bar-col {
  flex: 1 1 auto;
  max-width: 24px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
.bar {
  width: 100%;
  min-height: 2px;
  background: var(--bar-color);
  border-radius: 4px 4px 0 0;
  transition: opacity 0.15s ease;
}
.bar-col:hover .bar { opacity: 0.75; }
.bar-col .bar-label {
  display: none;
}
.bar-col:nth-child(5n + 1) .bar-label {
  display: block;
  margin-top: 6px;
  font-size: 0.65rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Tables */
.table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.92rem;
}
.table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table tbody tr { transition: background-color 0.12s ease; }
.table tbody tr:hover { background: var(--page); }

/* Status badges -- color + text label together, per fixed status palette */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-pending { background: var(--status-warning-bg); color: var(--status-warning); }
.badge-approved { background: var(--status-good-bg); color: var(--status-good); }
.badge-rejected { background: var(--status-critical-bg); color: var(--status-critical); }
.badge-duplicate { background: var(--status-duplicate-bg); color: var(--status-duplicate); }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  font-size: 0.92rem;
  transition: color 0.15s ease;
}
.tabs a:hover { color: var(--text-primary); }
.tabs a.active { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }

/* Empty states */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  color: var(--text-muted);
  text-align: center;
}
.empty-state .empty-icon { font-size: 2rem; }

/* Forms */
.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}
input[type='text'], select, textarea {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  color: var(--text-primary);
  font: inherit;
  transition: border-color 0.15s ease;
}
input[type='text']:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:hover { filter: var(--btn-hover-filter); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary, .btn-discord { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-success { background: var(--status-good); border-color: var(--status-good); color: #fff; }
.btn-danger { background: var(--status-critical); border-color: var(--status-critical); color: #fff; }

.question-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.question-list li { display: flex; gap: 6px; align-items: center; }
.question-row { display: flex; gap: 8px; flex: 1; }
.question-row input { flex: 1; }
.inline-form { display: inline; }
.icon-btn {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s ease;
  line-height: 1;
}
.icon-btn:hover { background: var(--page); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.question-row button { padding: 8px 10px; }

.action-card { display: flex; flex-direction: column; gap: 14px; }
.action-card form { display: flex; gap: 10px; align-items: flex-start; }
.reject-form textarea { flex: 1; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.9rem; }
.alert-success { background: var(--status-good-bg); color: var(--status-good); }
.alert-error { background: var(--status-critical-bg); color: var(--status-critical); }

.qa-list dt { font-weight: 600; margin-top: 12px; color: var(--text-secondary); }
.qa-list dt:first-child { margin-top: 0; }
.qa-list dd { margin: 4px 0 0; white-space: pre-wrap; }

.back-link { display: inline-block; margin: 20px 0 0; color: var(--text-secondary); text-decoration: none; font-size: 0.88rem; transition: color 0.15s ease; }
.back-link:hover { color: var(--text-primary); }

.login-card {
  max-width: 380px;
  margin: 90px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  text-align: center;
}
.login-card .result-icon { font-size: 2.5rem; margin-bottom: var(--space-2); }
.login-card h1 { margin-top: 0; justify-content: center; }
.login-card .btn { margin-top: 14px; width: 100%; }

/* Info blocks used on application-detail.ejs */
.info-row { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); margin: 0 0 var(--space-2); }
.info-row:last-child { margin-bottom: 0; }
.info-label { color: var(--text-secondary); font-weight: 600; }
