:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafd;
  --line: #dfe7f0;
  --text: #17202a;
  --muted: #66758a;
  --brand: #4d5cff;
  --brand-strong: #2945dd;
  --danger: #e1293d;
  --success: #159b58;
  --warn: #d88114;
  --violet: #7c3aed;
  --cyan: #0891b2;
  --shadow: 0 12px 32px rgba(31, 45, 61, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}
a { color: var(--brand-strong); text-decoration: none; }
p { line-height: 1.45; }
button, .button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: white;
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .07s, color .12s;
  user-select: none;
  white-space: nowrap;
}
button:not(:disabled):hover, .button:not(:disabled):hover {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
  box-shadow: 0 4px 14px rgba(77, 92, 255, .28);
}
button:not(:disabled):active, .button:not(:disabled):active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .15);
}
button:focus-visible, .button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
button:disabled, .button:disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}
button.ghost, .ghost {
  background: white;
  color: var(--brand-strong);
}
button.ghost:not(:disabled):hover, .ghost:not(:disabled):hover {
  background: #eef1ff;
  border-color: var(--brand);
}
button.ghost:not(:disabled):active, .ghost:not(:disabled):active {
  background: #dde3ff;
}
button.danger, .danger {
  border-color: var(--danger);
  background: #fff5f6;
  color: var(--danger);
}
button.danger:not(:disabled):hover, .danger:not(:disabled):hover {
  background: #ffe4e7;
  border-color: var(--danger);
  box-shadow: 0 4px 12px rgba(225, 41, 61, .18);
}
button.danger:not(:disabled):active, .danger:not(:disabled):active {
  background: #ffcdd2;
  transform: translateY(1px);
}
.success-action {
  border-color: var(--success);
  background: var(--success);
  color: white;
}
.success-action:not(:disabled):hover {
  background: #0f7d46;
  border-color: #0f7d46;
  box-shadow: 0 4px 12px rgba(21, 155, 88, .28);
}
.success-action:not(:disabled):active {
  background: #0c6a3b;
  transform: translateY(1px);
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: white;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(77, 92, 255, .12);
}
textarea { resize: vertical; }
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: white;
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand {
  color: var(--text);
  display: grid;
  gap: 8px;
  font-weight: 900;
}
/* Универсально для квадратной иконки и широкого wordmark-логотипа бренда:
   ограничиваем высотой, ширина по пропорции. */
.brand img {
  display: block;
  max-height: 40px;
  width: auto;
  max-width: 168px;
  border-radius: 8px;
}
.brand span {
  font-size: 13px;
  letter-spacing: 0;
}
.side-nav {
  display: grid;
  gap: 6px;
}
.side-nav a {
  color: #334155;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 700;
}
.side-nav a.active {
  color: var(--brand-strong);
  background: #eef1ff;
}
.nav-icon {
  width: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-user-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}
.topbar-role {
  font-size: 12px;
  color: var(--muted);
}
.topbar-logout-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  transition: border-color .15s, color .15s;
}
.topbar-logout-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.client-switcher-form { display: flex; align-items: center; }
.client-switcher-select {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: white;
  cursor: pointer;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-shell { min-width: 0; }
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .9);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}
.topbar-title {
  font-weight: 900;
  font-size: 16px;
}
.topbar-sync {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  flex: 1;
  justify-content: center;
}
.topbar-sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.topbar-sync-dot--active {
  background: var(--brand);
  animation: pulse 1.5s ease-in-out infinite;
}
.topbar-sync-active {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--brand-strong);
  font-weight: 600;
}
.topbar-sync-spinner {
  display: inline-block;
  animation: spin 1.2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.scan-banner {
  background: #eef1ff;
  border: 1px solid #cdd4ff;
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--brand-strong);
  margin-bottom: 12px;
}
.scan-banner-spinner {
  display: inline-block;
  animation: spin 1.2s linear infinite;
  font-size: 16px;
  flex-shrink: 0;
}
.scan-bar-track {
  display: inline-block;
  width: 100px;
  height: 6px;
  background: #c7d2fe;
  border-radius: 3px;
  vertical-align: middle;
}
.scan-bar-fill {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 3px;
  transition: width .4s;
}
.scan-bar-pct {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}
.logout-form {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.page {
  padding: 22px;
  max-width: 1760px;
  margin: 0 auto;
}

.comments-topbar {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 190px auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.crm-search {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 220px;
  gap: 10px;
}
.date-filter-strip {
  border-bottom: 1px solid var(--line);
  padding: 6px 16px;
  background: var(--bg);
}
.date-filter-strip form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.date-filter-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.date-filter-sep {
  font-size: 12px;
  color: var(--muted);
}
.date-picker-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.date-text-input {
  font-size: 12px;
  padding: 3px 28px 3px 8px;
  height: 28px;
  width: 108px;
  letter-spacing: 0.3px;
}
.date-picker-native {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.date-picker-icon {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  line-height: 1;
  color: var(--muted);
}
button.date-picker-icon:not(:disabled):hover {
  background: none;
  color: var(--text);
  box-shadow: none;
}
.date-load-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 0 12px;
  height: 28px;
  min-height: 28px;
  line-height: 26px;
  border-radius: 6px;
  white-space: nowrap;
}
.date-load-btn:disabled { opacity: 0.6; cursor: default; }
.date-reset-btn {
  background: none;
  color: var(--muted);
  border: 1px solid var(--line);
}
button.date-reset-btn:not(:disabled):hover { background: #f0f2f5; color: var(--text); border-color: var(--muted); box-shadow: none; }
.date-range-error {
  font-size: 11px;
  color: var(--danger, #c0392b);
  white-space: nowrap;
}
.list-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 32px 20px;
  color: var(--muted);
  font-size: 14px;
}
.list-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.date-clear-btn {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.date-clear-btn:hover { color: var(--text); background: var(--line); }
.account-status-pill {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--text);
}
.account-status-pill strong {
  display: block;
  font-size: 13px;
}
.account-status-pill span:not(.ig-dot) {
  color: var(--success);
  font-size: 12px;
}
.ig-dot {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, #ff7a00, #f00075 52%, #5148ff);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.kpi-card {
  min-height: 104px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 14px;
  display: grid;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  box-shadow: 0 8px 22px rgba(31, 45, 61, .04);
}
.kpi-card.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(77, 92, 255, .1);
}
.kpi-card strong {
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}
.kpi-card small { color: var(--muted); }
.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 12px;
  background: #eef1ff;
}
.kpi-remove .kpi-icon, .kpi-error .kpi-icon { background: #ffecef; }
.kpi-review .kpi-icon { background: #fff2d8; }
.kpi-reply .kpi-icon { background: #e7f7ee; }
.kpi-hidden .kpi-icon { background: #f0ebff; }

.sync-strip {
  border: 1px solid #aab5ff;
  background: #fbfcff;
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  color: #4b5870;
  margin-bottom: 14px;
}
.sync-icon { color: var(--brand); font-size: 18px; }
.sync-ok { color: var(--success); margin-left: auto; }
.sync-note { color: var(--muted); }

.dashboard-grid {
  display: grid;
  /* Три колонки равной ширины (по трети). Тот же template + gap, что у KPI-ряда
     (.comments-kpis) — плитки и колонки одинаковой ширины и ровно друг под другом. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
  /* Три панели одной высоты в один экран; каждая скроллится внутри (как в
     почтовом клиенте) — без пустоты снизу. Отступ 330px = всё над гридом
     (топбар + поиск + период + KPI). Переопределяется в брейкпоинтах ниже. */
  height: calc(100vh - 330px);
  min-height: 520px;
}
.queue-panel, .detail-card, .rail-card, .state-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.queue-panel { overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.detail-panel { display: flex; flex-direction: column; min-height: 0; }
.detail-card { flex: 1; min-height: 0; overflow-y: auto; }
.panel-head {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.panel-head h1 {
  margin: 0 0 3px;
  font-size: 20px;
}
.panel-sync-time {
  font-size: 11px;
  color: var(--muted);
  align-self: flex-end;
  white-space: nowrap;
}
.panel-head p, .meta, .muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.queue-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 0 14px 12px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  /* Скроллбар скрываем на десктопе чтобы вкладки выглядели как одна строка без полосы.
     На мобильном (<768px) overlay-скроллбар появляется естественно. */
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* IE/Edge legacy */
}
.queue-tabs::-webkit-scrollbar { display: none; }   /* Chrome/Safari */
.queue-tabs a {
  white-space: nowrap;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  border: 1px solid transparent;
  flex-shrink: 0;
  font-size: 14px;
}
.queue-tabs a.active {
  color: var(--brand-strong);
  background: #eef1ff;
  border-color: #cdd4ff;
}
.queue-tabs span { margin-left: 4px; }

.comments-list {
  display: grid;
  align-content: start;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.comment-card {
  display: grid;
  grid-template-columns: 24px 38px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: white;
  align-items: start;
}
.comment-card.selected {
  background: #fbfcff;
  box-shadow: inset 3px 0 0 var(--brand);
}
.comment-card input { width: auto; margin-top: 4px; }
.avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(135deg, #eef1ff, #e7f7ee);
  color: var(--brand-strong);
  font-weight: 900;
  border: 1px solid var(--line);
}
.avatar-letter {
  position: relative;
  z-index: 1;
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 2;
}
.avatar-xs { width: 24px; height: 24px; font-size: 10px; }
.avatar-sm { width: 36px; height: 36px; font-size: 13px; }
.avatar-md { width: 40px; height: 40px; font-size: 14px; }
.avatar-lg { width: 54px; height: 54px; font-size: 18px; }
.comment-card-main {
  color: var(--text);
  display: grid;
  gap: 8px;
  min-width: 0;
}
.comment-card-head {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
.comment-card-head strong { color: var(--text); font-size: 13px; }
.comment-card-head time { margin-left: auto; }
.comment-card p {
  margin: 0;
  line-height: 1.4;
}
.comment-card-foot {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.verdict, .risk, .ig-mark, .status, .score {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-weight: 700;
  font-size: 12px;
}
.verdict-success, .score-low, .status-success { background: #e8f8ef; color: var(--success); }
.verdict-warn, .score-mid, .status-warn { background: #fff4dc; color: var(--warn); }
.verdict-danger, .score-high, .status-danger { background: #ffecef; color: var(--danger); }
.verdict-neutral, .status-neutral { background: var(--panel-soft); color: var(--muted); }
.risk, .ig-mark, .status { background: var(--panel-soft); color: var(--muted); border: 1px solid var(--line); }
.status-success { background: #e8f8ef; color: var(--success); border-color: transparent; }
.status-warn { background: #fff4dc; color: var(--warn); border-color: transparent; }
.status-danger { background: #ffecef; color: var(--danger); border-color: transparent; }
.status-neutral { background: var(--panel-soft); color: var(--muted); }

.compact-batchbar {
  width: auto;
  margin: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: auto auto auto minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
}
.selected-count {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}
.mini-button {
  min-height: 34px;
  padding: 7px 10px;
}

.detail-card {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.detail-head {
  display: flex;
  gap: 14px;
  align-items: start;
}
.detail-head > div { min-width: 0; flex: 1; }
.detail-head .status { margin-left: auto; }
.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
}
.detail-head h2 {
  margin: 4px 0;
  font-size: 22px;
}
.detail-head p { margin: 0; color: var(--muted); }
.post-context {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 12px;
}
.post-context p {
  margin: 0;
  font-size: 15px;
}
.ai-panel {
  border: 1px solid var(--line);
  background: #fbfcff;
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 8px;
  position: relative;
}

/* Inline loading state for AI verdict re-analysis — strictly per DESIGN.md:
   brand-tint background, brand spinner, body weight 700, semantic focus on action */
.ai-panel-loading-mask {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(238, 241, 255, .92);  /* brand-tint with slight transparency */
  border: 1px solid var(--brand);
  border-radius: 10px;
  z-index: 5;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px;
}
.ai-panel.is-reanalyzing { box-shadow: 0 0 0 3px rgba(77, 92, 255, .12); }
.ai-panel.is-reanalyzing .ai-panel-loading-mask { display: flex; }
.ai-panel-loading-spinner {
  color: var(--brand);
  font-size: 28px;
  font-weight: 700;
  animation: spin 1.2s linear infinite;
}
.ai-panel-loading-text {
  color: var(--brand-strong, #2945dd);
  font-size: 14px;
  font-weight: 700;
}
.ai-panel-loading-sub {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.ai-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}
.ai-verdict {
  display: block;
  font-size: 17px;
  margin-top: 3px;
}
.success-text { color: var(--success); }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }
.neutral-text { color: var(--muted); }
.ai-panel p { margin: 0; }
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.reply-panel {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 10px;
}
.reply-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.reply-panel h3 {
  margin: 0;
  font-size: 16px;
}
.reply-form {
  display: grid;
  gap: 10px;
}
.reply-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.empty-detail {
  min-height: 320px;
  align-content: center;
  text-align: center;
}

.right-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.rail-card {
  padding: 14px;
  display: grid;
  gap: 12px;
}
/* Виджет активности заполняет остаток высоты рельса; список скроллится внутри,
   чтобы правая колонка ровнялась по высоте с очередью без пустоты снизу. */
.rail-activity {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
}
.rail-activity .activity-list {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}
/* В узком рельсе гасим full-bleed отрицательные поля айтемов (margin:0 -8px на
   дашборде) — иначе они шире скролл-контейнера и дают горизонтальную прокрутку. */
.rail-activity .activity-item { margin-left: 0; margin-right: 0; }
.rail-card h2 {
  margin: 0;
  font-size: 15px;
}
.rail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.account-row, .role-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.account-row-link {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
  padding: 2px;
  transition: background .15s;
}
.account-row-link:hover { background: var(--panel-soft, rgba(77,92,255,.06)); }
.account-row-link strong { color: var(--text); }
.account-row-ext {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  flex-shrink: 0;
  opacity: .55;
  padding: 4px 6px;
  transition: opacity .15s;
}
.account-row-ext:hover { opacity: 1; color: var(--brand, #4d5cff); }
.account-icon, .role-icon {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #eef1ff;
  color: var(--brand-strong);
  font-weight: 900;
}
.account-row p, .role-row p, .api-error p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.api-error {
  border: 1px solid #ffd2d8;
  background: #fff8f9;
  border-radius: 10px;
  padding: 10px;
}
.api-error-summary {
  border: 1px solid #ffd2d8;
  background: #fff8f9;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
}
.api-error-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.compact-api-error {
  padding: 8px;
}
.api-error .api-error-comment {
  color: var(--text);
  font-weight: 700;
}
.api-error a {
  display: inline-flex;
  margin-top: 8px;
  font-weight: 800;
}
.mini-identity {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notice {
  border-radius: 8px;
  padding: 9px 10px;
}
.notice.error { background: #ffecef; color: var(--danger); }
.notice.success { background: #e8f8ef; color: var(--success); }
.notice.warning { background: #fff4dc; color: var(--warn); }
.notice.info { background: #eef1ff; color: var(--brand-strong); }
.page-notice { margin-bottom: 14px; }
.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px;
}
.empty-queue {
  display: grid;
  justify-items: center;
  gap: 8px;
}
.empty-queue strong {
  color: var(--text);
  font-size: 15px;
}
.empty-queue span {
  max-width: 460px;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}
h1 { margin: 0 0 6px; font-size: 24px; }
h2 { margin: 0 0 14px; font-size: 17px; }
.list {
  display: grid;
  gap: 10px;
}
.row-card, .panel, .settings-form {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.row-card {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}
.accounts-page {
  max-width: 1180px;
}
.accounts-toolbar {
  align-items: center;
}
.accounts-toolbar p {
  margin: 0;
  max-width: 720px;
  color: var(--muted);
}
.accounts-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 12px;
}
@media (min-width: 920px) {
  .accounts-list { grid-template-columns: repeat(2, 1fr); }
}
.account-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 14px;
}
.account-main {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}
.account-main strong {
  display: inline-flex;
  margin-right: 8px;
  font-size: 16px;
}
.account-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.account-footer .meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  margin: 0;
}
.account-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.account-btns form {
  margin: 0;
}
.account-btns .button,
.account-btns button {
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  line-height: 1.3;
}
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.split {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
}
.panel, .settings-form {
  display: grid;
  gap: 14px;
}
.settings-section {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--panel-soft);
}
.settings-section h2 {
  margin: 0;
}
.settings-section p {
  margin: 0;
  color: var(--muted);
}
.settings-page {
  max-width: 980px;
}
.settings-toolbar p {
  margin: 0;
  max-width: 720px;
  color: var(--muted);
}
.settings-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  overflow: hidden;
}
.settings-row {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}
.settings-row h2 {
  margin: 0 0 6px;
}
.settings-row p {
  margin: 0;
  color: var(--muted);
}
.settings-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.settings-fields label span {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}
.settings-actions {
  padding: 14px 18px;
  display: flex;
  justify-content: flex-end;
}
.connect-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}
.connect-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  display: grid;
  gap: 16px;
}
.connect-card h1 {
  max-width: 760px;
}
.lead {
  max-width: 820px;
  color: var(--muted);
  font-size: 15px;
  margin: 0;
}
.connect-steps {
  display: grid;
  gap: 10px;
}
.connect-step {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  padding: 12px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.connect-step span {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #eef1ff;
  color: var(--brand-strong);
  display: grid;
  place-items: center;
  font-weight: 900;
}
.connect-step p { margin: 0; color: var(--text); }
.connect-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.connect-side {
  gap: 12px;
}
.ai-rules-form textarea {
  min-height: 0;
  overflow-y: hidden;
  resize: vertical;
}
.ai-rules-masonry {
  columns: 2;
  column-gap: 14px;
}
.ai-rules-masonry > .settings-section {
  break-inside: avoid;
  margin-bottom: 14px;
}
.ai-rules-reply-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}
.learn-col {
  display: grid;
  gap: 12px;
  align-content: start;
  justify-items: start;
}
.learn-rules-preview {
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  max-height: 180px;
  overflow-y: auto;
  color: var(--text);
}
.learn-status {
  font-size: 13px;
  margin: 4px 0 0;
  color: var(--muted);
}
.learn-status.ok { color: var(--success); }
.learn-status.err { color: var(--danger); }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.checkbox-line {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.checkbox-line input {
  width: 18px;
  height: 18px;
}
.inline-password {
  display: grid;
  grid-template-columns: 180px 84px;
  gap: 8px;
}
.users-page {
  max-width: 1180px;
}
.users-toolbar p {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
}
.compact-form-grid {
  display: grid;
  gap: 10px;
}

/* ─── Users page ──────────────────────────────────────────────────────── */
.users-page {
  display: grid;
  gap: 18px;
}
.user-create-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) 180px auto;
  gap: 10px;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.user-create-row > input,
.user-create-row > .pw-wrap input,
.user-create-row > select {
  min-height: 40px;
}
.user-create-submit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  white-space: nowrap;
}
.user-create-submit i { font-size: 18px; }

.users-table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 18px 6px;
  box-shadow: var(--shadow);
}
.users-table-head, .user-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) 260px 120px 140px;
  gap: 16px;
  align-items: center;
}
.users-table-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 14px 0 12px;
  border-bottom: 1px solid var(--line);
}
.user-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.user-row:last-child { border-bottom: 0; }
.user-row-muted { opacity: .55; }
.user-row > .status,
.user-row > .status-active {
  justify-self: start;
}

.user-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.user-avatar {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.user-name-block {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.user-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.user-name-line strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-name-tag {
  font-size: 11px;
  color: var(--muted);
}
.meta-super {
  display: inline-block;
  padding: 2px 8px;
  background: #ede9fe;
  color: #6d28d9;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.user-role-form {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: start;
}
.user-role-form select {
  width: 170px;
  min-height: 36px;
  padding: 6px 10px;
  font: inherit;
}

.status-active {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status-active-dot {
  width: 7px; height: 7px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}
.status-active--on { background: #e8f8ef; color: var(--success); }
.status-active--off { background: var(--panel-soft); color: var(--muted); }

.user-row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.user-row-actions form { display: contents; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  padding: 0;
  min-height: 0;
  min-width: 0;
  font: inherit;
  box-shadow: none;
}
.icon-btn i { font-size: 18px; line-height: 1; }
.icon-btn:hover {
  background: var(--brand-tint, #eef1ff);
  color: var(--brand-strong);
  border-color: var(--brand-tint, #eef1ff);
  transform: none;
  box-shadow: none;
}
.icon-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.icon-btn-danger { color: #b91c1c; }
.icon-btn-danger:hover {
  background: #ffecef;
  color: #b91c1c;
  border-color: #ffecef;
}
.icon-btn-primary {
  background: var(--brand-tint, #eef1ff);
  color: var(--brand-strong);
  border-color: var(--brand-tint, #eef1ff);
}
.icon-btn-primary:hover {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}


/* <details> popover for password change */
.action-popover { position: relative; }
.action-popover > summary {
  list-style: none;
  cursor: pointer;
}
.action-popover > summary::-webkit-details-marker { display: none; }
.action-popover[open] > summary {
  background: var(--brand-tint, #eef1ff);
  color: var(--brand-strong);
  border-color: var(--brand-tint, #eef1ff);
}
.action-popover-body {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(31, 45, 61, .12);
  padding: 12px;
  width: 280px;
}
.pw-popover-form {
  display: grid;
  gap: 8px;
}
.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap input {
  flex: 1;
  padding-right: 36px;
}
.pw-eye {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  color: var(--muted);
  transition: color .15s;
}
.pw-eye:hover, .pw-eye-active {
  color: var(--brand);
}
.login-page {
  min-height: calc(100vh - 56px);
  display: grid;
  place-items: center;
}
.login-panel {
  width: min(380px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}

@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* Рельс уезжает вниз на всю ширину → фикс-высота «в экран» больше не нужна:
     возвращаем натуральную высоту и обычный скролл страницы. */
  .dashboard-grid {
    grid-template-columns: minmax(460px, 1.15fr) minmax(380px, 1fr);
    height: auto;
    min-height: 0;
    align-items: start;
  }
  .queue-panel { display: block; }
  .comments-list { max-height: 690px; flex: none; }
  .detail-panel { display: block; }
  .detail-card { flex: none; overflow-y: visible; }
  .right-rail {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .rail-activity { flex: none; }
  .rail-activity .activity-list { overflow: visible; }
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comments-topbar, .crm-search, .dashboard-grid, .right-rail, .split, .grid-2, .connect-layout, .users-grid, .settings-row, .settings-fields {
    grid-template-columns: 1fr;
  }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar, .toolbar, .row-card, .actions {
    align-items: stretch;
    flex-direction: column;
  }
  .accounts-list, .account-actions { grid-template-columns: 1fr; }
  .users-table-head { display: none; }
  .user-row, .user-password-form { grid-template-columns: 1fr; }
  .compact-batchbar { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}

/* ─── Dashboard page ─── */
/* ─── Premium Dashboard ────────────────────────────────────────────────── */
.dashboard-page {
  display: grid;
  gap: 16px;
  max-width: 1400px;
}

/* Page header */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}
.dash-header-title h1 { margin: 0 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.dash-header-title p { margin: 0; font-size: 13px; color: var(--muted); }
.dash-period-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 4px 4px 12px;
  box-shadow: 0 1px 2px rgba(31,45,61,.04);
}
.dash-period-form i { color: var(--muted); font-size: 16px; }
.dash-period-form select { border: 0; background: transparent; min-height: 32px; padding: 4px 8px; font-weight: 700; cursor: pointer; box-shadow: none; }
.dash-period-form select:focus { outline: none; box-shadow: none; }

/* Banner */
.dash-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}
.dash-banner i { font-size: 18px; flex-shrink: 0; }
.dash-banner-warn {
  background: #fff8ec;
  color: #7a4f00;
  border: 1px solid #f5d8a0;
}
.dash-banner-warn i { color: var(--warn); }
.dash-banner-neutral {
  background: var(--panel-soft);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* KPI grid: 6 in a row, deltas */
.dash-kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.kpi-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.6px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-suffix { font-size: 14px; font-weight: 700; color: var(--muted); letter-spacing: 0; }
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}
.kpi-delta span { color: var(--muted); font-weight: 500; }
.kpi-delta.delta-up    { color: var(--success); }
.kpi-delta.delta-up::before    { content: "▲"; font-size: 9px; }
.kpi-delta.delta-down  { color: var(--danger); }
.kpi-delta.delta-down::before  { content: "▼"; font-size: 9px; }
.kpi-delta.delta-flat  { color: var(--muted); font-weight: 600; }
.kpi-delta.delta-clear { color: var(--success); font-weight: 600; }
.kpi-delta.delta-clear::before { content: "✓ "; font-weight: 700; }

/* Dash cards (generic) */
.dash-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.dash-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.dash-card-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.1px;
}
.dash-card-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.dash-card-link {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-strong);
  text-decoration: none;
}
.dash-card-link:hover { text-decoration: underline; }
.dash-card-body { padding: 16px 20px 18px; flex: 1; min-height: 0; }

/* Section grids — cards stretch to row height for visual alignment */
.dash-grid-3 {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  gap: 14px;
}
.dash-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.dash-card-wide { grid-column: span 1; }

/* Hero card (compact, sits in row with chart + risks) */
.dash-card-hero { }
.dash-hero-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 18px 20px 22px;
}
.dash-hero-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6b7cff, #4d5cff);
  color: white;
  font-size: 26px;
  box-shadow: 0 6px 16px rgba(77, 92, 255, .25);
  margin-bottom: 4px;
}
.dash-hero-number {
  font-size: 44px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1.5px;
  line-height: 1;
}
.dash-hero-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* Risk distribution bars */
.risk-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.risk-list li {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 80px;
  align-items: center;
  gap: 6px 12px;
  grid-template-areas: "name num" "bar bar";
}
.risk-name { grid-area: name; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.risk-num  { grid-area: num; font-size: 12px; font-weight: 700; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.risk-num em { font-style: normal; font-weight: 500; color: var(--muted); }
.risk-bar  { grid-area: bar; background: var(--panel-soft); border-radius: 999px; height: 6px; overflow: hidden; }
.risk-bar-fill { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.risk-dot { width: 8px; height: 8px; border-radius: 999px; }
.risk-dot-low,  .risk-bar-low  { background: #4dd190; }
.risk-dot-med,  .risk-bar-med  { background: #f5b042; }
.risk-dot-high, .risk-bar-high { background: #e1293d; }
.risk-total { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.risk-total strong { color: var(--text); font-weight: 800; }

/* Categories / words shared horizontal bars */
.cat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.cat-list li {
  display: grid;
  grid-template-columns: minmax(90px, 1.2fr) 1fr 80px;
  align-items: center;
  gap: 10px;
}
.cat-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar { background: var(--panel-soft); border-radius: 999px; height: 6px; overflow: hidden; }
.cat-bar-fill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-strong)); transition: width .4s ease; }
.cat-bar-purple { background: linear-gradient(90deg, #b87bff, #7c3aed); }
.cat-num { font-size: 12px; font-weight: 700; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.cat-num em { font-style: normal; font-weight: 500; color: var(--muted); }
.cat-total {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
}
.cat-total strong { color: var(--text); font-weight: 800; }
.cat-total-row { display: inline-flex; align-items: center; gap: 8px; }
.cat-total-row i { font-size: 14px; color: var(--brand-strong); flex-shrink: 0; }
.cat-total-row-muted { color: var(--muted); }
.cat-total-row-muted i { color: var(--muted); }
.cat-total-row-muted strong { color: var(--text); font-weight: 700; }

/* Activity feed */
.activity-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.activity-list li { display: block; }
.activity-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px;
  margin: 0 -8px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background .12s;
}
.activity-item:hover { background: var(--panel-soft); }
.activity-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  font-size: 15px;
  color: white;
}
.activity-item[data-color="red"]    .activity-icon { background: linear-gradient(135deg, #f06b80, #e1293d); }
.activity-item[data-color="orange"] .activity-icon { background: linear-gradient(135deg, #ffb86b, #d88114); }
.activity-item[data-color="green"]  .activity-icon { background: linear-gradient(135deg, #4dd190, #159b58); }
.activity-item[data-color="blue"]   .activity-icon { background: linear-gradient(135deg, #6b7cff, #4d5cff); }
.activity-item[data-color="purple"] .activity-icon { background: linear-gradient(135deg, #b87bff, #7c3aed); }
.activity-body { min-width: 0; flex: 1; }
.activity-text {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.activity-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.activity-meta strong { color: var(--text); font-weight: 700; }

/* Accounts table inside dashboard */
.acc-table-head, .acc-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 110px 180px 160px;
  align-items: center;
  gap: 14px;
}
.acc-last-activity { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.acc-table-head {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.acc-row { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.acc-row:last-child { border-bottom: 0; }
.acc-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.acc-avatar { width: 28px; height: 28px; border-radius: 999px; object-fit: cover; flex-shrink: 0; background: var(--panel-soft); }
.acc-avatar-fallback { display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #b87bff, #6b7cff); color: white; font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.acc-name { font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.acc-name:hover { color: var(--brand, #4d5cff); text-decoration: underline; }
.acc-ext-link { color: var(--muted); text-decoration: none; font-size: 13px; flex-shrink: 0; opacity: .6; transition: opacity .15s; }
.acc-ext-link:hover { opacity: 1; color: var(--brand, #4d5cff); }
.acc-platform { color: var(--muted); font-size: 13px; }
.num-col { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.acc-errors-bad { color: var(--danger); font-weight: 800; }
@media (max-width: 1280px) {
  .dash-kpis { grid-template-columns: repeat(3, 1fr); }
  .dash-grid-3 { grid-template-columns: 1fr 1fr; }
  .dash-card-wide { grid-column: span 2; }
  .dash-card-hero { grid-column: span 2; }
}
@media (max-width: 920px) {
  .dash-kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid-3, .dash-grid-2 { grid-template-columns: 1fr; }
  .dash-card-wide, .dash-card-hero { grid-column: auto; }
  .dash-header { flex-direction: column; align-items: flex-start; }
  .acc-table-head, .acc-row { grid-template-columns: 1.4fr 90px 1fr 100px; gap: 8px; font-size: 12px; }
}
@media (max-width: 600px) {
  .dash-kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 22px; }
  .acc-table-head, .acc-row { grid-template-columns: 1fr; gap: 4px; }
  .acc-table-head { display: none; }
}

/* ─── DM status badges on comment cards ─────────────────────────────────── */
.dm-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}
.dm-badge-sent {
  background: #e8f7ee;
  color: var(--success);
  border-color: #b8e6c9;
}
.dm-badge-error {
  background: #fff5e8;
  color: var(--warn);
  border-color: #f5d8a0;
}

.dm-status-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid;
  margin-bottom: 12px;
}
.dm-status-panel strong { font-size: 14px; }
.dm-status-panel .meta { font-size: 12px; color: var(--muted); }
.dm-status-panel form { margin-top: 4px; }
.dm-status-sent {
  background: #e8f7ee;
  border-color: #b8e6c9;
  color: var(--success);
}
.dm-status-error {
  background: #fff5e8;
  border-color: #f5d8a0;
  color: var(--warn);
}

/* Indented public reply under a comment in the queue */
.comment-thread-reply {
  display: flex;
  gap: 8px;
  margin: 8px 0 8px 56px;
  padding: 10px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-left: 2px solid var(--brand);
  border-radius: 0 8px 8px 0;
  font-size: 12px;
  color: var(--muted);
}
.thread-arrow {
  color: var(--brand);
  flex-shrink: 0;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
}
.thread-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.thread-text { color: var(--text); line-height: 1.4; }
@media (max-width: 480px) {
  .comment-thread-reply { margin-left: 28px; padding: 8px 10px; }
}

/* ─── Inline button loading state ───────────────────────────────────────── */
.btn-spinner {
  display: inline-block;
  animation: spin 1.2s linear infinite;
  font-weight: 700;
  margin-right: 4px;
}
.btn-loading {
  opacity: .85;
  cursor: progress !important;
  pointer-events: none;
}

/* Action overlay — full-screen feedback during single comment action */
.action-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 45, .55);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.action-overlay-card {
  background: white;
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(20, 28, 45, .25);
  min-width: 280px;
  max-width: 90vw;
}
.action-overlay-spinner {
  font-size: 36px;
  color: var(--brand);
  animation: spin 1.2s linear infinite;
  display: inline-block;
  margin-bottom: 12px;
  font-weight: 700;
}
.action-overlay-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.action-overlay-sub {
  font-size: 13px;
  color: var(--muted);
}

/* ─── Reanalyze progress ────────────────────────────────────────────────── */
.reanalyze-status { margin-top: 10px; min-height: 20px; }
.reanalyze-status .running { color: var(--brand-strong); }
.reanalyze-spinner {
  display: inline-block;
  animation: spin 1.2s linear infinite;
  font-weight: 700;
}
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.reanalyze-bar {
  margin-top: 8px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.reanalyze-bar-fill {
  height: 100%;
  background: var(--brand);
  transition: width .4s ease;
}

/* ─── Mobile adaptation ─────────────────────────────────────────────────── */
/* Hamburger button: hidden on desktop, visible on <768px */
.sidebar-toggle {
  display: none;
  background: none;
  border: 0;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  padding: 6px 10px;
  min-height: auto;
  cursor: pointer;
  border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--panel-soft); box-shadow: none; }
.sidebar-toggle:active { transform: none; box-shadow: none; }

/* Backdrop overlay for mobile sidebar */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 45, .42);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
}
body.sidebar-open .sidebar-backdrop { display: block; }
body.sidebar-open { overflow: hidden; }

/* ─── Tablet portrait + phone landscape: 768px and below ────────────────── */
@media (max-width: 768px) {
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 260px;
    max-width: 80vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 100;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    overflow-y: auto;
    box-shadow: 4px 0 16px rgba(20, 28, 45, .12);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .side-nav { grid-template-columns: 1fr; }

  .topbar {
    height: 48px;
    padding: 0 12px;
    gap: 8px;
    flex-direction: row;
    align-items: center;
  }
  .topbar-title { font-size: 15px; }
  .topbar-user-name, .topbar-role { display: none; }
  .topbar-logout-btn { padding: 6px 10px; font-size: 13px; min-height: 36px; }

  .page { padding: 12px; }

  /* Account cards: buttons full width 50% pairs on narrow */
  .account-btns .button,
  .account-btns button { flex: 1 1 calc(50% - 4px); }

  /* Touch targets */
  button, .button, select { min-height: 44px; }
  .ghost.mini-button, .mini-button { min-height: 36px; }
  input[type="text"], input[type="number"], input[type="date"],
  input[type="email"], input[type="password"], select, textarea {
    font-size: 16px; /* prevent iOS zoom on focus */
  }

  /* Typography */
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
}

/* Detail drawer back button — hidden on desktop */
.detail-back-btn {
  display: none;
  background: none;
  border: 0;
  color: var(--brand-strong);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 14px;
  cursor: pointer;
  align-self: flex-start;
  min-height: auto;
  border-radius: 6px;
}
.detail-back-btn:hover { background: var(--panel-soft); box-shadow: none; }
.detail-back-btn:active { transform: none; box-shadow: none; }

/* ─── Comments page drawer mode at <768px ───────────────────────────────── */
@media (max-width: 768px) {
  /* AI rules masonry — single column on mobile (was columns: 2) */
  .ai-rules-masonry { columns: 1; }
  .ai-rules-masonry > .settings-section { margin-bottom: 12px; }
  .ai-rules-reply-grid { grid-template-columns: 1fr; }

  /* Comment card head — wrap username/creator/time; prevent overflow that breaks card width */
  .comment-card { overflow: hidden; }
  .comment-card-head {
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .comment-card-head strong,
  .comment-card-head span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .comment-card-head time { margin-left: 0; flex-basis: 100%; font-size: 11px; }
  .comment-card p {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .dashboard-grid { grid-template-columns: 1fr; gap: 10px; }
  .right-rail { display: none; } /* Right rail hidden on mobile to save space */
  .queue-tabs {
    padding: 0 10px 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;          /* Firefox: показываем тонкий */
    -ms-overflow-style: auto;
  }
  .queue-tabs::-webkit-scrollbar { display: block; height: 4px; }
  .queue-tabs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }
  .date-filter-strip { padding: 8px 10px; }
  .date-filter-strip > form { flex-wrap: wrap; gap: 8px; }
  .panel-head { padding: 12px; }
  .panel-head h1 { font-size: 18px; }

  /* Detail panel as slide-in drawer */
  .detail-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 80;
    overflow-y: auto;
    background: var(--bg);
    padding: 8px;
  }
  body.detail-open .detail-panel { transform: translateX(0); }
  body.detail-open { overflow: hidden; }
  .detail-back-btn { display: inline-flex; align-items: center; }

  /* Batch bar — 2 rows on mobile */
  .compact-batchbar { flex-wrap: wrap; }
}

/* ─── Phone portrait: 480px and below ───────────────────────────────────── */
@media (max-width: 480px) {
  .dash-kpis { grid-template-columns: 1fr; gap: 10px; }
  .dash-kpi-card { padding: 16px 14px; }
  .dash-kpi-value { font-size: 24px; }
  .dash-hero { padding: 28px 16px 22px; }
  .dash-hero-number { font-size: clamp(40px, 12vw, 64px); }

  .page { padding: 10px; }

  .account-btns .button,
  .account-btns button { flex: 1 1 100%; }

  .compact-batchbar { gap: 8px; padding: 10px; }

  /* Comment cards tighter */
  .comment-card { padding: 10px; gap: 8px; }
}

/* ── Stats page ──────────────────────────────────────── */
/* Stats page */
.stats-page { display: flex; flex-direction: column; gap: 20px; }
.stats-account-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stats-account-select { font-size: 14px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; color: var(--text); flex-shrink: 0; }

/* Account header */
.stats-header { display: flex; align-items: center; gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; }
.stats-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.stats-avatar-placeholder { width: 64px; height: 64px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; flex-shrink: 0; }
.stats-header-info { display: flex; flex-direction: column; gap: 6px; }
.stats-username { margin: 0; font-size: 18px; font-weight: 700; }
.stats-header-counts { display: flex; gap: 20px; flex-wrap: wrap; }
.stats-header-stat { font-size: 13px; color: var(--muted); }
.stats-header-stat strong { color: var(--text); font-weight: 600; }

/* Metric cards — unified grid for primary + account-insights */
/* ── Stats KPI: B+1 layout — все 9 плашек в один ряд ────────────────────
   Над плашками идёт ряд .stats-group-headers с заголовками групп
   (span-2 / span-3 / span-4). Каждая плашка имеет верхнюю chip-полоску
   цвета своей группы (--group-color). На узком экране плашки переносятся,
   headers скрываются — chip-полоска становится top-border. */

.stats-group-headers {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 10px;
  align-items: end;
}
/* YouTube layout: 7 cards (2 dynamic + 3 posts + 2 yt-analytics) */
.stats-group-headers.platform-youtube,
.stats-metrics-row.platform-youtube {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.stats-group-headers.no-insights {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.stats-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 0 4px;
  min-width: 0;
}
.stats-group-header .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--group-color, var(--muted));
  flex-shrink: 0;
}
.stats-group-header .title {
  font-size: 11px; font-weight: 800;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
}
.stats-group-header .sub {
  font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stats-group-header.span-2 { grid-column: span 2; }
.stats-group-header.span-3 { grid-column: span 3; }
.stats-group-header.span-4 { grid-column: span 4; }

.stats-metrics-row {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 24px;
}
.stats-metrics-row.no-insights {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stats-metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 14px;
  display: flex; flex-direction: column; gap: 5px;
  position: relative;
  min-width: 0;
  transition: transform .12s, box-shadow .12s;
}
.stats-metric-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(31, 45, 61, .05);
}
.stats-metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 14px; right: 14px;
  height: 3px;
  background: var(--group-color, transparent);
  border-radius: 0 0 3px 3px;
}
.stats-metric-card .stats-metric-header {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px;
}
.stats-metric-card .stats-metric-icon {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid; place-items: center;
  flex-shrink: 0;
  font-size: 13px;
  background: var(--group-bg, var(--panel-soft));
  color: var(--group-color, var(--muted));
}
.stats-metric-card .stats-metric-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stats-metric-card .stats-metric-value {
  font-size: 22px; font-weight: 800;
  letter-spacing: -.3px; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.stats-metric-card .stats-metric-suffix {
  font-size: 13px; font-weight: 700; color: var(--muted);
  margin-left: 2px;
}
.stats-metric-card .stats-metric-delta {
  font-size: 10px; font-weight: 600;
  margin-top: 1px;
}
.stats-metric-card .stats-metric-delta.pos { color: var(--success); }
.stats-metric-card .stats-metric-delta.neg { color: var(--danger); }
.stats-metric-card .stats-metric-delta span { color: var(--muted); font-weight: 400; }
.stats-metric-card .stats-metric-hint {
  font-size: 10px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Group accent colors */
.stats-metric-card.group-dynamic,
.stats-group-header.group-dynamic {
  --group-color: var(--brand);
  --group-bg: rgba(77, 92, 255, .12);
}
.stats-metric-card.group-posts,
.stats-group-header.group-posts {
  --group-color: var(--violet);
  --group-bg: rgba(124, 58, 237, .12);
}
.stats-metric-card.group-insights,
.stats-group-header.group-insights {
  --group-color: var(--cyan);
  --group-bg: rgba(8, 145, 178, .12);
}

@media (max-width: 1500px) {
  .stats-metrics-row,
  .stats-metrics-row.no-insights,
  .stats-group-headers,
  .stats-group-headers.no-insights {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .stats-group-header.span-4 { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .stats-metrics-row,
  .stats-metrics-row.no-insights {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stats-group-headers { display: none; }
  .stats-metric-card::before { display: none; }
  .stats-metric-card { border-top: 3px solid var(--group-color, var(--line)); }
}
.stats-metric-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.stats-metric-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stats-metric-value { font-size: 20px; font-weight: 700; color: var(--text); }
.stats-metric-hint { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* Reconnect banner */
.stats-reconnect-banner { display: flex; align-items: center; gap: 10px; background: #fff8ec; border: 1px solid #f5c87a; border-radius: 8px; padding: 12px 16px; font-size: 13px; color: #7a4f00; }
.stats-reconnect-icon { font-size: 16px; flex-shrink: 0; }

/* Sections */
.stats-section { display: flex; flex-direction: column; gap: 10px; }
.stats-section-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats-trend-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; position: relative; height: 220px; }

/* Posts table */
.stats-table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; white-space: nowrap; background: var(--panel-soft); }
.stats-table th.num, .stats-table td.num { text-align: right; }
.stats-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.stats-table tbody tr:last-child td { border-bottom: none; }
.stats-row { cursor: pointer; transition: background 0.12s; }
.stats-row:hover { background: rgba(77,92,255,.04); }
.stats-caption { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-caption a { color: inherit; text-decoration: none; }
.stats-caption a:hover { text-decoration: underline; }
.stats-type { color: var(--muted); font-size: 12px; }
.media-badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.media-badge--reels   { background: #e8d5ff; color: #6c1fc0; }
.media-badge--video   { background: #d4eaff; color: #1a5fa0; }
.media-badge--image   { background: #e5e5e5; color: #555; }
.media-badge--carousel { background: #fce8d0; color: #b05f10; }
.reach-split-chip { display: inline-block; margin-left: 4px; font-size: 0.68rem; color: var(--muted); white-space: nowrap; }
.stats-date { white-space: nowrap; color: var(--muted); }
.stats-sparkline { width: 82px; }
.stats-chart-row td { padding: 0; }
.stats-chart-wrap { padding: 0; background: var(--panel-soft); border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.stats-chart-canvas-zone { position: relative; height: 210px; overflow: hidden; padding: 0 14px 10px; }
.stats-trend-pending { margin: 0; padding: 20px 0; text-align: center; color: var(--muted); font-size: 13px; }
.stats-section-hint { font-size: 11px; font-weight: 400; color: var(--muted); text-transform: none; letter-spacing: 0; }
.stats-refresh-btn { display: flex; align-items: center; gap: 4px; padding: 7px 14px; border: 1px solid var(--brand); border-radius: 8px; background: var(--panel); color: var(--brand); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .12s; }
.stats-refresh-btn:hover:not(:disabled) { background: rgba(77,92,255,.07); }
.stats-refresh-btn:disabled { opacity: .6; cursor: default; }
.stats-refresh-icon { font-size: 15px; display: inline-block; }
.stats-refresh-icon.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stats-metric-icon { font-size: 14px; }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { background: rgba(77,92,255,.04); }
.sort-arrow { font-size: 10px; color: var(--brand); }

/* ── Stats: period selector & top bar ─────────────────────────────────── */
.stats-top-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.stats-top-bar .stats-account-bar { margin-bottom: 0; }
.stats-period-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.stats-period-btn { padding: 5px 13px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 500; cursor: pointer; transition: background .12s, border-color .12s, color .12s; white-space: nowrap; }
.stats-period-btn:hover { border-color: var(--brand); color: var(--brand); background: rgba(77,92,255,.07); }
.stats-period-btn--active { border-color: var(--brand); background: var(--brand); color: #fff; }
.stats-period-btn--active:hover { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.stats-daterange { display: flex; align-items: center; gap: 6px; margin-left: 6px; }
.stats-trend-wrap--tall { height: 260px; }

/* ── Stats: metric delta ──────────────────────────────────────────────── */
.stats-metric-delta { font-size: 11px; margin-top: 3px; min-height: 15px; }
.stats-metric-delta.pos { color: #27a862; }
.stats-metric-delta.neg { color: #e05252; }

/* ── Stats: two-column charts grid ───────────────────────────────────── */
.stats-charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 0; }
@media (max-width: 700px) { .stats-charts-grid { grid-template-columns: 1fr; } }
.stats-charts-grid .stats-section { margin-bottom: 0; }

/* ── Stats: delta badges in history table ─────────────────────────────── */
.delta-badge { display: inline-block; padding: 1px 5px; border-radius: 4px; font-size: 11px; font-weight: 600; line-height: 1.4; }
.delta-badge.pos { background: rgba(39,168,98,.12); color: #27a862; }
.delta-badge.neg { background: rgba(224,82,82,.10); color: #e05252; }

/* ── Stats: history table ──────────────────────────────────────────────── */
.stats-history-table td { padding: 8px 12px; }
.stats-loading { margin: 0; padding: 24px 0; text-align: center; color: var(--muted); font-size: 13px; }

/* ── Stats: accounts comparison panel ─────────────────────────────────── */
.stats-compare-section { background: var(--panel); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); }
.stats-compare-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stats-compare-sort {
  border: 1px solid var(--line); border-radius: 8px; padding: 0.35rem 0.8rem;
  font-size: 0.83rem; background: var(--panel-soft); color: var(--text); cursor: pointer;
  outline: none; width: auto; flex-shrink: 0;
}
.stats-compare-sort:focus { border-color: var(--brand); }
.cmp-rank { color: var(--muted); font-weight: 700; font-size: 13px; }
.cmp-acc-cell { display: flex; align-items: center; gap: 10px; }
.cmp-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.cmp-avatar-ph {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.cmp-name { display: block; font-weight: 600; color: var(--brand); text-decoration: none; font-size: 14px; }
.cmp-name:hover { text-decoration: underline; }
.cmp-ig-link { font-size: 11px; color: var(--muted); text-decoration: none; }
.cmp-ig-link:hover { color: var(--brand); }
.stats-avatar { cursor: pointer; transition: opacity .15s; }
.stats-avatar:hover { opacity: .82; }

/* ── Section tabs: caption-style underline (Smart Dispatcher) ───────────── */
/* Pattern: text-only tabs subordinated to section title. brand color shows
   only via 2px underline on active tab. No fills, no borders, no shouty pills.
   Per DESIGN.md: brand ≤10% of screen, reserved for action / active state.
   Selectors prefixed with `button.` to override the global `button { background: brand; min-height: 38px }`
   rule with sufficient specificity (0,1,1) — and hover/active variants get (0,3,1) to beat the global
   `button:not(:disabled):hover` (0,2,1). */
.chart-mode-row { display: flex; flex-wrap: wrap; gap: 18px; padding: 8px 14px 4px; align-items: baseline; }
button.chart-mode-btn {
  display: inline-flex; align-items: baseline;
  padding: 2px 0 5px; margin: 0;
  border: 0; border-bottom: 2px solid transparent;
  background: transparent; box-shadow: none; transform: none;
  min-height: 0; min-width: 0;
  color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  cursor: pointer; transition: color .12s, border-color .12s;
  outline: none;
}
button.chart-mode-btn:not(:disabled):hover {
  background: transparent; box-shadow: none; transform: none;
  color: var(--text);
  border-color: transparent; border-bottom-color: transparent;
}
button.chart-mode-btn:not(:disabled):active {
  background: transparent; box-shadow: none; transform: none;
}
button.chart-mode-btn:focus-visible {
  outline: none;
  border-bottom-color: var(--brand-strong);
}
button.chart-mode-btn.on,
button.chart-mode-btn.on:not(:disabled):hover {
  background: transparent; box-shadow: none; transform: none;
  color: var(--brand-strong);
  border-bottom-color: var(--brand-strong);
}
.chart-mode-sep { display: none; }
.stats-section-title--sub { font-size: 12px; margin: 0 0 8px; }
/* Section header with inline tabs + meta on the right */
.stats-section-header {
  display: flex; align-items: baseline; gap: 22px;
  flex-wrap: wrap; margin: 0 0 12px;
}
.stats-section-header .stats-section-title { margin: 0; }
.stats-section-header .chart-mode-row { padding: 0; flex: 0 1 auto; }
.stats-section-header .stats-section-hint { margin-left: auto; }
.audience-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.audience-grid .stats-section { padding: 0; }
.audience-grid .stats-trend-wrap { height: 260px; }
.chart-badges-row { display: flex; gap: 8px; padding: 0 14px 6px; align-items: center; }
.chart-badge { display: inline-flex; flex-direction: column; gap: 1px; padding: 4px 9px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); }
.chart-badge-val { font-size: 13px; font-weight: 700; }
.chart-badge-lbl { font-size: 10px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.chart-period-lbl { font-size: 11px; color: var(--muted); margin-left: auto; }
.chart-hist-label { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 6px 14px 2px; border-top: 1px solid var(--line); }
.chart-hist-zone { position: relative; height: 100px; padding: 0 14px 10px; }
.chart-toggle-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px 3px 6px; border-radius: 6px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-size: 12px; cursor: pointer;
  transition: all .12s;
}
.chart-toggle-btn.active { border-color: color-mix(in srgb, var(--c) 35%, transparent); background: color-mix(in srgb, var(--c) 10%, transparent); color: var(--text); }
.chart-toggle-btn:hover:not(.active) { background: var(--panel-soft); color: var(--text); }

/* ── Batch bar: progress row ───────────────────────────────────────────── */
.compact-batchbar { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.batchbar-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%;
}
.batchbar-progress-wrap {
  display: flex; flex-direction: column; gap: 5px; padding: 8px 0 2px;
}
.batchbar-progress-bar {
  height: 3px; background: var(--line); border-radius: 2px; overflow: hidden;
}
.batchbar-progress-fill {
  height: 100%; background: var(--brand); border-radius: 2px;
  animation: batchbar-sweep 1.5s cubic-bezier(0.65,0,0.35,1) infinite;
  transform-origin: left;
}
@keyframes batchbar-sweep {
  0%   { transform: translateX(-100%) scaleX(0.4); }
  50%  { transform: translateX(60%) scaleX(0.7); }
  100% { transform: translateX(200%) scaleX(0.4); }
}
.batchbar-status-text {
  font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .01em;
}
.batchbar--loading .batchbar-row select,
.batchbar--loading .batchbar-row button { opacity: 0.45; pointer-events: none; }

/* ── Toast notifications ───────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none; max-width: 340px;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px;
  background: var(--text); color: #f8fafd;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 18px rgba(23,32,42,.22);
  animation: toast-in 220ms cubic-bezier(0.16,1,.3,1) both;
  min-width: 200px;
}
.toast--success .toast-icon { color: #5ceb9a; flex-shrink: 0; }
.toast--error { background: #fff5f6; color: var(--danger); border: 1px solid #f5c0c6; }
.toast--error .toast-icon { color: var(--danger); flex-shrink: 0; }
.toast-text { flex: 1; }
.toast-close {
  background: none; border: none; cursor: pointer; padding: 0 0 0 4px;
  font-size: 16px; line-height: 1; color: inherit; opacity: 0.55;
  transition: opacity .12s; flex-shrink: 0;
}
.toast-close:hover { opacity: 1; }
.toast--out { animation: toast-out 200ms cubic-bezier(0.7,0,.84,0) both; }
@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateY(0);   opacity: 1; }
  to   { transform: translateY(8px); opacity: 0; }
}

/* ── Delete confirmation dialog ────────────────────────────────────────── */
#delete-confirm-dialog {
  border: none; border-radius: 12px; padding: 28px;
  max-width: 400px; width: calc(100% - 32px);
  box-shadow: var(--shadow);
}
#delete-confirm-dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-title { margin: 0 0 16px; font-size: 1rem; font-weight: 700; color: var(--text); }
.delete-previews { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.delete-preview-item {
  font-size: 13px; color: var(--muted); line-height: 1.4;
  background: var(--panel-soft); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px;
}
.delete-preview-more { font-size: 12px; color: var(--muted); font-weight: 600; padding-left: 2px; }
.dialog-warning { margin: 0 0 20px; font-size: 13px; color: var(--danger); font-weight: 600; }

/* ── Reduced motion overrides ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .toast, .toast--out { animation: none; opacity: 1; transform: none; }
  .toast--out { opacity: 0; }
  .batchbar-progress-fill { animation: none; width: 100%; }
}
.chart-toggle-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #888); flex-shrink: 0; }

/* ── /crm/comments KPI strip ───────────────────────────────────────────── */
.comments-period-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}
.comments-period-label { font-weight: 700; color: var(--muted); }
.comments-period-dates { color: var(--muted); }

.dash-kpis.comments-kpis {
  /* Три KPI-плитки равной ширины (по трети), независимо от пропорций колонок ниже. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

/* ── KPI mobile responsive — должно идти ПОСЛЕ всех desktop-правил
   .dash-kpis / .comments-kpis, чтобы перебивать их cascade ──────────────── */
@media (max-width: 1023px) {
  .dash-kpis,
  .dash-kpis.comments-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
}
@media (max-width: 600px) {
  .dash-kpis,
  .dash-kpis.comments-kpis {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .kpi-card { padding: 12px 14px; }
  .kpi-value { font-size: 22px; }
  .kpi-label { font-size: 9px; letter-spacing: .06em; }
  .kpi-delta { font-size: 11px; flex-wrap: wrap; }
  .kpi-delta span { display: none; }
}
a.kpi-card-clickable {
  text-decoration: none;
  color: inherit;
  transition: background .12s, border-color .12s;
}
a.kpi-card-clickable:hover {
  background: var(--panel-soft);
  border-color: #cdd4ff;
}

/* ── Risk pill in comment cards ───────────────────────────────────────── */
.risk-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}
.risk-pill .risk-dot { flex-shrink: 0; }
.risk-pill-num {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Inverted delta for "bad-when-up" metrics (e.g. % нежелательных, скрыто, удалено):
   стрелка показывает направление изменения, цвет — оценку (рост = тревога). */
.kpi-delta.delta-up-bad { color: var(--danger); }
.kpi-delta.delta-up-bad::before { content: "▲"; font-size: 9px; }
.kpi-delta.delta-down-good { color: var(--success); }
.kpi-delta.delta-down-good::before { content: "▼"; font-size: 9px; }

/* Platform mark inline icon */
.ig-mark i { font-size: 13px; margin-right: 4px; vertical-align: -2px; }
.ig-mark.platform-instagram i { color: #c13584; }
.ig-mark.platform-youtube   i { color: #ff0000; }
.ig-mark.platform-tiktok    i { color: var(--text); }

/* Accounts page — per-platform sections + dual connect buttons */
.accounts-section { margin-top: 24px; }
.accounts-section-title { margin: 0 0 12px; font-size: 1rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.accounts-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
