:root {
  --color-bg: #16141d;
  --color-surface: #201d2b;
  --color-surface-muted: #2a2637;
  --color-border: #3a3548;
  --color-primary: #a78bfa;
  --color-primary-emphasis: #c4b5fd;
  --color-primary-hover: #7c3aed;
  --color-primary-light: #2f2a45;
  --color-primary-soft: #221f30;
  --color-text: #ece9f5;
  --color-text-muted: #9a94ac;
  --color-success: #34d399;
  --color-success-light: #16332a;
  --color-danger: #f87171;
  --color-danger-light: #3a1f22;
  --color-warning: #fbbf24;
  --color-warning-light: #362a12;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);

  /* Qualitative chart palette, one per application status */
  --chart-saved: #6b7280;
  --chart-applied: #a78bfa;
  --chart-online_assessment: #38bdf8;
  --chart-interview: #fbbf24;
  --chart-offer: #34d399;
  --chart-rejected: #f87171;
  --chart-withdrawn: #78716c;
}

* { box-sizing: border-box; }

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

a { color: var(--color-primary); transition: color 0.15s ease; }
a:hover { color: var(--color-primary-emphasis); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* ---- Nav ---- */
.nav {
  background: linear-gradient(180deg, var(--color-surface), var(--color-primary-soft));
  border-bottom: 3px solid var(--color-primary);
  margin-bottom: 32px;
}

.nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  color: var(--color-primary-emphasis);
  text-decoration: none;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin-right: auto;
}

.nav-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
  color: var(--color-bg);
  font-weight: 900;
  font-size: 1rem;
  box-shadow: var(--shadow);
}

.nav-links { display: flex; gap: 18px; align-items: center; }
.nav-links a {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.nav-links a:hover { color: var(--color-primary); border-color: var(--color-primary-light); }
.nav-links form { display: inline; }

.nav-user {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.badge-admin {
  background: var(--color-primary);
  color: #16141d;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---- View-as banner ---- */
.viewing-banner {
  background: linear-gradient(90deg, var(--color-primary-hover), var(--color-primary));
  color: #16141d;
  padding: 10px 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.viewing-banner form { display: inline; }
.viewing-banner button {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.3);
  color: #16141d;
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s ease;
}
.viewing-banner button:hover { background: rgba(0, 0, 0, 0.25); }

/* ---- Cards / surfaces ---- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card h2, .card h3 { margin-top: 0; color: var(--color-primary-emphasis); }

/* ---- Auth pages ---- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--color-bg), #241f38 60%, #3b2f5c 140%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  border-top: 4px solid var(--color-primary);
}

.auth-card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
  color: var(--color-primary-emphasis);
  font-weight: 800;
}

.auth-card p.subtitle { color: var(--color-text-muted); margin-top: 0; margin-bottom: 24px; font-size: 0.9rem; }

.auth-footer {
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* ---- Forms ---- */
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; color: var(--color-text); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="url"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--color-bg);
  color: var(--color-text);
  margin-bottom: 16px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.25);
}

textarea { resize: vertical; min-height: 80px; }

.btn {
  display: inline-block;
  background: var(--color-primary);
  color: #16141d;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.btn:hover { background: var(--color-primary-hover); color: white; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(167, 139, 250, 0.3); }
.btn:active { transform: translateY(0); }
.btn-block { width: 100%; text-align: center; }
.btn-secondary { background: var(--color-surface-muted); color: var(--color-primary-emphasis); }
.btn-secondary:hover { background: var(--color-primary-light); box-shadow: none; }
.btn-danger { background: var(--color-danger); color: #16141d; }
.btn-danger:hover { background: #ef4444; color: white; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

.form-row { display: flex; gap: 16px; }
.form-row > div { flex: 1; }
.form-status { font-size: 0.82rem; color: var(--color-text-muted); margin-left: 10px; }

/* ---- Alerts ---- */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  margin-bottom: 18px;
}
.alert-error { background: var(--color-danger-light); color: var(--color-danger); }
.alert-success { background: var(--color-success-light); color: var(--color-success); }
.alert-info { background: var(--color-primary-light); color: var(--color-primary-emphasis); }
.alert code {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--color-text);
  border-radius: 4px;
  word-break: break-all;
  font-size: 0.82rem;
}

/* ---- Stat cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; color: var(--color-primary-emphasis); }
.stat-card .stat-label { font-size: 0.78rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

/* ---- Charts ---- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 720px) {
  .charts-grid { grid-template-columns: 1fr; }
}
.chart-card { display: flex; flex-direction: column; align-items: center; }
.donut-chart { width: 220px; height: 220px; }
.donut-segment { transition: stroke-width 0.15s ease; }
.donut-segment:hover { stroke-width: 32; }
.donut-center-value { fill: var(--color-primary-emphasis); font-size: 2rem; font-weight: 800; font-family: inherit; }
.donut-center-label { fill: var(--color-text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; font-family: inherit; }
.chart-legend { list-style: none; padding: 0; margin: 16px 0 0; width: 100%; font-size: 0.85rem; }
.chart-legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--color-text-muted); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }

.funnel-card { align-items: stretch; }
.funnel-chart { width: 100%; }
.funnel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.funnel-label { width: 110px; flex-shrink: 0; font-size: 0.82rem; color: var(--color-text-muted); }
.funnel-track { flex: 1; background: var(--color-surface-muted); border-radius: 999px; height: 18px; overflow: hidden; }
.funnel-bar { height: 100%; border-radius: 999px; transition: width 0.3s ease; min-width: 2px; }
.funnel-count { width: 28px; text-align: right; font-size: 0.82rem; font-weight: 700; color: var(--color-text); }
.funnel-terminal-outcomes { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.terminal-chip { padding: 4px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.terminal-chip-rejected { background: var(--color-danger-light); color: var(--color-danger); }
.terminal-chip-withdrawn { background: var(--color-surface-muted); color: var(--color-text-muted); }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
th { color: var(--color-primary-emphasis); font-weight: 700; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--color-primary-soft); }
td.actions, th.actions { text-align: right; white-space: nowrap; }

.sortable-th { cursor: pointer; user-select: none; }
.sortable-th:hover { color: var(--color-primary); }
.sort-indicator { opacity: 0.7; margin-left: 2px; }

/* ---- Status pills ---- */
.pill {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: capitalize;
}
.pill-saved, .pill-applied { background: var(--color-surface-muted); color: var(--color-primary-emphasis); }
.pill-online_assessment, .pill-interview { background: var(--color-primary); color: #16141d; }
.pill-offer { background: var(--color-success); color: #16141d; }
.pill-rejected, .pill-withdrawn { background: var(--color-danger); color: #16141d; }

/* ---- Timeline ---- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline-item {
  padding: 12px 0 12px 20px;
  border-left: 2px solid var(--color-border);
  margin-left: 6px;
  position: relative;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 17px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.timeline .event-meta { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 2px; }
.timeline .event-source-email_scraper, .ev-source.event-source-email_scraper { color: var(--color-primary-emphasis); font-weight: 700; }

.timeline-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.timeline-actions { font-size: 0.78rem; white-space: nowrap; }
.timeline-actions a { font-weight: 600; }
.ev-description { margin-top: 2px; }

.timeline-edit-form { margin-top: 8px; }
.timeline-edit-form textarea { min-height: 60px; }

.quick-actions { display: flex; align-items: center; gap: 8px; margin: 16px 0 12px; flex-wrap: wrap; }
.quick-actions-label { font-size: 0.82rem; color: var(--color-text-muted); font-weight: 600; }

/* ---- Quick links ---- */
.quick-link-add-form { display: flex; gap: 8px; margin-bottom: 14px; }
.quick-link-add-form input { flex: 1; margin: 0; }
.quick-link-add-form button { flex-shrink: 0; }

.quick-links-list { list-style: none; padding: 0; margin: 0; }
.quick-link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.quick-link-item:last-child { border-bottom: none; }
.quick-link-url {
  display: inline-block;
  max-width: 480px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.quick-link-actions { display: flex; gap: 6px; flex-shrink: 0; white-space: nowrap; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 1.5rem; color: var(--color-primary-emphasis); }

.empty-state { color: var(--color-text-muted); padding: 32px 0; text-align: center; }

.slots-indicator { font-size: 0.85rem; color: var(--color-text-muted); font-weight: 600; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters a {
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.filters a:hover { border-color: var(--color-primary); color: var(--color-primary); }
.filters a.active { background: var(--color-primary); border-color: var(--color-primary); color: #16141d; }
