*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --text: #15181d;
  --muted: #5f6674;
  --faint: #9aa1ad;
  --line: #e2e5ea;
  --accent: #2451b8;
  --accent-ink: #ffffff;
  --accent-soft: #e7edfb;
  --call: #157a3d;
  --wa: #1a9a50;
  --tg: #1d80c2;
  --new: #d8353b;
  --spam: #a3301d;
  --spam-soft: #fbebe7;
  --maybe: #875700;
  --maybe-soft: #fcf2d9;
  --ok: #17733f;
  --ok-soft: #e3f4ea;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(21, 24, 29, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --danger: #c62828;
  /* Только светлая тема: даже при тёмной теме телефона интерфейс остаётся светлым. */
  color-scheme: light;
}

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .9em; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

svg.i {
  width: 22px; height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-inline: 16px;
  padding-block: calc(env(safe-area-inset-top) + 8px) 10px;
}

@supports (backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
}

.topbar-inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.topbar-title { margin: 0; font-size: 26px; font-weight: 750; letter-spacing: -.01em; }
.topbar-title-sm { font-size: 17px; font-weight: 650; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 0; border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--line); }

.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px;
  margin-left: -8px; padding-right: 8px;
  color: var(--accent);
  font-size: 17px; font-weight: 550;
  text-decoration: none;
  flex: none;
}

.search { position: relative; }
.search .input { padding-right: 44px; }
.search-clear {
  position: absolute; right: 4px; top: 50%;
  transform: translateY(-50%);
  display: grid; place-items: center;
  width: 40px; height: 40px;
  color: var(--muted);
}

.tabs {
  display: flex; gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.tab {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px;
  padding: 0 6px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 15px; font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.tab[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--new);
  color: #fff;
  font-size: 12px; line-height: 20px; font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.count-muted { background: var(--line); color: var(--muted); }

.chips {
  display: flex; gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px; font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--site); }
.chip[aria-current="page"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- Страница ---------- */

.page {
  max-width: 672px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 12px calc(env(safe-area-inset-bottom) + 40px);
  display: flex; flex-direction: column; gap: 12px;
}

.center { display: flex; justify-content: center; }

.empty { text-align: center; color: var(--muted); padding-block: 56px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.empty-title { color: var(--text); font-size: 19px; font-weight: 650; }
.empty a { color: var(--accent); }

/* ---------- Список заявок ---------- */

.list { display: flex; flex-direction: column; gap: 8px; }
.list:empty { display: none; }

.lead {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.lead.is-spam { background: var(--surface-2); }

.lead-link {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
  padding: 13px 10px 13px 16px;
  text-decoration: none;
}
.lead-link:active { background: var(--surface-2); }

.lead-line { display: flex; align-items: baseline; gap: 10px; }
.lead-name {
  flex: 1; min-width: 0;
  font-size: 17px; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lead.is-spam .lead-name { color: var(--muted); }
.new-dot {
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--new);
  vertical-align: 2px;
}
.lead-time { flex: none; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.lead-contact { font-size: 16px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; font-size: 13px; color: var(--muted); }
.lead-source { overflow-wrap: anywhere; }

.lead-call {
  flex: none;
  display: grid; place-items: center;
  width: 64px;
  border-left: 1px solid var(--line);
  color: var(--call);
}
.lead-call svg.i { width: 24px; height: 24px; }
.lead-call:active { background: var(--ok-soft); }

.site-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 550; }
.site-tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--site, var(--faint)); flex: none; }

.pill {
  display: inline-flex; align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px; line-height: 20px; font-weight: 650;
  white-space: nowrap;
}
.pill-repeat { background: var(--accent-soft); color: var(--accent); }
.pill-spam { background: var(--spam-soft); color: var(--spam); }
.pill-maybe { background: var(--maybe-soft); color: var(--maybe); }

.more { margin-top: 4px; }

.lead-name.is-contact { font-variant-numeric: tabular-nums; }

/* ---------- Выбор и удаление ---------- */

.text-btn {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 16px; font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
}
.text-btn-strong { font-weight: 700; }
.text-btn:active { opacity: .6; }

.lead-check {
  display: none;
  flex: none;
  width: 52px;
  place-items: center;
  border-right: 1px solid var(--line);
  cursor: pointer;
}
.lead-check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); cursor: pointer; }

.is-selecting .lead-check { display: grid; }
.is-selecting .lead-call,
.is-selecting .new-banner,
.is-selecting [data-hide-when-selecting] { display: none !important; }
.is-selecting .page { padding-bottom: calc(env(safe-area-inset-bottom) + 110px); }
.lead.is-checked { border-color: var(--accent); background: var(--accent-soft); }

.bulk-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(21, 24, 29, .08);
  padding-inline: 16px;
  padding-block: 12px calc(env(safe-area-inset-bottom) + 12px);
}
.bulk-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bulk-count { font-weight: 600; }

.btn.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; filter: none; }

.lead-footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 0 16px; }
.link-btn.link-btn-danger { color: var(--danger); }

.new-banner {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 20;
  padding: 12px 20px;
  border: 0; border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- Карточка заявки ---------- */

.hero { display: flex; flex-direction: column; gap: 4px; padding: 6px 2px 2px; }
.hero-name { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 750; letter-spacing: -.01em; text-wrap: balance; overflow-wrap: anywhere; }
.hero-phone { align-self: flex-start; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; text-decoration: none; }
.hero-phone.is-bad,
.hero-name.is-bad { color: var(--spam); text-decoration: line-through; }
.hero-name-phone { color: inherit; text-decoration: none; font-variant-numeric: tabular-nums; }
.hero-time { color: var(--muted); font-size: 14px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px;
  padding: 0 12px;
  border-radius: 14px;
  color: #fff;
  font-size: 17px; font-weight: 650;
  text-decoration: none;
  transition: transform .08s ease;
}
.action:active { transform: scale(.98); }
.action-call { grid-column: 1 / -1; min-height: 64px; font-size: 19px; background: var(--call); }
.action-wa { background: var(--wa); }
.action-tg { background: var(--tg); }
.action-mail { grid-column: 1 / -1; background: var(--surface); color: var(--text); border: 1px solid var(--line); }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--radius);
}
.notice-spam { background: var(--spam-soft); color: var(--spam); }
.notice-maybe { background: var(--maybe-soft); color: var(--maybe); }
.notice-body { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.notice-title { font-weight: 700; }
.notice-text { font-size: 14px; color: var(--text); }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 16px;
  box-shadow: var(--shadow);
}
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 8px 2px; }
.block-head .block-title { margin: 0; }
.block-title {
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 13px; font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.message { padding-bottom: 14px; font-size: 16px; overflow-wrap: anywhere; }

.facts { margin: 0; }
.facts > div {
  display: grid;
  grid-template-columns: minmax(96px, 34%) 1fr;
  gap: 12px;
  padding-block: 12px;
  border-top: 1px solid var(--line);
}
.facts > div:first-child { border-top: 0; }
.facts dt { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dd a { color: var(--accent); }

details + details { border-top: 1px solid var(--line); }
summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px;
  list-style: none;
  font-weight: 600;
  cursor: pointer;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: "";
  width: 8px; height: 8px;
  margin-right: 4px;
  border-right: 2px solid var(--faint);
  border-bottom: 2px solid var(--faint);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s ease;
  flex: none;
}
details[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }

.kv { margin: 0 0 14px; font-size: 14px; }
.kv > div { padding-block: 8px; border-top: 1px solid var(--line); }
.kv dt { color: var(--muted); }
.kv dd { margin: 2px 0 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: 13px; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px;
  padding-block: 10px;
  text-decoration: none;
}
.row > svg.i { color: var(--faint); width: 18px; height: 18px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-main strong { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.row-main small { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--site); flex: none; }

/* ---------- Кнопки и формы ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 0; border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { filter: brightness(.94); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn-block { display: flex; width: 100%; }

.link-btn {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.form { display: flex; flex-direction: column; gap: 6px; padding-block: 4px 16px; }
.form > label { margin-top: 10px; font-size: 15px; font-weight: 600; }
.form > .btn { margin-top: 14px; align-self: flex-start; }
.form > .btn-block { align-self: stretch; }

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 16px;
}
textarea.input { min-height: 0; resize: vertical; }
.input-mono { font-family: var(--mono); font-size: 14px; }
select.input { appearance: auto; }

.color-row { display: flex; align-items: center; gap: 12px; }
input[type="color"] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }

.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 550; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.hint { color: var(--muted); font-size: 13px; }
.muted-text { color: var(--muted); font-size: 14px; padding-block: 4px 12px; }

.flash { padding: 12px 16px; border-radius: 12px; background: var(--ok-soft); color: var(--ok); font-weight: 550; }
.flash-error { background: var(--spam-soft); color: var(--spam); }

.steps { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; font-size: 15px; }
.copy { display: flex; gap: 8px; align-items: flex-start; }
.code {
  flex: 1; min-width: 0;
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
}
.settings > .block > .hint { padding-bottom: 14px; }
.settings .hint a { color: var(--accent); }

.status {
  display: inline-flex;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px; line-height: 20px; font-weight: 650;
  background: var(--surface-2);
  color: var(--muted);
}
.st-lead { background: var(--ok-soft); color: var(--ok); }
.st-merged { background: var(--accent-soft); color: var(--accent); }
.st-error, .st-bad_key { background: var(--spam-soft); color: var(--spam); }
.st-ignored, .st-new { background: var(--maybe-soft); color: var(--maybe); }

.raw {
  margin: 0 0 14px;
  padding: 12px;
  max-height: 60vh;
  overflow: auto;
  border-radius: 10px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Вход ---------- */

.login {
  min-height: 100vh;
  min-height: 100svh;
  display: grid; place-items: center;
  padding-inline: 16px;
  padding-block: 32px;
}
.login-card { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.login-mark {
  display: grid; place-items: center;
  width: 64px; height: 64px;
  margin-bottom: 4px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-ink);
}
.login-mark svg.i { width: 32px; height: 32px; }
.login-title { margin: 0; font-size: 26px; font-weight: 750; }
.login-hint { color: var(--muted); }
.login-card .code { margin-top: 8px; text-align: left; }

.pin-form { width: 100%; display: flex; flex-direction: column; align-items: center; }
.pin-field { position: relative; margin-top: 18px; }
.pin-input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: 0;
  cursor: default;
}
.pin-dots { display: flex; gap: 16px; padding: 8px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--faint); transition: background .1s, border-color .1s; }
.pin-dots span.is-filled { background: var(--text); border-color: var(--text); }
.pin-form.is-busy .pin-dots span { background: var(--accent); border-color: var(--accent); }
.pin-error { min-height: 22px; margin-top: 6px; color: var(--spam); font-size: 14px; font-weight: 550; }

.pin-pad { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.pin-pad button {
  height: 64px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line), var(--shadow);
  font-size: 26px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  display: grid; place-items: center;
  touch-action: manipulation;
}
.pin-pad button:active { background: var(--line); }
.pin-pad button[data-erase] { background: transparent; box-shadow: none; color: var(--muted); }

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