:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2f6fed;
  --accent-soft: #e9f0ff;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --chip: #eef0f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --panel: #161920;
    --text: #e7e9ee;
    --muted: #98a1b0;
    --line: #262a33;
    --accent: #5b8cff;
    --accent-soft: #1b2744;
    --accent-text: #0b0d12;
    --ok: #4ade80;
    --ok-soft: #12291b;
    --warn: #fbbf24;
    --warn-soft: #2b2310;
    --bad: #f87171;
    --bad-soft: #2d1414;
    --chip: #20242d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.sub { color: var(--muted); margin: 4px 0 0; max-width: 760px; }

/* --- layout --- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 14px; border-right: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); text-decoration: none; font-weight: 700; font-size: 17px; padding: 2px 8px; }
.brand svg { width: 28px; height: 28px; }
.brand span { color: var(--text); letter-spacing: -.01em; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500;
}
nav a:hover { background: var(--chip); }
nav a.active { background: var(--accent-soft); color: var(--accent); }
.count { font-size: 12px; font-weight: 600; min-width: 20px; text-align: center; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-text); }
.count:empty { display: none; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; padding: 0 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--warn); }
.dot.err { background: var(--bad); }

main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; resize: vertical; line-height: 1.45; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; min-width: 0; }
label > input:not([type=checkbox]):not([type=range]), label > select { width: 100%; min-width: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; }
legend { font-size: 13px; font-weight: 500; padding: 0 4px; }
.check { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; margin: 4px 14px 4px 0; font-weight: 400; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 16px 0 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: var(--chip); padding: 3px; border-radius: 10px; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type=search] { width: 200px; }

/* --- stats --- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12.5px; }

/* --- cards --- */
.list { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.lead-main { display: grid; grid-template-columns: 46px 1fr auto; gap: 14px; align-items: start; padding: 14px 16px; cursor: pointer; }
.score {
  width: 46px; height: 46px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.s-high { background: var(--ok-soft); color: var(--ok); }
.s-mid { background: var(--warn-soft); color: var(--warn); }
.s-low, .s-none { background: var(--chip); color: var(--muted); }
.lead-title { font-weight: 600; font-size: 15px; line-height: 1.35; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 5px; font-size: 12.5px; }
.chip { background: var(--chip); padding: 1px 8px; border-radius: 6px; font-weight: 500; }
.chip.ghost { background: transparent; border: 1px solid var(--line); }
.chip.demo { background: var(--warn-soft); color: var(--warn); }
.money { font-weight: 600; }
.reason { color: var(--muted); font-size: 13px; margin-top: 5px; }
.status { font-weight: 600; }
.st-drafted, .st-approved { color: var(--accent); }
.st-submitted { color: var(--ok); }
.st-skipped, .st-filtered_out { color: var(--muted); }
.lead-quick { display: flex; gap: 6px; }
.lead-detail { border-top: 1px solid var(--line); padding: 14px 16px 16px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px; }
.desc { white-space: pre-wrap; color: var(--text); font-size: 13.5px; max-height: 340px; overflow: auto; }
.draft-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; border: 1px dashed var(--line); border-radius: var(--radius); }
.banner { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; margin-top: 16px; }

/* --- качество, воронка, кейсы --- */
.flags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.flag { font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--chip); font-weight: 500; }
.flag.scam { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.flag.warn { background: var(--warn-soft); color: var(--warn); }
.flag.good { background: var(--ok-soft); color: var(--ok); }
.flag.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 400; }
.card.lead.scam { border-color: var(--bad-soft); }
.s-scam { background: var(--bad-soft); color: var(--bad); }
.client { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 8px; }
.outcomes { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.chip.outcome { background: var(--accent-soft); color: var(--accent); }
.chip.o-hired { background: var(--ok-soft); color: var(--ok); }
.chip.o-lost { background: var(--chip); color: var(--muted); }
.usage { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }
.use { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; }
.use.over { border-color: var(--bad); color: var(--bad); }
.count.warn { background: var(--warn); }
.stats-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat.good b { color: var(--ok); }
h2.section { margin: 24px 0 10px; }
.fu { padding: 14px 16px; }
.fu-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.hist-list { display: flex; flex-direction: column; gap: 2px; padding: 8px 14px; }
.hist { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.hist .lead-title { font-size: 14px; }
.bids { padding: 4px 18px 8px; }
.bids h3 { font-size: 14px; margin: 6px 0 8px; }
.bid { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.bid.short { border-color: var(--accent); }
.bid-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bid .snippet { margin: 6px 0 0; font-size: 13.5px; }
.limits { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.case { display: flex; flex-direction: column; gap: 10px; }

/* --- inbox --- */
.inbox-item { padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; }
.inbox-item.done { opacity: .6; }
.kind { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.kind.bid { color: var(--ok); }
.snippet { white-space: pre-wrap; margin: 6px 0 0; }
.reply { grid-column: 1 / -1; background: var(--chip); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 13.5px; }

/* --- postings --- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; margin-bottom: 18px; }
form { display: flex; flex-direction: column; gap: 12px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.posting { margin-bottom: 16px; }
.posting-head { padding: 16px 18px 6px; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; padding: 10px 18px 18px; }
.variant { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.variant-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.variant input[type=text] { width: 100%; }
.st-posted { color: var(--ok); }

/* --- sources --- */
table { width: 100%; border-collapse: collapse; }
.table-scroll { overflow-x: auto; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.err-text { color: var(--bad); font-size: 12.5px; max-width: 360px; word-break: break-word; }
.steps { margin: 6px 0 0; padding-left: 20px; }
.steps li { margin: 4px 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }

/* --- dialog & toast --- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px; width: min(560px, 92vw); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: .2s ease; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--bad); color: #fff; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  main { padding: 18px 16px 50px; }
  .stats, .stats-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .limits { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lead-main { grid-template-columns: 40px 1fr; }
  .lead-quick { grid-column: 1 / -1; }
  .lead-detail, .grid-2, .grid-3, .row { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .filters input[type=search] { width: 100%; }
}

/* v0.4: ставка и ответы на вопросы */
.bid-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; font-size: 13.5px; }
details.answers { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
details.answers summary { cursor: pointer; font-weight: 600; }
details.answers .qa { margin-top: 10px; }
details.answers .q { font-weight: 600; font-size: 13px; }
details.answers .a { white-space: pre-wrap; font-size: 13.5px; }

/* v0.6: вход */
.login { max-width: 460px; margin: 40px auto; }
.login h1 { margin-top: 0; }
.sidebar-foot a { color: var(--muted); }

/* v0.5: инструкция */
.help-check h2 .muted { font-weight: 500; font-size: 14px; }
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.checklist li { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 8px; }
.checklist li:hover { background: var(--chip, rgba(0,0,0,.03)); }
.checklist .mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px;
  background: var(--line); color: var(--muted); }
.checklist li.done .mark { background: #e7f6ec; color: #15803d; }
.checklist li:not(.done) .mark { background: #fdf3e2; color: #b45309; }
.checklist li.done b { font-weight: 500; }
.help-toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; }
.help-sec { margin-top: 14px; scroll-margin-top: 16px; }
.help-sec p { margin: 8px 0; }
.help-table td { vertical-align: top; padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); }
.help-table td:first-child { white-space: nowrap; width: 1%; }
.badge-legend { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; margin: 8px 0; font-size: 13px; }
.dbadge { font: 600 11px/1 system-ui, sans-serif; border-radius: 6px; padding: 4px 6px; white-space: nowrap; justify-self: start;
  background: #eef0f4; color: #374151; }
.dbadge.draft { background: #2f6fed; color: #fff; }
.dbadge.sent { background: #e7f6ec; color: #15803d; }
.dbadge.scam { background: #fdecec; color: #b91c1c; }
.dbadge.dim { background: #f3f4f6; color: #9ca3af; font-weight: 500; }
.faq dt { font-weight: 600; margin-top: 12px; }
.faq dd { margin: 4px 0 0; color: var(--muted); }
@media (max-width: 640px) {
  .help-table td:first-child { white-space: normal; width: 38%; }
  .checklist li { grid-template-columns: 26px 1fr; }
  .checklist li .btn { grid-column: 2; justify-self: start; }
}
