/* ============================================================
   Темы оформления. Каждая тема задаёт цвета, плотность и меню.
   Тема ставится атрибутом <html data-theme="…" data-layout="top|side">.
   v4  — Минимализм, меню сверху (по умолчанию)
   v8  — Контраст, чёрно-белый с жёлтым, меню сверху
   v3  — Мессенджер, зелёно-бирюзовый, меню слева
   v10 — Плотный, меню слева, больше строк на экране
   ============================================================ */

:root,
[data-theme="v4"] {
  --bg: #fafafb;
  --surface: #ffffff;
  --surface-2: #f4f3fb;
  --text: #1d1b33;
  --muted: #6d6a86;
  --border: #e7e5f2;
  --accent: #534ab7;
  --accent-text: #ffffff;
  --accent-soft: #eeedfe;
  --nav-bg: #ffffff;
  --nav-text: #4a4766;
  --nav-muted: #8a87a3;
  --nav-hover: #f4f3fb;
  --nav-active-bg: transparent;
  --nav-active-text: #26215c;
  --nav-active-line: #534ab7;
  --nav-border: #e7e5f2;
  --chat-bg: #fafafb;
  --bubble-client: #ffffff;
  --bubble-client-text: var(--text);
  --bubble-bot: #eeedfe;
  --bubble-bot-text: #26215c;
  --bubble-op: #e3f4ec;
  --bubble-op-text: #134b33;
  --radius: 10px;
  --font-size: 15px;
  --pad: 20px;
  --main-pad: 32px;
  --btn-pad: 8px 16px;
  --input-pad: 9px 12px;
  --cell-pad: 12px 10px;
  --item-pad: 12px 14px;
  --gap: 12px;
}

[data-theme="v8"] {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --text: #141413;
  --muted: #5f5e5a;
  --border: #d3d1c7;
  --accent: #f0a42a;
  --accent-text: #141413;
  --accent-soft: #fdf0d6;
  --nav-bg: #1d1d1b;
  --nav-text: #f1efe8;
  --nav-muted: #b4b2a9;
  --nav-hover: #2c2c2a;
  --nav-active-bg: #f0a42a;
  --nav-active-text: #141413;
  --nav-active-line: #f0a42a;
  --nav-border: #1d1d1b;
  --chat-bg: #f6f5f1;
  --bubble-client: #ffffff;
  --bubble-client-text: var(--text);
  --bubble-bot: #f1efe8;
  --bubble-bot-text: #141413;
  --bubble-op: #fac775;
  --bubble-op-text: #141413;
  --radius: 6px;
  --font-size: 15px;
  --pad: 18px;
  --main-pad: 28px;
  --btn-pad: 8px 16px;
  --input-pad: 9px 12px;
  --cell-pad: 11px 10px;
  --item-pad: 11px 14px;
  --gap: 12px;
}

[data-theme="v3"] {
  --bg: #eef4f1;
  --surface: #ffffff;
  --surface-2: #f0f6f3;
  --text: #102a22;
  --muted: #5b7068;
  --border: #d6e4dd;
  --accent: #0f6e56;
  --accent-text: #ffffff;
  --accent-soft: #e1f5ee;
  --nav-bg: #0f6e56;
  --nav-text: #e1f5ee;
  --nav-muted: #9fd9c3;
  --nav-hover: rgba(255, 255, 255, .10);
  --nav-active-bg: rgba(255, 255, 255, .18);
  --nav-active-text: #ffffff;
  --nav-active-line: #ffffff;
  --nav-border: rgba(255, 255, 255, .18);
  --chat-bg: #e5ede9;
  --bubble-client: #ffffff;
  --bubble-client-text: var(--text);
  --bubble-bot: #d9f7ea;
  --bubble-bot-text: #08503f;
  --bubble-op: #9fe1cb;
  --bubble-op-text: #04342c;
  --radius: 12px;
  --font-size: 15px;
  --pad: 16px;
  --main-pad: 24px;
  --btn-pad: 8px 14px;
  --input-pad: 8px 10px;
  --cell-pad: 10px 8px;
  --item-pad: 10px 12px;
  --gap: 12px;
}

[data-theme="v10"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e1e4e8;
  --accent: #185fa5;
  --accent-text: #ffffff;
  --accent-soft: #e6f1fb;
  --nav-bg: #f1efe8;
  --nav-text: #444441;
  --nav-muted: #888780;
  --nav-hover: #e6e4dc;
  --nav-active-bg: #dfe9f5;
  --nav-active-text: #0c447c;
  --nav-active-line: #185fa5;
  --nav-border: #e1dfd6;
  --chat-bg: #f4f5f7;
  --bubble-client: #ffffff;
  --bubble-client-text: var(--text);
  --bubble-bot: #e6f1fb;
  --bubble-bot-text: #0c447c;
  --bubble-op: #e3f4e6;
  --bubble-op-text: #1a5c2a;
  --radius: 6px;
  --font-size: 14px;
  --pad: 12px;
  --main-pad: 16px;
  --btn-pad: 5px 10px;
  --input-pad: 6px 8px;
  --cell-pad: 6px 8px;
  --item-pad: 7px 10px;
  --gap: 8px;
}

/* v2 — Тёмный операторский: тёмный фон, зелёные акценты, меньше устают глаза */
[data-theme="v2"] {
  --bg: #1f1f1d;
  --surface: #2c2c2a;
  --surface-2: #363633;
  --text: #f1efe8;
  --muted: #a9a79e;
  --border: #44443f;
  --accent: #74b13a;
  --accent-text: #11240a;
  --accent-soft: #2b3d1d;
  --nav-bg: #173404;
  --nav-text: #d6ecc0;
  --nav-muted: #97c459;
  --nav-hover: rgba(255, 255, 255, .07);
  --nav-active-bg: rgba(151, 196, 89, .22);
  --nav-active-text: #ffffff;
  --nav-active-line: #97c459;
  --nav-border: #24470b;
  --chat-bg: #242422;
  --bubble-client: #3a3a37;
  --bubble-client-text: #f1efe8;
  --bubble-bot: #2b3d1d;
  --bubble-bot-text: #d6ecc0;
  --bubble-op: #3b6d11;
  --bubble-op-text: #f1f8e8;
  --ok: #8fd16a;
  --ok-soft: #22381a;
  --warn: #e7b84c;
  --warn-soft: #3d3215;
  --danger: #f0716f;
  --danger-soft: #45201f;
  --radius: 8px;
  --font-size: 15px;
  --pad: 16px;
  --main-pad: 24px;
  --btn-pad: 8px 14px;
  --input-pad: 8px 10px;
  --cell-pad: 10px 8px;
  --item-pad: 10px 12px;
  --gap: 12px;
  color-scheme: dark;
}

/* v7 — Мятная клиника: мягкие мятные тона, крупные скругления */
[data-theme="v7"] {
  --bg: #f6fbf9;
  --surface: #ffffff;
  --surface-2: #eef8f4;
  --text: #0b3a30;
  --muted: #5f7f76;
  --border: #d6ece4;
  --accent: #2fa784;
  --accent-text: #ffffff;
  --accent-soft: #e1f5ee;
  --nav-bg: #e1f5ee;
  --nav-text: #085041;
  --nav-muted: #4f8a78;
  --nav-hover: #d0eee3;
  --nav-active-bg: #5dcaa5;
  --nav-active-text: #04342c;
  --nav-active-line: #2fa784;
  --nav-border: #c9e9dd;
  --chat-bg: #f6fbf9;
  --bubble-client: #ffffff;
  --bubble-client-text: var(--text);
  --bubble-bot: #f1efe8;
  --bubble-bot-text: #3a3a36;
  --bubble-op: #9fe1cb;
  --bubble-op-text: #04342c;
  --radius: 14px;
  --font-size: 15px;
  --pad: 18px;
  --main-pad: 28px;
  --btn-pad: 8px 18px;
  --input-pad: 9px 12px;
  --cell-pad: 11px 10px;
  --item-pad: 11px 14px;
  --gap: 12px;
}

/* v12 — Три панели: справа в диалогах карточка клиента */
[data-theme="v12"] {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --text: #2c2c2a;
  --muted: #6e6d68;
  --border: #e2e0d8;
  --accent: #0f6e56;
  --accent-text: #ffffff;
  --accent-soft: #e1f5ee;
  --nav-bg: #f1efe8;
  --nav-text: #444441;
  --nav-muted: #888780;
  --nav-hover: #e6e4dc;
  --nav-active-bg: #ffffff;
  --nav-active-text: #0f6e56;
  --nav-active-line: #0f6e56;
  --nav-border: #e2e0d8;
  --chat-bg: #fafaf8;
  --bubble-client: #f1efe8;
  --bubble-client-text: var(--text);
  --bubble-bot: #ffffff;
  --bubble-bot-text: var(--text);
  --bubble-op: #0f6e56;
  --bubble-op-text: #ffffff;
  --radius: 8px;
  --font-size: 14px;
  --pad: 16px;
  --main-pad: 20px;
  --btn-pad: 7px 12px;
  --input-pad: 7px 10px;
  --cell-pad: 9px 8px;
  --item-pad: 9px 12px;
  --gap: 10px;
}
[data-theme="v12"] .msg.bot { border-color: var(--border); }

/* общие статусные цвета (тёмная тема задаёт свои) */
:root {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root:not([data-theme="v2"]) {
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --danger: #cf222e;
  --danger-soft: #fdecee;
  color-scheme: light;
}

/* ============================================================
   Основа
   ============================================================ */

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: var(--font-size); line-height: 1.5; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: calc(var(--radius) - 2px); padding: var(--btn-pad);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.danger:hover { background: var(--danger-soft); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button.link.lang-active { color: var(--text); font-weight: 700; text-decoration: underline; }

textarea { resize: vertical; line-height: 1.45; }
input, select, textarea {
  font: inherit; width: 100%; padding: var(--input-pad); border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 4px 0; }
.check input { width: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--pad); }
.auth-card { width: 100%; max-width: 380px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 1em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack > * + * { margin-top: var(--gap); }

/* ============================================================
   Каркас: меню слева (по умолчанию)
   ============================================================ */

.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.layout > div { min-width: 0; }
.sidebar {
  background: var(--nav-bg); color: var(--nav-text); border-right: 1px solid var(--nav-border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; padding: 4px 10px 14px; color: var(--nav-text); text-decoration: none; }
/* Логотип: цвета из темы. В меню — цвет активного пункта на фоне меню, на экране входа — акцент. */
.logo { display: inline-flex; align-items: center; gap: 10px; --logo-main: var(--accent); --logo-on: var(--accent-text); color: var(--text); }
.sidebar .logo, .topbar .logo { --logo-main: var(--nav-active-line); --logo-on: var(--nav-bg); color: var(--nav-text); }
.logo-mark { display: inline-flex; flex: none; }
.logo-mark svg { display: block; }
.logo-name { display: flex; flex-direction: column; line-height: 1.1; }
.logo-name b { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.logo-name small { font-size: 11px; font-weight: 500; opacity: .75; letter-spacing: .4px; }
.topbar .brand { padding: 0; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 16px; }
.nav a { display: block; padding: 8px 10px; border-radius: calc(var(--radius) - 2px); color: var(--nav-text); text-decoration: none; }
.nav a:hover { background: var(--nav-hover); }
.nav a.active { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 600; box-shadow: inset 3px 0 0 var(--nav-active-line); }
.nav .group { font-size: 12px; color: var(--nav-muted); padding: 14px 10px 4px; }
.sidebar .me { margin-top: auto; padding: 10px; border-top: 1px solid var(--nav-border); font-size: 13px; }
.sidebar .me a, .sidebar .me button.link { color: var(--nav-text); }
.sidebar .me .muted { color: var(--nav-muted); }
.sidebar .topclose { color: var(--nav-text); }
.main { padding: var(--main-pad); min-width: 0; }
.topbar { display: none; }
.topclose { display: none; }

/* ============================================================
   Каркас: меню сверху (темы v4 и v8)
   ============================================================ */

[data-layout="top"] .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
[data-layout="top"] .sidebar {
  flex-direction: row; align-items: center; gap: 16px; height: auto; overflow: visible; min-width: 0;
  padding: 0 20px; border-right: none; border-bottom: 1px solid var(--nav-border); z-index: 10;
}
/* меню прокручивается вбок, если пунктов больше, чем места */
[data-layout="top"] .nav { min-width: 0; scrollbar-width: thin; }
[data-layout="top"] .sidebar .me .muted { display: none; }
[data-layout="top"] .sidebar > .row { flex-wrap: nowrap; }
[data-layout="top"] .brand { padding: 0; white-space: nowrap; }
[data-layout="top"] .nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; align-self: stretch; }
[data-layout="top"] .nav a {
  white-space: nowrap; border-radius: 0; padding: 0 10px; display: flex; align-items: center;
  min-height: 56px; box-shadow: none; border-bottom: 3px solid transparent;
}
[data-layout="top"] .nav a.active { border-bottom-color: var(--nav-active-line); box-shadow: none; }
[data-layout="top"] .nav .group { display: none; }
[data-layout="top"] .sidebar .me {
  margin: 0; padding: 0; border: none; display: flex; align-items: center; gap: 10px; white-space: nowrap;
}
[data-layout="top"] .sidebar .me button.link { margin-top: 0 !important; }
[data-layout="top"] .main { width: 100%; max-width: 1440px; margin: 0 auto; }
/* контрастная тема: активный пункт — жёлтая плашка */
[data-theme="v8"][data-layout="top"] .nav a.active { border-radius: 4px; min-height: 36px; align-self: center; border-bottom: none; }

@media (max-width: 760px) {
  .layout, [data-layout="top"] .layout { grid-template-columns: 1fr; grid-template-rows: auto; }
  .sidebar, [data-layout="top"] .sidebar {
    display: none; position: fixed; inset: 0; z-index: 20; height: auto;
    flex-direction: column; align-items: stretch; padding: 16px 12px; gap: 4px; overflow-y: auto;
  }
  .layout.menu-open .sidebar, [data-layout="top"] .layout.menu-open .sidebar { display: flex; }
  [data-layout="top"] .nav { flex-direction: column; flex: none; overflow: visible; }
  [data-layout="top"] .nav a { min-height: 0; padding: 10px; border-bottom: none; border-radius: 6px; }
  [data-layout="top"] .nav a.active { box-shadow: inset 3px 0 0 var(--nav-active-line); }
  [data-layout="top"] .sidebar .me { margin-top: auto; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px; border-top: 1px solid var(--nav-border); }
  [data-layout="top"] .sidebar .me .muted { display: block; }
  .topclose { display: inline; }
  .topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--nav-bg); color: var(--nav-text); border-bottom: 1px solid var(--nav-border); }
  .main { padding: 16px; }
}

/* ============================================================
   Статусы
   ============================================================ */

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
th.num, td.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
/* Пометки мессенджеров: WA — зелёная, INST — розовая, TG — голубая; читаются в светлых и тёмных темах. */
.m-wa { --m: #2fa45a; }
.m-inst { --m: #d4537e; }
.m-tg { --m: #2a8bd6; }
.badge.m-wa, .badge.m-inst, .badge.m-tg { background: color-mix(in srgb, var(--m) 18%, transparent); color: var(--m); }
.messenger-select { width: auto; min-width: 76px; padding: 3px 8px; font-size: 12px; font-weight: 600; }
.messenger-select.m-wa, .messenger-select.m-inst, .messenger-select.m-tg { color: var(--m); border-color: color-mix(in srgb, var(--m) 55%, transparent); background-color: color-mix(in srgb, var(--m) 12%, var(--surface)); }
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
.filter-field { display: flex; flex-direction: column; gap: 4px; margin: 0; min-width: 190px; }
.filter-tail { margin-left: auto; gap: 12px; align-items: center; }

/* ============================================================
   WhatsApp
   ============================================================ */

.agent-card { cursor: pointer; }
.agent-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.agent-card .name { font-weight: 600; }
.connect-box { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
@media (max-width: 900px) { .connect-box { grid-template-columns: 1fr; } }
/* WhatsApp: список агентов столбцом слева со своей прокруткой, выбранный агент справа. */
.wa-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: var(--gap); align-items: start; }
.wa-side { display: flex; flex-direction: column; gap: 10px; height: calc(100vh - 110px); min-height: 320px; position: sticky; top: var(--main-pad); }
[data-layout="top"] .wa-side { height: calc(100vh - 165px); }
.wa-list { flex: 1; min-height: 0; overflow-y: auto; padding-right: 6px; }
.wa-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.wa-filter button { padding: 4px 10px; font-size: 13px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; }
.wa-filter button .count { font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.wa-filter button.ok .count { background: var(--ok-soft); color: var(--ok); }
.wa-filter button.off .count { background: var(--warn-soft); color: var(--warn); }
.wa-filter button.problem .count { background: var(--danger-soft); color: var(--danger); }
.wa-filter button.selected { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.wa-empty { padding: 12px 4px; }
.wa-cards { display: flex; flex-direction: column; gap: calc(var(--gap) - 4px); }
.wa-group + .wa-group { margin-top: 18px; }
.wa-group h2 { position: sticky; top: 0; z-index: 1; background: var(--bg); margin: 0 0 8px; padding: 4px 0; }
.wa-detail { min-width: 0; }
@media (max-width: 900px) {
  .wa-layout { grid-template-columns: 1fr; }
  .wa-side, [data-layout="top"] .wa-side { height: auto; min-height: 0; position: static; }
  .wa-list { max-height: 45vh; }
}
.qr { width: 264px; height: 264px; background: #fff; border-radius: 8px; padding: 8px; border: 1px solid var(--border); display: grid; place-items: center; }
.qr img { width: 100%; height: 100%; image-rendering: pixelated; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 32px; letter-spacing: 4px; font-weight: 700; }
ol.steps { padding-left: 20px; margin: 8px 0; }

/* ============================================================
   Диалоги
   ============================================================ */

.dlg-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: calc(100vh - 110px); min-height: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
[data-layout="top"] .dlg-layout { height: calc(100vh - 160px); }
[data-theme="v10"] .dlg-layout { grid-template-columns: 280px minmax(0, 1fr); height: calc(100vh - 80px); }
.dlg-side { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.dlg-list { overflow-y: auto; flex: 1; }
.dlg-item { padding: var(--item-pad); border-bottom: 1px solid var(--border); cursor: pointer; }
.dlg-item:hover { background: var(--surface-2); }
.dlg-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.dlg-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
[data-theme="v3"] .chat-head { background: var(--accent); color: var(--accent-text); border-bottom: none; }
[data-theme="v3"] .chat-head .muted, [data-theme="v3"] .chat-head .back { color: var(--accent-soft); }
.chat-head .back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; background: var(--chat-bg); display: flex; flex-direction: column; gap: calc(var(--gap) - 4px); }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 12px; border: 1px solid transparent; }
[data-theme="v10"] .msg { padding: 5px 9px; border-radius: 8px; }
.msg.client { align-self: flex-start; background: var(--bubble-client); color: var(--bubble-client-text); border-color: var(--border); }
.msg.bot { align-self: flex-end; background: var(--bubble-bot); color: var(--bubble-bot-text); }
.msg.operator { align-self: flex-end; background: var(--bubble-op); color: var(--bubble-op-text); }
.msg.service { align-self: center; max-width: 90%; font-size: 13px; color: var(--muted); background: transparent; border: 1px dashed var(--border); }
.msg.pending { opacity: .6; }
.msg-who { font-size: 12px; opacity: .75; margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-quote { font-size: 13px; opacity: .8; border-left: 3px solid currentColor; padding-left: 8px; margin-bottom: 4px; white-space: pre-wrap; }
.msg-img { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; margin-top: 6px; }
.composer { border-top: 1px solid var(--border); padding: 10px 14px; display: grid; gap: 8px; background: var(--surface); }
@media (max-width: 760px) {
  .dlg-layout, [data-layout="top"] .dlg-layout, [data-theme="v10"] .dlg-layout { grid-template-columns: 1fr; height: calc(100vh - 150px); }
  .dlg-layout .dlg-chat { display: none; }
  .dlg-layout.show-chat .dlg-side { display: none; }
  .dlg-layout.show-chat .dlg-chat { display: flex; }
  .chat-head .back { display: inline; }
  .msg { max-width: 90%; }
}

/* теги диалогов */
.tag { display: inline-block; font-size: 12px; font-weight: 600; line-height: 1.5; padding: 1px 8px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
button.tag { cursor: pointer; padding: 2px 10px; }
button.tag:hover { filter: brightness(.96); }
.tag.c-gray { background: #ecebe6; color: #444441; }
.tag.c-blue { background: #e6f1fb; color: #0c447c; }
.tag.c-green { background: #e6f4e3; color: #27500a; }
.tag.c-yellow { background: #faeeda; color: #633806; }
.tag.c-orange { background: #fae4d9; color: #712b13; }
.tag.c-red { background: #fcebeb; color: #791f1f; }
.tag.c-purple { background: #eeedfe; color: #3c3489; }
.tag.c-teal { background: #e1f5ee; color: #085041; }
.tag.off { background: transparent; color: var(--muted); border: 1px dashed var(--border); font-weight: 500; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-tags { padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.dlg-info { display: none; }
/* тема «Три панели»: справа карточка клиента с тегами */
[data-theme="v12"] .dlg-layout { grid-template-columns: 300px minmax(0, 1fr) 260px; }
[data-theme="v12"] .dlg-info { display: block; border-left: 1px solid var(--border); background: var(--surface-2); overflow-y: auto; }
[data-theme="v12"] .chat-tags { display: none; }
@media (max-width: 1100px) {
  [data-theme="v12"] .dlg-layout { grid-template-columns: 280px minmax(0, 1fr); }
  [data-theme="v12"] .dlg-info { display: none; }
  [data-theme="v12"] .chat-tags { display: block; }
}
@media (max-width: 760px) {
  [data-theme="v12"] .dlg-layout { grid-template-columns: 1fr; }
}

/* ============================================================
   Каталог услуг
   ============================================================ */

.item-title { font-weight: 600; }
.item.off { opacity: .65; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text); }
.answer { white-space: pre-wrap; margin-top: 10px; padding: 10px; border-radius: 8px; background: var(--surface-2); }
.preview { white-space: pre-wrap; font: 13px/1.45 ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; }
summary { cursor: pointer; }

/* ============================================================
   Таблицы, окна, уведомления
   ============================================================ */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: var(--cell-pad); border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 500; }
[data-theme="v8"] th { color: var(--text); font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }

.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 30; }
.modal { background: var(--surface); border-radius: var(--radius); padding: var(--pad); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 780px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 520px) { .two-col { grid-template-columns: 1fr; } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }

/* выбор филиала в меню */
.nav-branch { padding: 0 10px 12px; }
.nav-branch label { color: var(--nav-muted); margin: 0 0 4px; font-size: 12px; }
.nav-branch select { background: var(--surface); color: var(--text); padding: 6px 8px; }
[data-layout="top"] .nav-branch { padding: 0; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
[data-layout="top"] .nav-branch label { margin: 0; }
[data-layout="top"] .nav-branch select { width: 200px; }
@media (max-width: 760px) {
  [data-layout="top"] .nav-branch { display: block; padding: 0 10px 12px; }
  [data-layout="top"] .nav-branch select { width: 100%; }
}

/* выбор агентов в форме сотрудника */
.agent-picker { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); margin-top: 6px; }
.agent-group + .agent-group { border-top: 1px solid var(--border); }
.agent-group-head { padding: 8px 10px; margin: 0; background: var(--surface-2); position: sticky; top: 0; }
.agent-group-head .muted { margin-left: auto; }
.agent-group-items { padding: 4px 10px 6px 34px; }

/* переключатель из двух-трёх кнопок (расположение меню) */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); overflow: hidden; }
.segmented button { border: none; border-radius: 0; min-width: 110px; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.selected { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* выбор темы в профиле */
.theme-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.theme-option { border: 2px solid var(--border); border-radius: var(--radius); padding: 8px; cursor: pointer; background: var(--surface); text-align: left; }
.theme-option.selected { border-color: var(--accent); }
.theme-option .swatch { height: 56px; border-radius: 6px; display: flex; overflow: hidden; margin-bottom: 6px; border: 1px solid rgba(0, 0, 0, .08); }
.theme-option .swatch span { flex: 1; }

/* Номер клиента в «Диалогах»: нажатие копирует номер. */
.phone-copy {
  padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 18px; font-weight: 600;
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--text);
  cursor: copy; white-space: nowrap;
}
.phone-copy:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); border-style: solid; }
