:root {
  --bg: #F7F8FA;
  --card: #FFFFFF;
  --ink: #101828;
  --muted: #667085;
  --faint: #98A2B3;
  --line: #E4E7EC;
  --line-strong: #D7DBE0;
  --accent: #0A84FF;
  --accent-d: #0066CC;
  --accent-tint: #EAF3FF;
  --ok: #12B76A;
  --ok-tint: #E7F9EF;
  --amber: #B54708; --amber-tint: #FFF6E8;
  --purple: #5925DC; --purple-tint: #F3F0FF;
  --teal: #0876A8; --teal-tint: #E6F7FE;
  --red: #C4320A; --red-tint: #FFECE5;
  --slate-tint: #F2F4F7;
  --shadow: 0 1px 2px rgba(16,24,40,.04);
  --r-s: 10px; --r-m: 14px; --r-l: 16px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14.5px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1;
}
a { color: var(--accent-d); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.topbar {
  background: var(--card); color: var(--ink); padding: 15px 28px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--ink); font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar-right { color: var(--muted); font-size: 13.5px; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 24px 28px 56px; }
.logout-link { color: var(--muted); font-size: 13.5px; }
.logout-link:hover { color: var(--ink); }

/* form controls, shared */
input, select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--r-s);
  font-size: 14px; background: var(--slate-tint); color: var(--ink); font-family: inherit;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { outline: none; border-color: var(--accent); background: #fff;
  box-shadow: 0 0 0 3px var(--accent-tint); }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: var(--r-s);
  padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
button:hover { background: var(--accent-d); }
button:disabled { background: var(--line-strong); color: #fff; cursor: not-allowed; }
.btn-link { color: var(--accent-d); font-size: 13.5px; }

/* login page */
.login-body { min-height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); font: 14.5px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-l);
  padding: 34px 30px; box-shadow: 0 12px 32px rgba(16,24,40,.08); width: 340px; max-width: 92vw; }
.login-brand { font-size: 20px; font-weight: 700; color: var(--ink); text-align: center; letter-spacing: -.01em; }
.login-sub { color: var(--muted); font-size: 13.5px; text-align: center; margin-top: 4px; margin-bottom: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { font-size: 15px; padding: 10px 12px; }
.login-card button { padding: 11px; font-size: 15px; margin-top: 6px; }
.login-error { background: var(--red-tint); color: var(--red); border: 1px solid #f5c6c6;
  border-radius: var(--r-s); padding: 9px 12px; font-size: 13.5px; text-align: center; margin-bottom: 16px; }

/* counters */
.counters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; margin-bottom: 22px; }
.counter { position: relative; display: block; background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--cc, var(--line-strong)); border-radius: var(--r-m);
  padding: 16px 16px; box-shadow: var(--shadow); color: inherit; text-decoration: none; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease; }
.counter:hover { transform: translateY(-1px); text-decoration: none; border-color: var(--line-strong);
  border-left-color: var(--cc, var(--line-strong)); }
.counter.active { background: var(--slate-tint); border-color: var(--ink); border-left-color: var(--cc);
  box-shadow: inset 0 0 0 1px var(--ink); }
.counter.active .counter-num, .counter.active .counter-title { color: var(--ink); }
.counter-num { font-size: 27px; font-weight: 700; letter-spacing: -.02em; color: var(--ink); }
.counter-title { color: var(--muted); font-size: 13px; margin-top: 5px; }
.c-total { --cc: var(--ink); }
.c-drafted { --cc: var(--amber); }
.c-to_send { --cc: var(--purple); }
.c-sent { --cc: var(--teal); }
.c-replied { --cc: var(--accent-d); }
.c-warm { --cc: var(--red); }
.c-dead { --cc: var(--faint); }

/* actions */
.actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 20px; }
.action-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-l);
  padding: 20px 22px; box-shadow: var(--shadow); }
.action-card h3 { margin: 0 0 14px; font-size: 14.5px; font-weight: 600; }
.action-card .row { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.action-card input { flex: 1; min-width: 90px; }

/* автодополнение категории (свой JS вместо datalist) */
.autocomplete { position: relative; flex: 1; min-width: 90px; }
.autocomplete input { width: 100%; }
.autocomplete-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-s);
  box-shadow: 0 8px 24px rgba(16,24,40,.14); max-height: 220px; overflow-y: auto; }
.autocomplete-item { padding: 8px 12px; font-size: 13.5px; cursor: pointer; }
.autocomplete-item:hover { background: var(--slate-tint); }

/* search checkboxes — pill-style toggles */
.checks { display: flex; flex-direction: row; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.checks-title { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; width: 100%; }
.check { display: flex; align-items: center; gap: 8px; padding: 7px 12px 7px 8px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 13.5px; color: var(--muted); cursor: pointer;
  width: fit-content; transition: background .12s ease, border-color .12s ease, color .12s ease; }
.check:hover { border-color: var(--line-strong); }
.check input { flex: none; width: 17px; min-width: 0; height: 17px; margin: 0;
  accent-color: var(--accent); cursor: pointer; }
.check:has(input:checked) { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-d); font-weight: 600; }

/* job banner */
.job { position: relative; display: flex; gap: 12px; align-items: flex-start; background: var(--accent-tint);
  border-radius: var(--r-m); padding: 14px 18px; margin-bottom: 20px; color: var(--accent-d);
  border-left: 4px solid var(--accent); font-size: 13.5px; }
.job-close { position: absolute; top: 6px; right: 8px; margin: 0; }
.job-close button { background: transparent; color: var(--accent-d); font-size: 20px; line-height: 1;
  padding: 2px 8px; font-weight: 400; }
.job-close button:hover { background: rgba(10,132,255,.12); color: var(--ink); }
.job-close-btn { margin-top: 10px; }
.job-close-btn button { background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: 600; }
.job-close-btn button:hover { background: var(--slate-tint); }
.job-ok { background: var(--ok-tint); border-left-color: var(--ok); color: #0C7A43; }
.job-ok .job-close button, .job-ok .job-close-btn button:hover { color: #0C7A43; }
.job-err { background: var(--red-tint); border-left-color: var(--red); color: var(--red); }
.job-log { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
  color: inherit; opacity: .85; white-space: pre-wrap; margin-top: 8px; max-height: 160px; overflow: auto; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(10,132,255,.25); border-top-color: var(--accent-d);
  border-radius: 50%; animation: spin .8s linear infinite; margin-top: 2px; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.soft-fade { transition: opacity .15s ease; }
.soft-fade.fading { opacity: .35; }
#job-box:empty { display: none; }

/* filters */
.filters-card { margin-bottom: 20px; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.filters-grid select, .filters-grid input { width: 100%; background: var(--slate-tint); }
.filters-bottom { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.filters-actions { display: flex; align-items: center; gap: 14px; }

.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.ok { color: var(--ok); font-weight: 700; }

/* leads — card list */
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; padding: 0 4px; }
.list-head h2 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.list-head .count { font-size: 13px; color: var(--faint); }
.list-head-right { display: flex; align-items: baseline; gap: 14px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 4px 0; }
.pagination .page-links { display: flex; gap: 16px; }
.pagination-compact { padding: 0; gap: 10px; }

.branch-badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: var(--slate-tint); color: var(--muted); font-size: 11px; font-weight: 600; vertical-align: middle; }

.leads { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-l);
  box-shadow: var(--shadow); overflow: hidden; padding: 6px; }
.leads-head-row, .lead-row { display: grid;
  grid-template-columns: 28px 40px minmax(160px, 1fr) 220px 140px;
  gap: 14px; align-items: center; padding: 10px 10px; }
.leads-head-row { padding: 8px 10px; }
.col-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--faint); }
.col-check { display: flex; align-items: center; justify-content: center; }
.col-check input { cursor: pointer; accent-color: var(--accent); }

.leads-body .lead-row { border-radius: var(--r-s); text-decoration: none; cursor: pointer; }
.leads-body .lead-row:hover { background: var(--slate-tint); }
.leads-body .lead-row .col-check { cursor: default; }
.leads-body .lead-row + .lead-row { box-shadow: inset 0 1px 0 var(--line); }

.avatar { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center;
  justify-content: center; font-weight: 600; font-size: 13.5px; color: var(--muted); background: var(--slate-tint); }
.leads-body .lead-row:nth-child(6n+2) .avatar { background: var(--amber-tint); color: var(--amber); }
.leads-body .lead-row:nth-child(6n+3) .avatar { background: var(--purple-tint); color: var(--purple); }
.leads-body .lead-row:nth-child(6n+4) .avatar { background: var(--teal-tint); color: var(--teal); }
.leads-body .lead-row:nth-child(6n+5) .avatar { background: var(--accent-tint); color: var(--accent-d); }
.leads-body .lead-row:nth-child(6n+6) .avatar { background: var(--red-tint); color: var(--red); }

.info { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.info .name { font-weight: 600; font-size: 14px; color: var(--ink); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.info .name:hover { text-decoration: underline; }
.info .sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.contact { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.contact .em { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact .ph { color: var(--muted); }

.lead-empty { padding: 28px 10px; }

/* badges — soft pills */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px 4px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; width: fit-content; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.b-new { background: var(--slate-tint); color: #475467; }
.b-drafted { background: var(--amber-tint); color: var(--amber); }
.b-to_send { background: var(--purple-tint); color: var(--purple); }
.b-sent { background: var(--teal-tint); color: var(--teal); }
.b-replied { background: var(--accent-tint); color: var(--accent-d); }
.b-warm { background: var(--red-tint); color: var(--red); }
.b-dead { background: var(--slate-tint); color: var(--faint); }

/* lead card */
.lead-head { display: flex; align-items: center; gap: 14px; margin: 16px 0 20px; flex-wrap: wrap; }
.lead-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.lead-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-l);
  padding: 20px 22px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 14px; font-size: 14.5px; font-weight: 600; }
dl { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
dt { color: var(--muted); font-size: 13px; }
dd { margin: 0; }
.mail-subject { margin-bottom: 10px; }
.mail-body { white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.6;
  background: var(--slate-tint); border: 1px solid var(--line); border-radius: var(--r-s); padding: 14px; margin: 0; }

.history-card { margin-top: 16px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history-list li { font-size: 13.5px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.history-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.history-list .muted { margin-right: 8px; }

.status-actions { margin-top: 16px; }
.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.status-buttons form { margin: 0; }
.badge-btn { border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 7px 15px; border-radius: 999px; font-weight: 600; font-size: 13.5px; }
.badge-btn:hover { background: var(--slate-tint); }
.badge-btn.current { background: var(--ink); color: #fff; border-color: var(--ink); }

@media (max-width: 900px) {
  .counters { grid-template-columns: repeat(4, 1fr); }
  .actions, .lead-grid { grid-template-columns: 1fr; }
  dl { grid-template-columns: 100px 1fr; }
  .leads-head-row { display: none; }
  .leads-body .lead-row {
    grid-template-columns: 24px 34px 1fr; grid-template-areas: "check av name" "check av contact" "check av status";
    row-gap: 4px; padding: 12px 10px;
  }
  .lead-row .col-check { grid-area: check; align-self: start; }
  .lead-row .avatar { grid-area: av; }
  .lead-row .info { grid-area: name; }
  .lead-row .contact { grid-area: contact; flex-direction: row; gap: 10px; }
  .lead-row .badge { grid-area: status; }
}
@media (max-width: 560px) {
  .wrap { padding: 18px 16px 44px; }
  .topbar { padding: 14px 16px; }
  .counters { grid-template-columns: repeat(2, 1fr); }
  .counter { padding: 13px 14px; }
  .counter-num { font-size: 22px; }
  .action-card { padding: 16px; }
}
