:root {
  --bg: #0a0c14;
  --surface: #12151f;
  --surface2: #1a1f2e;
  --border: #2a3348;
  --text: #e8eaef;
  --muted: #8892a8;
  --accent: #e07a5f;
  --accent2: #3d5a80;
  --success: #52b788;
  --danger: #e63946;
  --warning: #f4a261;
  --radius: 12px;
  --font: 'Syne', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── Landing / spider web ─────────────────────────────── */
.landing-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

.web-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse at center, #151929 0%, #0a0c14 70%);
}

.web-background svg {
  width: 100%;
  height: 100%;
  animation: webPulse 8s ease-in-out infinite;
}

@keyframes webPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.landing-center {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 2rem;
  width: 100%;
  max-width: 420px;
}

.brand { text-align: center; }

.brand-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

.brand h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.auth-card {
  width: 100%;
  background: rgba(18, 21, 31, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.auth-card h2 {
  font-size: 1.25rem;
  margin-bottom: 1.25rem;
  font-weight: 600;
}

.auth-card label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  margin-top: 0.85rem;
}

.auth-card input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224,122,95,0.15);
}

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

.auth-note { text-align: center; margin-top: 1rem; font-size: 0.85rem; color: var(--warning); }

.landing-footer {
  position: fixed;
  bottom: 1rem;
  z-index: 1;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #c45c42);
  color: #fff;
}

.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }

.auth-card .btn-primary,
.crawl-form .btn-primary,
.profile-form .btn-primary {
  width: 100%;
  margin-top: 1.25rem;
}

.btn-primary.btn-sm {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-danger.btn-sm {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #0a0c14; }
.btn-warning { background: var(--warning); color: #0a0c14; }

.btn-icon {
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  margin: 0 0.15rem;
}

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 0.75rem; }
.success-msg { color: var(--success); font-size: 0.85rem; margin-top: 0.75rem; }

/* ── App layout ─────────────────────────────────────── */
.app-body { min-height: 100vh; }

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand { font-weight: 800; font-size: 1.1rem; }

.badge-admin {
  font-size: 0.65rem;
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.nav-user { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.nav-link { color: var(--muted); font-size: 0.85rem; }

.app-layout {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  flex-shrink: 0;
}

.sidebar-item {
  display: block;
  padding: 0.75rem 1.5rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}

.sidebar-item:hover { color: var(--text); background: var(--surface2); text-decoration: none; }
.sidebar-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(224,122,95,0.08);
}

.main-content {
  flex: 1;
  padding: 2rem;
  max-width: 1100px;
}

.panel { display: none; }
.panel.active { display: block; }

.main-content h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.95rem; }

/* ── Forms ──────────────────────────────────────────── */
.crawl-form label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; margin-top: 1rem; }

.crawl-form textarea,
.crawl-form input {
  width: 100%;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 0.5rem;
}

.crawl-form .btn-primary { width: auto; margin-top: 1.5rem; }

.status-banner {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.status-banner.running { background: rgba(61,90,128,0.3); border: 1px solid var(--accent2); }
.status-banner.success { background: rgba(82,183,136,0.15); border: 1px solid var(--success); }
.status-banner.error { background: rgba(230,57,70,0.15); border: 1px solid var(--danger); }

/* ── Live crawl progress ────────────────────────────── */
.crawl-progress {
  margin-top: 1.25rem;
  background: linear-gradient(145deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.progress-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.progress-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.progress-elapsed {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.progress-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(126, 184, 218, 0.25);
  border-top-color: #7eb8da;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-bar-track {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--success));
  border-radius: 999px;
  transition: width 0.4s ease;
  min-width: 2%;
}

.progress-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.progress-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  text-align: center;
}

.progress-stat span {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
  font-family: var(--mono);
  line-height: 1.2;
}

.progress-stat label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 0.15rem;
}

.progress-current {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  word-break: break-all;
}

.progress-feed {
  list-style: none;
  max-height: 140px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin: 0;
}

.progress-feed li {
  font-size: 0.78rem;
  font-family: var(--mono);
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--muted);
  animation: feed-in 0.3s ease;
}

.progress-feed li.success { color: var(--success); }
.progress-feed li.warn { color: #e9c46a; }

@keyframes feed-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.crawl-progress.is-complete .progress-spinner {
  animation: none;
  border-color: var(--success);
  border-top-color: var(--success);
  background: var(--success);
}

.crawl-progress.is-complete .progress-bar-fill {
  background: var(--success);
}

/* ── Jobs list / timeline ───────────────────────────── */
.jobs-list { display: flex; flex-direction: column; gap: 0.75rem; }

.jobs-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 1rem;
  border-left: 2px solid var(--border);
  margin-left: 0.5rem;
  padding-left: 1.5rem;
}

.timeline-item {
  position: relative;
  margin-bottom: 1rem;
  cursor: pointer;
}

.timeline-dot {
  position: absolute;
  left: -1.85rem;
  top: 1.25rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  border: 2px solid var(--bg);
}

.timeline-dot.completed { background: var(--success); }
.timeline-dot.running, .timeline-dot.queued { background: #7eb8da; }
.timeline-dot.failed { background: var(--danger); }

.timeline-body {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.timeline-meta {
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: var(--mono);
  flex-shrink: 0;
}

.job-urls {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
  word-break: break-all;
}

.empty-msg { color: var(--muted); margin-top: 1rem; }

.field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.field-header label { margin: 0; }

/* ── Email copy box ─────────────────────────────────── */
.email-result-box {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.email-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.email-box-header strong {
  flex: 1;
  min-width: 0;
}

.history-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.timeline-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.timeline-item .job-card {
  cursor: pointer;
}

.email-copy-field {
  width: 100%;
  padding: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  resize: vertical;
  line-height: 1.5;
}

/* ── Profile ────────────────────────────────────────── */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
}

.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.profile-card h3 { margin-bottom: 1rem; }
.profile-card h4 { font-size: 0.85rem; margin: 1.25rem 0 0.5rem; }

.profile-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
}

.profile-dl dt { color: var(--muted); font-weight: 600; }
.profile-dl dd { margin: 0; font-family: var(--mono); font-size: 0.85rem; }

.ip-list { list-style: none; }
.ip-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.ip-list code { font-size: 0.85rem; }

.profile-form label { display: block; margin-top: 0.75rem; font-size: 0.85rem; }
.profile-form input {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.profile-form .btn { margin-top: 1rem; }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-row input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.form-msg { margin-top: 0.75rem; font-size: 0.85rem; }
.form-msg.success { color: var(--success); }
.form-msg.error { color: var(--danger); }

.muted { color: var(--muted); font-weight: 400; }

.modal-wide { max-width: 640px; }

.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s;
}

.job-card:hover { border-color: var(--accent2); }

.job-card .job-meta { font-size: 0.8rem; color: var(--muted); font-family: var(--mono); }

.status-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pill.completed { background: rgba(82,183,136,0.2); color: var(--success); }
.status-pill.running, .status-pill.queued, .status-pill.cancelling { background: rgba(61,90,128,0.3); color: #7eb8da; }
.status-pill.cancelled { background: rgba(244,162,97,0.2); color: var(--warning); }
.status-pill.failed { background: rgba(230,57,70,0.2); color: var(--danger); }

.crawl-progress.is-cancelled .progress-spinner {
  animation: none;
  border-color: var(--warning);
  border-top-color: var(--warning);
  background: var(--warning);
}

/* ── Stats grid ─────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
}

.stat-card .stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

/* ── Tables ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin-top: 1rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }

.data-table tr:hover td { background: var(--surface2); }

/* ── Activity ───────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }

.activity-item {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.activity-item .time { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; min-width: 160px; }
.activity-item .action { font-weight: 600; color: var(--accent); min-width: 140px; }

/* ── Settings ───────────────────────────────────────── */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1rem;
  max-width: 480px;
}

.settings-card h3 { margin-bottom: 0.5rem; }
.settings-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }
.settings-status { margin-top: 0.75rem; font-weight: 600; }

/* ── Modal ──────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.email-list {
  list-style: none;
  margin-top: 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.email-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-item { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .sidebar-item.active { border-bottom-color: var(--accent); border-left: none; }
  .form-row { grid-template-columns: 1fr; }
}
