/* ─────────────────────────────────────────────────────────────────
   JobMatch — Apple-flavored UI. System font, generous whitespace,
   restrained color, soft depth. Auto light/dark with manual override.
   ───────────────────────────────────────────────────────────────── */

:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --border: #e3e3e6;
  --accent: #0071e3;
  --accent-press: #0058b0;
  --green: #2aa745;
  --green-bg: #e7f6ea;
  --blue: #0071e3;
  --blue-bg: #e6f0fd;
  --amber: #b6791f;
  --amber-bg: #fbf0db;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 28px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 980px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --text: #f5f5f7;
  --text-2: #aeaeb2;
  --text-3: #8e8e93;
  --border: #38383a;
  --accent: #0a84ff;
  --accent-press: #409cff;
  --green: #30d158; --green-bg: #16331f;
  --blue: #0a84ff;  --blue-bg: #122a44;
  --amber: #ffd60a; --amber-bg: #332a08;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 12px 40px rgba(0,0,0,.5);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  transition: background .4s ease, color .4s ease;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

/* ── Top bar ───────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 52px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.wordmark {
  font-weight: 600; font-size: 19px; letter-spacing: -.02em;
  display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none;
}
.wordmark .dot, .auth-brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--green));
  -webkit-mask: radial-gradient(circle, transparent 31%, #000 32%);
          mask: radial-gradient(circle, transparent 31%, #000 32%);
}
.auth-brand .dot { width: 20px; height: 20px; flex: none; }
.topnav { display: flex; align-items: center; gap: 6px; }
.navlink {
  border: 0; background: transparent; color: var(--text-2);
  font-size: 14px; font-weight: 500; padding: 7px 12px; border-radius: 8px;
  transition: background .2s, color .2s;
}
.navlink:hover { background: var(--surface-2); color: var(--text); }
.navlink.active { color: var(--text); }
.count { color: var(--text-3); font-size: 12px; }
.icon-btn {
  border: 0; background: transparent; color: var(--text-2);
  width: 34px; height: 34px; border-radius: 9px; font-size: 16px;
  transition: background .2s; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 500;
  padding: 6px 13px; border-radius: 999px; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: border-color .2s, transform .1s;
}
.chip:hover { border-color: var(--text-3); }
.chip:active { transform: scale(.97); }

/* Skills chip editor (atomic skills — no delimiter parsing, commas allowed in a skill) */
.chip-editor {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.chip-editor:focus-within { border-color: var(--text-3); }
.skill-chips { display: contents; }
.skill-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 6px 4px 11px; font-size: 13px;
}
.skill-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skill-chip button {
  border: none; background: transparent; color: var(--text-3); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 3px; border-radius: 50%;
}
.skill-chip button:hover { color: var(--text); }
.chip-input {
  border: none; outline: none; background: transparent; color: var(--text);
  font-size: 13.5px; flex: 1; min-width: 150px; padding: 4px 2px;
}

/* ── Layout ────────────────────────────────────────────────────── */
.container { max-width: var(--maxw); margin: 0 auto; padding: 0 24px 96px; }
.view { animation: fade .45s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero { text-align: center; padding: 72px 0 36px; }
.hero.compact { padding: 56px 0 28px; }
.display {
  font-size: clamp(34px, 5vw, 52px); font-weight: 700; letter-spacing: -.035em;
  line-height: 1.06; margin: 0 0 16px;
}
.lede { font-size: 19px; color: var(--text-2); max-width: 540px; margin: 0 auto; line-height: 1.45; }

/* ── Buttons ───────────────────────────────────────────────────── */
.primary {
  border: 0; background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 500; padding: 11px 22px; border-radius: 999px;
  transition: background .2s, transform .08s, box-shadow .2s;
  box-shadow: var(--shadow-sm);
}
.primary:hover { background: var(--accent-press); }
.primary:active { transform: scale(.97); }
.primary.big { font-size: 17px; padding: 15px 34px; }
.secondary {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500; padding: 9px 18px; border-radius: 999px;
  transition: border-color .2s, transform .08s;
}
.secondary:hover { border-color: var(--text-3); }
.secondary:active { transform: scale(.97); }
.ghost-link {
  border: 0; background: transparent; color: var(--accent);
  font-size: 14px; font-weight: 500; padding: 6px 2px;
}
.ghost-link:hover { text-decoration: underline; }

.action-row { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.refine-toggle {
  border: 0; background: transparent; color: var(--text-2); font-size: 14px;
  font-weight: 500; display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px;
  border-radius: 8px; transition: background .2s, color .2s;
}
.refine-toggle:hover { background: var(--surface-2); color: var(--text); }
.refine-toggle .chev { transition: transform .25s; font-size: 11px; }
.refine-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

/* ── Dropzone ──────────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border); border-radius: 22px; background: var(--surface);
  padding: 56px 32px; text-align: center; max-width: 600px; margin: 0 auto;
  transition: border-color .25s, background .25s, transform .15s; outline: none;
}
.dropzone:hover, .dropzone:focus { border-color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: var(--blue-bg); transform: scale(1.01); }
.drop-icon {
  width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--surface-2); color: var(--accent);
  display: grid; place-items: center; font-size: 22px; font-weight: 600;
}
.drop-title { font-size: 18px; font-weight: 600; margin-bottom: 5px; }
.drop-sub { color: var(--text-3); font-size: 14px; margin-bottom: 16px; }
.paste-area { max-width: 600px; margin: 18px auto 0; display: flex; flex-direction: column; gap: 12px; }
.paste-area textarea {
  width: 100%; min-height: 200px; padding: 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px; resize: vertical;
}
.paste-area .primary { align-self: center; }
.note {
  max-width: 600px; margin: 16px auto 0; text-align: center; color: var(--amber);
  background: var(--amber-bg); padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px;
}

/* ── Refine drawer ─────────────────────────────────────────────── */
.refine {
  margin: 26px auto 0; max-width: var(--maxw); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; animation: drawer .3s ease;
}
@keyframes drawer { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.refine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 22px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field > span em { color: var(--accent); font-style: normal; font-weight: 600; }
.field input:not([type="checkbox"]):not([type="range"]):not([type="file"]),
.field select, .field textarea {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
/* Neutralize the browser's autofill tint (yellow in light, lavender in dark) so
   autofilled fields match every other input. */
input:-webkit-autofill, input:-webkit-autofill:hover,
input:-webkit-autofill:focus, input:-webkit-autofill:active,
textarea:-webkit-autofill, select:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--text);
  transition: background-color 9999s ease 0s;
}
.range-hint { font-size: 12px; color: var(--text-3); }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* Auth overlay (#12b) — covers the app until a session exists. */
.auth-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 34px 30px;
  display: flex; flex-direction: column; gap: 14px;
}
.auth-brand {
  font-size: 24px; font-weight: 700; letter-spacing: -0.4px;
  display: flex; align-items: center; gap: 10px;
}
.auth-sub { font-size: 14px; color: var(--text-2); margin: -6px 0 4px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .primary { margin-top: 4px; }
.auth-error { font-size: 13px; color: #c0392b; }
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { width: 100%; padding-right: 62px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: var(--accent); font-family: inherit;
  font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 6px 8px;
}
.pw-toggle:hover { color: var(--accent-press); }
.auth-switch { font-size: 13.5px; color: var(--text-2); margin: 2px 0 0; }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* Hover hints — custom bubble (native title tooltips have a browser-fixed
   ~1s delay and tiny text; this shows instantly on the label itself). */
.field span[data-tip] {
  position: relative; cursor: help; width: fit-content;
  text-decoration: underline dotted var(--text-3);
  text-underline-offset: 3px;
}
.field span[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 9px); left: 0;
  width: max-content; max-width: 300px;
  padding: 9px 12px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  font-size: 13.5px; font-weight: 500; line-height: 1.45; white-space: normal;
  box-shadow: var(--shadow); z-index: 60;
  opacity: 0; transform: translateY(3px); pointer-events: none;
  transition: opacity .09s ease, transform .09s ease;
}
.field span[data-tip]::before {
  content: ""; position: absolute; bottom: calc(100% + 4px); left: 12px;
  border: 5px solid transparent; border-top-color: var(--text);
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity .09s ease;
}
.field span[data-tip]:hover::after { opacity: 1; transform: none; }
.field span[data-tip]:hover::before { opacity: 1; }

.switch-field { flex-direction: row; align-items: center; justify-content: space-between; }
.switch-hint { display: block; font-style: normal; font-weight: 400; font-size: 12px; color: var(--text-3); }
.switch { position: relative; display: inline-block; width: 46px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .25s;
}
.switch .track:before {
  content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .25s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track:before { transform: translateX(18px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: 1px solid var(--border); background: var(--bg); color: var(--text-2);
  font-size: 13px; font-weight: 500; padding: 7px 14px; border-radius: 999px;
  transition: all .18s;
}
.pill:hover { border-color: var(--text-3); }
.pill.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.refine-foot { margin-top: 18px; display: flex; justify-content: flex-end; }

.banner {
  margin: 22px auto 0; max-width: var(--maxw); background: var(--blue-bg); color: var(--text);
  border-radius: var(--radius-sm); padding: 13px 18px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.banner a { font-weight: 600; }

/* ── Results ───────────────────────────────────────────────────── */
.results-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 40px 0 22px; gap: 16px;
}
.results-head h2 { font-size: 28px; font-weight: 700; letter-spacing: -.025em; margin: 0; }
.results-meta { color: var(--text-3); font-size: 14px; margin: 6px 0 0; }

.cards { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .25s, border-color .2s;
  display: grid; grid-template-columns: 64px 1fr auto; gap: 18px; align-items: start;
  animation: fade .4s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--text-3); }

.score {
  width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center;
  font-size: 22px; font-weight: 700; letter-spacing: -.02em; flex-direction: column;
}
.score small { font-size: 9px; font-weight: 600; opacity: .7; letter-spacing: .04em; }
.score.strong { background: var(--green-bg); color: var(--green); }
.score.shot   { background: var(--blue-bg);  color: var(--blue); }
.score.stretch{ background: var(--amber-bg); color: var(--amber); }

.card-body { min-width: 0; }
.card-title { font-size: 17px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 4px; }
.card-sub { font-size: 13px; color: var(--text-2); margin: 0 0 10px; }
.card-sub .src { color: var(--text-3); }

/* Sponsored slot in the results feed (free plan only). Calm + clearly labeled, and
   opts out of the .card grid/hover so it never mimics a real job match. */
.ad-card {
  display: block; padding: 14px 18px;
  background: transparent; border: 1px dashed var(--border); box-shadow: none;
}
.ad-card:hover { transform: none; box-shadow: none; border-color: var(--border); }
.ad-tag {
  font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 6px;
}
.ad-slot {
  min-height: 56px; display: grid; place-items: center;
  border-radius: var(--radius); background: var(--surface);
}
.ad-placeholder { font-size: 13px; color: var(--text-3); }
.ad-placeholder .link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--blue); font: inherit; text-decoration: underline;
}

/* Refine ↔ profile inheritance state: quiet when inheriting, visible when overriding */
.inherit-hint { display: block; font-size: 11.5px; margin-top: 4px; min-height: 0; }
.inherit-hint.inherited { color: var(--text-3); }
.inherit-hint.edited { color: var(--blue); }
.inherit-reset {
  background: none; border: none; padding: 0; cursor: pointer;
  color: inherit; font: inherit; text-decoration: underline;
}
.verdict {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; margin-left: 8px; vertical-align: middle;
}
.verdict.strong { background: var(--green-bg); color: var(--green); }
.verdict.shot   { background: var(--blue-bg);  color: var(--blue); }
.verdict.stretch{ background: var(--amber-bg); color: var(--amber); }
.reason { font-size: 14px; color: var(--text); margin: 0 0 12px; line-height: 1.45; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 12px; color: var(--text-2); background: var(--surface-2);
  padding: 4px 10px; border-radius: 999px;
}
.tag.gap { color: var(--amber); background: var(--amber-bg); }

.card-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.card-actions .primary { padding: 9px 16px; font-size: 13px; text-align: center; }
.iconrow { display: flex; gap: 6px; justify-content: flex-end; }
.mini {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  width: 34px; height: 34px; border-radius: 9px; font-size: 15px; transition: all .18s;
}
.mini:hover { border-color: var(--text-3); color: var(--text); }
.mini.on { color: var(--accent); border-color: var(--accent); }
.mini.applied-on { color: var(--green); border-color: var(--green); background: var(--green-bg); }

.applied-badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; margin-left: 8px; vertical-align: middle;
  background: var(--green-bg); color: var(--green);
}

/* Settings: hidden & applied management rows */
.hidden-mgmt { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.hr-head { margin: 6px 0 0; font-weight: 600; }
.hidden-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px;
}
.hr-meta { min-width: 0; display: flex; flex-direction: column; }
.hr-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hr-sub { font-size: 12px; color: var(--text-3); }
.hr-undo { padding: 5px 12px; font-size: 12px; flex-shrink: 0; }

/* Insights (#15): roles you keep scoring high on */
.insights { margin: 22px auto 0; max-width: 640px; text-align: center; }
.insights-label { font-size: 13px; color: var(--text-3); }
.insights-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.insight-chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: border-color .15s, background .15s;
}
.insight-chip:hover { border-color: var(--accent); background: var(--accent-bg, var(--surface)); }
.insight-chip .ic-meta { color: var(--text-3); font-size: 11px; margin-left: 5px; }

/* Suggest roles (#16) */
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.suggest-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--accent);
  border-radius: 8px; padding: 3px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit; flex-shrink: 0;
}
.suggest-btn:hover { border-color: var(--accent); }
.suggest-btn:disabled { opacity: .5; cursor: default; }
.suggested-roles { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0 2px; }
.suggested-role {
  border: 1px dashed var(--border); background: transparent; color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.suggested-role:hover { border-style: solid; border-color: var(--accent); }
.suggested-role::before { content: "+ "; color: var(--accent); }

/* Costs / AI usage log */
.cost-totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0 8px; }
.cost-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px; text-align: center; background: var(--surface);
}
.cc-num { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.cc-lbl { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.cost-h { font-size: 15px; font-weight: 600; margin: 24px 0 10px; }
.cost-table { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.ct-row {
  display: grid; grid-template-columns: 1.4fr 0.6fr 1.4fr 1fr; gap: 12px;
  padding: 10px 14px; font-size: 13px; align-items: center;
  border-top: 1px solid var(--border);
}
.ct-row.r5 { grid-template-columns: 1.3fr 1fr 2fr 1.3fr 0.9fr; }
.ct-row:first-child { border-top: none; }
.ct-head { font-weight: 600; color: var(--text-3); font-size: 12px; background: var(--surface); }
.ct-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-3); }
.ct-row input { width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 7px; padding: 5px 8px; font-size: 13px; font-family: inherit; }
.ct-row input:focus { outline: none; border-color: var(--accent); }

/* Settings: add-company-by-name resolver row */
.resolve-row { display: flex; gap: 10px; }
.resolve-row input {
  flex: 1; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.resolve-row input:focus { outline: none; border-color: var(--accent); }
.resolve-row .primary { padding: 9px 18px; font-size: 13px; flex-shrink: 0; }

.empty { text-align: center; color: var(--text-2); font-size: 15px; padding: 56px 20px; }
.empty .big { font-size: 19px; font-weight: 600; color: var(--text); display: block; margin-bottom: 8px; }

/* ── History ───────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-bucket {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.history-head {
  display: flex; align-items: center; gap: 14px; padding: 16px 20px; cursor: pointer;
  transition: background .15s;
}
.history-head:hover { background: var(--surface-2); }
.history-when { display: flex; flex-direction: column; min-width: 150px; }
.history-when .d { font-weight: 600; font-size: 15px; }
.history-when .t { color: var(--text-3); font-size: 13px; }
.history-meta { flex: 1; min-width: 0; }
.history-meta .q { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-meta .s { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.history-head .chev { color: var(--text-3); transition: transform .25s; font-size: 12px; }
.history-bucket.open .history-head .chev { transform: rotate(180deg); }
.history-del {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-3);
  width: 32px; height: 32px; border-radius: 8px; font-size: 14px; transition: all .18s;
}
.history-del:hover { border-color: var(--amber); color: var(--amber); }
.history-body { padding: 0 16px 16px; display: none; }
.history-bucket.open .history-body { display: block; }
.history-body .cards { margin-top: 4px; }

/* adjustable Minimum-fit control on results + history */
.fit-control {
  display: flex; align-items: center; gap: 14px; margin: 0 2px 16px;
  background: var(--surface-2); border-radius: 999px; padding: 9px 18px;
}
.fit-control > span { font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.fit-control > span strong { color: var(--accent); }
.fit-control .thr-range { flex: 1; accent-color: var(--accent); }
.fit-control .src-filter-label { font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.fit-control .src-filter, .fit-control .sort-mode {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-family: inherit;
  max-width: 200px; cursor: pointer;
}
.fit-control .src-filter:focus, .fit-control .sort-mode:focus { outline: none; border-color: var(--accent); }
@media (max-width: 640px) { .fit-control { flex-wrap: wrap; } .fit-control .thr-range { min-width: 140px; } }
.show-more {
  display: block; width: 100%; margin: 14px 0 4px; padding: 12px;
  border: 1px dashed var(--border); background: var(--surface); color: var(--text-2);
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; transition: all .18s;
}
.show-more:hover { border-color: var(--accent); color: var(--accent); }
.below-cards { margin-top: 12px; }

/* ── Loader ────────────────────────────────────────────────────── */
.loader { text-align: center; color: var(--text-2); }

/* Loading: an animated aperture icon + one status line. When scoring begins the
   icon shrinks & slows and hands off to the centered progress bar (#18-era UX). */
.loader { padding: 74px 0; }
.loadwrap {
  --spd: 1;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  transition: gap .5s ease;
}
/* The aperture mark: a brand-gradient disc with an iris hole that contracts as
   the whole disc slowly rotates. Gradient uses --blue/--green so it recolors for
   dark mode + the purple accent automatically. */
.apIcon {
  width: 64px; height: 64px;
  transition: width .5s cubic-bezier(.3,.7,.3,1), height .5s cubic-bezier(.3,.7,.3,1);
}
.apDisc {
  transform-box: view-box; transform-origin: 32px 32px;
  animation: apSpin calc(var(--spd) * 11s) linear infinite;
}
.apHole { animation: apHole calc(var(--spd) * 4.4s) cubic-bezier(.45,0,.25,1) infinite; }
@keyframes apSpin { to { transform: rotate(360deg); } }
@keyframes apHole { 0%, 100% { r: 16px; } 48%, 62% { r: 7px; } }

#loadingText {
  font-size: 15px; font-weight: 500; color: var(--text); text-align: center; margin: 0;
}
/* (#9) bouncing-dots wave on the status line during the indeterminate phases.
   Each dot bounces up-and-down; staggered delays send a wave left→right. */
.ldots { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle;
         transform: translateY(2px); }   /* sit on the text's baseline, not above it */
.ldots i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-2);
  animation: ldotbounce 1.2s ease-in-out infinite;
}
.ldots i:nth-child(2) { animation-delay: .15s; }
.ldots i:nth-child(3) { animation-delay: .30s; }
@keyframes ldotbounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-7px); opacity: 1; }
}
.loadwrap.compact .ldots { display: none; }   /* hidden once the progress bar takes over */
.lbarwrap {
  width: 320px; max-width: 80%; height: 8px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); overflow: hidden;
  opacity: 0; max-height: 0; transform: scaleX(.2);
  transition: opacity .45s ease, transform .55s cubic-bezier(.3,.7,.3,1), max-height .45s ease;
}
#loadBar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width .5s cubic-bezier(.3,.7,.3,1);
}
.est {
  font-size: 13px; color: var(--text-3); margin: 0; text-align: center;
  font-variant-numeric: tabular-nums; opacity: 0; max-height: 0; overflow: hidden;
  transition: opacity .4s ease, max-height .4s ease;
}
/* Scoring / verifying: shrink + slow the icon, reveal the bar + estimate. */
.loadwrap.compact { --spd: 1.8; }
.loadwrap.compact .apIcon { width: 34px; height: 34px; }
.loadwrap.compact .lbarwrap { opacity: 1; max-height: 20px; transform: scaleX(1); }
.loadwrap.compact .est { opacity: 1; max-height: 18px; }

/* Developer mode: hide operator/technical surfaces unless dev mode is on. */
html[data-dev="off"] .dev-only { display: none !important; }

/* Purple accent theme (Settings → Appearance). Swaps the blue family; green stays. */
[data-accent="purple"] {
  --accent: #6d4cf2; --accent-press: #5733d6; --accent-bg: #ece7fe;
  --blue: #6d4cf2; --blue-bg: #ece7fe;
}
[data-accent="purple"][data-theme="dark"] {
  --accent: #9d86ff; --accent-press: #b3a3ff; --accent-bg: #2a2350;
  --blue: #9d86ff; --blue-bg: #2a2350;
}

/* ── Modals ────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(0,0,0,.4); backdrop-filter: blur(4px); animation: fade .25s ease; padding: 20px;
}
.sheet {
  width: 100%; max-width: 540px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow);
  overflow: hidden; animation: pop .3s cubic-bezier(.2,.8,.3,1);
}
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px; border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.sheet-body { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.sheet-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.setting-group { display: flex; flex-direction: column; gap: 12px; }
.setting-group h3 { margin: 0; font-size: 15px; font-weight: 600; }
.setting-group h3 .opt { color: var(--text-3); font-weight: 500; font-size: 12px; margin-left: 6px; }
.muted { color: var(--text-2); font-size: 13.5px; margin: 0; line-height: 1.5; }
.muted code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.field > span em { color: var(--green); }
/* Embeddings dev tab: coverage gauge + run-history table */
.emb-gauge { display: flex; flex-direction: column; gap: 6px; }
.emb-bar { height: 8px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.emb-fill { height: 100%; width: 0; border-radius: 5px;
  background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .4s ease; }
.emb-actions { display: flex; gap: 10px; }
.emb-runs { width: 100%; border-collapse: collapse; font-size: 12px; }
.emb-runs th, .emb-runs td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.emb-runs th { color: var(--text-3); font-weight: 500; }
.emb-runs .st-completed { color: var(--green); }
.emb-runs .st-failed { color: #d6453f; }
.emb-runs .st-processing, .emb-runs .st-queued { color: var(--text-2); }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
/* keep paired controls level even if one label wraps to two lines */
.profile-grid .field { justify-content: flex-end; }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); z-index: 200;
  animation: toastin .3s ease;
}
@keyframes toastin { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.toast { display: inline-flex; align-items: center; gap: 14px; }
.toast-action {
  background: transparent; border: none; color: var(--bg); font: inherit; font-weight: 700;
  cursor: pointer; padding: 0; opacity: .85; text-decoration: underline; text-underline-offset: 2px;
}
.toast-action:hover { opacity: 1; }
/* card fading out during the X-undo window */
.card.dismissing { opacity: .35; transition: opacity .25s ease; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .refine-grid, .profile-grid { grid-template-columns: 1fr; }
  .card { grid-template-columns: 52px 1fr; }
  .card-actions { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .score { width: 52px; height: 52px; font-size: 18px; }
  .topnav .navlink { padding: 7px 8px; }
}
