:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1b2330;
  --muted: #667085;
  --accent: #1f8fd6;
  --accent-soft: #e6f3fc;
  --ok: #12a150;
  --ok-soft: #e7f6ee;
  --warn: #c77700;
  --warn-soft: #fff4e0;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --gray-soft: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.layout { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #16202c; color: #c9d3df; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; display: flex; gap: 8px; align-items: center; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: #2aabee; box-shadow: 0 0 0 4px rgba(42, 171, 238, .2); }
.nav a { display: flex; align-items: center; gap: 10px; color: #c9d3df; padding: 8px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(42, 171, 238, .16); color: #fff; }
.nav .icon { width: 18px; text-align: center; opacity: .9; }
.sidebar .me { margin-top: auto; font-size: 13px; padding: 10px; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar .me button { background: none; border: 0; color: #8fa1b5; padding: 0; cursor: pointer; font: inherit; }
.main { padding: 24px 32px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

/* ---------- плашки ---------- */
.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: #7a4a00; border: 1px solid #f5d9a8; }
.banner.danger { background: var(--danger-soft); color: #8a1c14; border: 1px solid #f5c2bd; }
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; background: var(--ok-soft); color: #0b5c2e; border: 1px solid #bfe5cf; }
.flash.error { background: var(--danger-soft); color: #8a1c14; border-color: #f5c2bd; }
.errors { background: var(--danger-soft); border: 1px solid #f5c2bd; color: #8a1c14; border-radius: var(--radius); padding: 10px 14px 10px 30px; margin: 0 0 16px; }
.warnings { background: var(--warn-soft); border: 1px solid #f5d9a8; color: #7a4a00; border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.bot-card { display: block; color: inherit; }
.bot-card:hover { text-decoration: none; border-color: #c5d3e2; }
.bot-card .name { font-weight: 600; }
.kv { display: flex; gap: 18px; margin-top: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.kv b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- таблицы ---------- */
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable:hover td { background: #f9fbfd; cursor: pointer; }
.table .snip { color: var(--muted); font-size: 13px; max-width: 460px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- бейджи ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: #475467; white-space: nowrap; }
.badge.blue { background: var(--accent-soft); color: #0b5d94; }
.badge.green { background: var(--ok-soft); color: #0b6b35; }
.badge.orange { background: var(--warn-soft); color: #8a5300; }
.badge.red { background: var(--danger-soft); color: #a3261b; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }

/* ---------- кнопки и формы ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a7fc0; }
.btn.danger { color: var(--danger); border-color: #f1c2bd; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 500; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline { display: inline; }
form.stack > * + * { margin-top: 14px; }
.field label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field .hint, .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd6df; border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 143, 214, .25); border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }
.duration { display: flex; gap: 6px; }
.duration input { width: 110px; }
.duration select { width: 120px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 3px; }
.radio-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-cards label { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; display: flex; gap: 8px; align-items: center; cursor: pointer; font-weight: 500; }
.radio-cards label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; background: var(--bg); border-top: 1px solid var(--border); padding: 12px 0; margin-top: 8px; }

/* ---------- редактор сообщения ---------- */
.editor .toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.editor .toolbar button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px; padding: 3px 9px; cursor: pointer; font-size: 13px; }
.editor .toolbar button:hover { background: var(--accent-soft); }
.editor textarea[name=text] { min-height: 190px; font-size: 15px; }
.counter { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; gap: 10px; }
.counter .over { color: var(--danger); font-weight: 600; }
.media-list { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.media-item { width: 132px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); font-size: 12px; }
.media-item .thumb { height: 88px; display: flex; align-items: center; justify-content: center; background: #e9eef4; color: var(--muted); font-size: 26px; }
.media-item .thumb img, .media-item .thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-item .meta { padding: 5px 7px; }
.media-item .meta .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview { background: #d9e7f1; border-radius: var(--radius); padding: 14px; }
.bubble { background: #fff; border-radius: 12px; padding: 9px 12px; max-width: 420px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); font-size: 14.5px; }
.bubble .btns { margin-top: 8px; display: grid; gap: 4px; }
.bubble .btns span { display: block; text-align: center; background: #eef5fb; color: #1f7bc0; border-radius: 8px; padding: 6px; font-weight: 550; font-size: 13.5px; }

/* ---------- прогресс ---------- */
.progress { height: 12px; background: var(--gray-soft); border-radius: 999px; overflow: hidden; display: flex; }
.progress > span { display: block; height: 100%; }
.progress .sent { background: var(--ok); }
.progress .blocked { background: #f0a14a; }
.progress .failed { background: var(--danger); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* ---------- календарь ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 220px; display: flex; flex-direction: column; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day.past { background: #fafbfc; }
.day-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }
.day-head a { font-size: 18px; line-height: 1; padding: 0 4px; }
.day-body { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.post-chip { display: block; border-radius: 8px; padding: 6px 8px; background: var(--surface-2); border: 1px solid var(--border); color: inherit; font-size: 12.5px; border-left: 3px solid #98a2b3; }
.post-chip:hover { text-decoration: none; border-color: #c5d3e2; }
.post-chip.scheduled { border-left-color: var(--accent); }
.post-chip.published { border-left-color: var(--ok); opacity: .8; }
.post-chip.failed, .post-chip.check { border-left-color: var(--danger); background: #fff7f6; }
.post-chip.draft { border-left-style: dashed; }
.post-chip .t { font-weight: 650; }
.post-chip .c { color: var(--muted); }
.post-chip .x { color: var(--text); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { color: var(--text); justify-content: center; padding-bottom: 14px; font-size: 20px; }

.steps li { margin-bottom: 6px; }
.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; }

@media (max-width: 980px) {
  .calendar { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 10px 12px; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; }
  .sidebar .me { display: none; }
  .brand { padding-bottom: 8px; }
  .main { padding: 16px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .table .hide-sm { display: none; }
}
