:root {
  --color-bg: #0b0f1a;
  --color-bg-alt: #121826;
  --color-surface: #161d2e;
  --color-ink: #f1f5f9;
  --color-ink-muted: #94a3b8;
  --color-ink-soft: #64748b;
  --color-accent: #8b5cf6;
  --color-accent-hover: #7c3aed;
  --color-accent-soft: rgba(139, 92, 246, 0.18);
  --color-border: rgba(148, 163, 184, 0.16);
  --color-border-strong: rgba(148, 163, 184, 0.28);
  --font-display: Unbounded, system-ui, sans-serif;
  --font-body: Manrope, system-ui, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-soft: 0 12px 40px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 20px 50px rgba(139, 92, 246, 0.25);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --bs-body-bg: var(--color-bg);
  --bs-body-color: var(--color-ink);
  --bs-border-color: var(--color-border);
  --bs-primary: var(--color-accent);
  --bs-link-color: #c4b5fd;
  --bs-link-hover-color: #ddd6fe;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--color-ink);
  background: var(--color-bg);
  overflow-x: hidden;
}

.page-glow {
  pointer-events: none;
  position: fixed;
  inset: -20% auto auto 40%;
  width: 55vw;
  height: 55vw;
  z-index: 0;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.22), transparent 65%);
  filter: blur(20px);
}
.page-grid {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 20%, rgba(139, 92, 246, 0.16), transparent 32%),
    radial-gradient(circle at 78% 18%, rgba(56, 189, 248, 0.08), transparent 28%),
    linear-gradient(rgba(148, 163, 184, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px);
  background-size: auto, auto, 48px 48px, 48px 48px;
  mask-image: radial-gradient(ellipse at 40% 18%, #000 18%, transparent 78%);
}

.top, .wrap, #login-wrap { position: relative; z-index: 1; }

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 1.25rem;
  min-height: 72px;
  gap: 16px;
  background: rgba(11, 15, 26, 0.82);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-border);
}
.top .brand { margin-left: max(0px, calc((100% - 1280px) / 2)); }
.top .top-actions { margin-right: max(0px, calc((100% - 1280px) / 2)); }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: inherit;
  text-decoration: none;
  text-transform: lowercase;
}
.brand:hover { color: inherit; }
.logo-strong {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--color-accent);
}
.logo-badge {
  display: inline-grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 999px;
  background: var(--color-accent);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
}
.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.text-btn {
  background: none;
  border: 0;
  padding: 8px 12px;
  color: var(--color-ink-muted);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.text-btn:hover { color: var(--color-ink); }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 80px;
  width: 100%;
}

.hero h1, .display-h, .modal-title, .login-card h1 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.12;
}
.hero h1 {
  font-size: clamp(2rem, 4.4vw, 3.1rem);
  margin: 8px 0 12px;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  color: var(--color-ink-soft);
  margin: 0;
}
.lede {
  color: var(--color-ink-muted);
  font-size: 17px;
  line-height: 1.5;
  max-width: 42rem;
  margin: 0 0 28px;
}
.display-h {
  font-size: 1.45rem;
  margin: 0 0 12px;
}

.go, .btn-primary {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6, #4f46e5);
  box-shadow: 0 10px 30px rgba(139, 92, 246, 0.28);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s var(--ease);
}
.go:hover, .btn-primary:hover {
  background: linear-gradient(135deg, #7c3aed, #4338ca);
  color: #fff;
}
.go:disabled { opacity: 0.5; cursor: wait; }
.go-accent { box-shadow: var(--shadow-lift); }

.chip {
  border: 1px solid var(--color-border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-ink);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.chip:hover { color: var(--color-ink); border-color: #cbd5e1; background: rgba(255, 255, 255, 0.08); }
.chip.on, .chip.active {
  background: var(--color-accent-soft);
  color: #e9d5ff;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.35);
}
.chip--danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); }
.chip--danger:hover { background: rgba(248, 113, 113, 0.08); }
.chip--warn { color: var(--warn); }
.chip .n { font-weight: 700; color: #fff; }

.desk {
  background: linear-gradient(165deg, rgba(139, 92, 246, 0.08), transparent 42%), var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
}

#login-wrap {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 15, 26, 0.72);
  backdrop-filter: blur(16px);
}
#login-wrap.d-none { display: none !important; }
.login-card { width: min(420px, 92vw); padding: 32px 28px; }
.login-card h1 { font-size: 2rem; margin: 8px 0 20px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: border-color .15s var(--ease), transform .15s var(--ease), box-shadow .15s var(--ease);
}
.stat:hover {
  border-color: var(--color-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lift);
}
.stat .n {
  font-family: var(--font-display);
  font-size: 1.55rem;
  line-height: 1;
  letter-spacing: -0.03em;
}
.stat .l { color: var(--color-ink-muted); font-size: .8rem; margin-top: 6px; }

.crm-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0 4px;
  margin: 8px 0 28px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--color-border);
}
.crm-tabs .nav-item { list-style: none; }
.crm-tabs .nav-link {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--color-ink-muted);
  border-radius: 0;
  padding: 12px 18px 14px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.crm-tabs .nav-link::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg, #8b5cf6, #60a5fa);
  opacity: 0;
  transform: scaleX(0.6);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.crm-tabs .nav-link:hover {
  color: var(--color-ink);
  background: transparent;
  border-color: transparent;
}
.crm-tabs .nav-link.active {
  color: #fff;
  background: transparent;
  border-color: transparent;
}
.crm-tabs .nav-link.active::after {
  opacity: 1;
  transform: scaleX(1);
}

.seg-bar { display: flex; flex-wrap: wrap; gap: 8px; }

.form-control, .form-select, textarea.form-control {
  background: rgba(11, 15, 26, 0.55);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--color-ink);
  box-shadow: none;
}
.form-control::placeholder { color: var(--color-ink-soft); }
.form-control:focus, .form-select:focus {
  background: rgba(11, 15, 26, 0.8);
  color: var(--color-ink);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 4px var(--color-accent-soft);
}
.form-select option { background: var(--color-bg-alt); color: var(--color-ink); }
.form-label { font-size: 13px; font-weight: 600; color: var(--color-ink-muted); letter-spacing: .03em; }
.form-text, .form-check-label { color: var(--color-ink-muted); }
.form-check-input {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: var(--color-border-strong);
}
.form-check-input:checked {
  background-color: var(--color-accent);
  border-color: var(--color-accent);
}
.muted { color: var(--color-ink-muted); }
.hr-soft { border: 0; border-top: 1px solid var(--color-border); margin: 22px 0; }
.text-danger { color: var(--bad) !important; }

.table { color: var(--color-ink); --bs-table-bg: transparent; --bs-table-color: var(--color-ink); }
.table > :not(caption) > * > * {
  background: transparent;
  color: var(--color-ink);
  border-color: var(--color-border);
  vertical-align: middle;
}
.table thead th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-ink-soft);
  font-weight: 600;
}
.table-hover > tbody > tr.lead-row:hover > * {
  background: var(--color-accent-soft);
  color: var(--color-ink);
}
.lead-row { cursor: pointer; }
.lead-row.deleted { opacity: .5; }
.url-cell { max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell a { color: inherit; text-decoration: none; font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell a:hover { color: #c4b5fd; }
.company-cell {
  max-width: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.group-head td {
  background: transparent !important;
  color: var(--color-ink-soft);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding-top: 16px !important;
  padding-bottom: 6px !important;
  font-weight: 600;
}

.badge {
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--color-ink);
}
.badge-new, .badge.ok { background: rgba(52, 211, 153, 0.14); color: var(--ok); }
.badge-sent, .badge-processed, .badge.warn { background: rgba(251, 191, 36, 0.14); color: var(--warn); }
.badge-opened, .badge-clicked { background: var(--color-accent-soft); color: #c4b5fd; }
.badge-bounced, .badge-unsubscribed, .badge.bad, .badge-deleted {
  background: rgba(248, 113, 113, 0.14); color: var(--bad);
}
.badge-ignored { background: rgba(148, 163, 184, 0.12); color: var(--color-ink-muted); }
.badge-role { background: transparent; border: 1px solid var(--color-border); color: var(--color-ink-muted); }

.tag-pill {
  display: inline-block;
  font-size: .72rem;
  padding: .2rem .5rem;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.28);
  margin: 0 2px 2px 0;
}
.tag-pill a { color: inherit; text-decoration: none; }

.pagination { gap: 6px; }
.page-link {
  border-radius: 999px !important;
  border: 1px solid var(--color-border);
  color: var(--color-ink);
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 12px;
}
.page-item.active .page-link {
  background: linear-gradient(135deg, #8b5cf6, #4f46e5);
  border-color: transparent;
  color: #fff;
}
.page-link:hover { background: var(--color-accent-soft); color: #e9d5ff; }

.modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  color: var(--color-ink);
}
.modal-header, .modal-footer { border-color: var(--color-border); }
.modal-title { font-size: 1.45rem; }
.btn-close { filter: invert(1) grayscale(1); opacity: .7; }

textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.log-json {
  background: #0b0f1a;
  color: #cbd5e1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.who-pill {
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 13px;
  color: var(--color-ink-muted);
}

h5, h6 { font-weight: 600; color: var(--color-ink); }
code { color: #c4b5fd; }
.btn { border-radius: var(--radius-sm); font-weight: 600; }
.btn-success {
  background: linear-gradient(135deg, #8b5cf6, #4f46e5);
  border: 0;
  color: #fff;
}
.btn-success:hover { background: linear-gradient(135deg, #7c3aed, #4338ca); color: #fff; }
.btn-outline-danger, .btn-outline-warning, .btn-outline-secondary, .btn-outline-info, .btn-outline-light {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--color-border-strong);
  color: var(--color-ink);
}
.btn-outline-light:hover, .btn-outline-info:hover, .btn-outline-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-ink);
  border-color: #cbd5e1;
}
.btn-outline-danger, .btn-danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); background: transparent; }
.btn-danger:hover, .btn-outline-danger:hover { background: rgba(248, 113, 113, 0.1); color: var(--bad); }
.btn-warning { background: rgba(251, 191, 36, 0.14); border-color: transparent; color: var(--warn); }
.btn-warning:hover { background: rgba(251, 191, 36, 0.22); color: var(--warn); }
.input-group .form-select { border-radius: var(--radius-md); }
.desk.table-responsive {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0 0;
  -webkit-overflow-scrolling: touch;
}
.desk.table-responsive .table {
  margin-bottom: 0;
  table-layout: fixed;
  width: 100%;
}
.desk.table-responsive th:first-child,
.desk.table-responsive td:first-child { padding-left: 18px; width: 42px; }
.desk.table-responsive th:last-child,
.desk.table-responsive td:last-child { padding-right: 18px; }
#tab-leads .desk.table-responsive th:nth-child(2),
#tab-leads .desk.table-responsive td:nth-child(2) { width: 18%; }
#tab-leads .desk.table-responsive th:nth-child(3),
#tab-leads .desk.table-responsive td:nth-child(3) { width: 18%; }
#tab-leads .desk.table-responsive th:nth-child(4),
#tab-leads .desk.table-responsive td:nth-child(4) { width: 16%; }
#tab-leads .desk.table-responsive th:nth-child(5),
#tab-leads .desk.table-responsive td:nth-child(5) { width: 16%; }
#tab-leads .desk.table-responsive th:nth-child(6),
#tab-leads .desk.table-responsive td:nth-child(6) { width: 16%; }
#tab-leads .desk.table-responsive th:nth-child(7),
#tab-leads .desk.table-responsive td:nth-child(7) { width: 12%; }

.email-cell,
.problems-cell,
.seg-cell,
.status-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0; /* table-layout:fixed — даёт ячейке схлопнуться по width колонки */
}
.seg-cell .tag-pill {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.status-cell .badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-item.disabled .page-link.page-ellipsis {
  background: transparent;
  border-color: transparent;
  color: var(--color-ink-soft);
  cursor: default;
  padding-left: 4px;
  padding-right: 4px;
}
.pagination {
  flex-wrap: wrap;
  max-width: 100%;
}
.input-group > .chip { border-radius: 999px; }

.form-control:-webkit-autofill,
.form-control:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--color-ink);
  transition: background-color 9999s;
  caret-color: var(--color-ink);
}

.segment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.segment-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.segment-card .display-h {
  font-size: 1.15rem;
  margin: 4px 0 0;
}
.segment-count {
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: -0.03em;
  color: #c4b5fd;
  line-height: 1;
}
.segment-offer {
  margin: 10px 0;
  font-size: 0.92rem;
  color: var(--color-ink);
}
.segment-examples {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 4.5rem;
}

#tpl-modal .modal-dialog {
  max-height: calc(100dvh - 1.5rem);
  margin: 0.75rem auto;
}
#tpl-modal .modal-content {
  max-height: calc(100dvh - 1.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#tpl-modal #tpl-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}
#tpl-modal #tpl-form .modal-header,
#tpl-modal #tpl-form .modal-footer {
  flex: 0 0 auto;
}
#tpl-modal #tpl-form .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.tpl-preview-body {
  color: var(--color-ink);
  font-size: 0.95rem;
  line-height: 1.55;
  max-height: 280px;
  overflow: auto;
}
#tpl-preview-body p { margin: 0 0 0.75em; }
#tpl-preview-wrap {
  background: rgba(11, 15, 26, 0.45);
}

.import-job-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.import-progress-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--muted);
}
.import-progress-meta #import-pct {
  color: var(--color-ink);
  font-weight: 600;
}
.import-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.import-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
  transition: width 0.35s ease;
}
.import-log {
  max-height: 220px;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}
.import-log-line { margin: 0 0 4px; color: var(--muted); }
.import-log-warn { color: var(--warn); }
.import-log-error { color: var(--bad); }
.import-st {
  font-size: 0.8rem;
  font-weight: 600;
}
.import-st-running, .import-st-pending { color: #a78bfa; }
.import-st-completed { color: #4ade80; }
.import-st-failed { color: var(--bad); }
.import-st-cancelled { color: var(--warn); }
