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

:root {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --border: #2a2d3e;
  --accent: #5b8dee;
  --accent-hover: #4a7de0;
  --green: #4caf7d;
  --yellow: #f5c842;
  --red: #e05555;
  --text: #e8eaf6;
  --muted: #8b8fa8;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ──────────────────────────────────────────────────────────── */
header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
header .logo { font-size: 1.4rem; font-weight: 700; color: var(--accent); }
header .mode-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Main layout ─────────────────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 1.5rem;
  gap: 2rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Search box ──────────────────────────────────────────────────────── */
.search-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.search-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.search-card p {
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-size: 0.93rem;
}

textarea#query {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.9rem 1rem;
  resize: vertical;
  min-height: 90px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
textarea#query:focus { border-color: var(--accent); }

.row { display: flex; gap: 0.75rem; margin-top: 1rem; align-items: center; flex-wrap: wrap; }

button#search-btn {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 2rem;
  cursor: pointer;
  transition: background 0.2s;
}
button#search-btn:hover { background: var(--accent-hover); }
button#search-btn:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }

/* ─── Progress panel ──────────────────────────────────────────────────── */
#progress-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: none;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.progress-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1rem;
  font-weight: 600;
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.75); }
}
.progress-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
}
#jobs-live-count { color: var(--green); font-weight: 600; }

.progress-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7eb3ff);
  border-radius: 2px;
  transition: width 0.6s ease;
  width: 0%;
}

/* Stage steps */
.stage-steps {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.stage-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: all 0.3s;
  opacity: 0.35;
}
.stage-step.active {
  opacity: 1;
  background: rgba(91,141,238,0.07);
  border-color: rgba(91,141,238,0.25);
}
.stage-step.done {
  opacity: 0.6;
}
.step-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all 0.3s;
}
.stage-step.active .step-icon {
  background: var(--accent);
  color: #fff;
}
.stage-step.done .step-icon {
  background: var(--green);
  color: #fff;
}
.stage-step.done .step-icon::before { content: "✓"; }
.stage-step.done .step-icon > * { display: none; }
.step-label {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
}
.step-detail {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 1px;
}

.source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.source-chip {
  font-size: 0.72rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  color: var(--muted);
  transition: all 0.3s;
}
.source-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(91,141,238,0.08);
}
.progress-hint {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.7;
}

/* ─── Search history ─────────────────────────────────────────────────── */
#history-panel { width: 100%; }
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.history-title { font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.history-clear {
  font-size: 0.75rem;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.history-clear:hover { color: var(--red); }
.history-list { display: flex; flex-direction: column; gap: 0.3rem; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
  gap: 1rem;
}
.history-item:hover { border-color: var(--accent); }
.history-query { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.history-meta { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

/* ─── Results panel ───────────────────────────────────────────────────── */
#results-panel {
  width: 100%;
  display: none;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.results-header h2 { font-size: 1rem; font-weight: 600; }

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--green);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.25rem;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.2s;
}
.download-btn:hover { opacity: 0.85; }

table.jobs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.jobs-table th {
  background: #12152a;
  padding: 0.7rem 0.85rem;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.jobs-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.jobs-table tr:last-child td { border-bottom: none; }
.jobs-table tr:hover td { background: rgba(91,141,238,0.05); }

.score-pill {
  display: inline-block;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 20px;
}
.score-high { background: rgba(76,175,125,0.15); color: var(--green); }
.score-mid  { background: rgba(245,200,66,0.15); color: var(--yellow); }
.score-low  { background: rgba(139,143,168,0.1); color: var(--muted); }

.company { font-weight: 600; }
.title a { color: var(--accent); text-decoration: none; }
.title a:hover { text-decoration: underline; }
.source-tag {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}

/* ─── Footer ──────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 1.5rem;
  border-top: 1px solid var(--border);
}
footer a { color: var(--muted); }

/* ─── Error toast ─────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #2d1a1a;
  border: 1px solid var(--red);
  color: #ff8080;
  border-radius: 8px;
  padding: 0.75rem 1.2rem;
  font-size: 0.88rem;
  display: none;
  max-width: 400px;
  z-index: 999;
}
