:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1e222a;
  --muted: #6b7280;
  --border: #e3e4e8;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#statusbar h1 { font-size: 18px; margin: 0; flex: 0 0 auto; }
#scrape-status { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.idle { background: var(--muted); }
.dot.running { background: var(--green); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { filter: brightness(1.1); }

#tabs { display: flex; gap: 4px; padding: 8px 20px 0; }
#tabs .tab { background: transparent; color: var(--muted); border-radius: 6px 6px 0 0; }
#tabs .tab.active { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-bottom: none; }

main { padding: 16px 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Two visually distinct search modes, each in its own labelled card.
   Filter search = pastel green; AI search = purple (overridden below). */
.search-group {
  position: relative;
  border: 1px solid #a5d6b0;
  border-radius: 8px;
  padding: 16px 12px 12px;
  margin-bottom: 12px;
  background: color-mix(in srgb, #a5d6b0 8%, var(--panel));
}
.search-group__label {
  position: absolute;
  top: -9px;
  left: 12px;
  padding: 0 6px;
  background: color-mix(in srgb, #a5d6b0 8%, var(--panel));
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #3d8a55;
}
.search-group--ai {
  border-color: #6b3fd4;
  background: color-mix(in srgb, #6b3fd4 6%, var(--panel));
}
.search-group--ai .search-group__label {
  color: #6b3fd4;
  background: color-mix(in srgb, #6b3fd4 6%, var(--panel));
}
/* While an AI search is running, tint the whole card so it reads as "busy". */
.search-group--ai.pending { border-color: #8a63e0; }
.search-group--ai.pending .search-group__label::after { content: " — searching…"; }

#filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
#filters input, #filters select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg, #fff);
  font-size: 13px;
}
#f-q { flex: 1; min-width: 220px; }
#search-btn { background: var(--accent); }

/* Spinner shown while the AI search is pending. */
.btn-spinner { width: 11px; height: 11px; border-width: 2px; vertical-align: -1px; margin-right: 0.3rem; }
.btn-done { color: var(--green); font-weight: 700; margin-right: 0.3rem; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid color-mix(in srgb, #6b3fd4 30%, transparent);
  border-top-color: #6b3fd4;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* On buttons the spinner sits on the accent background — use a whitish ring so
   the rotation is clearly visible. Placed after .spinner to win the cascade. */
.btn-spinner {
  width: 11px; height: 11px;
  border-color: rgba(255, 255, 255, 0.45);
  border-top-color: #ffffff;
}
#ai-status.done { color: var(--green); font-weight: 600; }
#ai-status.pending { color: #6b3fd4; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { background: #fafafa; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: attr(data-arrow); font-size: 10px; margin-left: 4px; }
th.sortable.sorted { color: var(--text); }
tbody tr:hover { background: #f0f4ff; cursor: pointer; }

/* AI search row */
.hidden { display: none !important; }
#ai-filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#ai-filters input, #ai-filters select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg, #fff);
  font-size: 13px;
}
#f-ai { flex: 1; min-width: 340px; resize: vertical; font: inherit; line-height: 1.35; }
/* Dedicated status line below the AI search row: reserving its height keeps
   the textarea/row from resizing when the result summary appears. */
#ai-actions { display: flex; justify-content: flex-start; gap: 8px; margin-top: 6px; }
#ai-status-row { display: flex; align-items: center; gap: 6px; min-height: 1.5rem; margin-top: 2px; }
#ai-filters textarea {
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
  background: var(--panel); color: var(--text);
}
#ai-status { font-size: 12px; color: var(--muted); }
#ai-search-btn { background: #6b3fd4; }

/* companies bar chart */
.chart-title { font-size: 14px; margin: 4px 0 8px; color: var(--muted); }
#companies-chart { margin-bottom: 16px; display: flex; flex-direction: column; gap: 3px; }
.bar-row { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 1px 0; }
.bar-row:hover .bar-label { color: var(--text); }
.bar-label { flex: 0 0 220px; font-size: 12px; text-align: right; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.bar-track { flex: 1; background: #eef1f6; border-radius: 3px; height: 16px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: #3b6cf0; border-radius: 3px; min-width: 2px; }
.bar-value { flex: 0 0 40px; font-size: 12px; font-weight: 600; }

/* favorite + delete columns */
#jobs-actions, #companies-actions { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.check-all { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
#delete-selected:disabled, #scrape-selected:disabled { opacity: .5; cursor: default; }
.col-check, .col-fav { width: 1%; text-align: center; white-space: nowrap; }

/* Jobs-tab bulk delete (select-all, per-row checkboxes, Delete selected) is
   admin-only — hidden for regular users. `body[data-admin]` is set on boot.
   Scoped to #jobs-table so the admin Companies table's checkboxes are untouched. */
#jobs-actions { display: none; }
#jobs-table .col-check { display: none; }
body[data-admin="1"] #jobs-actions { display: flex; }
body[data-admin="1"] #jobs-table .col-check { display: table-cell; }
.star { cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.star:hover, .star.on { color: #f5b301; }
tr.inactive td { color: var(--muted); text-decoration: line-through; }
td.title { font-weight: 600; }
td.error-cell { color: var(--red); font-size: 12px; max-width: 320px; }

.linkish { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
/* Logs tab: window shows ~10 runs; older runs reachable by scrolling. */
#runs-scroll { max-height: 27rem; overflow-y: auto; }
#runs-scroll thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
#f-ai-history { max-width: 16rem; }
/* Sub-tabs inside a main tab (Admin, AI Insights) */
.subtabs { display: flex; gap: 0.25rem; margin: 0 0 1rem; border-bottom: 1px solid var(--border); }
.subtab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 0.4rem 0.8rem; cursor: pointer; color: var(--muted); font-size: 0.9rem;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

/* Recruiting Trends */
.trend-fit { display: flex; align-items: center; gap: 1.1rem; margin-top: 0.9rem; }
.trend-fit h3 { margin: 0 0 0.2rem; }
.fit-big { font-size: 2.6rem; font-weight: 700; line-height: 1; min-width: 4.5rem; text-align: right; }
.fit-big.fit-high { color: var(--green); }
.fit-big.fit-mid { color: var(--amber); }
.fit-big.fit-low { color: var(--red); }
/* Job-drawer: CV picker under the posting link, and a large fit score coloured
   like the CV-based analysis — green ≥75 / orange ≥50 / black below. */
.drawer-cv-row { margin: 4px 0; }
.drawer-score { display: flex; align-items: baseline; gap: 8px; margin: 8px 0; }
.drawer-score .fit-big { min-width: 0; text-align: left; }
.drawer-score-box .fit-big.fit-low { color: var(--text); }
.drawer-score-missing { margin-top: 2px; }
/* Scrollable lists (Firm subscriptions ~20 rows, Usage history ~10 rows) with a
   sticky header so the columns stay visible while scrolling. */
.scroll-y { overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.scroll-y table { margin: 0; }
.scroll-y thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.scroll-subs { max-height: 42rem; }   /* ≈ first 20 firms, then scroll */
.scroll-ledger { max-height: 22rem; } /* ≈ first 10 entries, then scroll */
.scroll-matches { max-height: 42rem; } /* ≈ first 20 CV match rows, then scroll */

/* LLM-usage totals (month-to-date + grand total) sit in the table foot. */
#llm-usage-table tfoot .total-row td { border-top: 2px solid var(--border); padding-top: 8px; }
.scroll-llm-runs { max-height: 31rem; } /* ≈ 15 per-run rows, then scroll */

/* Fit-band gap synthesis (CV analysis). */
.gapsyn { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 14px; margin-top: 10px; }
@media (max-width: 720px) { .gapsyn { grid-template-columns: 1fr; } }
.gapsyn-band { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.gapsyn-band h4 { margin: 0 0 8px; }
.gapsyn-band ul { margin: 4px 0 10px; padding-left: 18px; }
.gapsyn-band li { margin: 3px 0; }
.gapsyn-label { font-weight: 600; margin: 8px 0 2px; }
.gapsyn-reality { font-style: italic; color: var(--muted); }
/* The AI verdict — a labelled badge, deliberately NOT styled like a clickable button. */
.gapsyn-verdict { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.gapsyn-rec { font-weight: 700; color: var(--text, inherit); }

/* CV version list + preview (Profile tab). */
.cv-list { width: 100%; border-collapse: collapse; margin: 8px 0; }
.cv-list td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cv-list tr.cv-selected { background: color-mix(in srgb, var(--accent, #6366f1) 8%, transparent); }
.cv-list a { color: var(--link, #6366f1); text-decoration: none; }
.cv-list a:hover { text-decoration: underline; }
.cv-showanalysis { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.cv-actions { white-space: nowrap; }
.cv-analysis-row td { background: color-mix(in srgb, var(--accent, #6366f1) 5%, transparent); padding: 10px 14px; }
.cv-preview { margin-top: 10px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.cv-preview-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--panel-alt, rgba(127,127,127,.08)); }
.cv-preview-close { font-size: 12px; }
.cv-preview-text { margin: 0; padding: 12px; max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.4; }

/* No in-scope offers → the overlap share is undefined; show a muted label, not 0%. */
.fit-big.fit-nodata { font-size: 1rem; font-weight: 600; color: var(--muted); line-height: 1.2; }
/* Both fit numbers carry an explanatory tooltip — hint that they're hoverable. */
#tr-fit-pct[title], .fit-metric[title] { cursor: help; }
.fit-metric { border-bottom: 1px dotted var(--muted); }
.trend-mix { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.trend-col h4 { margin: 0 0 0.4rem; }
.bar-value.up { color: var(--green); }
.bar-value.down { color: var(--red); }
td.up { color: var(--green); font-weight: 600; }
td.down { color: var(--red); font-weight: 600; }
.callout { margin: 0.75rem 0; padding: 0.75rem 1rem; border: 1px solid var(--amber); border-left-width: 4px; border-radius: 8px; background: color-mix(in srgb, #d97706 6%, transparent); }
.callout h4 { margin: 0 0 0.4rem; color: var(--amber); }
.evidence-link { color: var(--accent); text-decoration: underline; cursor: pointer; }
#tr-analysis h4 { margin: 0.9rem 0 0.3rem; }
.cv-profile { margin: 0.75rem 0; padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 8px; }
.cv-group-label { margin: 0.6rem 0 0.2rem; font-weight: 600; }
.htf { margin-left: 0.35rem; cursor: help; font-size: 0.9em; }
.row-link { cursor: pointer; }
.row-link:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.cv-profile h3 { margin: 0 0 0.4rem; }
.skill-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.chip { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; background: #e0e7ff; color: var(--accent); font-size: 0.8rem; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: #eef1f6;
  color: var(--muted);
}
.badge.remote { background: #dcfce7; color: var(--green); }
.badge.hybrid { background: #fef3c7; color: var(--amber); }
.badge.onsite { background: #e0e7ff; color: var(--accent); }
.badge.completed, .badge.ok, .badge.confirmed { background: #dcfce7; color: var(--green); }
.badge.completed_with_errors, .badge.suggested, .badge.pending { background: #fef3c7; color: var(--amber); }
.badge.failed, .badge.error, .badge.rejected { background: #fee2e2; color: var(--red); }
.badge.running { background: #dbeafe; color: var(--accent); }

#pager { display: flex; align-items: center; gap: 12px; margin-top: 10px; color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.panel h2 { margin-top: 0; font-size: 15px; }
.hint { color: var(--muted); font-size: 12px; }
#import-result { margin-top: 10px; color: var(--muted); }

/* Drawer */
#drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 90vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.08);
  padding: 20px;
  overflow-y: auto;
  z-index: 20;
}
#drawer.hidden { display: none; }
#drawer-close {
  position: absolute;
  top: 10px; right: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  padding: 2px 8px;
}
#drawer h2 { margin: 0 40px 8px 0; }
.meta { color: var(--muted); margin: 4px 0; }
.description {
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  color: #2a2f38;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  overflow-wrap: anywhere;
}
/* Plain-text descriptions keep their original line breaks. */
.description:not(.rich) {
  white-space: pre-wrap;
}
/* Rich (HTML) descriptions: give block elements sensible spacing. */
.description.rich > :first-child { margin-top: 0; }
.description.rich > :last-child { margin-bottom: 0; }
.description.rich p { margin: 0 0 0.75em; }
.description.rich h1,
.description.rich h2,
.description.rich h3,
.description.rich h4,
.description.rich h5,
.description.rich h6 {
  margin: 1em 0 0.4em;
  font-size: 14px;
  font-weight: 600;
}
.description.rich ul,
.description.rich ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.description.rich li { margin: 0.2em 0; }
.description.rich a { color: var(--accent); }
.description.rich blockquote {
  margin: 0 0 0.75em;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.description.rich hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.contacts { margin: 14px 0; padding: 10px 12px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; }
.contacts h3 { margin: 0 0 6px; font-size: 14px; }
.contacts h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.contact { margin: 3px 0; }

/* Toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast {
  background: var(--text);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 380px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}
.toast.error { background: var(--red); }
.toast.new { background: var(--green); }

#run-detail { margin-top: 16px; }

/* Profile tab */
.prof-label { display: block; margin: 10px 0 6px; font-size: 13px; color: var(--muted); max-width: 640px; }
.prof-label input { display: block; width: 100%; box-sizing: border-box; margin-top: 4px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg, #fff); font-size: 13px; }
#crit-save { margin-top: 10px; }
#subs-table input[type="text"] { width: 100%; box-sizing: border-box; padding: 5px 7px;
  border: 1px solid var(--border); border-radius: 5px; font-size: 12px; }
#subs-table .subs-cc { max-width: 90px; }

/* Account / admin */
.keyrow { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.keyrow > span:first-child { flex: 0 0 160px; font-size: 13px; }
.keyrow input { flex: 1; max-width: 380px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input[type="email"], .inline-form input[type="text"] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
#ledger-table td, #admin-users-table td { font-size: 12px; }

/* Candidate-signal grid in the job drawer */
dl.signals {
  display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px;
  background: #f6f8fc; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; margin: 10px 0; font-size: 13px;
}
dl.signals dt { color: var(--muted); font-weight: 600; }
dl.signals dd { margin: 0; }

/* Advert-age filter (days) */
.age-filter { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.age-filter input { width: 64px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* Apply-by (application deadline) column */
td.apply-by { white-space: nowrap; }
td.apply-by.soon { color: var(--amber); font-weight: 600; }
td.apply-by.closed { color: var(--muted); text-decoration: line-through; }

/* Insights tab */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.two-col h3 { margin: 4px 0 6px; font-size: 14px; }
#ins-match-table .fit { font-weight: 700; white-space: nowrap; }
.fit-high { color: var(--green); } .fit-mid { color: var(--amber); } .fit-low { color: var(--muted); }
#tailor-result { background: #f6f8fc; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 10px 0; font-size: 13px; }
#tailor-result h4 { margin: 8px 0 4px; font-size: 12px; text-transform: uppercase; color: var(--muted); }

/* ----- predefined portal categories (facet editor in Firm subscriptions) ----- */
.facet-editor { padding: 8px 4px; display: flex; flex-direction: column; gap: 6px; }
.facet-cat > summary { cursor: pointer; font-weight: 600; }
.facet-cat input[type="search"] { margin: 6px 0 4px; width: min(320px, 100%); }
.facet-list { max-height: 260px; overflow-y: auto; display: grid;
              grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
              gap: 2px 14px; padding: 4px 2px; }
.facet-item { display: flex; align-items: baseline; gap: 4px; font-size: 0.92em;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.facet-actions { margin-top: 4px; }
.facet-editor-row td { background: color-mix(in srgb, var(--panel, #f6f7f9) 88%, transparent); }

/* clickable table rows (Macro salary table -> firm's offers) */
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: color-mix(in srgb, var(--accent, #3b82f6) 10%, transparent); }

/* destructive row action (Admin -> Companies "Delete") */
button.btn-danger { background: #b91c1c; color: #fff; }
button.btn-danger:hover { filter: brightness(1.15); }

/* headhunter-sourced offers (hiring firm anonymous, agency in the middle) */
.badge.headhunter { background: #7c3aed; color: #fff; margin-left: 6px; }

/* admin-only UI (model selection, house API keys) — hidden for regular users */
.admin-only { display: none; }
body[data-admin="1"] .admin-only { display: block; }
