: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-global-search {
  position: relative;
  flex: 0 1 180px;
  max-width: 220px;
  min-width: 120px;
  margin: 0 0.35rem;
}
.crm-global-search-ico {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--crm-muted);
  pointer-events: none;
  display: flex;
}
.crm-global-search input {
  width: 100%;
  margin: 0;
  padding: 0.55rem 0.85rem 0.55rem 2.2rem;
  border: 1px solid var(--crm-line);
  border-radius: 999px;
  background: var(--crm-paper);
  font: inherit;
  font-size: 0.82rem;
}
.crm-global-search input:focus {
  outline: none;
  border-color: #b7d0fb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 86, 255, 0.12);
}
.crm-global-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: min(70vh, 420px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--crm-line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(24, 36, 80, 0.14);
  z-index: 60;
  padding: 6px;
}
.crm-gs-section {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--crm-muted);
}
.crm-gs-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}
.crm-gs-item:hover {
  background: var(--crm-blue-soft);
  text-decoration: none;
}
.crm-gs-title {
  grid-column: 1;
  font-weight: 600;
  font-size: 13px;
  color: var(--crm-ink);
}
.crm-gs-meta {
  grid-column: 1;
  font-size: 12px;
  color: var(--crm-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-gs-item .stage-pill {
  grid-column: 2;
  grid-row: 1 / span 2;
  max-width: 120px;
}
.crm-gs-empty {
  padding: 14px 12px;
  color: var(--crm-muted);
  font-size: 13px;
  text-align: center;
}
.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-link.crm-nav-hot-tasks {
  color: #b45309;
  background: #fff7ed;
  font-weight: 600;
  border: 1px solid #fed7aa;
}
.crm-nav-link.crm-nav-hot-tasks:hover,
.crm-nav-link.crm-nav-hot-tasks.is-active {
  color: #9a3412;
  background: #ffedd5;
}
.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;
}

/* Контакты: высота окна, скролл только у таблицы — правая колонка не уезжает */
.crm-shell:has(.contacts-page) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.crm-main:has(.contacts-page) {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.crm-main:has(.contacts-page) > .amo-header {
  flex-shrink: 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;
}
.quick-filters {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.quick-filter {
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  background: #fff;
  color: var(--amo-muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.quick-filter:hover {
  background: #f7f9fb;
  color: var(--amo-ink);
}
.quick-filter.is-active {
  background: #eef4ff;
  border-color: #c9dbff;
  color: var(--amo-blue);
}
.day-filters {
  margin-left: 4px;
  padding-left: 8px;
  border-left: 1px solid var(--amo-line);
}
.board-extra-filters {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  padding-left: 8px;
  border-left: 1px solid var(--amo-line);
  flex-wrap: wrap;
}
.board-filter-select select {
  height: 28px;
  max-width: 200px;
  padding: 0 8px;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--amo-ink);
  cursor: pointer;
}
.day-filter-date-wrap {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}
.day-filter-date {
  cursor: pointer;
  gap: 4px;
  appearance: none;
  font: inherit;
}
.day-filter-date-label {
  pointer-events: none;
}
.day-filter-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  display: grid;
  gap: 8px;
  min-width: 220px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.day-filter-panel[hidden] {
  display: none !important;
}
.day-filter-field {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--amo-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.day-filter-field input[type="date"] {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--amo-line);
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--amo-ink);
  text-transform: none;
  letter-spacing: 0;
}
.day-filter-panel-actions {
  display: flex;
  justify-content: flex-end;
}
.day-filter-panel-actions .btn {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
}
.day-filter-clear {
  min-width: 28px;
  padding: 0;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  color: var(--amo-muted);
}
.day-filter-clear:hover {
  color: var(--amo-ink);
}
.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 34px 0 34px;
  background: #f7f9fb;
  font: inherit;
  color: var(--amo-ink);
}
.amo-search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}
.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-search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--amo-muted);
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}
.amo-search-clear:hover,
.amo-search-clear.is-active {
  color: #b42318;
  background: #fee2e2;
}

.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;
  min-height: 0;
}

/* ——— Kanban ——— */
.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--kanban-col-w, 260px);
  gap: 10px;
  align-items: stretch;
  height: calc(100vh - 90px);
  min-height: 480px;
}
.column {
  background: transparent;
  min-height: 0;
  max-height: 100%;
  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: 0;
  padding: 0 0 8px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.column-sentinel {
  flex: 0 0 auto;
  min-height: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0 2px;
}
.column-sentinel[hidden] {
  display: none;
}
.column-loader {
  font-size: 11px;
  color: var(--amo-muted);
}
.column-loader[hidden] {
  display: none;
}

.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-merge-target {
  border-color: var(--crm-ok);
  box-shadow: 0 0 0 2px rgba(15, 138, 90, 0.35), 0 4px 14px rgba(15, 138, 90, 0.18);
  background: #f0faf5;
}
.board.is-merge-hint::after {
  content: "Отпустите — объединить в эту сделку";
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 80;
  padding: 10px 16px;
  border-radius: 10px;
  background: #14352a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(20, 53, 42, 0.35);
  pointer-events: none;
}
.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-fields {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.card-field {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 11px;
  line-height: 1.35;
  color: var(--amo-muted);
}
.card-field-name {
  flex: 0 0 auto;
  max-width: 46%;
  color: var(--amo-muted);
}
.card-field-name::after {
  content: ':';
}
.card-field-value {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--amo-ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.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: calc(1.45em * 2 + 18px); /* 2 строки по умолчанию, тянется вниз */
  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: #fff8e6; color: #c47f00; }
.tag.email { background: #eef4ff; color: #4c8bf5; }
.tag.telegram { background: #e8f5fc; color: #229ed9; }
.tag.max { background: #f3e8ff; color: #7c3aed; }
.tag.whatsapp { background: #e7f8ed; color: #128c7e; }
.tag.avito { background: #fff4e5; color: #c2410c; }
.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;
}

.col-picker {
  position: relative;
}
.col-picker-btn {
  white-space: nowrap;
}
.col-picker-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 280px;
  max-height: min(70vh, 480px);
  overflow: auto;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(20, 40, 80, 0.12);
}
.col-picker-hint {
  margin: 0 0 6px;
  padding: 0 6px;
  font-size: 11px;
  color: var(--amo-muted, #8896a8);
}
.col-picker-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.col-picker-item {
  display: grid;
  grid-template-columns: 18px auto 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  font-size: 13px;
  border-radius: 3px;
  border: 1px solid transparent;
  background: #fff;
  user-select: none;
}
.col-picker-item:hover {
  background: #f3f7ff;
}
.col-picker-item.is-dragging {
  opacity: 0.55;
  border-color: #9bb8e8;
}
.col-picker-item.is-drag-over {
  border-top-color: #4c8bf5;
}
.col-picker-item input {
  width: auto;
  margin: 0;
}
.col-picker-handle {
  cursor: grab;
  color: #9aa8b8;
  font-size: 14px;
  line-height: 1;
  text-align: center;
}
.col-picker-handle:active {
  cursor: grabbing;
}
.col-picker-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-picker-move {
  display: inline-flex;
  gap: 2px;
}
.col-picker-move button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--amo-line);
  border-radius: 3px;
  background: #fff;
  color: #5a6b7d;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.col-picker-move button:hover:not(:disabled) {
  background: #eef4ff;
  border-color: #9bb8e8;
}
.col-picker-move button:disabled {
  opacity: 0.35;
  cursor: default;
}
.col-picker-reset {
  display: block;
  width: 100%;
  margin-top: 8px;
  font-size: 12px;
}
#deals-table [data-col].is-col-hidden {
  display: none !important;
}
#deals-table {
  font-size: 13px;
}
#deals-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f5f8;
  border-bottom: 1px solid #dde2ea;
  color: #5b667a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding: 9px 10px;
}
#deals-table tbody td {
  padding: 8px 10px;
  vertical-align: middle;
  border-bottom: 1px solid #e8ebf0;
  color: #1f2937;
}
#deals-table tbody tr:hover td {
  background: #f7f9fc;
}
#deals-table [data-col="amount"] {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#deals-table [data-col="stage"] {
  white-space: nowrap;
}
#deals-table .table-link {
  color: #2563eb;
  font-weight: 500;
  text-decoration: none;
}
#deals-table .table-link:hover {
  text-decoration: underline;
  color: #1d4ed8;
}
#deals-table .table-muted {
  color: #6b7280;
}

.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;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}
.contacts-actions-col {
  width: 1%;
}
.contacts-name-cell {
  font-weight: 500;
}
.contacts-phone-cell,
.contacts-bd-cell {
  white-space: nowrap;
}
.amo-search-with-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 680px;
}
.contacts-filters {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.contacts-filters input[type="search"] {
  flex: 1;
  min-width: 120px;
  width: auto;
}
.contacts-month-filter {
  flex-shrink: 0;
  margin: 0;
}
.contacts-month-filter select {
  height: 34px;
  border: 1px solid var(--amo-line);
  border-radius: 18px;
  background: #f7f9fb;
  padding: 0 12px;
  font: inherit;
  color: var(--amo-ink);
  max-width: 150px;
  cursor: pointer;
}
.contacts-month-filter select:focus {
  outline: none;
  border-color: #b7d0fb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.12);
}
.contacts-filter-hint {
  margin: 0 0 12px;
  font-size: 13px;
}
/* Две колонки: таблица со своим скроллом, «Пригласить» остаётся в кадре */
.board-wrap.contacts-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 12px;
}
.contacts-page .contacts-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(440px, 560px);
  gap: 14px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
.contacts-main {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.contacts-main > .contacts-filter-hint,
.contacts-main > .contacts-bulk-bar {
  flex-shrink: 0;
}
.contacts-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.contacts-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 0 1px 0 var(--amo-line);
}
.contacts-aside {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  align-self: stretch;
}
.contacts-aside-panel {
  margin: 0;
  flex-shrink: 0;
}
.contacts-aside-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.contacts-aside-hint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.4;
}
.contacts-aside-sel {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--amo-ink);
}
.contacts-aside-label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
}
.contacts-aside-label input,
.contacts-aside-label textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: inherit;
}
.contacts-aside-form.form-grid {
  grid-template-columns: 1fr;
}
.contact-dup-warn {
  padding: 10px 12px;
  border: 1px solid #e2b6b6;
  background: #fdf2f2;
  color: #8a2f2f;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}
.contact-dup-warn a {
  color: #6b1f1f;
  font-weight: 600;
}
.contact-dup-warn ul {
  margin: 6px 0 0;
  padding-left: 18px;
}
.contacts-aside-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 500;
}
.contacts-aside-actions .btn[hidden],
#btn-contact-invite-send[hidden],
#btn-invite-clear-list[hidden],
#contact-invite-preview-wrap[hidden] {
  display: none !important;
}
.contacts-aside-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.contacts-aside-actions .btn-primary {
  flex: 1 1 auto;
  min-width: 140px;
}
#btn-invite-clear-list {
  flex: 1 1 100%;
}
.invite-campaign-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin: 0 0 12px;
}
.invite-campaign-select-wrap {
  flex: 1 1 160px;
  margin: 0;
}
.invite-campaign-select-wrap select {
  width: 100%;
}
.invite-campaign-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding-bottom: 1px;
}
.invite-tpl-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}
.invite-tpl-head {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--amo-muted);
}
.invite-tpl-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.invite-tpl-used {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--amo-muted);
}
.contact-invite-preview-inline,
.contact-poll-preview-inline {
  margin: 0 0 10px;
}
.reply-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
@media (max-width: 1100px) {
  .crm-shell:has(.contacts-page) {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .crm-main:has(.contacts-page) {
    display: block;
    overflow: visible;
    height: auto;
    max-height: none;
  }
  .board-wrap.contacts-page {
    flex: none;
    overflow: visible;
    min-height: auto;
  }
  .contacts-page .contacts-layout {
    grid-template-columns: 1fr;
    flex: none;
    min-height: auto;
  }
  .contacts-main {
    max-height: none;
    overflow: visible;
  }
  .contacts-table-wrap {
    flex: none;
    max-height: min(70vh, 640px);
  }
  .contacts-aside {
    max-height: none;
    overflow: visible;
  }
}
.contacts-cong-col {
  width: 1%;
  white-space: nowrap;
  text-align: center;
}
.contacts-cong-cell {
  text-align: center;
  vertical-align: middle;
}
.contacts-cong-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  cursor: pointer;
}
.contacts-cong-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.contacts-sel-col,
.contacts-sel-cell {
  width: 1%;
  text-align: center;
  vertical-align: middle;
}
.contacts-sel-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.contacts-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #f3f7fd;
  border: 1px solid #d6e4f8;
  border-radius: 8px;
  font-size: 13px;
}
.contacts-bulk-limit {
  margin-right: 4px;
}
.contact-merge-pick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}
.contact-merge-pick {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--amo-border, #d8e0ec);
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
}
.contact-merge-pick:hover {
  border-color: #8eb6e8;
  background: #f5f9ff;
}
.contact-merge-pick.is-selected {
  border-color: #3b82f6;
  background: #eef6ff;
  box-shadow: inset 0 0 0 1px #3b82f6;
}
.contact-merge-pick input {
  margin-top: 3px;
}
.contact-merge-pick-meta {
  display: block;
  font-size: 12px;
  color: var(--amo-muted, #6b7c93);
  margin-top: 2px;
}
.deal-merge-mode-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}
.deal-merge-mode-row input {
  margin-top: 2px;
}
.contact-merge-status {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
  background: #fff8e8;
  border: 1px solid #f0d78c;
  color: #6b5420;
}
.contact-merge-status.is-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}
.contact-merge-status.is-ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.contacts-action-status {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
  background: #fff8e8;
  border: 1px solid #f0d78c;
  color: #6b5420;
}
.contacts-action-status.is-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}
.contact-invite-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.contact-invite-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(380px, 0.85fr);
  gap: 24px;
  flex: 1;
  min-height: 0;
}
.contact-invite-preview,
.contact-invite-template {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.contact-invite-subtitle {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--amo-muted);
}
.contact-invite-hint {
  margin: 0 0 10px;
  font-size: 12px;
}
.contact-invite-table-wrap {
  flex: 1;
  min-height: 220px;
  overflow: auto;
  border: 1px solid var(--amo-line);
  border-radius: 8px;
}
.contact-invite-table-wrap .data {
  margin: 0;
}
.contact-invite-table-wrap th,
.contact-invite-table-wrap td {
  font-size: 13px;
}
.contact-invite-name-cell {
  min-width: 180px;
  vertical-align: middle;
}
.contact-invite-name-input {
  width: 100%;
  max-width: 260px;
  height: 32px;
  border: 1px solid var(--amo-line);
  border-radius: 6px;
  padding: 0 8px;
  font: inherit;
  background: #fff;
}
.contact-invite-name-input:focus {
  outline: none;
  border-color: #b7d0fb;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.12);
}
.contact-invite-name-input:disabled {
  background: #f5f7fa;
  color: var(--amo-ink);
}
.contact-invite-fullname {
  margin-top: 4px;
  font-size: 11px;
}
.contact-invite-template textarea {
  flex: 1;
  min-height: 280px;
  width: 100%;
  resize: vertical;
  border: 1px solid var(--amo-line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  line-height: 1.45;
}
.contact-invite-template textarea:focus {
  outline: none;
  border-color: #b7d0fb;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.12);
}
.contact-invite-actions {
  padding: 12px 16px 16px;
  margin-top: 0;
  border-top: 1px solid var(--amo-line);
  flex-shrink: 0;
}
.contact-invite-progress {
  margin: 8px 0 0;
  font-size: 12px;
}
.invite-status-ok { color: #1a7f37; }
.invite-status-skip { color: var(--amo-muted); }
.invite-status-err { color: #c62828; }
.invite-status-send { color: #1565c0; }
.invite-note-first {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  color: #9a6700;
}
@media (max-width: 960px) {
  .contact-invite-layout {
    grid-template-columns: 1fr;
    overflow: auto;
  }
}
.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-toolbar {
  flex-shrink: 0;
}
.contact-history-search input {
  width: 100%;
}
.contact-history-timeline {
  flex: 1;
  min-height: 280px;
  max-height: min(70vh, 640px);
  overflow: auto;
  padding-right: 4px;
}
.contact-history-more {
  flex-shrink: 0;
  text-align: center;
  padding-top: 4px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #d5dbe3;
  border-radius: 3px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--amo-ink);
}
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  max-width: none;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  accent-color: #4c8bf5;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #b7d0fb;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.12);
}
input[type="checkbox"]:focus,
input[type="radio"]:focus {
  border-color: transparent;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.18);
}
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: 80;
}
.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(1440px, 98vw);
  max-height: min(94vh, 980px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* После .modal — иначе width:560px перебивает */
.modal.modal-invite {
  width: min(1760px, 99vw);
  max-height: min(96vh, 1080px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--amo-line);
  flex-shrink: 0;
}
.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(480px, 1.25fr) minmax(400px, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.modal-wide #form-edit.modal-body {
  overflow-y: auto;
  min-height: 0;
  overscroll-behavior: contain;
  flex: 1;
}

/* ——— Deal edit: fullscreen + sticky actions ——— */
#modal-edit.modal-backdrop {
  padding: 0;
  place-items: stretch;
  background: rgba(15, 23, 42, 0.55);
}
#modal-edit .deal-modal {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
}
#modal-edit .modal-head {
  padding: 12px 16px 12px 20px;
  background: #fff;
  z-index: 2;
}
#modal-edit .modal-head h2 {
  font-size: 17px;
  padding-right: 12px;
  line-height: 1.3;
}
#modal-edit .modal-close {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
  padding: 0 0 2px;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
#modal-edit .modal-close:hover {
  background: #fee2e2;
  border-color: #fecaca;
  color: #b91c1c;
}
#modal-edit .modal-split {
  grid-template-columns: minmax(420px, 1.15fr) minmax(380px, 1fr);
}
#modal-edit .deal-edit-form {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  min-height: 0;
  overscroll-behavior: contain;
}
#modal-edit .deal-edit-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px 10px;
  overscroll-behavior: contain;
}
#modal-edit .deal-edit-actions {
  flex-shrink: 0;
  margin: 0;
  padding: 12px 18px;
  border-top: 1px solid var(--amo-line);
  background: #fff;
  box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.06);
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 2;
}
#modal-edit .deal-edit-actions .btn-primary {
  margin-left: auto;
}
#modal-edit .deal-edit-main-grid {
  grid-template-columns: minmax(160px, 1.8fr) minmax(120px, 1fr) minmax(120px, 1fr) minmax(90px, 0.7fr) minmax(110px, 0.9fr);
  gap: 8px 10px;
}
#modal-edit .deal-edit-fields-grid {
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px 10px;
}
#modal-edit .deal-edit-fields-grid label:has(.crm-field-textarea),
#modal-edit .deal-edit-fields-grid label:has(input[type="url"]),
#modal-edit .deal-edit-fields-grid label:has(.crm-field-link) {
  grid-column: 1 / -1;
}
#modal-edit .deal-edit-fields-grid label:has(input[type="date"]),
#modal-edit .deal-edit-fields-grid label:has(input[type="number"]) {
  max-width: 168px;
}
#modal-edit .deal-edit-contact-grid {
  grid-template-columns: minmax(140px, 1fr) minmax(180px, 1.2fr);
  gap: 8px 10px;
}
#modal-edit .deal-edit-scroll .contact-box {
  margin-top: 8px;
}
@media (max-width: 1100px) {
  #modal-edit .deal-edit-main-grid {
    grid-template-columns: 1fr 1fr;
  }
  #modal-edit .deal-field-title {
    grid-column: 1 / -1;
  }
}
/* Mobile toggles: hidden on desktop */
.deal-mobile-info-toggle,
.deal-mobile-note-toggle {
  display: none;
}

@media (max-width: 900px) {
  /* Chat-first deal card: collapse form/notes, give timeline the viewport */
  #modal-edit .modal-split {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    overflow: hidden;
  }
  #modal-edit .deal-mobile-info-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    order: 1;
    flex-shrink: 0;
    width: 100%;
    margin: 0;
    padding: 0.7rem 1rem;
    border: 0;
    border-bottom: 1px solid var(--amo-line);
    background: #f8fafc;
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  #modal-edit .deal-mobile-info-toggle-main {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
  }
  #modal-edit .deal-mobile-info-toggle-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--amo-muted);
  }
  #modal-edit .deal-mobile-info-summary {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #modal-edit .deal-mobile-info-chevron {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    border-right: 2px solid #94a3b8;
    border-bottom: 2px solid #94a3b8;
    transform: rotate(45deg);
    margin-top: -4px;
    transition: transform 0.15s ease;
  }
  #modal-edit .deal-modal.is-deal-info-open .deal-mobile-info-chevron {
    transform: rotate(-135deg);
    margin-top: 4px;
  }
  #modal-edit .deal-edit-form {
    order: 2;
    display: none;
    min-height: 0;
    max-height: min(52dvh, 440px);
    border-bottom: 1px solid var(--amo-line);
    background: #fff;
  }
  #modal-edit .deal-modal.is-deal-info-open .deal-edit-form {
    display: flex;
  }
  #modal-edit .deal-edit-scroll {
    padding: 10px 12px 8px;
  }
  #modal-edit .deal-edit-actions {
    padding: 10px 12px;
    gap: 6px;
  }
  #modal-edit .deal-edit-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }
  #modal-edit .deal-edit-actions .btn-primary {
    margin-left: 0;
    flex: 1 1 100%;
  }
  #modal-edit .history-pane {
    order: 3;
    flex: 1 1 auto;
    min-height: 0;
    border-left: 0;
    border-top: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  #modal-edit .history-head {
    padding-bottom: 2px;
  }
  #modal-edit .reply-form {
    padding-top: 8px;
    gap: 6px;
  }
  #modal-edit .reply-form textarea {
    min-height: 2.6rem;
    max-height: 5.5rem;
  }
  #modal-edit .deal-mobile-note-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 0.55rem 0.75rem;
    border: 1px dashed #c5d0de;
    border-radius: 10px;
    background: #fff;
    color: var(--amo-muted);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
  }
  #modal-edit .deal-modal.is-note-open .deal-mobile-note-toggle {
    border-style: solid;
    border-color: var(--amo-line);
    color: var(--amo-ink, #1e293b);
  }
  #modal-edit .note-form {
    display: none;
  }
  #modal-edit .deal-modal.is-note-open .note-form {
    display: grid;
  }
}

.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;
  border: 0;
  font-family: inherit;
  line-height: 1.35;
}
.contact-channel-chip.is-action {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.contact-channel-chip.is-action:hover {
  background: #dcebff;
  color: #0f4a78;
}
.contact-link-hint.is-ok {
  color: #1b6b3a;
  background: #f0fff4;
  border-color: #b7e4c7;
}
.contact-link-hint.is-warn {
  color: #9a6700;
  background: #fff8e8;
  border-color: #f0d78c;
}
.contact-link-hint.is-error {
  color: #b42318;
  background: #fff5f5;
  border-color: #f3c1c1;
}
.contact-link-hint.is-loading {
  color: #475569;
  background: #f8fafc;
  border-color: #d8e0ec;
}
.contact-identities-box {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--amo-border, #d8e0ec);
  border-radius: 10px;
  background: #f8fafc;
}
.contact-identities-box legend {
  padding: 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--amo-text, #1a2332);
}
.contact-identities-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.contact-identities-list:empty::before {
  content: 'Пока нет дополнительных каналов';
  color: var(--amo-muted, #6b7c93);
  font-size: 13px;
}
.contact-identity-row {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 8px;
  align-items: center;
}
.contact-identity-row select,
.contact-identity-row input {
  width: 100%;
  min-width: 0;
}
.contact-identity-add {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 8px;
  align-items: center;
}
@media (max-width: 640px) {
  .contact-identity-row,
  .contact-identity-add {
    grid-template-columns: 1fr;
  }
}
.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;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}
.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;
  min-height: 0;
  max-height: none;
  overflow: hidden;
}
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.history-head h3 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.note-form { display: grid; gap: 8px; flex-shrink: 0; }
.reply-form {
  display: grid;
  gap: 8px;
  margin-top: 0;
  padding-top: 10px;
  border-top: 1px solid var(--amo-line);
  flex-shrink: 0;
}
.reply-form select {
  width: 100%;
  margin-top: 4px;
}
.reply-canned select {
  width: 100%;
  margin-top: 4px;
}
.reply-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
}
.reply-attach {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.reply-attach-btn {
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}
.reply-attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}
.reply-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 6px 2px 8px;
  border-radius: 6px;
  background: #f1f5f9;
  border: 1px solid var(--amo-line, #e2e8f0);
  font-size: 12px;
  color: #334155;
}
.reply-attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.reply-attach-rm {
  border: 0;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.reply-attach-rm:hover { color: #0f172a; }
.crm-canned-import {
  margin: 10px 0 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.crm-canned-section {
  margin: 18px 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: #334155;
}
.crm-canned-section:first-of-type {
  margin-top: 8px;
}
.crm-canned-top {
  display: grid;
  grid-template-columns: 1.4fr 120px;
  gap: 10px;
}
.crm-canned-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 8px;
}
.crm-canned-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--amo-line);
}
.crm-canned-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.crm-canned-form {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.crm-canned-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 88px;
  font: inherit;
}
.crm-canned-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}
.crm-canned-meta label {
  margin: 0;
}
.crm-canned-active {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-bottom: 8px;
}
.crm-canned-delete {
  margin: 0;
  padding-top: 22px;
}
.timeline {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.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-message.is-auto-reply {
  border-left-color: #7c6af2;
  background: #f7f5ff;
}
.timeline-robot-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #5b4fc9;
  background: #ebe7ff;
}
.timeline-group-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #1f6b4a;
  background: #e6f6ee;
}
.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;
  max-height: 280px;
  overflow: auto;
  overscroll-behavior: contain;
}
.timeline-load-more {
  display: flex;
  justify-content: center;
  padding: 8px 0 12px;
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(to bottom, var(--surface, #fff) 70%, transparent);
}
.timeline-load-more .btn {
  font-size: 12px;
}
.timeline-attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.timeline-att {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}
.timeline-att-img {
  display: block;
  max-width: min(320px, 100%);
  max-height: 240px;
  border-radius: 8px;
  border: 1px solid var(--border, #e2e8f0);
  object-fit: contain;
  background: #f8fafc;
}
.timeline-att-thumb {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: zoom-in;
  display: inline-block;
  max-width: 100%;
  text-align: left;
}
.timeline-att-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 0;
  background: #f1f5f9;
  color: #334155;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  max-width: 100%;
  cursor: pointer;
  text-align: left;
}
.timeline-att-file:hover {
  background: #e2e8e0;
}
button.timeline-att-file {
  font-family: inherit;
}
.timeline-att-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}
.timeline-att-action {
  appearance: none;
  border: 1px solid #d7d2c8;
  background: #fff;
  color: #3f3a32;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.timeline-att-action:hover {
  background: #f5f2ea;
  border-color: #c9c2b4;
}
button.timeline-att-action {
  font-family: inherit;
}
.timeline-att-hint {
  font-size: 11px;
  color: #8a8378;
}
.timeline-att-caption {
  font-size: 12px;
  color: #64748b;
}
#modal-att-preview {
  z-index: 95; /* поверх карточки сделки */
}
.att-preview-modal {
  max-width: min(960px, 96vw);
  width: 96vw;
}
.att-preview-body {
  min-height: 200px;
  max-height: min(72vh, 820px);
  overflow: auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
}
.att-preview-img {
  display: block;
  max-width: 100%;
  max-height: min(68vh, 760px);
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}
.att-preview-frame {
  width: 100%;
  height: min(68vh, 760px);
  border: 0;
  border-radius: 8px;
  background: #fff;
}
.att-preview-fallback {
  text-align: center;
  max-width: 420px;
  padding: 24px 16px;
  color: #475569;
}
.att-preview-fallback-icon {
  font-size: 42px;
  line-height: 1;
  margin-bottom: 10px;
}
.att-preview-fallback-name {
  font-weight: 700;
  color: #0f172a;
  word-break: break-word;
  margin-bottom: 6px;
}
.att-preview-actions {
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border, #e2e8f0);
}
.timeline-att-pending {
  font-size: 12px;
  color: #94a3b8;
}
.timeline-body.timeline-html {
  white-space: normal;
  line-height: 1.45;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 280px;
  max-width: 100%;
  word-break: break-word;
  overscroll-behavior: contain;
}
.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-field-map-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.crm-field-map-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) 24px minmax(160px, 1fr);
  gap: 8px;
  align-items: center;
}
.crm-field-map-arrow {
  text-align: center;
  color: var(--amo-muted, #8896a8);
  font-size: 14px;
}
@media (max-width: 720px) {
  .crm-field-map-row {
    grid-template-columns: 1fr;
  }
  .crm-field-map-arrow {
    display: none;
  }
}

.crm-settings-h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* Редактор полей сделки: одна сетка для шапки и строк */
.crm-fields-editor {
  border: 1px solid var(--amo-line, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.crm-fields-grid {
  --crm-fields-cols:
    minmax(88px, 0.7fr)
    minmax(140px, 1.3fr)
    minmax(100px, 0.85fr)
    minmax(120px, 1.1fr)
    64px
    64px
    64px
    auto;
  display: grid;
  grid-template-columns: var(--crm-fields-cols);
  gap: 8px 10px;
  align-items: center;
  padding: 10px 12px;
}
.crm-fields-head {
  background: #f8fafc;
  border-bottom: 1px solid var(--amo-line, #e2e8f0);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--amo-muted, #64748b);
}
.crm-fields-row {
  border-bottom: 1px solid var(--amo-line, #e2e8f0);
}
.crm-fields-row:last-child {
  border-bottom: 0;
}
.crm-fields-empty {
  margin: 0;
  padding: 14px 12px;
}
.crm-fields-save {
  display: contents;
}
.crm-fields-code {
  font-size: 12px;
  word-break: break-all;
  color: #334155;
}
.crm-fields-save input[type="text"],
.crm-fields-save input[name="name"],
.crm-fields-save input[type="number"],
.crm-fields-save select,
.crm-fields-save textarea {
  width: 100%;
  margin: 0;
  min-width: 0;
  box-sizing: border-box;
}
.crm-fields-save textarea {
  min-height: 2.4rem;
  max-height: 4.8rem;
  resize: vertical;
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
}
.crm-fields-save input[type="number"] {
  text-align: center;
}
.crm-fields-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: var(--amo-muted, #64748b);
  white-space: nowrap;
}
.crm-fields-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.crm-fields-delete {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.crm-fields-actions-head {
  min-width: 5.5rem;
}
.crm-fields-create-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  padding-top: 22px;
}
.crm-fields-create-check input {
  width: auto;
  margin: 0;
}
.crm-fields-create-options {
  grid-column: 1 / -1;
}
@media (max-width: 960px) {
  .crm-fields-editor {
    overflow-x: auto;
  }
  .crm-fields-grid {
    min-width: 820px;
  }
}

.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-opt-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.crm-opt-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--amo-line, #e2e8f0);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  user-select: none;
}
.crm-opt-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.crm-opt-toggle-ui {
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
  margin-top: 2px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: background .15s ease;
}
.crm-opt-toggle-ui::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .2);
  transition: transform .15s ease;
}
.crm-opt-toggle input:checked + .crm-opt-toggle-ui {
  background: var(--crm-blue, #2563eb);
}
.crm-opt-toggle input:checked + .crm-opt-toggle-ui::after {
  transform: translateX(18px);
}
.crm-opt-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.crm-opt-toggle-text strong {
  font-size: 0.92rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--crm-text, #0f172a);
}
.crm-opt-body {
  padding: 0 2px 2px;
  transition: opacity .15s ease;
}
.crm-opt-body.is-dimmed {
  opacity: 0.55;
}
.crm-opt-preview {
  min-width: 0;
  padding: 10px 12px;
  border: 1px dashed var(--amo-line, #e2e8f0);
  border-radius: 8px;
  background: #fff;
}
.crm-opt-preview-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--amo-muted, #64748b);
  margin-bottom: 6px;
}
.crm-opt-preview-url {
  display: block;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-all;
  color: var(--crm-blue, #2563eb);
  background: transparent;
}
.crm-opt-steps {
  margin: 12px 0 0;
  padding-left: 1.2rem;
  font-size: 12px;
  line-height: 1.5;
}
.crm-opt-steps li + li {
  margin-top: 2px;
}
@media (max-width: 720px) {
  .crm-opt-head {
    flex-direction: column;
  }
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  /* как в образце: пастельная заливка + тёмный читаемый текст */
  background: color-mix(in srgb, var(--stage, #64748b) 22%, #fff);
  color: #1e293b;
  border: 1px solid color-mix(in srgb, var(--stage, #64748b) 18%, transparent);
}
.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-rule-debt {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.25);
  background: #fff1f2;
}
.card.is-rule-unconfirmed,
.card.is-rule-warning {
  border-color: #f59e0b;
  background: #fffbeb;
}
.card.is-rule-danger {
  border-color: #dc2626;
}
.card.is-rule-info {
  border-color: #0ea5e9;
}
/* «Требует внимания» — салатовый фон (поверх warning/sla) */
.card.is-attention,
.card.is-attention.is-sla-idle,
.card.is-attention.is-rule-warning,
.card.is-attention.is-rule-unconfirmed,
.card.is-attention.is-rule-info {
  background: #dff3b8;
  border-color: #9fcf6a;
  box-shadow: 0 0 0 1px rgba(124, 179, 66, 0.28);
}
.card.is-attention.is-rule-debt,
.card.is-attention.is-rule-danger {
  background: #dff3b8;
  border-color: #9fcf6a;
  box-shadow: 0 0 0 1px rgba(124, 179, 66, 0.28);
}
.card-rule-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.card-rule-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.card-rule-badge.is-danger {
  background: #fee2e2;
  color: #b91c1c;
}
.card-rule-badge.is-warning {
  background: #fef3c7;
  color: #92400e;
}
.card-rule-badge.is-info {
  background: #e0f2fe;
  color: #075985;
}
.card-attention {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: #15803d;
  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-litepms-bookings { display: flex; flex-direction: column; gap: 0.55rem; }
.crm-litepms-booking-row {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: var(--surface-2, #f8fafc);
  font-size: 0.88rem;
  line-height: 1.35;
}
.crm-litepms-booking-main { margin-bottom: 0.15rem; }
.card-booking-count {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
  vertical-align: middle;
}
.crm-task {
  display: grid;
  grid-template-columns: auto 1fr auto 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); }
.crm-task-create-trigger {
  margin-top: 0.65rem;
}
.crm-task-create-backdrop {
  z-index: 90;
}
.crm-task-create-dialog {
  width: min(440px, 94vw);
  max-height: min(90vh, 640px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.crm-task-create-dialog .modal-head {
  flex-shrink: 0;
}
.crm-task-create-dialog .modal-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  font-size: 24px;
  line-height: 1;
  padding: 0 0 2px;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}
.crm-task-create-dialog .modal-close:hover {
  background: #fee2e2;
  border-color: #fecaca;
  color: #b91c1c;
}
.crm-task-create-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 16px;
}
.crm-task-create-field {
  display: grid;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}
.crm-task-create-field input {
  font-weight: 400;
}
.crm-task-create-due {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.crm-task-create-due label {
  display: grid;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}
.crm-task-create-due input {
  font-weight: 400;
}
.crm-task-create-hint {
  margin: 0;
  font-size: 12px;
}
.crm-task-create-assignees {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--crm-line, #e2e8f0);
  border-radius: 12px;
  background: #f8fafc;
}
.crm-task-create-assignees legend {
  padding: 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}
.crm-task-assignee-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.35rem 0.75rem;
  max-height: 180px;
  overflow: auto;
  padding: 4px 0 2px;
}
.crm-task-assignee-list label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 400;
  cursor: pointer;
}
.crm-task-who-all { color: var(--crm-muted); font-style: italic; }
.crm-task .crm-task-who {
  font-size: 11px;
  color: var(--crm-muted);
  white-space: nowrap;
}
.crm-task-create-actions {
  margin: 4px 0 0;
  justify-content: flex-end;
}
@media (max-width: 520px) {
  .crm-task-create-due {
    grid-template-columns: 1fr;
  }
}

@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%; }
  .quick-filters { width: 100%; }
  .quick-filter { flex: 1; justify-content: center; }
  .modal-split { grid-template-columns: 1fr; }
  .history-pane { border-left: 0; border-top: 1px solid var(--amo-line); }
  .kanban { grid-auto-columns: min(var(--kanban-col-w, 260px), 85vw); }
  .crm-stage-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .crm-nav {
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }
  .crm-global-search {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
    margin: 0.15rem 0 0;
  }
  .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;
    height: 100vh;
    height: 100dvh;
    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;
}

/* Beeline / channel subscription status on settings edit */
.channel-status {
  border: 1px solid var(--amo-line);
  border-radius: 4px;
  padding: 12px 14px;
  background: #fafbfc;
  margin: 0 0 4px;
}
.channel-status__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.channel-status__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}
.channel-status__label {
  font-size: 14px;
  color: var(--amo-ink);
}
.channel-status__until {
  font-size: 12px;
  color: var(--amo-muted);
}
.channel-status__hint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--amo-muted);
}
.channel-status__meta {
  display: grid;
  gap: 8px;
  margin: 0;
}
.channel-status__meta > div {
  display: grid;
  grid-template-columns: minmax(110px, 140px) 1fr;
  gap: 6px 12px;
  align-items: start;
  font-size: 12px;
}
.channel-status__meta dt {
  margin: 0;
  color: var(--amo-muted);
  font-weight: 500;
}
.channel-status__meta dd {
  margin: 0;
  color: var(--amo-ink);
  word-break: break-word;
}
.channel-status__meta code {
  font-size: 11px;
  background: #fff;
  border: 1px solid var(--amo-line);
  border-radius: 2px;
  padding: 1px 5px;
}
.channel-status__warn {
  color: #b45309;
}
.channel-status--ok {
  border-color: #bbf7d0;
  background: #f0fdf4;
}
.channel-status--ok .channel-status__dot { background: #16a34a; }
.channel-status--soon {
  border-color: #fde68a;
  background: #fffbeb;
}
.channel-status--soon .channel-status__dot { background: #d97706; }
.channel-status--expired,
.channel-status--missing {
  border-color: #fecaca;
  background: #fff1f0;
}
.channel-status--expired .channel-status__dot,
.channel-status--missing .channel-status__dot { background: #dc2626; }

.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 12px;
}
.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: #8b93a1;
}
.ga-actions {
  display: inline-flex;
  gap: 4px;
}
.ga-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #64748b;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.ga-icon-btn:hover:not(:disabled) {
  border-color: #94a3b8;
  color: #0f172a;
}
.ga-icon-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.ga-icon-btn.ga-copied {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}
.ga-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.ga-badge-ok {
  background: #dcfce7;
  color: #166534;
}
.ga-badge-warn {
  background: #fef3c7;
  color: #92400e;
}
.ga-meta {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 400;
}
.ga-error-hint {
  font-size: 12px;
  color: #b91c1c;
  font-weight: 500;
}
.ga-hint {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.45;
}
.ga-hint code {
  font-size: 12px;
}

/* Форма настроек Green API — отдельный блок, не ломается form-grid */
.ga-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}
.ga-section {
  border: 1px solid #eceff3;
  border-radius: 10px;
  background: #fafbfc;
  padding: 14px 16px;
}
.ga-section-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}
.ga-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}
.ga-fields-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ga-fields-auto {
  grid-template-columns: minmax(0, 1fr) 140px;
  margin-top: 10px;
}
.ga-field-wide {
  grid-column: 1 / -1;
}
.ga-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--amo-muted);
  font-weight: 500;
}
.ga-form label input,
.ga-form label select,
.ga-form label textarea {
  font-weight: 400;
  color: var(--amo-ink);
}
.ga-help {
  display: block;
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 400;
}
.ga-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  margin: 0;
  font-size: 13px;
  color: var(--amo-ink);
  font-weight: 500;
  cursor: pointer;
}
.ga-check input[type="checkbox"] {
  width: auto !important;
  max-width: none;
  margin: 3px 0 0;
  flex: 0 0 auto;
  align-self: flex-start;
}
.ga-check > span {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  line-height: 1.4;
}
.ga-check .ga-help {
  display: block;
  margin: 4px 0 0;
  font-weight: 400;
}
.ga-webhook-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e8ecf1;
}
.ga-webhook-url {
  flex: 1 1 220px;
  min-width: 0;
  font-size: 12px;
  word-break: break-all;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 6px 8px;
}
@media (max-width: 720px) {
  .ga-row {
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
  }
  .ga-label {
    grid-column: 1 / -1;
  }
  .ga-fields,
  .ga-fields-2,
  .ga-fields-auto {
    grid-template-columns: 1fr;
  }
}

/* Duplicate deals finder */
.crm-dup-head{display:flex;flex-direction:column;gap:8px;margin-bottom:10px}
.crm-dup-head .crm-badge{margin-right:4px}
.crm-dup-warn{padding:8px 10px;border-radius:8px;background:#fff4e5;color:#9a3412;font-size:12px}
.crm-dup-table th:first-child,.crm-dup-table td:first-child{white-space:nowrap;width:1%}
.crm-dup-radio,.crm-dup-check{display:flex;align-items:center;gap:4px;font-size:11px;color:var(--crm-muted);margin:2px 0}
.crm-dup-radio input,.crm-dup-check input{margin:0}

/* New message toast (desktop) */
.crm-toast-host {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 1.5rem));
}
.crm-toast {
  pointer-events: auto;
  width: min(360px, calc(100vw - 1.5rem));
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.7rem;
  align-items: start;
  padding: 0.8rem 0.85rem;
  border: 1px solid #d7def7;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85) inset,
    0 14px 36px rgba(24, 36, 80, 0.16);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transform: translateX(112%);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
}
.crm-toast.is-in {
  transform: translateX(0);
  opacity: 1;
}
.crm-toast.is-out {
  transform: translateX(112%);
  opacity: 0;
}
.crm-toast-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: hsl(var(--crm-toast-hue, 220) 62% 48%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}
.crm-toast-body { min-width: 0; }
.crm-toast-label {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--crm-blue);
}
.crm-toast-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--crm-ink, #14151a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-toast-preview {
  margin: 0.2rem 0 0;
  font-size: 0.84rem;
  color: var(--crm-muted, #6b7280);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.crm-toast-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--crm-muted, #6b7280);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.crm-toast-close:hover { background: #f1f3f7; }

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

/* ——— Tasks page ——— */
.crm-tasks-total { font-size: 0.9rem; margin-left: 0.5rem; }
.crm-tasks-filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.crm-tasks-admin-actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.crm-tasks-admin-actions .btn { white-space: nowrap; }
.crm-tasks-filter-form {
  display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; margin: 0;
}
.crm-tasks-filter-form select {
  margin: 0;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--crm-line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.crm-tasks-board { display: grid; gap: 1.25rem; }
.crm-tasks-section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.45rem;
}
.crm-tasks-section-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--crm-muted);
}
.crm-tasks-section-count {
  min-width: 1.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--crm-blue-soft);
  color: var(--crm-blue);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}
.crm-tasks-empty { margin: 0; padding: 0.35rem 0 0.5rem; font-size: 0.88rem; }
.crm-tasks-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--crm-line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.crm-task-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid #eef0f4;
}
.crm-task-row:last-child { border-bottom: 0; }
.crm-task-row.is-overdue { background: #fff7f7; }
.crm-task-row.is-today { background: #f7faf3; }
.crm-task-row.is-done {
  opacity: 0.45;
  transition: opacity 0.2s ease;
}
.crm-task-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.15rem;
  cursor: pointer;
}
.crm-task-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--crm-blue);
  cursor: pointer;
}
.crm-task-main { min-width: 0; }
.crm-task-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--crm-ink);
  line-height: 1.35;
}
.crm-task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  margin-top: 0.3rem;
  align-items: center;
  font-size: 0.8rem;
  color: var(--crm-muted);
}
.crm-task-deal {
  color: var(--crm-blue);
  text-decoration: none;
  font-weight: 600;
}
.crm-task-deal:hover { text-decoration: underline; }
.crm-task-stage {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--stage, #64748b) 16%, #fff);
  color: var(--stage, #64748b);
  font-size: 0.72rem;
  font-weight: 700;
}
.crm-task-due {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--crm-muted);
  white-space: nowrap;
  padding-top: 0.15rem;
}
.crm-task-row.is-overdue .crm-task-due { color: #b91c1c; }
.crm-task-row.is-today .crm-task-due { color: #3f7d1a; }

@media (max-width: 720px) {
  .crm-task-row {
    grid-template-columns: auto 1fr;
  }
  .crm-task-due {
    grid-column: 2;
    padding-top: 0;
  }
}


/* Telegram health: a shared server snapshot, beside the current user. */
.crm-tg-health { position: relative; color: var(--crm-muted); }
.crm-tg-health-badge {
  display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer;
  padding: 0.4rem 0.65rem; border-radius: 999px; background: var(--crm-paper);
  font-size: 0.75rem; white-space: nowrap; list-style: none;
}
.crm-tg-health-badge::-webkit-details-marker { display: none; }
.crm-tg-health-badge:focus-visible { outline: 2px solid var(--crm-blue); outline-offset: 2px; }
.crm-tg-health-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.crm-tg-health[data-status="ok"] { color: var(--crm-ok); }
.crm-tg-health[data-status="warning"],
.crm-tg-health[data-status="delayed"] { color: #946200; }
.crm-tg-health[data-status="error"] { color: var(--crm-danger); }
.crm-tg-health-panel {
  position: absolute; right: 0; top: calc(100% + 0.6rem); z-index: 60;
  width: min(340px, calc(100vw - 2rem)); padding: 1rem;
  border: 1px solid var(--crm-line); border-radius: var(--crm-radius);
  background: var(--crm-card); color: var(--crm-ink); line-height: 1.5;
  white-space: normal; overflow-wrap: anywhere;
}
.crm-tg-health-panel p { margin: 0.6rem 0; }
.crm-tg-health-panel ul { padding-left: 1rem; margin: 0.6rem 0; }
.crm-tg-health-panel ul:empty { display: none; }
.crm-tg-health-panel li + li { margin-top: 0.5rem; }
.crm-tg-health-panel small { color: var(--crm-muted); }
@media (max-width: 860px) {
  .crm-tg-health-panel { position: static; width: 100%; margin-top: 0.6rem; }
}

/* ——— Служебное / отчёт руководителя ——— */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.crm-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  padding: 0 0 24px;
}
.crm-tools-card {
  display: block;
  padding: 18px 18px 16px;
  background: var(--crm-card, #fff);
  border: 1px solid var(--crm-line, #e5eaf0);
  border-radius: var(--crm-radius, 6px);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.crm-tools-card:hover {
  border-color: var(--amo-blue, #4c8bf5);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}
.crm-tools-card-kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--crm-muted, #64748b);
  margin-bottom: 6px;
}
.crm-tools-card-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}
.crm-tools-card p { margin: 0 0 12px; font-size: 13px; line-height: 1.45; }
.crm-tools-card-cta {
  font-size: 12px;
  font-weight: 600;
  color: var(--amo-blue, #4c8bf5);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.crm-rpt-filters { padding: 4px 0; }
.crm-rpt-kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 8px;
}
.crm-rpt-kpi {
  background: var(--crm-card, #fff);
  border: 1px solid var(--crm-line, #e5eaf0);
  border-radius: var(--crm-radius, 6px);
  padding: 12px 14px;
  min-width: 0;
}
.crm-rpt-kpi.is-good { border-color: #bbf7d0; background: #f0fdf4; }
.crm-rpt-kpi.is-bad { border-color: #fecaca; background: #fef2f2; }
.crm-rpt-kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--crm-muted, #64748b);
  margin-bottom: 4px;
}
.crm-rpt-kpi-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--crm-ink, #0f172a);
  word-break: break-word;
}
.crm-rpt-kpi-sub {
  font-size: 12px;
  color: var(--crm-muted, #64748b);
  margin-top: 4px;
}
.crm-rpt-delta {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
}
.crm-rpt-delta.is-up { color: #15803d; }
.crm-rpt-delta.is-down { color: #b42318; }
.crm-rpt-delta.is-flat { color: var(--crm-muted, #64748b); }
.crm-rpt-note {
  margin: 0 0 16px;
  font-size: 12px;
}
.crm-rpt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 0 0 16px;
}
.crm-rpt-grid .panel { margin: 0; }
.crm-rpt-stage-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.crm-rpt-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  vertical-align: middle;
}
.crm-rpt-tag.is-good { background: #dcfce7; color: #166534; }
.crm-rpt-tag.is-bad { background: #fee2e2; color: #991b1b; }
.crm-rpt-aging {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.crm-rpt-aging > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 4px;
}
.crm-rpt-aging strong { font-size: 18px; }
.crm-rpt-aging strong.is-warn { color: #b45309; }
.crm-rpt-aging strong.is-bad { color: #b42318; }
table.data td.num,
table.data th.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 1100px) {
  .crm-rpt-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .crm-rpt-grid { grid-template-columns: 1fr; }
  .crm-rpt-aging { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .crm-rpt-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-rpt-aging { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.crm-rpt-settings > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: baseline;
}
.crm-rpt-settings > summary::-webkit-details-marker { display: none; }
.crm-rpt-settings-summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  color: var(--crm-muted, #64748b);
}
.crm-rpt-settings[open] > .crm-rpt-settings-summary::before { content: '▾'; }
.crm-rpt-channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px 12px;
}
.crm-rpt-channel-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--crm-line, #e5eaf0);
  border-radius: 4px;
  background: #f8fafc;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.crm-rpt-channel-item input { margin-top: 2px; flex-shrink: 0; }
.crm-rpt-channel-item.is-inactive { opacity: 0.65; }

/* ——— Входящие: очередь + карточка ——— */
.crm-shell:has(.inbox-page) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.crm-main:has(.inbox-page) {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.inbox-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0;
}
.inbox-header {
  flex-shrink: 0;
  align-items: center;
}
.inbox-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  margin-left: 0.5rem;
  border-radius: 999px;
  background: var(--crm-blue);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.inbox-hint {
  margin-left: 0.75rem;
  font-size: 12px;
}
.inbox-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--crm-line);
  border-radius: var(--crm-radius);
  background: var(--crm-card);
  overflow: hidden;
  box-shadow: var(--crm-shadow);
}
.inbox-feed {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--crm-line);
  background: #fafbfc;
}
.inbox-feed-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.inbox-feed-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--crm-muted);
}
.inbox-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
.inbox-item:hover {
  border-color: #c9d4f5;
  box-shadow: 0 2px 8px rgba(47, 86, 255, 0.06);
}
.inbox-item.is-active {
  border-color: var(--crm-blue);
  background: var(--crm-blue-soft);
  box-shadow: inset 3px 0 0 var(--crm-blue);
}
.inbox-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.inbox-item-title {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.inbox-item-time {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--crm-muted);
}
.inbox-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
  font-size: 11px;
  color: var(--crm-muted);
}
.inbox-item-channel {
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-weight: 600;
  color: var(--crm-blue);
  font-size: 10px;
}
.inbox-item-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--crm-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.inbox-item-preview {
  margin-top: 6px;
  font-size: 12px;
  color: var(--crm-ink);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.inbox-item-pipeline {
  margin-top: 4px;
  font-size: 11px;
}
.inbox-deal {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: #fff;
  overflow: hidden;
}
/* display:flex/grid иначе перебивает атрибут hidden — обе панели «видны» и делят высоту */
.inbox-deal-empty[hidden],
.inbox-deal-panel[hidden],
.inbox-deal-info[hidden],
.inbox-deal-chat .reply-form[hidden],
.inbox-deal-chat .note-form[hidden],
.inbox-deal-chat .reply-canned[hidden],
#inbox-open-kanban[hidden] {
  display: none !important;
}
.inbox-deal-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--crm-ink);
  padding: 2rem;
  min-height: 0;
}
.inbox-deal-empty .muted { margin: 0; }
.inbox-deal-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.inbox-deal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--crm-line);
  flex-shrink: 0;
}
.inbox-deal-back,
.inbox-mobile-note-toggle {
  display: none;
}
.inbox-deal-title {
  margin: 0;
  font-size: 1.1rem;
  font-family: var(--crm-serif);
  font-weight: 600;
  line-height: 1.25;
}
.inbox-deal-sub {
  margin-top: 4px;
  font-size: 12px;
}
.inbox-deal-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  justify-content: flex-end;
}
.inbox-deal-info {
  display: block;
  padding: 12px 14px;
  border-bottom: 1px solid var(--crm-line);
  background: #fafbfc;
  flex-shrink: 0;
  overflow: auto;
  max-height: 32%;
}
.inbox-deal-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
.inbox-deal-info-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
}
.inbox-deal-info-grid input,
.inbox-deal-info-grid select {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--crm-line);
  border-radius: 8px;
  background: #fff;
}
.inbox-deal-info-actions {
  margin-top: 12px;
}
.inbox-deal-chat {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.inbox-deal-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 6px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--crm-muted);
  flex-shrink: 0;
}
.inbox-timeline.timeline {
  flex: 1 1 auto;
  min-height: 120px;
  overflow: auto;
  padding: 4px 14px 8px;
  gap: 8px;
}
.inbox-deal-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--crm-line);
  background: #fafbfc;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(46vh, 360px);
  overflow: auto;
}
.inbox-deal-composer .reply-form {
  margin: 0;
  padding: 0;
  border: 0;
}
.inbox-deal-composer .note-form {
  margin: 0;
}
.inbox-deal-composer textarea {
  max-height: 96px;
}

@media (max-width: 900px) {
  /* Master–detail: список ИЛИ переписка на весь экран */
  .inbox-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  .inbox-feed {
    border-right: none;
    border-bottom: 0;
    min-height: 0;
  }
  .inbox-page:not(.is-deal-open) .inbox-deal {
    display: none;
  }
  .inbox-page.is-deal-open .inbox-feed {
    display: none;
  }
  .inbox-page.is-deal-open .inbox-hint,
  .inbox-page.is-deal-open #inbox-refresh {
    display: none;
  }
  .inbox-deal-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: -4px 0 0 -4px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    color: var(--crm-ink);
  }
  .inbox-deal-back:active {
    background: #f1f3f7;
  }
  .inbox-deal-head {
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }
  .inbox-deal-head-main {
    min-width: 0;
    flex: 1;
  }
  .inbox-deal-title {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .inbox-deal-sub {
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .inbox-deal-head-actions {
    gap: 4px;
  }
  .inbox-deal-head-actions .btn {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
  }
  .inbox-deal-chat-head {
    padding: 4px 12px 2px;
  }
  .inbox-timeline.timeline {
    min-height: 0;
    padding: 4px 10px 8px;
  }
  .inbox-deal-composer {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    max-height: none;
    gap: 6px;
  }
  .inbox-deal-composer .reply-form textarea {
    min-height: 2.4rem;
    max-height: 4.8rem;
  }
  .inbox-mobile-note-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 0.5rem 0.7rem;
    border: 1px dashed #c5d0de;
    border-radius: 10px;
    background: #fff;
    color: var(--crm-muted);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
  }
  .inbox-page.is-note-open .inbox-mobile-note-toggle {
    border-style: solid;
    border-color: var(--crm-line);
    color: var(--crm-ink);
  }
  .inbox-page:not(.is-note-open) .inbox-deal-composer .note-form {
    display: none !important;
  }
  .inbox-deal-info-grid {
    grid-template-columns: 1fr;
  }
  .inbox-deal-info {
    max-height: min(42dvh, 360px);
  }
  .inbox-hint { display: none; }
}

/* ——— Personal todos (/todos) ——— */
.crm-todo-total { font-size: 0.9rem; margin-left: 0.5rem; }
.crm-todo-owner { font-size: 0.9rem; margin-left: 0.25rem; }
.crm-todo-filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.crm-todo-user-form { margin: 0; }
.crm-todo-user-form select {
  margin: 0;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--crm-line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  min-width: 12rem;
}
.crm-todo-board { display: grid; gap: 1.15rem; max-width: 720px; }
.crm-todo-composer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding: 0.15rem 0 0.35rem;
}
.crm-todo-input {
  flex: 1 1 220px;
  min-width: 0;
  margin: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--crm-line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.crm-todo-due {
  margin: 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--crm-line);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.crm-todo-section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.45rem;
}
.crm-todo-section-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--crm-muted);
}
.crm-todo-section-count {
  min-width: 1.4rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--crm-blue-soft);
  color: var(--crm-blue);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}
.crm-todo-empty { margin: 0; padding: 0.35rem 0 0.5rem; font-size: 0.88rem; }
.crm-todo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--crm-line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.crm-todo-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid #eef0f4;
}
.crm-todo-row:last-child { border-bottom: 0; }
.crm-todo-row.is-overdue { background: #fff7f7; }
.crm-todo-row.is-today { background: #f7faf3; }
.crm-todo-row.is-done { opacity: 0.55; }
.crm-todo-row.is-done .crm-todo-title { text-decoration: line-through; }
.crm-todo-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.15rem;
  cursor: pointer;
}
.crm-todo-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--crm-blue);
  cursor: pointer;
}
.crm-todo-main { min-width: 0; }
.crm-todo-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--crm-ink);
  line-height: 1.35;
  word-break: break-word;
}
.crm-todo-meta {
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--crm-muted);
}
.crm-todo-del {
  border: 0;
  background: transparent;
  color: var(--crm-muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
  border-radius: 8px;
}
.crm-todo-del:hover { color: #b91c1c; background: #fef2f2; }
@media (max-width: 640px) {
  .crm-todo-composer { flex-direction: column; align-items: stretch; }
  .crm-todo-due, #crm-todo-due-today, #crm-todo-add { width: 100%; }
}
