:root {
  --bg: #0a0b0e;
  --bg2: #111318;
  --bg3: #191c23;
  --border: #262b36;
  --text: #e8ebf1;
  --muted: #8b95a7;
  --accent: #ff6e14;
  --accent2: #ff8b45;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 58px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

.tab:hover { color: var(--text); background: var(--bg3); }
.tab.active { color: var(--text); background: var(--bg3); font-weight: 600; }

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  text-align: center;
}
.badge:empty { display: none; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.demo-pill {
  background: var(--amber);
  color: #000;
  font-weight: 700;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  cursor: default;
}

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 7, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.login-box { width: 340px; }
.login-title { text-align: center; margin-bottom: 16px; }

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.acc-info-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.acc-info-row span:first-child { color: var(--muted); }
.acc-info-row span:last-child { min-width: 0; overflow-wrap: anywhere; }
.demo-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: var(--amber);
  color: #000;
  padding: 1px 7px;
  border-radius: 8px;
  margin-left: 6px;
  vertical-align: middle;
}

main { padding: 26px 24px; max-width: 1800px; margin: 0 auto; }
.tab-page { display: none; }
.tab-page.active { display: block; }

h1 { font-size: 22px; margin-bottom: 18px; }
h2 { font-size: 13px; margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }

/* ---- Главная ---- */
.home-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 18px; }
.home-head h1 { margin: 0; }
.home-date { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.stat-num { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-lbl { color: var(--text); font-weight: 600; margin-top: 6px; }
.stat-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat-sub.warn { color: var(--accent); }
.stat-sub.ok { color: var(--green); }

.home-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.home-cols .panel { margin-bottom: 0; }

.home-chat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
}
.home-chat:last-child { border-bottom: none; }
.home-chat:hover { background: var(--bg3); }
.home-chat-info { flex: 1; min-width: 0; }
.home-chat-name { font-weight: 600; }
.home-chat-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.home-acc {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
}
.home-acc:last-child { border-bottom: none; }
.home-acc:hover { background: var(--bg3); }
.home-acc-info { min-width: 0; }
.home-acc-name { font-weight: 600; }
.home-acc-sub { color: var(--muted); font-size: 13px; }

/* ---- Аккаунты: строки ---- */
.acc-rows { display: flex; flex-direction: column; gap: 8px; }
.acc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color .15s;
}
.acc-row:hover { border-color: var(--accent); }
.acc-row.open { border-color: var(--accent); background: var(--bg2); }
.acc-row-name { font-weight: 600; }
.acc-row-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.acc-row-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.acc-row-check { color: var(--muted); font-size: 12px; }
.acc-detail {
  margin-top: 10px;
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
}
.acc-detail:not(.hidden) { animation: unfold .28s ease; }
@keyframes unfold {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}
.acc-detail .modal-head { margin-bottom: 10px; }
.acc-proxy-edit { margin-top: 10px; }
.acc-proxy-edit-lbl { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.acc-proxy-edit-row { display: flex; gap: 8px; }
.acc-proxy-edit-row input { flex: 1; min-width: 0; }
.acc-proxy-edit-row input:disabled { opacity: .5; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:disabled:hover { border-color: var(--border); }

.admin-cols { display: grid; grid-template-columns: minmax(0, 860px) 300px; gap: 16px; justify-content: center; align-items: start; }
.admin-panel input { width: 100%; }
.admin-side { display: flex; flex-direction: column; gap: 10px; }
.admin-side input { width: 100%; }
.admin-side .hint { margin: 0; }
#tab-admin h1 { text-align: center; }
.admin-users { margin-top: 12px; display: flex; flex-direction: column; }
.admin-user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 4px; border-bottom: 1px solid var(--border); font-size: 13px;
  cursor: pointer;
}
.admin-user-row:hover { color: var(--accent); }
.admin-user-row.open { color: var(--accent); background: var(--bg2); border-radius: 8px; }
.admin-user-row.banned { opacity: .55; }
.admin-user-row.banned.open { opacity: 1; }
.ban-tag { background: rgba(239,68,68,.15); color: var(--red); }
.admin-user-id { color: var(--muted); width: 44px; flex-shrink: 0; }
.admin-user-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.admin-user-date { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.login-box .form-row + .btn { margin-top: 4px; align-self: center; }

.status { font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 600; white-space: nowrap; color: var(--muted); background: rgba(139,149,167,.12); }
.status.active, .status.ok { background: rgba(34,197,94,.15); color: var(--green); }
.status.auth_error, .status.error, .status.config_error { background: rgba(239,68,68,.15); color: var(--red); }
.status.captcha, .status.proxy_error, .status.network_error { background: rgba(245,158,11,.15); color: var(--amber); }
.status.new { background: rgba(139,149,167,.15); color: var(--muted); }

.chats-layout {
  display: grid;
  grid-template-columns: 250px 250px 1fr 330px;
  gap: 14px;
  height: calc(100vh - 120px);
}
.chats-accs { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; overflow-y: auto; padding: 8px; }
.acc-mini-list { display: flex; flex-direction: column; gap: 4px; }
.acc-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}
.acc-mini:hover { background: var(--bg3); color: var(--text); }
.acc-mini.active { background: var(--bg3); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.acc-mini-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.acc-mini-dot.green { background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,.65); }
.acc-mini-dot.amber { background: var(--amber); box-shadow: 0 0 6px rgba(245,158,11,.65); }
.acc-mini-dot.muted { background: var(--muted); opacity: .55; }
.acc-mini-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text); }
.chats-left { display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.chats-right { display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }

.chat-tabs { display: flex; gap: 6px; padding: 8px 8px 0; flex-wrap: wrap; }
.chat-filter {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.chat-filter:hover { color: var(--text); }
.chat-filter.active { color: var(--text); border-color: var(--accent); background: var(--bg3); }
.chat-filter .cnt { font-size: 12px; margin-left: 2px; opacity: .8; }
.chat-filter.active .cnt { color: var(--accent); opacity: 1; }

.chats-toolbar { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); }
.chats-toolbar select { flex: 1; }

.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  gap: 10px;
  padding: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.chat-item:hover { background: var(--bg3); }
.chat-item.selected { background: var(--bg3); border-left: 3px solid var(--accent); }

.avatar { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; object-fit: cover; background: var(--bg3); }
.avatar.sm { width: 34px; height: 34px; }
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-last { color: var(--text); opacity: .8; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread-dot .chat-item-name { font-weight: 700; }
.chat-item.unread-dot .chat-item-name::after {
  content: "\25CF";
  color: var(--green);
  margin-left: 6px;
  font-size: 10px;
}

.chat-header { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-name { font-weight: 700; }
.chat-title-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.chat-sep { color: var(--border); }
.chat-subject { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-brief { color: var(--muted); font-size: 12px; margin-top: 2px; }

.chat-status-row { margin-left: auto; flex-shrink: 0; }
.chat-status-row select {
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}

.ad-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.ad-strip:hover { background: var(--bg3); }
.ad-strip-lbl { color: var(--accent); font-size: 12px; font-weight: 600; white-space: nowrap; }
.ad-strip-title { color: var(--muted); font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ad-caret { color: var(--muted); font-size: 12px; transition: transform .3s ease; }

.ad-panel {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  border-bottom: 1px solid transparent;
  transition: max-height .35s ease, opacity .3s ease, border-color .3s ease;
}
.ad-panel.open { max-height: 220px; opacity: 1; border-bottom-color: var(--border); }
.ad-panel-inner { display: flex; gap: 14px; padding: 12px 16px; align-items: center; }
.ad-photo { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: var(--bg3); }
.ad-info { min-width: 0; }
.ad-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-price { color: var(--accent); font-size: 13px; margin-top: 4px; }

.chats-side { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-width: 0; }
.side-panel { display: flex; flex-direction: column; gap: 10px; }
.side-panel textarea { width: 100%; resize: vertical; }
.tr-dirs { display: flex; gap: 6px; }
.tr-dir.active { border-color: var(--accent); color: var(--accent); }
.tr-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tr-out { color: var(--fg); font-size: 13px; white-space: pre-wrap; word-break: break-word; min-height: 14px; }

.status-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-pill.hidden { display: none !important; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 70%; padding: 10px 14px; border-radius: 14px; line-height: 1.45; word-wrap: break-word; }
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--bg3); border-bottom-left-radius: 4px; }
.msg-date { font-size: 11px; opacity: .6; margin-top: 4px; }
.msg-tr-btn { display: inline-block; font-size: 11px; color: var(--muted); cursor: pointer; margin-top: 4px; margin-right: 8px; user-select: none; }
.msg-tr-btn:hover { color: var(--accent); }
.msg-ru { margin-top: 6px; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.04); border-left: 2px solid var(--accent); padding: 4px 8px; border-radius: 4px; white-space: pre-wrap; }
.msg-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.msg-photos img { max-width: 220px; max-height: 160px; border-radius: 8px; display: block; }

.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-input-row textarea {
  flex: 1;
  resize: none;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}
.tpl-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
}
.tpl-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--fg);
  cursor: pointer;
}
.tpl-chip:hover { border-color: var(--accent); }

.chat-item-st { margin-top: 5px; }
.chat-st-badge {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

input, select, textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.form-row { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.form-inline { margin: 0; }
.file-label { color: var(--muted); font-size: 13px; }

.btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--red); }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; padding: 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.cell-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

.tpl-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.acc-cols { grid-template-columns: minmax(320px, 620px) minmax(420px, 700px); justify-content: center; }
.tpl-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.tpl-list { display: flex; flex-direction: column; gap: 8px; }
.tpl-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.tpl-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; }
.tpl-row-main { flex: 1; min-width: 0; }
.tpl-row-name { font-weight: 600; }
.tpl-row-body { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.tpl-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tpl-edit { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.tpl-edit input[type="text"], .tpl-edit input:not([type]) { width: 100%; }
.tpl-edit textarea { width: 100%; resize: vertical; }
.tpl-edit-row { display: flex; gap: 8px; align-items: center; }
.tpl-edit-row input[type="color"] { width: 46px; height: 34px; padding: 2px; }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }
.hint code { background: var(--bg3); padding: 1px 6px; border-radius: 4px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  z-index: 100;
  max-width: 70vw;
}
.toast.error { border-color: var(--red); color: #fca5a5; }

.update-popup {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 12px 16px;
  z-index: 90;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.toast.ok { border-color: var(--green); color: #86efac; }

@media (max-width: 1500px) {
  .chats-layout { grid-template-columns: 215px 215px 1fr 300px; }
}

@media (max-width: 800px) {
  .chats-layout { grid-template-columns: 1fr; height: auto; }
  .chats-accs { max-height: 220px; }
  .chats-left { max-height: 300px; }
  .chat-messages { min-height: 300px; }
  .home-cols { grid-template-columns: 1fr; }
  .chats-layout { grid-template-columns: 1fr !important; }
  .chats-side { max-height: 320px; }
  .tpl-cols, .acc-cols, .admin-cols { grid-template-columns: 1fr; }
  .acc-row { flex-direction: column; align-items: flex-start; }
  .ad-panel.open { max-height: 320px; }
}
