/* OperatorWatch v2 — стили. Slate-graphite тема, светлее чем было. */

:root {
  --bg:        #161c28;
  --bg-2:     #1c2433;
  --bg-3:     #232c3e;
  --panel:    #1d2533;
  --panel-2:  #232c3d;
  --border:   #2f3a52;
  --border-strong: #3b4763;
  --text:     #e7ecf3;
  --text-2:   #b6c0d2;
  --muted:    #7a8499;
  --accent:   #5fd882;
  --accent-2: #34c46a;
  --accent-soft: #1f3a2c;
  --warn:     #facc15;
  --warn-soft:#3a2e16;
  --bad:      #f87171;
  --bad-soft: #3a1d1d;
  --info:     #79a8e8;
  --info-soft:#1d3146;
  --shadow:   0 6px 18px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 10px;
  padding: 9px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; }
.logo {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 7px; color: #0c1418; font-weight: 800;
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  box-shadow: 0 4px 10px rgba(95, 216, 130, 0.18);
  flex-shrink: 0;
}
.title { font-weight: 700; font-size: 13px; line-height: 1; color: #fff; white-space: nowrap; }
.brand-logo { height: 30px; width: 30px; display: block; flex-shrink: 0; }
.brand-text { font-weight: 800; font-size: 17px; letter-spacing: .3px; line-height: 1; color: #fff; white-space: nowrap; }
.brand-accent { color: #2f8bff; }
.subtitle { color: var(--muted); font-size: 10px; margin-top: 2px; }

/* Вкладки — строго в один ряд; на узких экранах горизонтальный скролл вместо переноса. */
.tabs {
  display: flex; gap: 1px; justify-self: center;
  flex-wrap: nowrap; overflow-x: auto; max-width: 100%;
  scrollbar-width: thin;
}
.tabs::-webkit-scrollbar { height: 4px; }
.tab {
  background: transparent; color: var(--text-2); border: 1px solid transparent;
  padding: 6px 7px; border-radius: 7px; cursor: pointer; font-size: 11.5px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--bg-3); color: #fff; }
.tab.active { background: var(--panel-2); color: #fff; border-color: var(--border-strong); }

.meta { display: flex; align-items: center; gap: 5px; }
.status { font-size: 11px; padding: 5px 10px; border-radius: 6px; background: var(--bg-3); color: var(--muted); border: 1px solid var(--border); }
.status.ok   { color: var(--accent); border-color: #28553a; background: var(--accent-soft); }
.status.fail { color: var(--bad);    border-color: #5a2727; background: var(--bad-soft); }

.btn-mini {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  padding: 6px 11px; border-radius: 6px; cursor: pointer; font-size: 14px;
  text-decoration: none; display: inline-flex; align-items: center; line-height: 1;
  transition: background .15s;
}
.btn-mini:hover { background: var(--panel-2); }

main { padding: 18px 22px 50px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 13px; margin-bottom: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 17px;
  box-shadow: var(--shadow);
}
.card.warn { border-color: #5b3b1d; background: linear-gradient(180deg, var(--panel), var(--warn-soft)); }
.card.good { border-color: #28553a; background: linear-gradient(180deg, var(--panel), var(--accent-soft)); }
.card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.card-value { font-size: 26px; font-weight: 700; margin-top: 7px; color: #fff; }
.card-value.small { font-size: 13px; font-weight: 500; color: var(--text-2); }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 13px; margin-bottom: 13px; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; margin-bottom: 13px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 12px; font-size: 14px; color: #fff; font-weight: 600; }
.panel h4 { margin: 0 0 10px; font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.panel.hidden { display: none; }

.muted { color: var(--muted); font-size: 11px; }
.center { text-align: center; }
.pad { padding: 30px 14px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
table th, table td { text-align: left; padding: 8px 11px; border-bottom: 1px solid var(--border); vertical-align: top; }
table th { font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; background: var(--panel); }
table tbody tr:hover { background: var(--bg-3); }
table td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; }
table th.num, table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table td.text { max-width: 480px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag { display: inline-block; padding: 2px 7px; border-radius: 5px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.tag.tg { background: var(--info-soft); color: var(--info); }
.tag.wa { background: var(--accent-soft); color: var(--accent); }
.tag.op { background: var(--warn-soft); color: var(--warn); }
.tag.cl { background: #2c1d3a; color: #c084fc; }

.row-link { cursor: pointer; }
.row-link:hover { background: #283145; }

.score-pill { display: inline-block; padding: 3px 10px; border-radius: 13px; font-weight: 700; font-size: 12px; min-width: 38px; text-align: center; }
.score-bad  { background: var(--bad-soft);    color: var(--bad); }
.score-mid  { background: var(--warn-soft);   color: var(--warn); }
.score-good { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.filters label.checkbox-inline { flex-direction: row; align-items: center; gap: 6px; text-transform: none; padding-bottom: 8px; }
.filters label.checkbox-inline input[type="checkbox"] {
  width: 16px; height: 16px; min-width: 0; padding: 0; margin: 0; flex: none;
  border-radius: 4px; accent-color: var(--accent); cursor: pointer;
}
.filters input, .filters select {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 11px; font-size: 12px; min-width: 140px; font-family: inherit;
}
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 216, 130, 0.12); }

.btn, .btn-light, .btn-primary {
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text);
  padding: 8px 16px; border-radius: 7px; cursor: pointer; font-size: 12px; font-family: inherit;
  font-weight: 500;
  transition: background .15s, transform .05s;
}
.btn:hover, .btn-light:hover { background: var(--panel-2); }
.btn:active, .btn-light:active, .btn-primary:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: var(--accent-2); color: #0c1418; font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.07); }

.pager { display: flex; align-items: center; gap: 14px; margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--border); }

/* DIALOGS */
.dialogs-layout { display: grid; grid-template-columns: 380px 1fr; gap: 13px; height: calc(100vh - 116px); min-height: 520px; }
.dialogs-list { display: flex; flex-direction: column; padding: 0; overflow: hidden; margin: 0; }
.dialogs-filters { display: flex; flex-direction: column; gap: 7px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.dialogs-filters input,
.dialogs-filters select {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 11px; font-size: 12px; font-family: inherit; width: 100%;
  color-scheme: dark;            /* тёмный нативный список/стрелка */
}
.dialogs-filters select {
  -webkit-appearance: none; appearance: none; cursor: pointer; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8499' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.dialogs-filters select option { background: var(--bg-2); color: var(--text); }
.dialogs-filters input:focus,
.dialogs-filters select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 216, 130, 0.12); }
.chats-container { flex: 1; overflow-y: auto; }
.chats-group { border-bottom: 1px solid var(--border); }
.chats-group-head { display: flex; justify-content: space-between; padding: 9px 14px; background: var(--bg-3); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; z-index: 1; }
.chat-item { padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .12s; }
.chat-item:hover { background: var(--bg-3); }
.chat-item.active { background: #2a3a55; border-left: 3px solid var(--accent); padding-left: 11px; }
.chat-item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-item-title { font-weight: 600; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-item-time { color: var(--muted); font-size: 11px; }
.chat-item-snippet { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; }
.chat-item-meta { display: flex; justify-content: space-between; font-size: 10.5px; margin-top: 4px; }

.conversation { display: flex; flex-direction: column; padding: 0; overflow: hidden; margin: 0; }
.conversation-head { padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--bg-3); }
.conversation-title { font-size: 14px; font-weight: 600; color: #fff; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.conversation-sub { margin-top: 5px; font-size: 11px; }

.conversation-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.analysis-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 14px;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
  border: 1px solid var(--border-strong);
  transition: filter .12s, transform .08s;
}
.analysis-badge:hover { filter: brightness(1.15); }
.analysis-badge:active { transform: scale(0.97); }
.analysis-badge-emoji { font-size: 13px; line-height: 1; }
.analysis-badge-score { font-variant-numeric: tabular-nums; font-size: 13px; }
.analysis-badge-label { font-size: 10px; font-weight: 600; opacity: 0.75; letter-spacing: 0.04em; text-transform: uppercase; }
.analysis-badge-good { background: var(--accent-soft); color: var(--accent); border-color: #28553a; }
.analysis-badge-mid  { background: var(--warn-soft);   color: var(--warn);   border-color: #5b3b1d; }
.analysis-badge-bad  { background: var(--bad-soft);    color: var(--bad);    border-color: #5a2727; }
.analysis-badge-err  { background: var(--bg-3);        color: var(--bad);    border-color: var(--border-strong); }

.blocked-tag {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 6px; padding: 2px 8px;
  background: var(--bad-soft); color: var(--bad);
  border: 1px solid #5a2727; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.blocked-marker { color: var(--bad); margin-right: 2px; }
.chat-item.is-blocked .chat-item-title { color: var(--bad); }
.chat-item.is-blocked { opacity: 0.85; }

/* Маркеры в названии чата (удалённые / заблокированные) */
.mk-deleted-count {
  display: inline-block;
  font-weight: 700;
  font-size: 11px;
  margin-right: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  vertical-align: middle;
}
/* Удалил оператор — самое подозрительное, красный */
.mk-deleted-count.mk-by-operator {
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid #5a2727;
}
/* Удалил клиент — менее критично, желтоватый */
.mk-deleted-count.mk-by-client {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #5b3b1d;
}
/* Чат полностью удалён — большая красная плашка */
.mk-deleted-full {
  display: inline-block;
  background: var(--bad);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 5px;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
.mk-blocked {
  display: inline-block;
  color: var(--bad);
  font-size: 11px;
  margin-right: 4px;
  padding: 1px 5px;
  background: var(--bad-soft);
  border-radius: 4px;
  vertical-align: middle;
}

/* Чат полностью удалён → красная подсветка всей плашки в списке диалогов */
.chat-item.is-fully-deleted {
  background: rgba(220, 38, 38, 0.12);
  border-left: 3px solid var(--bad);
}
.chat-item.is-fully-deleted:hover {
  background: rgba(220, 38, 38, 0.18);
}
.chat-item.is-fully-deleted.active {
  background: rgba(220, 38, 38, 0.22);
}
.chat-item.is-fully-deleted .chat-item-title {
  color: var(--bad);
  font-weight: 600;
}

/* Удалённые строки в таблицах (Сообщения / Висящие / Анализы / Обзор) */
tr.row-deleted {
  background: rgba(220, 38, 38, 0.10);
}
tr.row-deleted:hover { background: rgba(220, 38, 38, 0.16); }
tr.row-deleted td.text { text-decoration: line-through; opacity: 0.7; }

/* Удалённые сообщения в ленте диалога */
.msg.is-deleted .msg-text { text-decoration: line-through; opacity: 0.55; }
.msg-deleted {
  margin-left: 6px;
  font-size: 11px;
  color: var(--bad);
  background: var(--bad-soft);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ───── Папки ───── */
.folder-filter {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  color: var(--fg);
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 12px;
  max-width: 110px;
}
.folders-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 12px;
  align-items: start;
}
.folders-tree {
  padding: 6px 0;
  max-height: 70vh;
  overflow: auto;
}
.folder-node {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
}
.folder-node:hover { background: var(--bg-3); }
.folder-node.selected { background: var(--accent-soft); color: var(--accent); }
.folder-icon { width: 16px; }
.folder-name { flex: 1; }
.folder-count { font-size: 11px; }
.op-folder-select {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.folder-dashboard { padding: 6px 8px 16px; }
.folder-dash-head {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.folder-dash-head h2 { margin: 0; font-size: 20px; }
.card-value-bad { color: var(--bad); }

.sub-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin: 4px 0 12px;
}
.sub-tab {
  background: transparent;
  border: none;
  color: var(--muted, #888);
  padding: 8px 14px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: -1px;
}
.sub-tab:hover { color: var(--fg); }
.sub-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.folder-sub-content { padding-top: 6px; }

.score-pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--bg-3);
}
.score-pill.score-good { background: var(--accent-soft); color: var(--accent); }
.score-pill.score-mid  { background: var(--warn-soft);   color: var(--warn); }
.score-pill.score-bad  { background: var(--bad-soft);    color: var(--bad); }
.score-bad { color: var(--bad); }

.analysis-box { padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--bg); }
.analysis-box.hidden { display: none; }
.analysis-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.analysis-error {
  background: var(--bad-soft); color: var(--bad);
  border: 1px solid #5a2727; border-radius: 6px;
  padding: 8px 11px; font-size: 12px; margin-bottom: 10px;
}
.analysis-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.analysis-scores { display: flex; gap: 8px; flex-wrap: wrap; }
.analysis-score { display: flex; flex-direction: column; align-items: center; padding: 7px 11px; background: var(--panel-2); border-radius: 8px; min-width: 64px; border: 1px solid var(--border); }
.analysis-score-label { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.analysis-score-value { font-weight: 700; font-size: 14px; }
.analysis-summary { color: var(--text); font-size: 13px; line-height: 1.5; margin: 7px 0; }
.analysis-issues, .analysis-improvements { margin: 7px 0; padding: 0; list-style: none; }
.analysis-issues li, .analysis-improvements li { background: var(--panel-2); padding: 7px 11px; border-radius: 6px; margin-bottom: 5px; font-size: 12px; line-height: 1.5; }
.analysis-issues li.high { border-left: 3px solid var(--bad); }
.analysis-issues li.medium { border-left: 3px solid var(--warn); }
.analysis-issues li.low { border-left: 3px solid var(--info); }
.analysis-improvements li { border-left: 3px solid var(--accent); }
.analysis-section-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 11px 0 5px; font-weight: 600; }

.conversation-body { flex: 1; overflow-y: auto; padding: 16px 18px; background: var(--bg); display: flex; flex-direction: column; gap: 7px; }
.day-sep { align-self: center; background: var(--bg-3); color: var(--muted); font-size: 11px; padding: 4px 12px; border-radius: 12px; margin: 9px 0; }
.msg { display: flex; max-width: 75%; cursor: pointer; }
.msg.cl { align-self: flex-start; }
.msg.op { align-self: flex-end; }
.msg-bubble { padding: 8px 12px; border-radius: 11px; word-wrap: break-word; word-break: break-word; white-space: pre-wrap; border: 1px solid transparent; }
.msg.cl .msg-bubble { background: #283449; color: var(--text); border-color: #34425b; border-top-left-radius: 4px; }
.msg.op .msg-bubble { background: #224d36; color: #e7f5e9; border-color: #2e6648; border-top-right-radius: 4px; }
.msg:hover .msg-bubble { filter: brightness(1.1); }
.msg-text { font-size: 13px; line-height: 1.4; }
.msg-meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; font-size: 10px; color: var(--muted); justify-content: flex-end; }
.msg-status { background: var(--bg-3); padding: 1px 6px; border-radius: 4px; }
.msg-edited { font-style: italic; }
.msg-media { color: var(--warn); font-weight: 600; margin-right: 4px; }

/* MODAL */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px; max-width: 80vw; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; min-width: 600px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { margin: 0; padding: 18px; overflow: auto; flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text); white-space: pre-wrap; word-wrap: break-word; }

.editable-name input { background: transparent; border: 1px dashed transparent; color: var(--text); font: inherit; padding: 4px 7px; border-radius: 5px; width: 100%; }
.editable-name input::placeholder { color: var(--muted); font-style: italic; }
.editable-name input:hover { border-color: var(--border); }
.editable-name input:focus { outline: none; border-color: var(--accent); background: var(--bg-2); }

.op-name input { font-size: 13px; font-weight: 600; }

.btn-bad {
  background: #3a1d1d; border-color: #5a2727; color: #f8a8a8;
}
.btn-bad:hover { background: #4a2424; }

/* SETTINGS */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; margin: 14px 0; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; }
.form-grid label > .field-label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.form-grid input[type="text"], .form-grid input[type="number"] {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-grid input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 216, 130, 0.13); }
.form-grid small { color: var(--muted); font-size: 11px; line-height: 1.4; }
.form-grid small code { background: var(--bg-3); padding: 1px 6px; border-radius: 4px; font-size: 10.5px; }
.form-grid .checkbox-row { flex-direction: row; align-items: center; gap: 9px; grid-column: 1 / -1; padding: 8px 0; }
.form-grid .checkbox-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.form-grid .checkbox-row .field-label { font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 500; }

.ow-actions { display: flex; gap: 9px; margin-top: 16px; flex-wrap: wrap; }

.rules-view {
  background: var(--bg); color: var(--text-2);
  padding: 16px; border-radius: 8px; border: 1px solid var(--border);
  max-height: 500px; overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
  margin: 0;
}

/* HELP-ICON + POPUP */
.help-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px;
  background: var(--bg-3); color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: 50%;
  font-size: 11px; font-weight: 700; cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s, transform .1s;
}
.help-icon:hover { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.help-icon:active { transform: scale(0.94); }

.help-popup {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 14px 16px;
  max-width: 360px;
  width: max-content;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
  z-index: 200;
}
.help-popup.hidden { display: none; }
.help-popup-title { font-weight: 700; color: #fff; margin-bottom: 6px; font-size: 13px; }
.help-popup-body { color: var(--text-2); margin-bottom: 8px; }
.help-popup-body code { background: var(--bg-3); padding: 1px 6px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 11.5px; color: var(--text); }
.help-popup-example { background: var(--bg); border-left: 3px solid var(--accent); padding: 7px 11px; border-radius: 4px; font-size: 11.5px; color: var(--text-2); margin-top: 6px; }
.help-popup-example b { color: var(--text); font-weight: 600; }
.help-popup-close { position: absolute; top: 6px; right: 9px; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; }
.help-popup-close:hover { color: var(--text); }

/* Индикатор активных фильтров в табе «Диалоги» */
.dlg-filters-status {
  font-size: 11.5px;
  padding: 6px 10px;
  margin: 4px 0 6px 0;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.dlg-filters-status.status-clean { color: #6ee7b7; background: #14281f; border-color: #2f4f3e; }
.dlg-filters-status.status-active { color: #fbbf24; background: #2a2010; border-color: #5a3a25; }
.dlg-filters-status b { color: var(--text); font-weight: 600; }

.dlg-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.dlg-pager .muted { font-size: 12px; }
.dlg-pager button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Бейдж статуса сессии оператора (banned / offline / logout) — рядом с именем оператора */
.op-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  white-space: nowrap;
}
.op-badge.op-banned { background: #5b1d1d; color: #f87171; border: 1px solid #7b2828; }
.op-badge.op-offline { background: #3a2a1d; color: #fbbf24; border: 1px solid #5a3a25; }

/* Номер оператора рядом с именем — мелкий моноширинный тег, для опознавания одинаковых имён */
.op-phone {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 1px 6px;
  margin-left: 5px;
  border-radius: 4px;
  vertical-align: middle;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg-3);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Номер клиента — тот же стиль, но другой акцент чтобы не путать с оператором */
.client-phone {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 1px 6px;
  margin-left: 5px;
  border-radius: 4px;
  vertical-align: middle;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(125, 211, 252, 0.08);
  color: #7dd3fc;
  border: 1px solid rgba(125, 211, 252, 0.2);
}

/* Таб «Лиды» — мультивыбор операторов чекбоксами со скроллом */
.lead-op-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-2);
  margin-top: 4px;
}
.lead-op-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.lead-op-item:hover { background: var(--bg-3); }
.lead-op-item input { width: auto; margin: 0; flex-shrink: 0; }

/* Inline-rename имени оператора — кликабельный span */
.op-name-edit {
  display: inline-block;
  cursor: text;
  border-bottom: 1px dashed transparent;
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 4px;
  transition: background .12s, border-color .12s;
  min-width: 80px;
}
.op-name-edit:hover {
  background: var(--bg-3);
  border-bottom-color: var(--muted);
}
.op-name-edit.editing {
  background: var(--bg);
  border-bottom-color: transparent;
  padding: 0;
  margin: 0;
}
.op-name-edit.op-name-large {
  display: block;
  width: 100%;
  font-weight: 600;
  font-size: 13.5px;
  min-height: 22px;
  margin: 0 0 3px 0;
  padding: 4px 8px;
  box-sizing: border-box;
}
.op-name-edit.op-name-large.editing { padding: 0; }
.op-name-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 3px 7px;
  font: inherit;
  outline: none;
  min-width: 140px;
  width: 100%;
  box-sizing: border-box;
}

@media (max-width: 900px) {
  .dialogs-layout { grid-template-columns: 1fr; height: auto; }
  .dialogs-list { max-height: 50vh; }
  .form-grid { grid-template-columns: 1fr; }
  .help-popup { max-width: 90vw; }
}

/* ===== Вкладка «Админы» — форма добавления + папки ===== */
.adm-form { max-width: 720px; }
.adm-row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.adm-field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 240px; min-width: 200px; }
.adm-field .field-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.adm-form input[type="text"], .adm-form input[type="password"] {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--fg);
  padding: 9px 12px; border-radius: 7px; font-size: 14px; width: 100%; box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.adm-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 216, 130, .13); }

.adm-super-toggle {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px; margin-bottom: 14px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: 14px; color: var(--text);
}
.adm-super-toggle:hover { border-color: var(--border-strong); }
.adm-super-toggle input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

.adm-folders-wrap { margin-bottom: 4px; }
.adm-folders-title { font-size: 13px; color: var(--text-2); margin-bottom: 7px; }
.adm-folders-pick {
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg-3);
  padding: 5px; max-height: 240px; overflow-y: auto;
}
.adm-folder-opt {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 6px;
  cursor: pointer; font-size: 13.5px; color: var(--text);
}
.adm-folder-opt:hover { background: var(--panel-2); }
.adm-folder-opt input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

.adm-status { align-self: center; font-size: 13px; }
.adm-status.ok  { color: var(--accent); }
.adm-status.err { color: var(--bad); }

/* роль админа — бейдж */
.role-badge { display: inline-block; padding: 3px 11px; border-radius: 6px; font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.role-owner  { background: #1F7A50; color: #fff; }
.role-super  { background: var(--accent-soft); color: var(--accent); }
.role-scoped { background: var(--info-soft);   color: var(--info); }

/* действия в строках таблицы админов — единый стиль кнопок */
#adminsTable td.adm-actions { white-space: nowrap; }
.adm-btn {
  font-family: inherit; font-size: 12px; font-weight: 500; line-height: 1;
  padding: 6px 13px; margin-right: 6px; border-radius: 7px; cursor: pointer;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  transition: background .15s, border-color .15s;
}
.adm-btn:last-child { margin-right: 0; }
.adm-btn:hover { background: var(--panel-2); border-color: var(--border-strong); }
.adm-btn.danger { background: var(--bad-soft); color: var(--bad); border-color: #5a2727; }
.adm-btn.danger:hover { background: #4a2222; border-color: #6e3232; }

/* Кастомные чекбоксы во вкладке «Админы» — в цвет панели, с акцентной галочкой */
.adm-folder-opt input[type="checkbox"],
.adm-super-toggle input[type="checkbox"],
.adm-folders-pick input[type="checkbox"] {
  -webkit-appearance: none; appearance: none; margin: 0;
  width: 17px; height: 17px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--border-strong);
  position: relative; cursor: pointer; flex-shrink: 0;
  transition: border-color .15s, background .15s;
}
.adm-folder-opt input[type="checkbox"]:hover,
.adm-super-toggle input[type="checkbox"]:hover,
.adm-folders-pick input[type="checkbox"]:hover { border-color: var(--accent); }
.adm-folder-opt input[type="checkbox"]:checked,
.adm-super-toggle input[type="checkbox"]:checked,
.adm-folders-pick input[type="checkbox"]:checked { border-color: var(--accent); background: var(--panel-2); }
.adm-folder-opt input[type="checkbox"]:checked::after,
.adm-super-toggle input[type="checkbox"]:checked::after,
.adm-folders-pick input[type="checkbox"]:checked::after {
  content: ''; position: absolute; left: 5px; top: 1px;
  width: 4px; height: 9px; border: solid var(--accent);
  border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.adm-folder-opt input[type="checkbox"]:focus-visible,
.adm-super-toggle input[type="checkbox"]:focus-visible,
.adm-folders-pick input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== Скрытие супер-онли элементов у скоупленного админа (body.ow-not-super) ===== */
/* Статические элементы тоже прячутся JS-ом (data-super-only), это — подстраховка + динамика. */
.ow-not-super [data-super-only] { display: none !important; }
/* Динамически отрисованные кнопки в JS (сессии операторов, привязка/переподключение, выгрузка диалога): */
.ow-not-super .btn-wa-logout,
.ow-not-super .btn-wa-delete,
.ow-not-super .btn-tg-logout,
.ow-not-super .btn-tg-delete,
.ow-not-super a[href*="connect.php"],
.ow-not-super a[href*="connect_wa.php"] { display: none !important; }

/* ===== Скрытие Owner-онли элементов (выгрузки) у не-Owner (body.ow-not-owner) ===== */
.ow-not-owner [data-owner-only] { display: none !important; }
.ow-not-owner a[href*="action=export_dialog"] { display: none !important; }

/* ===== Вкладка «Сотрудники» ===== */
.emp-card { }
.emp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.emp-title { font-size: 15px; }
.emp-metrics { display: flex; align-items: center; gap: 8px; }
.emp-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.emp-accounts { width: 100%; }
.emp-accounts td { padding: 7px 9px; vertical-align: middle; }
.emp-attach { margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.emp-select {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 7px 11px; border-radius: 7px; font-size: 13px; max-width: 340px; font-family: inherit;
}
.emp-select:focus { outline: none; border-color: var(--accent); }

/* Инпуты в .adm-row вне .adm-form (например форма «Добавить сотрудника») */
.adm-row input[type="text"], .adm-row input[type="password"] {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 7px; font-size: 14px; width: 100%; box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.adm-row input[type="text"]:focus, .adm-row input[type="password"]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 216, 130, .13);
}

/* Баннер статуса аккаунта в шапке диалога (оффлайн/бан/реконнект) */
.acc-banner { margin: 8px 0 2px; padding: 8px 12px; border-radius: 7px; font-size: 12.5px; line-height: 1.4; border: 1px solid; }
.acc-banner-banned, .acc-banner-off { background: var(--bad-soft);  color: var(--bad);  border-color: #5a2727; }
.acc-banner-recon                   { background: var(--warn-soft); color: var(--warn); border-color: #5b3b1d; }
/* Бейдж «идёт переподключение» у имени аккаунта */
.op-badge.op-recon { background: var(--warn-soft); color: var(--warn); }

/* Медиа в сообщениях (голос/фото/видео/стикер/документ) */
.msg-media-block { margin-bottom: 4px; }
.msg-media-block audio { width: 240px; max-width: 100%; height: 36px; display: block; }
.msg-img { max-width: 260px; max-height: 320px; border-radius: 8px; display: block; cursor: zoom-in; }
.msg-video { max-width: 280px; max-height: 320px; border-radius: 8px; display: block; background:#000; }
.msg-sticker { max-width: 140px; max-height: 140px; display: block; }
.msg-doc { color: var(--info); text-decoration: none; font-size: 12.5px; }
.msg-doc:hover { text-decoration: underline; }

/* Тёмная тема для нативных плееров аудио/видео.
   У audio свой фон НЕ задаём — иначе прямоугольные углы проступают за пилюлей-панелью. */
.msg-media-block audio { color-scheme: dark; background: transparent; }
.msg-media-block video { color-scheme: dark; border-radius: 8px; }

/* Фильтр по дате в «Диалогах» — два поля в ряд */
.dlg-dates { display: flex; gap: 6px; }
.dlg-dates input { flex: 1; min-width: 0; }
