/* ============ Токены: светлая тема ============ */
:root {
  --bg: #eef2f1;          /* фон рабочей области — холодный серо-зелёный */
  --surface: #ffffff;     /* панели */
  --surface-2: #f6f8f7;   /* шапки таблиц, вложенные блоки */
  --text: #15201f;
  --muted: #5f6b69;
  --faint: #8a9794;
  --line: #dbe2e0;
  --line-strong: #c4cecb;
  --accent: #0f8b8d;      /* «сигнал» */
  --accent-ink: #0b6d6f;
  --accent-soft: #dff1f0;
  --live: #d98b16;        /* идёт сейчас / внимание */
  --ok: #18794e; --ok-soft: #e1f4ea;
  --bad: #c2362f; --bad-soft: #fbe7e5;
  --warn: #9a5b00; --warn-soft: #fdf0d9;
  --info: #0b6d6f; --info-soft: #dff1f0;
  --side: #10201e;        /* боковое меню */
  --side-text: #a9bab6;
  --side-active: #ffffff;
  --side-hover: #1a2e2b;
  --focus: 0 0 0 3px rgba(15, 139, 141, .28);
  --r-panel: 14px;
  --r-ctl: 8px;
  color-scheme: light;
}

/* ============ Тёмная тема ============ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1513; --surface: #131d1b; --surface-2: #18241f; --text: #e4ecea; --muted: #93a29e; --faint: #6c7c78;
    --line: #233230; --line-strong: #2f413e; --accent: #2bb3b1; --accent-ink: #5fd0ce; --accent-soft: #143331;
    --live: #f0a83a; --ok: #4cc38a; --ok-soft: #12301f; --bad: #f0716a; --bad-soft: #3a1917;
    --warn: #f0b354; --warn-soft: #36270c; --info: #5fd0ce; --info-soft: #143331;
    --side: #0a110f; --side-text: #8a9c97; --side-active: #ffffff; --side-hover: #15211e;
    --focus: 0 0 0 3px rgba(43, 179, 177, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1513; --surface: #131d1b; --surface-2: #18241f; --text: #e4ecea; --muted: #93a29e; --faint: #6c7c78;
  --line: #233230; --line-strong: #2f413e; --accent: #2bb3b1; --accent-ink: #5fd0ce; --accent-soft: #143331;
  --live: #f0a83a; --ok: #4cc38a; --ok-soft: #12301f; --bad: #f0716a; --bad-soft: #3a1917;
  --warn: #f0b354; --warn-soft: #36270c; --info: #5fd0ce; --info-soft: #143331;
  --side: #0a110f; --side-text: #8a9c97; --side-active: #ffffff; --side-hover: #15211e;
  --focus: 0 0 0 3px rgba(43, 179, 177, .35);
  color-scheme: dark;
}

/* ============ База ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Onest", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
h1 { font-size: 26px; line-height: 1.2; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 14px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 10px; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.plus { color: var(--ok); } .minus { color: var(--bad); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ============ Каркас: боковое меню + контент ============ */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--side) 232px, transparent 232px); }
.side {
  border-right: 1px solid var(--line);
  background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15.5px; letter-spacing: -0.01em; padding: 4px 10px 20px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 17px; height: 17px; color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; color: var(--side-text); padding: 9px 10px; border-radius: 9px;
  font-weight: 500; position: relative;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--side-hover); color: #e9f1ef; text-decoration: none; }
.nav a.active { background: var(--side-hover); color: var(--side-active); }
.nav a.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav .count { margin-left: auto; font-size: 11.5px; font-weight: 600; background: var(--live); color: #1b1300; border-radius: 99px; padding: 0 7px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid rgba(255,255,255,.07); padding-top: 12px; }
.side-foot button, .side-foot a {
  display: flex; align-items: center; gap: 11px; width: 100%; background: none; border: 0; color: var(--side-text);
  font: inherit; padding: 8px 10px; border-radius: 9px; cursor: pointer; text-align: left;
}
.side-foot button:hover, .side-foot a:hover { background: var(--side-hover); color: #e9f1ef; text-decoration: none; }
.side-foot svg { width: 17px; height: 17px; }
.side-user { font-size: 12px; color: var(--faint); padding: 6px 10px 0; }

.main { min-width: 0; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 32px 64px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; background: none; }
  .side { position: sticky; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; gap: 6px; overflow-x: auto; }
  .brand { padding: 0 6px 0 2px; }
  .brand > span:last-child { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .nav a.active::before { display: none; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; border: 0; padding: 0; }
  .side-foot .label, .side-user { display: none; }
  .wrap { padding: 20px 16px 48px; }
}

/* ============ Заголовок страницы ============ */
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head > div:first-child { min-width: 0; }
.head .muted { max-width: 72ch; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ============ Панели ============ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 20px; margin-bottom: 18px; }
.card > h2:first-child { margin-top: -2px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-3 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 960px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ============ Приборная полоса показателей ============ */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  margin-bottom: 18px; overflow: hidden;
}
.stat { padding: 16px 20px 17px; border-left: 1px solid var(--line); margin-left: -1px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin-top: 4px; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ============ Таблицы ============ */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); border-bottom-color: var(--line-strong); white-space: nowrap; }
th:first-child { border-top-left-radius: 8px; } th:last-child { border-top-right-radius: 8px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td, table tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

/* ============ Статусы ============ */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
/* Единственная анимация: «живой» индикатор */
.badge.live { background: var(--warn-soft); color: var(--live); }
.badge.pulse::before { animation: pulse 2.2s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }

/* ============ Уведомления ============ */
.flash { padding: 12px 14px 12px 16px; border-radius: 10px; margin-bottom: 14px; border: 1px solid; border-left-width: 4px; }
.flash.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--text); }
.flash.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--text); }
.flash.warn { background: var(--warn-soft); border-color: var(--live); color: var(--text); }

/* ============ Формы ============ */
label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
label.inline { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; margin: 6px 14px 6px 0; }
input[type=text], input[type=password], input[type=datetime-local], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
  font: inherit; color: var(--text); background: var(--surface); transition: border-color .12s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=file] { font: inherit; font-size: 13px; color: var(--muted); }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text); border-radius: 7px; padding: 6px 12px; margin-right: 10px; cursor: pointer; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.45; }

/* ============ Кнопки ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--text); padding: 8px 15px; border-radius: var(--r-ctl); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #04201f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #04201f; } }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 5px 11px; font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* ============ Прогресс рассылки ============ */
.progress { height: 8px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); border-radius: 99px; overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.progress .sent { background: var(--ok); } .progress .blocked { background: var(--bad); }
.progress .deactivated { background: var(--faint); } .progress .failed { background: var(--live); }

/* ============ Разное ============ */
.project { margin-bottom: 20px; }
.project-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }
.project-head h2 { margin: 0 6px 0 0; }
.bot-check { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; display: flex; gap: 9px; align-items: flex-start; font-weight: 500; margin: 0; cursor: pointer; background: var(--surface); }
.bot-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.preview { background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); border-radius: 14px; padding: 16px; }
.bubble { background: var(--surface); border-radius: 14px 14px 14px 4px; padding: 10px 12px; max-width: 420px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 0 var(--line-strong); }
.bubble .file { background: var(--surface-2); border-radius: 8px; padding: 8px; margin-bottom: 8px; font-size: 13px; }
.kb { max-width: 420px; margin-top: 4px; }
.kb-row { display: flex; gap: 4px; margin-top: 4px; }
.kb-row span { flex: 1; text-align: center; background: color-mix(in srgb, var(--surface) 75%, transparent); border-radius: 8px; padding: 6px; font-size: 13px; font-weight: 500; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; align-items: end; }
.filters label { margin-top: 0; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr; } }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.empty a { font-weight: 600; }
details summary { cursor: pointer; font-weight: 600; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; display: block; }
.empty-thumb { background: var(--surface-2); color: var(--faint); display: flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 1px var(--line); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.chips a { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line-strong); color: var(--text); font-weight: 500; font-size: 13px; background: var(--surface); }
.chips a:hover { text-decoration: none; border-color: var(--faint); }
.chips a.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.chips a .n { color: var(--faint); margin-left: 4px; }
.chips a.on .n { color: inherit; opacity: .7; }

/* ============ Вход ============ */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(circle at 20% 15%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 45%), var(--bg); }
.login { width: 100%; max-width: 380px; }
.login .brand { color: var(--text); padding: 0 0 18px; }

/* Выбор шаблона */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tpl button { all: unset; box-sizing: border-box; display: flex; flex-direction: column; gap: 8px; width: 100%; height: 100%; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 20px; }
.tpl button:hover { border-color: var(--accent); }
.tpl button:focus-visible { box-shadow: var(--focus); }
.tpl-icon { font-size: 28px; line-height: 1; }
.tpl-title { font-weight: 650; font-size: 16px; }
.tpl-desc { color: var(--muted); font-size: 13px; line-height: 1.45; flex: 1; }
.tpl-go { color: var(--accent-ink); font-weight: 600; font-size: 13px; }
.tpl-blank button { border-style: dashed; background: transparent; }

/* Узкое меню (иконки) — в конструкторе, чтобы схеме было просторнее */
@media (min-width: 901px) {
  .shell.nav-mini { grid-template-columns: 64px 1fr; background: linear-gradient(to right, var(--side) 64px, transparent 64px); }
  .shell.nav-mini .side { padding: 14px 8px; }
  .shell.nav-mini .brand { padding: 2px 9px 16px; }
  .shell.nav-mini .brand > span:not(.brand-mark),
  .shell.nav-mini .nav a span, .shell.nav-mini .side-foot .label, .shell.nav-mini .side-user { display: none; }
  .shell.nav-mini .nav a, .shell.nav-mini .side-foot button, .shell.nav-mini .side-foot a { justify-content: center; padding: 10px 0; }
  .shell.nav-mini .nav a.active::before { left: -8px; }
  /* Полный экран: меню прячется совсем */
  .shell.nav-mini.fe-full { grid-template-columns: 1fr; background: none; }
  .shell.nav-mini.fe-full .side { display: none; }
}
