:root {
  /* фон и поверхности */
  --bg: #FFFFFF;
  --bg-grey: #F9F9F9;          /* блоки и поля ввода */
  --line: #F2F1F1;             /* границы карточек */
  --line-field: #E8E7E7;       /* границы полей */
  --shadow: 0 2px 16px rgba(0, 0, 0, .06);

  /* акцент */
  --bg-red: #D51D35;
  --red-hover: #BD182E;
  --red-soft: #F6EBEC;
  --red-border: #D51D353D;

  /* тёмно-синий: заголовки, текст, кнопка отправки формы */
  --text-blue: #2B2B42;
  --bg-black-btn: #2B2B42;
  --black-hover: #1E1E30;

  /* серые для текста */
  --muted: #7D7B7B;
  --label: #C0C0C0;
  --disabled: #B2B2B2;

  /* статусы */
  --orange: #ED6F41;
  --orange-soft: rgba(237, 111, 65, .12);
  --green: #13C171;
  --green-soft: rgba(19, 193, 113, .08);

  /* совместимость со старыми именами в JS */
  --text: var(--text-blue);
  --red: var(--bg-red);
  --accent: var(--bg-red);
  --panel: var(--bg-grey);

  --r-field: 12px;   /* rounded-xl */
  --r-card: 16px;    /* rounded-2xl */
  --r-modal: 24px;   /* rounded-[24px] */
  --font: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text-blue);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--bg-red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; color: var(--text-blue); }
h1 { font-size: 28px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 14px; }
.hidden { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 24px; font-weight: 600; font-size: 18px; color: var(--text-blue); }
.brand img { width: 34px; height: 34px; display: block; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-field);
  color: var(--muted); cursor: pointer; user-select: none; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg-grey); color: var(--text-blue); }
.nav-item.active { background: var(--red-soft); color: var(--bg-red); }
.nav-item .count {
  margin-left: auto; font-size: 13px; color: var(--muted);
  min-width: 24px; text-align: center; padding: 0 6px; border-radius: 999px; background: var(--bg-grey);
}
.nav-item .count:empty { display: none; }
.nav-item.active .count { background: #fff; color: var(--bg-red); }
.sidebar-bottom { margin-top: auto; }

.main { padding: 32px 40px 64px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.page-head .muted { font-size: 15px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: var(--r-field);
  border: 1px solid var(--line-field); background: var(--bg); color: var(--text-blue);
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--bg-grey); }
.btn:disabled { color: var(--disabled); cursor: not-allowed; background: var(--bg-grey); border-color: var(--line); }
.btn .i { width: 18px; height: 18px; }
/* основное действие — красный */
.btn.primary { background: var(--bg-red); border-color: var(--bg-red); color: #fff; }
.btn.primary:hover { background: var(--red-hover); border-color: var(--red-hover); }
/* мягкая кнопка */
.btn.soft { background: var(--red-soft); border-color: transparent; color: var(--bg-red); }
.btn.soft:hover { background: #F1DDDF; }
/* отправка формы — тёмно-синяя */
.btn.dark { background: var(--bg-black-btn); border-color: var(--bg-black-btn); color: #fff; }
.btn.dark:hover { background: var(--black-hover); }
.btn.primary:disabled, .btn.dark:disabled { background: var(--line-field); border-color: var(--line-field); color: var(--disabled); }
.btn.danger { color: var(--bg-red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red-border); }
.btn.sm { height: 36px; padding: 0 14px; font-size: 14px; }
.btn.icon { width: 44px; padding: 0; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text-blue); background: var(--bg-grey); }
.btn.ghost.danger { color: var(--bg-red); }
.btn.ghost.danger:hover { background: var(--red-soft); }

input, textarea, select {
  width: 100%; padding: 11px 14px; border-radius: var(--r-field);
  border: 1px solid var(--line-field); background: var(--bg-grey); color: var(--text-blue);
  font: inherit; font-size: 16px; outline: none; transition: border-color .12s, background .12s;
}
input::placeholder, textarea::placeholder { color: var(--disabled); }
input:focus, textarea:focus, select:focus { border-color: var(--bg-red); background: var(--bg); }
input:disabled { color: var(--disabled); }
select { appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%237D7B7B' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--bg-red); padding: 0; flex: none; }
input[type="file"] { padding: 9px 12px; font-size: 14px; cursor: pointer; }
input[type="file"]::file-selector-button {
  border: none; background: var(--red-soft); color: var(--bg-red); font: inherit; font-weight: 500;
  padding: 6px 12px; border-radius: 8px; margin-right: 12px; cursor: pointer;
}
label.field { display: flex; flex-direction: column; gap: 6px; }
label.field > span { font-size: 13px; color: var(--label); font-weight: 500; }
label.field > span .muted { color: var(--label); }
.row { display: flex; gap: 14px; }
.row > * { flex: 1; }
.form { display: flex; flex-direction: column; gap: 18px; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 15px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.45; }

.switch { position: relative; display: inline-block; vertical-align: middle; width: 40px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line-field); cursor: pointer; transition: .15s;
}
.switch span::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.switch input:checked + span { background: var(--bg-red); }
.switch input:checked + span::before { transform: translateX(16px); }

/* ---------- cards ---------- */
.card {
  background: var(--bg-grey); border: 1px solid var(--line); border-radius: var(--r-card); padding: 22px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(370px, 1fr)); gap: 20px; }
.empty {
  border: 1.5px dashed var(--line-field); border-radius: var(--r-card); background: var(--bg-grey);
  padding: 48px 24px; text-align: center; color: var(--muted); line-height: 1.6;
}
.empty .btn { margin-top: 18px; }

.acc-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 17px;
  background: var(--red-soft); color: var(--bg-red);
}
.acc-title { flex: 1; min-width: 0; }
.acc-title .name { font-weight: 600; font-size: 18px; }
.acc-title .sub { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-status { margin: 16px 0 14px; display: flex; flex-direction: column; gap: 6px; min-height: 52px; }
.acc-status .detail { color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-field); padding: 10px 12px; }
.stat .v { font-weight: 600; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }
.acc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.acc-actions .grow { flex: 1 1 0; min-width: 0; }
.card > .acc-actions { flex-wrap: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 7px; align-self: flex-start;
  padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--line-field); color: var(--muted);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--green); background: var(--green-soft); border-color: transparent; }
.badge.yellow { color: var(--orange); background: var(--orange-soft); border-color: transparent; }
.badge.red { color: var(--bg-red); background: var(--red-soft); border-color: var(--red-border); }
.badge.blue { color: var(--text-blue); background: var(--bg); }
.badge.green.live::before { animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line-field); white-space: nowrap;
}

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 500; font-size: 13px; color: var(--label);
  padding: 12px 16px; border-bottom: 1px solid var(--line-field);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-field); vertical-align: middle; background: var(--bg); }
.table tr:last-child td { border-bottom: none; }
.table tr.off td { color: var(--disabled); }
.table tr:hover td { background: #FCFCFC; }
.table td.actions { text-align: right; white-space: nowrap; width: 1%; }
.table-card { padding: 0; overflow: hidden; background: var(--bg); box-shadow: var(--shadow); }
.table-card .table th { background: var(--bg-grey); }

/* ---------- messages ---------- */
.msg-card { display: flex; flex-direction: column; gap: 12px; }
.msg-card.off > *:not(.msg-top):not(.msg-actions) { opacity: .5; }
.msg-card.off .title { color: var(--disabled); }
.msg-top { display: flex; align-items: center; gap: 10px; }
.msg-top .title { font-weight: 600; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-body {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-field); padding: 12px 14px;
  white-space: pre-wrap; word-break: break-word; max-height: 170px; overflow: hidden;
  font-size: 15px; position: relative;
}
.msg-file { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.msg-file .i { width: 16px; height: 16px; }
.msg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: auto; }

/* ---------- logs ---------- */
.logbox {
  background: var(--bg-grey); border: 1px solid var(--line); border-radius: var(--r-card);
  height: calc(100vh - 180px); min-height: 300px; overflow-y: auto;
  font-family: var(--mono); font-size: 13.5px; padding: 12px 0;
}
.logline { display: flex; gap: 12px; padding: 3px 18px; }
.logline:hover { background: var(--bg); }
.logline .ts { color: var(--disabled); flex: none; }
.logline .acc { color: var(--text-blue); flex: none; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.logline .txt { white-space: pre-wrap; word-break: break-word; color: var(--text-blue); }
.logline.warning .txt { color: var(--orange); }
.logline.error .txt { color: var(--bg-red); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(43, 43, 66, .35); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--bg); border-radius: var(--r-modal);
  width: 100%; max-width: 540px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(43, 43, 66, .18);
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 22px 26px 6px; }
.modal-head h2 { flex: 1; }
.modal-head .btn.ghost { width: 36px; padding: 0; border-radius: 50%; }
.modal-body { padding: 16px 26px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 26px 24px; border-top: 1px solid var(--line); }
.modal .card { background: var(--bg-grey); }

.pick-list {
  border: 1px solid var(--line-field); border-radius: var(--r-field); max-height: 240px; overflow-y: auto;
  background: var(--bg-grey);
}
.pick-list label {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line-field); font-size: 15px;
}
.pick-list label:last-child { border-bottom: none; }
.pick-list label:hover { background: var(--bg); }
.pick-list .meta { margin-left: auto; color: var(--muted); font-size: 13px; text-align: right; }
.pick-list.disabled { opacity: .5; pointer-events: none; }
.seg { display: inline-flex; background: var(--bg-grey); border: 1px solid var(--line-field); border-radius: var(--r-field); padding: 3px; }
.seg label { padding: 6px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--bg-red); color: #fff; }

.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-title h3 { flex: 1; }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-field);
  padding: 12px 16px; max-width: 380px; box-shadow: var(--shadow), 0 8px 24px rgba(0, 0, 0, .06);
  font-size: 15px; animation: slide .2s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-blue); flex: none; }
.toast.error { background: var(--red-soft); border-color: var(--red-border); color: var(--bg-red); }
.toast.error::before { background: var(--bg-red); }
.toast.ok { background: #EEFAF4; border-color: transparent; }
.toast.ok::before { background: var(--green); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

.banner {
  display: flex; align-items: center; gap: 14px;
  background: var(--red-soft); border: 1px solid var(--red-border);
  color: var(--text-blue); border-radius: var(--r-card); padding: 14px 18px; margin-bottom: 22px; font-size: 15px;
}
.banner .i { color: var(--bg-red); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--bg); border-radius: var(--r-modal); box-shadow: var(--shadow); padding: 36px 32px; }
.login-card .brand { padding: 0 0 8px; justify-content: center; font-size: 22px; flex-direction: column; gap: 14px; }
.login-card .brand img { width: 56px; height: 56px; }
.login-card .btn { height: 50px; font-size: 16px; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; border-right: none; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 8px 8px; width: 100%; }
  .nav-item { padding: 8px 10px; }
  .sidebar-bottom { margin: 0; }
  .main { padding: 22px 16px 48px; }
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row { flex-direction: column; }
}

/* ---------- chats ---------- */
.chats-summary {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  margin: -6px 0 16px; color: var(--muted); font-size: 15px;
}
.chats-summary b { color: var(--text-blue); font-weight: 600; }
.chats-summary .badge { margin-left: auto; }
.chat-title { font-weight: 500; }
.chat-meta { font-size: 13px; color: var(--muted); }
.chat-meta.err { color: var(--bg-red); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.table td.actions .btn.ghost .i { width: 16px; height: 16px; }
.assignee { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; white-space: nowrap; }
.assignee .pin { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }
.acc-head .tag { align-self: flex-start; color: var(--bg-red); background: var(--red-soft); border-color: transparent; }
.confirm-text { line-height: 1.55; }
.confirm-text .mono { color: var(--muted); }
.deleted-list { margin: 10px 0; padding-left: 20px; }
.deleted-list li { margin: 3px 0; }
.was-deleted { color: var(--orange); font-weight: 500; }
.paid-badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px;
  background: var(--orange-soft); color: var(--orange); font-weight: 600; font-size: 12.5px;
}
.table tr.paid td:first-child { box-shadow: inset 3px 0 0 var(--orange); }
.paid-sum { display: inline-flex; align-items: center; gap: 10px; color: var(--orange); }
.paid-sum b { color: var(--orange); }
.limit-note { font-size: 13px; color: var(--orange); }
.acc-head .tag.checker { color: var(--text-blue); background: var(--bg); border-color: var(--line-field); }
.acc-head { flex-wrap: wrap; }
.code-where {
  background: var(--bg-grey); border: 1px solid var(--line); border-radius: var(--r-field);
  padding: 12px 14px; font-size: 14.5px; line-height: 1.5;
}
.code-where b { font-weight: 600; }
