:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --grid: #ecebe7;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --chip: #f0efec;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --border: #2e2e2b;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --grid: #262624;
    --chip: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --border: #2e2e2b; --text: #ffffff; --text-2: #c3c2b7;
  --muted: #8f8e86; --accent: #3987e5; --series-1: #3987e5; --grid: #262624; --chip: #383835;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
.muted { color: var(--muted); font-weight: normal; }
button, select, input, textarea { font: inherit; color: var(--text); }
button { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--text-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small { padding: 3px 8px; font-size: 12px; }
select, input:not([type=checkbox]):not([type=file]) { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; width: 100%; }

.top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav button { border: none; background: none; color: var(--text-2); }
nav button.active { background: var(--chip); color: var(--text); }
.agent { display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--chip); color: var(--text-2); }
.pill.running::before { content: "● "; color: var(--good); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }
.tab { display: none; }
.tab.active { display: block; }
.banner { background: var(--chip); border-left: 4px solid var(--warning); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tile-label { color: var(--text-2); font-size: 13px; }
.tile-value { font-size: 30px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; position: relative; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.row-head h2 { margin: 0; }
.row-head select { width: auto; }
.filters { display: flex; gap: 8px; }

.chart svg { width: 100%; height: 220px; display: block; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { opacity: .8; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: 12px; white-space: nowrap; }
td .company { font-weight: 600; }
td .sub { color: var(--muted); font-size: 12px; }
.score { font-variant-numeric: tabular-nums; font-weight: 600; }
.meter { width: 60px; height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
.chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--chip); color: var(--text-2); margin: 1px 2px 1px 0; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.applied::before, .status.shortlisted::before, .status.interview::before { background: var(--good); }
.status.needs_manual::before, .status.ready::before { background: var(--warning); }
.status.failed::before, .status.rejection::before { background: var(--critical); }
.actions-cell { display: flex; gap: 4px; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

.upload { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.settings .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 16px; }
.settings label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 13px; }
.settings small { color: var(--muted); }
.checks { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; color: var(--text-2); }
.checks label { display: flex; align-items: center; gap: 6px; }
.actions { display: flex; gap: 12px; align-items: center; }
.log div { padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log .warn { color: var(--serious); }
.log .error { color: var(--critical); }
.log time { color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }

dialog { max-width: 760px; width: calc(100% - 32px); border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog pre { white-space: pre-wrap; background: var(--chip); padding: 12px; border-radius: 8px; font: 13px/1.5 inherit; max-height: 300px; overflow: auto; }

@media (max-width: 640px) {
  .top { padding: 10px 16px; }
  main { padding: 16px; }
  .tile-value { font-size: 24px; }
}

/* ---------------- shared additions ---------------- */
.small { font-size: 12px; }
button:disabled { opacity: .55; cursor: default; }
button.wide { width: 100%; padding: 10px; }
button.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.chip.accent { background: var(--accent); color: var(--accent-ink); }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: calc(100% - 32px); }
details summary { cursor: pointer; color: var(--text-2); margin: 4px 0 12px; }
.danger-zone summary { color: var(--critical); }

/* ---------------- auth pages ---------------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-card .brand { font-size: 20px; }
.auth-card h1 { font-size: 20px; margin: 18px 0 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); font-size: 13px; }
.auth-card small { color: var(--muted); }
.auth-links { font-size: 13px; color: var(--text-2); text-align: center; margin-top: 16px; }
.form-error { color: var(--critical); font-size: 13px; min-height: 1em; }
.form-ok { color: var(--good); font-size: 13px; }

/* ---------------- onboarding ---------------- */
.setup .steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.setup .steps li.done { color: var(--muted); text-decoration: line-through; }
.setup .steps li.done a { color: var(--muted); }

/* ---------------- job search ---------------- */
.search-card { display: grid; gap: 12px; }
.search-row { display: grid; grid-template-columns: 2fr 1fr auto; gap: 8px; }
.search-row input { font-size: 15px; padding: 10px 12px !important; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-row select { width: auto; }
.toggle-group { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.toggle-group label { padding: 6px 10px; cursor: pointer; display: flex; gap: 5px; align-items: center; border-right: 1px solid var(--border); }
.toggle-group label:last-child { border-right: none; }
.chk { display: inline-flex; gap: 5px; align-items: center; padding: 6px 4px; color: var(--text-2); }
.results-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 2px 10px; font-size: 13px; }
.results.loading { opacity: .5; }
.job { display: grid; grid-template-columns: 1fr auto; gap: 16px; margin-bottom: 10px; }
.job h3 { margin: 0 0 2px; font-size: 16px; }
.job h3 a { color: var(--text); text-decoration: none; }
.job h3 a:hover { color: var(--accent); }
.job-company { font-weight: 600; margin-bottom: 6px; }
.job-company .muted { font-weight: 400; }
.job-chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.job-why, .job-snippet { margin: 8px 0 0; font-size: 13px; color: var(--text-2); }
.job-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; min-width: 150px; }
.job-side .actions-cell { justify-content: flex-end; }
.match-badge .score { font-size: 20px; text-align: right; }
.match-badge .meter { width: 80px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 16px 0; }
.analysis { display: flex; gap: 16px; background: var(--chip); padding: 12px; border-radius: 8px; margin: 12px 0; }
.analysis p { margin: 0 0 6px; }
.description { white-space: pre-wrap; font-size: 13px; line-height: 1.6; color: var(--text-2); max-height: 50vh; overflow: auto;
  border-top: 1px solid var(--border); padding-top: 8px; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.dialog-close { margin-top: 12px; text-align: right; }

@media (max-width: 640px) {
  .search-row { grid-template-columns: 1fr; }
  .job { grid-template-columns: 1fr; }
  .job-side { align-items: flex-start; min-width: 0; }
  .top { gap: 8px; }
  .brand { flex: 1; }
  nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  nav button { white-space: nowrap; }
  .agent { gap: 6px; }
  .agent .pill { display: none; }
  .user-name { display: none; }
}
