/* BD Engine — application styles.
   Tokens first; components below. --brand is set per tenant by /theme/<hex>.css. */

:root {
  --brand: #0096dd;
  --brand-ink: color-mix(in oklab, var(--brand) 78%, black);
  --brand-soft: color-mix(in oklab, var(--brand) 10%, white);
  --brand-line: color-mix(in oklab, var(--brand) 28%, white);

  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f1f4f7;
  --line: #e3e8ee;
  --line-strong: #cfd7e0;
  --text: #17212b;
  --text-2: #4a5866;
  --text-3: #7b8794;

  --good: #12805c;
  --good-soft: #e5f5ee;
  --warn: #a35a00;
  --warn-soft: #fdf1e1;
  --bad: #c0352b;
  --bad-soft: #fcebea;
  --info-soft: var(--brand-soft);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 6%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 12%);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-ink: color-mix(in oklab, var(--brand) 70%, white);
    --brand-soft: color-mix(in oklab, var(--brand) 18%, #10161c);
    --brand-line: color-mix(in oklab, var(--brand) 40%, #10161c);
    --bg: #0e1419;
    --surface: #151d24;
    --surface-2: #1b252e;
    --line: #26323d;
    --line-strong: #34424f;
    --text: #e6edf3;
    --text-2: #a9b6c2;
    --text-3: #7d8a97;
    --good: #3fbf8d;
    --good-soft: #10291f;
    --warn: #e0a046;
    --warn-soft: #2c2111;
    --bad: #f0776c;
    --bad-soft: #321614;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 50%);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
h3 { font-size: 14px; font-weight: 620; }
p { margin: 0 0 12px; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px; font-weight: 650; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 13px;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ws-switch { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.ws-switch summary { list-style: none; cursor: pointer; padding: 8px 10px; display: grid; }
.ws-switch summary::-webkit-details-marker { display: none; }
.ws-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.ws-current { font-weight: 600; }
.ws-switch ul { list-style: none; margin: 0; padding: 4px; border-top: 1px solid var(--line); }
.ws-switch a { display: block; padding: 6px 8px; border-radius: 5px; color: var(--text); }
.ws-switch a:hover { background: var(--surface); text-decoration: none; }
.ws-switch a[aria-current] { color: var(--brand-ink); font-weight: 600; }

.nav { display: grid; gap: 2px; margin-top: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 520;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand-ink); }
.nav-badge {
  margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 650; text-align: center;
}

.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 6px 0; border-top: 1px solid var(--line);
}
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 650; color: var(--text-2);
}
.user-meta { display: grid; min-width: 0; }
.user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 12px; color: var(--text-3); }

.main { padding: 28px 36px 64px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-body { padding: 16px 20px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; }
.section + .section { margin-top: 24px; }

.stat { padding: 16px 18px; }
.stat-label { font-size: 12.5px; color: var(--text-2); }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-note { font-size: 12px; color: var(--text-3); }

.empty { padding: 40px 24px; text-align: center; color: var(--text-2); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .icon { width: 28px; height: 28px; color: var(--text-3); margin-bottom: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in oklab, var(--surface-2) 60%, transparent); }
.table .actions { text-align: right; white-space: nowrap; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-sub { font-size: 12.5px; color: var(--text-3); }

/* ---------- Badges and score ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 560;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap;
}
.badge-brand { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand-line); }
.badge-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.score {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 10px;
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--text-2);
}
.score-high { background: var(--brand); color: #fff; }
.score-mid { background: var(--brand-soft); color: var(--brand-ink); }

.reasons { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.reasons li { display: flex; gap: 8px; font-size: 13px; color: var(--text-2); }
.reasons li::before { content: ""; flex: none; width: 6px; height: 6px; margin-top: 7px; border-radius: 50%; background: var(--brand); }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-weight: 560; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"],
input[type="search"], input[type="date"], input[type="datetime-local"], input[type="tel"], input[type="file"], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.checkbox { display: flex; gap: 8px; align-items: center; font-weight: 500; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 580; white-space: nowrap;
}
.button:hover { background: var(--surface-2); text-decoration: none; }
.button-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.button-danger { color: var(--bad); }
.button-sm { padding: 5px 10px; font-size: 13px; }
.button-block { width: 100%; }
.button[disabled] { opacity: 0.55; cursor: not-allowed; }
.icon-button {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--text); }
.link-button { border: 0; background: none; padding: 0; color: var(--brand-ink); font: inherit; cursor: pointer; }
.link-button:hover { text-decoration: underline; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar select { width: auto; min-width: 180px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 560; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--brand-ink); border-bottom-color: var(--brand); }

.pagination { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--text-2); font-size: 13px; }

/* ---------- Feedback ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 520; border: 1px solid transparent; }
.flash-info { background: var(--info-soft); color: var(--brand-ink); border-color: var(--brand-line); }
.flash-success { background: var(--good-soft); color: var(--good); }
.flash-error { background: var(--bad-soft); color: var(--bad); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--text-3); font-size: 13px; }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 17px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }

.email-preview { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); padding: 14px 16px; white-space: pre-wrap; font-size: 13.5px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.usage-bar { display: block; width: 100%; height: 8px; margin-top: 8px; }
.usage-track { fill: var(--surface-2); }
.usage-fill { fill: var(--brand); }
.usage-fill-full { fill: var(--warn); }
.note-count { font-variant-numeric: tabular-nums; }

/* ---------- Auth ---------- */
body.auth { background: radial-gradient(1200px 600px at 20% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; margin-bottom: 20px; }
.auth-title { font-size: 20px; margin-bottom: 16px; }
.choice-list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.choice { width: 100%; display: flex; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.choice:hover { border-color: var(--brand); }
.choice-title { font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; min-width: 0; }
  .nav { grid-auto-flow: column; overflow-x: auto; }
  .main { padding: 20px 16px 48px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .page-head { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Utilities ---------- */
.mt-12 { margin-top: 12px; }
.mt-0 { margin-top: 0; }
.pre-wrap { white-space: pre-wrap; }
details > summary { cursor: pointer; color: var(--text-2); }
details[open] > summary { margin-bottom: 10px; }

/* ---------- Charts (inline SVG) ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart-label { font: 11.5px var(--font); fill: var(--text-2); }
.chart-value { font: 600 11.5px var(--font); fill: var(--text); }
.chart-bar { fill: var(--brand); }
.chart-bar-muted { fill: var(--line-strong); }
.chart-bar-alt { fill: color-mix(in oklab, var(--brand) 35%, var(--surface)); }
.chart-axis { stroke: var(--line); stroke-width: 1; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; vertical-align: -1px; }
.key-sent { background: var(--brand); }
.key-replies { background: color-mix(in oklab, var(--brand) 35%, var(--surface)); }
a.card.stat { color: inherit; }
a.card.stat:hover { text-decoration: none; border-color: var(--brand-line); }
fieldset.field { border: 0; padding: 0; margin: 0; }
.card .card { box-shadow: none; }

/* ---------- Calls ---------- */
.button-quiet { color: var(--text-2); }
.call-list { list-style: none; margin: 0; padding: 0; }
.call { padding: 16px 20px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.call:last-child { border-bottom: 0; }
.call-head { display: flex; align-items: flex-start; gap: 12px; }
.call-dial { text-align: right; }
.call-reason { margin: 0; color: var(--text-2); }
.call-outcomes { display: grid; gap: 8px; }
.call-outcomes textarea { width: 100%; min-height: 0; }
.call-back .row { align-items: flex-end; }
.call-extra { border-top: 1px solid var(--line); }
@media (max-width: 820px) {
  .call-head { flex-wrap: wrap; }
  .call-dial { text-align: left; width: 100%; }
  .call-dial .button { width: 100%; justify-content: center; }
}
/* ---------- Candidates and matching ---------- */
.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset > legend { font-weight: 560; font-size: 13px; padding: 0; margin-bottom: 6px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; }
.check-grid .checkbox { font-weight: 400; font-size: 13.5px; }
.match { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; }
.match-jobs { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.match-people { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); display: grid; gap: 10px; }
.match-people form { margin: 0; }
.alert-card .table td { vertical-align: middle; }
.alert-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 820px) {
  .alert-card .table tr { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .alert-card .table td.actions { grid-column: 1 / -1; padding-top: 0; white-space: normal; }
  .alert-actions { justify-content: flex-start; }
  .match-people .row-between { flex-wrap: wrap; }
}

/* ---------- Source checks ---------- */
.progress { width: 100%; height: 8px; border: 0; border-radius: 4px; background: var(--surface-2); overflow: hidden; appearance: none; accent-color: var(--brand); }
.progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 4px; }
.progress::-webkit-progress-value { background: var(--brand); border-radius: 4px; }
.progress::-moz-progress-bar { background: var(--brand); border-radius: 4px; }
.preview-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }
.preview { padding: 16px 18px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.preview > *, .preview-head .grow { min-width: 0; }
.preview .truncate { display: block; }
.preview:has(.preview-tick:checked) { border-color: var(--brand-line); box-shadow: 0 0 0 1px var(--brand-line), var(--shadow); }
.preview.is-added { background: var(--surface-2); }
.preview-head { display: flex; align-items: flex-start; gap: 10px; }
.preview-head .badge { margin-right: 4px; }
.preview-tick { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); color: var(--good); font-weight: 700; text-align: center; line-height: 18px; }
.preview-title { display: block; font-weight: 620; font-size: 15px; cursor: pointer; overflow-wrap: anywhere; }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 13px; color: var(--text-2); }
.facts strong { color: var(--text); margin-right: 2px; }
.preview-company select { padding: 6px 9px; }
.problem-list { list-style: none; margin: 0; padding: 0; }
.problem-list li { padding: 12px 20px; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.problem-list li:last-child { border-bottom: 0; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 1; padding: 12px 0;
  background: var(--bg); border-top: 1px solid var(--line);
}
.usage-table td, .usage-table th { padding: 8px 12px; }
.form-grid > * { min-width: 0; }
code { overflow-wrap: anywhere; }
