:root {
  --crm-blue: #2f56ff;
  --crm-blue-press: #1d3fd4;
  --crm-blue-soft: #e8eeff;
  --crm-ink: #14151a;
  --crm-muted: #6b7280;
  --crm-line: #e6e8ee;
  --crm-paper: #f4f5f8;
  --crm-card: #ffffff;
  --crm-danger: #d11f4a;
  --crm-ok: #0f8a5a;
  --crm-radius: 14px;
  --crm-shadow: 0 10px 30px rgba(24, 36, 80, 0.07);
  --crm-serif: "Playfair Display", Georgia, serif;
  --crm-sans: "Montserrat", system-ui, sans-serif;

  /* legacy aliases used by board/kanban */
  --amo-bg: var(--crm-paper);
  --amo-sidebar: #2e3648;
  --amo-sidebar-hover: #3a4458;
  --amo-ink: var(--crm-ink);
  --amo-muted: var(--crm-muted);
  --amo-line: var(--crm-line);
  --amo-card: var(--crm-card);
  --amo-blue: var(--crm-blue);
  --amo-blue-hover: var(--crm-blue-press);
  --amo-red: var(--crm-danger);
  --amo-shadow: var(--crm-shadow);
  --amo-font: var(--crm-sans);
  --sidebar-w: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--crm-sans);
  color: var(--crm-ink);
  background: var(--crm-paper);
  min-height: 100vh;
  font-size: 13px;
  line-height: 1.35;
}

a { color: var(--crm-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.crm-shell { min-height: 100vh; display: flex; flex-direction: column; }

.crm-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid var(--crm-line);
  position: sticky;
  top: 0;
  z-index: 40;
}
.crm-nav-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex: 1;
  min-width: 0;
}
.crm-nav-panel-head { display: none; }
.crm-nav-links { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.crm-brand {
  font-family: var(--crm-serif);
  font-size: 1.35rem;
  color: var(--crm-ink);
  text-decoration: none;
  margin-right: 0.25rem;
  font-weight: 600;
  flex-shrink: 0;
  max-width: min(46vw, 240px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-brand:hover { text-decoration: none; color: var(--crm-blue); }
.crm-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  color: var(--crm-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
}
.crm-nav-link:hover, .crm-nav-link.is-active {
  color: var(--crm-blue);
  background: var(--crm-blue-soft);
  text-decoration: none;
}
.crm-nav-meta { display: flex; align-items: center; gap: 0.75rem; font-size: 0.78rem; flex-shrink: 0; }
.crm-nav-toggle,
.crm-nav-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--crm-line);
  border-radius: 10px;
  background: #fff;
  color: var(--crm-ink);
  cursor: pointer;
  flex-shrink: 0;
}
.crm-nav-toggle:hover,
.crm-nav-close:hover { background: var(--crm-blue-soft); border-color: #c9d6ff; }
.crm-nav-toggle-bars,
.crm-nav-toggle-bars::before,
.crm-nav-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.crm-nav-toggle-bars::before,
.crm-nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.crm-nav-toggle-bars::before { top: -6px; }
.crm-nav-toggle-bars::after { top: 6px; }
.crm-nav.is-open .crm-nav-toggle-bars { background: transparent; }
.crm-nav.is-open .crm-nav-toggle-bars::before { top: 0; transform: rotate(45deg); }
.crm-nav.is-open .crm-nav-toggle-bars::after { top: 0; transform: rotate(-45deg); }
.crm-nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 21, 26, 0.45);
    z-index: 55;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
}
.crm-nav-close {
  font-size: 1.6rem;
  line-height: 1;
  color: var(--crm-muted);
}
.crm-pill {
  background: var(--crm-blue-soft);
  color: var(--crm-blue);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-weight: 600;
}
.crm-ghost { color: var(--crm-muted); text-decoration: none; }
.crm-ghost:hover { color: var(--crm-ink); }

.crm-main {
  width: calc(100% - 1.5rem);
  max-width: none;
  margin: 0.75rem 0.75rem 2rem;
  flex: 1;
  min-width: 0;
}

/* legacy app/sidebar kept for guest layout only */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ——— Sidebar ——— */
.sidebar {
  background: var(--amo-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 12px;
  gap: 4px;
  z-index: 20;
}
.sidebar-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4c8bf5, #6aa1ff);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  color: #fff;
}
.nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  flex: 1;
}
.nav a {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: #c5ccd8;
  display: grid;
  place-items: center;
  position: relative;
  text-decoration: none;
}
.nav a:hover { background: var(--amo-sidebar-hover); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(76, 139, 245, 0.22); color: #fff; }
.nav a svg { width: 20px; height: 20px; fill: currentColor; }
.nav .badge {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--amo-red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.sidebar-foot button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c5ccd8;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.sidebar-foot button:hover { background: var(--amo-sidebar-hover); color: #fff; }
.sidebar-foot svg { width: 18px; height: 18px; fill: currentColor; }

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--amo-bg);
}

/* ——— Header ——— */
.amo-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--amo-line);
  min-height: 52px;
}
.amo-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
}
.pipeline-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--amo-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}
.pipeline-select {
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--amo-ink);
  cursor: pointer;
  max-width: 280px;
  padding: 0;
}
.stage-select {
  border: 1px solid var(--amo-line);
  background: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--amo-ink);
  cursor: pointer;
  max-width: 220px;
  padding: 4px 8px;
  border-radius: 3px;
}
.icon-quiet {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--amo-muted);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}
.icon-quiet:hover { background: #eef2f6; color: var(--amo-ink); }
.icon-quiet svg { width: 16px; height: 16px; fill: currentColor; }

.amo-search {
  flex: 1;
  max-width: 520px;
  position: relative;
}
.amo-search input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--amo-line);
  border-radius: 18px;
  padding: 0 14px 0 34px;
  background: #f7f9fb;
  font: inherit;
  color: var(--amo-ink);
}
.amo-search input:focus {
  outline: none;
  border-color: #b7d0fb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.12);
}
.amo-search .search-ico {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--amo-muted);
  display: grid;
  pointer-events: none;
}
.amo-search .search-ico svg { width: 14px; height: 14px; fill: currentColor; }

.amo-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.amo-stats {
  color: var(--amo-muted);
  font-size: 13px;
  white-space: nowrap;
}
.amo-stats b { color: var(--amo-ink); font-weight: 600; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 3px;
  height: 34px;
  padding: 0 14px;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-primary {
  background: var(--amo-blue);
  color: #fff;
}
.btn-primary:hover { background: var(--amo-blue-hover); }
.btn-secondary {
  background: #fff;
  color: var(--amo-ink);
  border-color: #d5dbe3;
}
.btn-secondary:hover { background: #f7f9fb; }
.btn.ghost {
  background: transparent;
  color: var(--amo-ink);
  border-color: #d5dbe3;
  text-transform: none;
  font-weight: 500;
}
.switch {
  display: inline-flex;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  overflow: hidden;
}
.switch a {
  height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  color: var(--amo-muted);
  text-decoration: none;
  background: #fff;
  font-size: 12px;
}
.switch a.active {
  background: #eef4ff;
  color: var(--amo-blue);
  font-weight: 600;
}

.board-wrap {
  flex: 1;
  padding: 12px 12px 20px;
  overflow: auto;
}

/* ——— Kanban ——— */
.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 260px;
  gap: 10px;
  align-items: start;
  min-height: calc(100vh - 90px);
}
.column {
  background: transparent;
  min-height: 480px;
  display: flex;
  flex-direction: column;
}
.column-head {
  background: transparent;
  padding: 0 2px 8px;
  border: 0;
  display: block;
}
.column-accent {
  height: 3px;
  border-radius: 2px;
  margin-bottom: 8px;
}
.column-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.column-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--amo-ink);
}
.column-sub {
  margin: 3px 0 0;
  color: var(--amo-muted);
  font-size: 12px;
}
.icon-btn {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 0;
  background: transparent;
  color: var(--amo-blue);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: #e8f1ff; }
.icon-btn.ghost {
  color: var(--amo-muted);
  font-size: 20px;
}
.column-add {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
}
.column-add:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.04);
}
.column-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 120px;
  padding: 0;
}

.card {
  background: var(--amo-card);
  border: 1px solid #e8ecf1;
  border-radius: 3px;
  padding: 10px 10px 8px;
  cursor: pointer;
  box-shadow: var(--amo-shadow);
  position: relative;
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease, opacity 0.15s ease;
}
.card[draggable="true"] { cursor: grab; }
.card[draggable="true"]:active { cursor: grabbing; }
.card:hover {
  border-color: #cfd8e3;
  box-shadow: 0 2px 8px rgba(46, 54, 72, 0.08);
}
.card.is-dragging {
  opacity: 0.35;
  transform: scale(0.98);
  box-shadow: none;
  border-style: dashed;
}
.card.is-just-moved {
  animation: crm-card-land 0.4s ease;
}
.card.is-soft-new {
  animation: crm-card-soft-in 0.45s ease;
}
.card.is-soft-gone {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
@keyframes crm-card-soft-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.card-drag-ghost {
  opacity: 0.92;
  box-shadow: 0 12px 28px rgba(46, 54, 72, 0.18);
  border-color: #9db7e8;
  transform: rotate(1.5deg);
  pointer-events: none;
}
.card-placeholder {
  min-height: 64px;
  border: 2px dashed #7aa2e3;
  border-radius: 3px;
  background: rgba(76, 139, 245, 0.08);
  animation: crm-placeholder-pulse 1s ease infinite;
}
.column-body.is-drag-over {
  background: rgba(76, 139, 245, 0.04);
  border-radius: 4px;
  outline: 2px dashed #4c8bf5;
  outline-offset: 2px;
}
@keyframes crm-card-land {
  0% { transform: scale(0.96); box-shadow: 0 0 0 0 rgba(76, 139, 245, 0.35); }
  60% { transform: scale(1.02); box-shadow: 0 0 0 4px rgba(76, 139, 245, 0.12); }
  100% { transform: scale(1); box-shadow: var(--amo-shadow); }
}
@keyframes crm-placeholder-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}
.card h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--amo-ink);
  line-height: 1.3;
}
.card-date {
  color: var(--amo-muted);
  font-size: 11px;
  white-space: nowrap;
}
.card-contact {
  margin-top: 4px;
  color: var(--amo-muted);
  font-size: 12px;
}
.card-amount {
  margin-top: 6px;
  font-weight: 600;
  color: var(--amo-ink);
  font-size: 12px;
}
.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.card-link {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
a.tag.card-link,
a.card-link.tag {
  background: #e8f7f4;
  color: #0f766e;
}
a.tag.card-link:hover,
a.card-link.tag:hover {
  background: #d5f0ea;
  color: #0b5f59;
  text-decoration: none;
}
.card-link:not(.tag) {
  background: #e8f4ff;
  color: #1a6fb5;
}
.card-link:not(.tag):hover {
  background: #d6ebff;
  color: #0f4f86;
}
.crm-field-link-wrap {
  position: relative;
}
.crm-field-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #1a6fb5;
  text-decoration: none;
}
.crm-field-link:hover {
  text-decoration: underline;
}
.crm-field-textarea-wrap {
  grid-column: 1 / -1;
}
.crm-field-textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  line-height: 1.45;
  font: inherit;
}
#create-custom-fields label:has(.crm-field-textarea),
#edit-custom-fields label:has(.crm-field-textarea) {
  grid-column: 1 / -1;
}
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  background: #edf1f5;
  color: #5b667a;
}
.tag.beeline { background: #e8f8ef; color: #2f9e5f; }
.tag.email { background: #eef4ff; color: #4c8bf5; }
.tag.telegram { background: #eaf6ff; color: #2a9fd8; }
.tag.litepms { background: #e8f7f4; color: #0f766e; }
.tag.source { background: #fff3e8; color: #c56a1a; }
.card-dot {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa6b5;
}
.card-dot.green { background: #41c275; }
.card-dot.orange { background: #f0a34c; }
.card-dot.blue { background: #4c8bf5; }
.card-spam-btn {
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 2;
  border: 1px solid #e8b4b4;
  background: #fff5f5;
  color: #b42318;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.card:hover .card-spam-btn,
.card-spam-btn:focus {
  opacity: 1;
}
.card-spam-btn:hover {
  background: #fee2e2;
}

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #eef4ff; }
.clickable-row.is-selected { background: #e8f1ff; }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #f5f9ff;
  border: 1px solid #c9dbf7;
  border-radius: 3px;
  flex-wrap: wrap;
}
.bulk-stage-select {
  min-width: 160px;
  max-width: 240px;
  padding: 4px 8px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  background: #fff;
}
.bulk-count {
  font-size: 13px;
  color: var(--amo-ink);
  font-weight: 600;
}
.col-check {
  width: 36px;
  text-align: center !important;
  vertical-align: middle !important;
}
.col-check input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.btn-danger {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
}
.btn-danger:hover {
  background: #912018;
  border-color: #912018;
}

.panel {
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  padding: 12px;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--amo-line);
  vertical-align: top;
}
table.data th {
  color: var(--amo-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.contacts-actions {
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
.modal-history {
  width: min(720px, 100%);
  max-height: min(92vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.contact-history-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.contact-history-timeline {
  flex: 1;
  min-height: 280px;
  max-height: min(70vh, 640px);
  overflow: auto;
  padding-right: 4px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #d5dbe3;
  border-radius: 3px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--amo-ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #b7d0fb;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.12);
}
label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--amo-muted);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.muted { color: var(--amo-muted); }
.empty {
  color: var(--amo-muted);
  font-size: 12px;
  padding: 8px 4px;
}
.error {
  background: #fff1f0;
  color: #c0392b;
  border: 1px solid #f5c6c2;
  border-radius: 3px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

/* ——— Guest / login ——— */
.guest {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--amo-bg);
}
.login-box {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 4px;
  box-shadow: var(--amo-shadow);
  padding: 24px;
}
.login-box h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
}

/* ——— Modal ——— */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(46, 54, 72, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  width: min(560px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(46, 54, 72, 0.2);
}
.modal-wide { width: min(1200px, 100%); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--amo-line);
}
.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.modal-body { padding: 16px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.modal-split {
  display: grid;
  grid-template-columns: minmax(340px, 0.85fr) minmax(420px, 1.25fr);
  min-height: 520px;
}
.contact-box {
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  padding: 12px;
  margin: 4px 0 0;
}
.contact-box legend {
  padding: 0 4px;
  color: var(--amo-muted);
  font-size: 12px;
}
.hint { margin: 6px 0 0; font-size: 12px; }
.suggest {
  margin: 4px 0 8px;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  background: #fff;
  max-height: 180px;
  overflow: auto;
}
.suggest-item {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--amo-line);
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover { background: #eef4ff; }
.suggest-item span { color: var(--amo-muted); font-size: 12px; }

.contact-channels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.contact-channel-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef6ff;
  color: #1e5a8a;
  font-size: 12px;
  font-weight: 500;
}
.contact-link-hint {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff8e8;
  border: 1px solid #f0d78c;
  color: #6b5420;
  font-size: 13px;
  line-height: 1.35;
}
.contact-merge-row {
  margin: 6px 0 8px;
}
.merge-panel {
  margin: 0 0 10px;
  padding: 10px;
  border: 1px dashed #c5d4e8;
  border-radius: 8px;
  background: #f8fbff;
}

.history-pane {
  border-left: 1px solid var(--amo-line);
  background: #f7f9fb;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(92vh, 900px);
  overflow: hidden;
}
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.history-head h3 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.note-form { display: grid; gap: 8px; }
.reply-form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--amo-line);
}
.reply-form select {
  width: 100%;
  margin-top: 4px;
}
.reply-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
}
.timeline {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.timeline-item {
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  padding: 10px;
}
.timeline-item.kind-call { border-left: 3px solid #f0a34c; }
.timeline-item.kind-message { border-left: 3px solid var(--amo-blue); }
.timeline-item.kind-message.is-out { border-left-color: #41c275; }
.timeline-item.kind-note { border-left: 3px solid #41c275; }
.timeline-item.kind-system { border-left: 3px solid #9aa6b5; }
.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}
.timeline-body { white-space: pre-wrap; }
.timeline-body.timeline-html {
  white-space: normal;
  line-height: 1.45;
  overflow-x: auto;
  max-width: 100%;
  word-break: break-word;
}
.timeline-html p { margin: 0 0 0.6em; }
.timeline-html p:last-child { margin-bottom: 0; }
.timeline-html a { color: var(--amo-blue); }
.timeline-html blockquote {
  margin: 0.5em 0;
  padding: 0.35em 0.75em;
  border-left: 3px solid var(--amo-line);
  color: #5a6573;
}
.timeline-html img {
  max-width: 100%;
  height: auto;
}
.timeline-html table {
  border-collapse: collapse;
  max-width: 100%;
  font-size: 12px;
}
.timeline-html td,
.timeline-html th {
  border: 1px solid var(--amo-line);
  padding: 4px 6px;
}
.timeline-foot {
  margin-top: 6px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.timeline-reply-btn {
  flex-shrink: 0;
  padding: 2px 8px;
  font-size: 11px;
  line-height: 1.3;
  min-height: 0;
}
.reply-form.reply-form-flash {
  animation: reply-form-flash 1.2s ease;
}
@keyframes reply-form-flash {
  0%, 100% { background: transparent; }
  20% { background: rgba(74, 144, 226, 0.12); }
}
.crm-call-audio-wrap {
  margin: 8px 0 4px;
  max-width: 100%;
}
.crm-call-audio {
  display: block;
  width: 100%;
  max-width: 360px;
  height: 36px;
}
.crm-call-no-rec {
  margin: 6px 0 2px;
  font-size: 12px;
}

/* ——— Settings module ——— */
.crm-settings-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 14px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--crm-line);
}
.crm-settings-tab {
  display: inline-flex;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  color: var(--crm-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
}
.crm-settings-tab:hover,
.crm-settings-tab.is-active {
  color: var(--crm-blue);
  background: var(--crm-blue-soft);
  text-decoration: none;
}
.crm-settings-h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.crm-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.crm-badge.ok { background: #e8f8ef; color: var(--crm-ok); }
.crm-badge.warn { background: #fff4e5; color: #b45309; }
.crm-stage-row {
  display: grid;
  grid-template-columns: 1.4fr 90px 70px 48px 110px 40px auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
}
.crm-stage-row input,
.crm-stage-row select {
  width: 100%;
  margin: 0;
}

.card.is-sla-idle {
  border-color: #f0a34c;
  outline: 1px solid #f0a34c;
  background: #fffaf3;
}
.card.is-attention {
  background: #fff8f0;
  border-color: #f0b27a;
  box-shadow: 0 0 0 1px rgba(240, 163, 76, 0.25);
}
.card.is-attention.is-sla-idle {
  background: #fff4e8;
}
.card-attention {
  margin-top: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: #b45309;
  line-height: 1.2;
}
.crm-sla-badge {
  display: inline-block;
  margin: 0 0 6px;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #fff4e5;
  color: #b45309;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
}
.crm-tag-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.crm-tag-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 12px;
  margin: 0;
}
.crm-tag-check span {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tg, #64748b) 18%, #fff);
  color: var(--tg, #64748b);
  font-weight: 600;
}
.crm-tasks { display: flex; flex-direction: column; gap: 0.4rem; }
.crm-task {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
  margin: 0;
  font-size: 13px;
}
.crm-task.is-done span { text-decoration: line-through; color: var(--crm-muted); }

@media (max-width: 960px) {
  .amo-header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .amo-header-left { min-width: 0; width: 100%; }
  .amo-header-right { width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .amo-search { max-width: none; order: 3; width: 100%; }
  .pipeline-select, .stage-select { max-width: 100%; }
  .modal-split { grid-template-columns: 1fr; }
  .history-pane { border-left: 0; border-top: 1px solid var(--amo-line); max-height: 42vh; }
  .kanban { grid-auto-columns: 240px; }
  .crm-stage-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .crm-nav {
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }
  .crm-nav-toggle { display: inline-flex; }
  .crm-nav-backdrop {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .crm-nav.is-open .crm-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .crm-nav-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 88vw);
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0.85rem 1rem 1.25rem;
    background: #fff;
    border-left: 1px solid var(--crm-line);
    box-shadow: -12px 0 40px rgba(24, 36, 80, 0.14);
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.75rem;
    z-index: 60;
    transform: translateX(105%);
    transition: transform 0.22s ease;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .crm-nav.is-open .crm-nav-panel { transform: translateX(0); }
  .crm-nav-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--crm-line);
  }
  .crm-nav-panel-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--crm-muted);
  }
  .crm-nav-close { display: inline-flex; }
  .crm-nav-links {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
  }
  .crm-nav-link {
    width: 100%;
    padding: 0.85rem 0.95rem;
    border-radius: 12px;
    font-size: 0.95rem;
  }
  .crm-nav-meta {
    margin-top: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--crm-line);
  }
  .crm-pill {
    text-align: center;
    padding: 0.55rem 0.8rem;
  }
  .crm-ghost {
    display: block;
    text-align: center;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--crm-line);
    border-radius: 12px;
    background: #fff;
  }
  body.crm-nav-open { overflow: hidden; }
  .crm-main {
    width: calc(100% - 0.75rem);
    margin: 0.5rem 0.375rem 1.25rem;
  }
}

@media (max-width: 640px) {
  .amo-stats { font-size: 12px; }
  .switch { flex: 1; }
  .switch a { flex: 1; text-align: center; }
  .btn-primary[data-open-create],
  .amo-header-right .btn-primary { width: 100%; }
  .amo-header-right { flex-direction: column; align-items: stretch; }
  .modal-backdrop {
    padding: 0;
    place-items: stretch;
    align-items: stretch;
  }
  .modal,
  .modal-wide {
    width: 100%;
    max-width: none;
    max-height: none;
    min-height: 100vh;
    min-height: 100dvh;
    border-radius: 0;
  }
  .modal-split {
    min-height: calc(100dvh - 56px);
  }
  .history-pane { max-height: none; }
  .data { font-size: 12px; }
  .data th, .data td { padding: 8px 6px; }
  .bulk-bar { gap: 8px; }
  .bulk-stage-select { max-width: none; width: 100%; }
  .ga-row {
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    padding: 12px;
  }
  .ga-label {
    grid-column: 1 / -1;
  }
}

/* Channels settings */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.channel-empty {
  text-align: center;
  padding: 28px 16px;
}
.channel-card {
  display: block;
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  padding: 14px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-align: left;
  width: 100%;
  cursor: pointer;
  font: inherit;
}
.channel-card:hover {
  border-color: #b7d0fb;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.1);
}
.channel-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.channel-card__type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--amo-muted);
}
.channel-card__name {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
  color: var(--amo-ink);
}
.channel-card__summary {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}
.channel-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 2px;
  margin-top: 8px;
}
.channel-badge.is-on {
  background: #e8f8ef;
  color: #15803d;
}
.channel-badge.is-off {
  background: #f1f3f5;
  color: var(--amo-muted);
}
.channel-badge.is-soon {
  background: #fff7ed;
  color: #b45309;
}
.channel-card--email { border-top: 3px solid #4c8bf5; }
.channel-card--beeline { border-top: 3px solid #f59e0b; }
.channel-card--telegram { border-top: 3px solid #38bdf8; }
.channel-card--max { border-top: 3px solid #7c3aed; }
.channel-card--greenapi { border-top: 3px solid #25d366; }
.channel-card--whatsapp { border-top: 3px solid #22c55e; }
.channel-pick { margin: 0; }
.channel-card--pick .channel-card__type {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--amo-ink);
  font-weight: 600;
}

/* ——— Green API instance card (кабинет-like) ——— */
.ga-overview {
  margin: 4px 0 8px;
}
.ga-card {
  border: 1px solid #eceff3;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}
.ga-row {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f2f5;
  min-height: 52px;
}
.ga-row:last-child {
  border-bottom: none;
}
.ga-label {
  font-size: 13px;
  color: #8b93a1;
  font-weight: 400;
}
.ga-value {
  font-size: 14px;
  color: #2e3648;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ga-value-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  white-space: normal;
}
.ga-token {
  letter-spacing: 0.04em;
  color: #5a6475;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.ga-actions {
  display: inline-flex;
  gap: 4px;
  justify-self: end;
}
.ga-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #9aa3b2;
  cursor: pointer;
}
.ga-icon-btn:hover:not(:disabled) {
  background: #f3f5f8;
  color: #4b5565;
}
.ga-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.ga-icon-btn.ga-copied {
  color: #16a34a;
  background: #ecfdf3;
}
.ga-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.ga-badge-ok {
  background: #e8f8ef;
  color: #15803d;
}
.ga-badge-warn {
  background: #fff7ed;
  color: #b45309;
}
.ga-meta {
  font-size: 12px;
  color: #9aa3b2;
  font-weight: 400;
}
.ga-error-hint {
  font-size: 12px;
  color: #c0392b;
  font-weight: 400;
}
.ga-hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
}
.ga-edit-title {
  margin: 12px 0 0;
  padding-top: 14px;
  border-top: 1px solid #eef1f5;
  font-size: 13px;
  font-weight: 600;
  color: var(--amo-ink);
}
.ga-check {
  display: flex !important;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--amo-ink);
}
.ga-check input[type="checkbox"] {
  margin-top: 2px;
  width: auto;
}
.ga-webhook-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #eef1f5;
  border-radius: 8px;
}
.ga-webhook-url {
  flex: 1 1 220px;
  font-size: 12px;
  word-break: break-all;
  background: transparent;
  padding: 0;
}
