:root {
  color-scheme: light dark;
  --bg: #000814;
  --panel: #1e2632;
  --border: #2c3644;
  --text: #ffffff;
  --muted: #aeb0b3;
  --accent: #0096d3;
  --good: #06b457;
  --bad: #dd272c;

  --cat-1: #feb02b;
  --cat-2: #dd272c;
  --cat-3: #9d3b8c;
  --cat-4: #0096d3;
  --cat-5: #06b457;

  --accent-gradient: linear-gradient(90deg, #feb02b 0%, #dd272c 25%, #9d3b8c 50%, #0096d3 75%, #06b457 100%);
}

* { box-sizing: border-box; }

@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/vendor/fonts/poppins-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/vendor/fonts/poppins-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/vendor/fonts/poppins-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/vendor/fonts/poppins-700.woff2') format('woff2');
}

body {
  margin: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.login-screen {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
  background: var(--bg);
}

.login-card { position: relative; z-index: 1; width: 100%; max-width: 340px; }

.login-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  mix-blend-mode: screen;
  will-change: transform;
  pointer-events: none;
}

.login-blob--1 {
  width: 480px;
  height: 480px;
  left: -120px;
  top: -80px;
  background: radial-gradient(circle, #06b457 0%, transparent 70%);
  animation: loginBlobDrift1 9s ease-in-out infinite;
}

.login-blob--2 {
  width: 520px;
  height: 520px;
  right: -160px;
  top: 10%;
  background: radial-gradient(circle, #9d3b8c 0%, transparent 70%);
  animation: loginBlobDrift2 11s ease-in-out infinite;
}

.login-blob--3 {
  width: 440px;
  height: 440px;
  left: 10%;
  bottom: -180px;
  background: radial-gradient(circle, #0096d3 0%, transparent 70%);
  animation: loginBlobDrift3 10s ease-in-out infinite;
}

.login-blob--4 {
  width: 360px;
  height: 360px;
  right: 8%;
  bottom: -140px;
  background: radial-gradient(circle, #feb02b 0%, transparent 70%);
  animation: loginBlobDrift1 13s ease-in-out infinite reverse;
}

@keyframes loginBlobDrift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(180px, 120px) scale(1.35); }
}

@keyframes loginBlobDrift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-160px, 180px) scale(1.3); }
}

@keyframes loginBlobDrift3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(140px, -160px) scale(1.4); }
}

@media (prefers-reduced-motion: reduce) {
  .login-blob { animation: none; }
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 0.5rem 1.25rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.app-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.app-switch-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.45rem;
  cursor: pointer;
  white-space: nowrap;
}

.app-switch-btn.active {
  background: var(--accent);
  color: white;
}

.side-nav { display: flex; flex-direction: column; gap: 0.2rem; }

.side-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  text-align: left;
  width: 100%;
}

.side-link:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.side-link.active { color: var(--text); background: rgba(0, 150, 211, 0.15); }

.side-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent-gradient);
}

.side-icon { width: 18px; height: 18px; flex-shrink: 0; fill: currentColor; }

.main-area { flex: 1; min-width: 0; }

main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.card h2 { margin-top: 0; font-size: 1rem; color: var(--muted); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: rgba(255,255,255,0.02); }

.row-link { cursor: pointer; color: var(--accent); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.form-grid input, .form-grid textarea, .form-grid select, #bulk-json {
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

.form-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.checkbox { flex-direction: row !important; align-items: center; gap: 0.4rem !important; }
.checkbox-group { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.5rem; }

.checkbox-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 0.5rem !important;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
}

.filter-bar { display: flex; gap: 1.5rem; align-items: flex-end; flex-wrap: wrap; }
.filter-label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.filter-label select {
  padding: 0.4rem 0.6rem;
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  min-width: 180px;
}

.range-buttons { display: flex; gap: 0.4rem; }

.project-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.project-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.project-chip:hover { border-color: var(--accent); color: var(--text); }

.project-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.project-chip .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-color, var(--muted));
  flex-shrink: 0;
}

.project-chip-clear {
  color: var(--bad);
  border-color: var(--bad);
  background: transparent;
}

.project-chip-clear:hover {
  background: var(--bad);
  color: white;
}
.range-btn {
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.range-btn.active { color: var(--text); background: rgba(79, 140, 255, 0.15); border-color: var(--accent); }

.crm-filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.crm-range-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.crm-range-filter input[type="date"] {
  padding: 0.35rem 0.5rem;
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.82rem;
}

#crm-range-error { margin-top: 0.5rem; }
#crm-range-error:empty { display: none; }

.summary-line { font-size: 0.95rem; color: var(--text); }
.summary-line b { color: var(--accent); }

.form-actions { grid-column: 1 / -1; display: flex; gap: 0.6rem; }

button.btn-primary, button.btn-secondary {
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-secondary { background: transparent; color: var(--text); }

.test-result { margin-top: 0.75rem; font-size: 0.85rem; white-space: pre-wrap; }
.ok { color: var(--good); }
.err { color: var(--bad); }

.hint { color: var(--muted); font-size: 0.85rem; margin-top: -0.5rem; }
.hint-inline { color: var(--muted); font-size: 0.8rem; }

.table-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}
.table-footer button:disabled { opacity: 0.4; cursor: not-allowed; }

#bulk-json { margin-bottom: 0.75rem; font-family: monospace; }

.pct-good { color: var(--good); }
.pct-bad { color: var(--bad); }

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  overflow: hidden;
}

.stat-tile::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-gradient);
}

.stat-label { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.4rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-value.good { color: var(--good); }
.stat-value.bad { color: var(--bad); }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
}

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.panel-header h2 { margin: 0; }

button.danger { color: var(--bad); border-color: var(--bad); }

.code-editor {
  width: 100%;
  min-height: 320px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  background: #0a0c10;
  color: #d8dbe0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background 0.15s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(720px, 92vw);
  height: min(800px, 88vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.preview-iframe-slot {
  flex: 1;
  display: flex;
}

.preview-iframe {
  flex: 1;
  border: none;
  background: white;
  width: 100%;
  height: 100%;
}

.template-subject-hint { color: var(--muted); font-size: 0.8rem; }

.modal-box-scroll {
  width: min(640px, 92vw);
  height: auto;
  max-height: 88vh;
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-section-title {
  grid-column: 1 / -1;
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.inline-checkbox {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  font-size: 0.8rem;
}

.input-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-icon-wrap input {
  flex: 1;
  min-width: 0;
}

.input-icon-wrap .input-icon {
  position: absolute;
  left: 0.6rem;
  width: 16px;
  height: 16px;
  fill: var(--muted);
  pointer-events: none;
}

.input-icon-wrap input {
  padding-left: 2.1rem;
}

.password-wrap input {
  padding-right: 2.3rem;
}

.password-toggle-btn {
  position: absolute;
  right: 0.4rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  opacity: 0.6;
  padding: 0.2rem 0.3rem;
}
.password-toggle-btn:hover { opacity: 1; }

.provider-fields {
  grid-column: 1 / -1;
  display: none;
}
.provider-fields.active { display: grid; }

.provider-hint { grid-column: 1 / -1; margin-top: 0; }

.provider-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.provider-choice-card {
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}
.provider-choice-card:hover { border-color: var(--accent); background: rgba(79, 140, 255, 0.08); }

.provider-choice-title { font-weight: 700; font-size: 1rem; margin-bottom: 0.4rem; }
.provider-choice-desc { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }

.CodeMirror {
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 480px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.85rem;
}

/* ---------- Dashboard: new card grid ---------- */

.grid-2 {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1.25rem;
}
.grid-2.reverse { grid-template-columns: 1fr 1.1fr; }

@media (max-width: 900px) {
  .grid-2, .grid-2.reverse { grid-template-columns: 1fr; }
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}
.card-head h2 { margin: 0; }

.card-legend {
  display: flex;
  gap: 0.9rem;
  font-size: 0.78rem;
  color: var(--muted);
  align-items: center;
}
.card-legend.muted-text { color: var(--muted); font-size: 0.78rem; }

.legend-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
}

.chart-tall-wrap { position: relative; height: 260px; }
.chart-tall-wrap canvas { width: 100% !important; height: 100% !important; }

.donut-row { display: flex; align-items: center; gap: 1.5rem; }
.donut-canvas-wrap { position: relative; width: 150px; height: 150px; flex-shrink: 0; }
.donut-canvas-wrap.small { width: 120px; height: 120px; }
.donut-canvas-wrap canvas { width: 100% !important; height: 100% !important; }

.donut-stats { display: flex; flex-direction: column; gap: 0.85rem; flex: 1; min-width: 0; }
.donut-stat-label { display: flex; align-items: center; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.15rem; }
.donut-stat-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.bar-list { display: flex; flex-direction: column; gap: 0.85rem; }
.bar-row { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 0.75rem; }
.bar-row-name { font-size: 0.85rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { position: relative; height: 9px; background: #0d0f14; border-radius: 100px; overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 100px; }
.bar-row-value { font-size: 0.82rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.source-list { display: flex; flex-direction: column; gap: 0.6rem; flex: 1; min-width: 0; }
.source-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.83rem; }
.source-item .name { color: var(--muted); flex: 1; }
.source-item .pct { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

.leader-list { display: flex; flex-direction: column; }
.leader-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.leader-row:last-child { border-bottom: none; padding-bottom: 0; }
.leader-avatar {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: #0b0d12;
  flex-shrink: 0;
}
.leader-main { flex: 1; min-width: 0; }
.leader-label { font-size: 0.85rem; color: var(--text); font-weight: 600; }
.leader-email { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-value { text-align: right; }
.leader-count { font-size: 0.92rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.leader-rate { font-size: 0.72rem; color: var(--good); }
.leader-empty, .bar-list-empty { color: var(--muted); font-size: 0.85rem; }

/* ---------- добавлено для почтовой панели ---------- */

.filter-bar { justify-content: space-between; width: 100%; }

td .btn-secondary,
td .btn-primary {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  margin-right: 0.3rem;
}

.modal-section-title button {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

#export-json { min-height: 260px; }

code {
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.85em;
}
