/* Оформление продолжает демо-мокап (ai-agent-demo.html): тёмная «рабочая»
   палитра, IBM Plex, плотная сетка. Интерфейс смены, а не сайт: плотность
   информации важнее воздуха. */

:root {
  --bg: #0A0F14;
  --panel: #121A21;
  --panel-2: #17212A;
  --panel-3: #1D2935;
  --border: #223040;
  --border-soft: #1C2833;
  --text: #E9EEF2;
  --dim: #7F93A1;
  --route: #3AA0FF;
  --urgent: #FF4B5C;
  --urgent-soft: rgba(255, 75, 92, .16);
  --amber: #FFB020;
  --amber-soft: rgba(255, 176, 32, .16);
  --good: #34D399;
  --good-soft: rgba(52, 211, 153, .16);
  --mine: #2E6FF2;
  --radius: 8px;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Дневная тема. Переключатель в шапке ставит data-theme="light" на <html>;
   значения подобраны так, чтобы смысл цветов не менялся: синий — маршрут,
   красный — экстренный, зелёный — подтверждено. Полупрозрачные «soft» цвета
   на светлом фоне чуть плотнее, иначе подсветка строк не читается. */
:root[data-theme="light"] {
  --bg: #F2F5F8;
  --panel: #FFFFFF;
  --panel-2: #F7F9FB;
  --panel-3: #EDF1F5;
  --border: #D3DCE4;
  --border-soft: #E2E8EE;
  --text: #16212B;
  --dim: #5A6B78;
  --route: #0B6FD4;
  --urgent: #D32030;
  --urgent-soft: rgba(211, 32, 48, .12);
  --amber: #B8780A;
  --amber-soft: rgba(184, 120, 10, .14);
  --good: #0F8A5F;
  --good-soft: rgba(15, 138, 95, .14);
  --mine: #1A58D0;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
button { font: inherit; }
code { font-family: var(--mono); font-size: .92em; color: var(--route); }
h2 { font-size: 17px; margin: 0 0 4px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 6px; font-weight: 600; }
.dim { color: var(--dim); margin: 0; }
.dim strong { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------- вход */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, #16232F, var(--bg)); z-index: 50; }
.login-card { width: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 26px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 30px 60px -30px #000; }
.login-mark { font-size: 30px; }
.login-card h1 { font-size: 18px; margin: 0; font-weight: 600; }
.login-sub { margin: -6px 0 6px; color: var(--dim); font-size: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--dim); }
.login-card input, .filter, .form input, .form select, .form textarea, .composer textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font: inherit; outline: none;
}
.login-card input:focus, .filter:focus, .form input:focus, .composer textarea:focus { border-color: var(--route); }
.login-card button { background: var(--route); color: #04121F; border: 0; border-radius: 6px; padding: 10px; font-weight: 600; cursor: pointer; }
.login-card button:disabled { opacity: .6; cursor: default; }
.login-sso { display: block; text-align: center; background: var(--route); color: #04121F; border-radius: 6px; padding: 11px; font-weight: 600; text-decoration: none; }
.login-sso:hover { filter: brightness(1.08); }
.login-password { display: flex; flex-direction: column; gap: 12px; }
.login-or { text-align: center; color: var(--dim); font-size: 12px; margin-top: 4px; }
.link-out { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.link-out textarea { width: 100%; font-family: var(--mono, monospace); font-size: 12px; word-break: break-all; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.login-error { background: var(--urgent-soft); color: #FFC3C9; border: 1px solid #5B2730; border-radius: 6px; padding: 8px 10px; font-size: 12px; }
.login-note { margin: 0; color: var(--dim); font-size: 11px; }

/* ----------------------------------------------------------------- каркас */
.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  flex: none; height: 46px; display: flex; align-items: center; gap: 16px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark { font-size: 16px; }
.brand-name { white-space: nowrap; }
.stand-badge {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 20px; background: var(--amber-soft); color: var(--amber); border: 1px solid #4A3A18;
}
.stand-badge[data-prod="1"] { background: var(--urgent-soft); color: #FF98A2; border-color: #5B2730; }

.tabs { display: flex; gap: 2px; margin-left: 6px; }
.tab {
  background: transparent; border: 0; color: var(--dim); padding: 7px 11px;
  border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.is-active { background: var(--panel-3); color: var(--text); }
.tab-badge { background: var(--route); color: #04121F; border-radius: 20px; font-size: 10px; font-weight: 700; padding: 1px 6px; font-family: var(--mono); }
.tab-badge--urgent { background: var(--urgent); color: #fff; }
.tab-badge--amber { background: var(--amber); color: #1A1200; }
/* Авторегистрация включена — раздел «Обращения» виден, но не нажимается */
.tab:disabled, .tab[aria-disabled="true"] { opacity: .4; cursor: not-allowed; pointer-events: none; }
.inq-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin: 8px 0; }
.inq-fields label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--dim); }
.inq-history { margin-top: 8px; font-size: 12px; color: var(--dim); }
.inq-history li { margin: 2px 0; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { background: transparent; border: 0; color: var(--dim); cursor: pointer; font-size: 14px; padding: 4px; border-radius: 5px; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn[data-off="1"] { opacity: .4; }
.channels { display: flex; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10px;
  padding: 3px 7px; border-radius: 20px; border: 1px solid var(--border); color: var(--dim); white-space: nowrap;
}
.chip .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.chip--ok { color: var(--good); border-color: transparent; background: var(--good-soft); }
.chip--off { color: var(--dim); }
.chip--bad { color: #FF98A2; border-color: transparent; background: var(--urgent-soft); }
.online { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.conn { color: var(--amber); border-color: var(--amber); }
.conn[data-state="open"] { color: var(--good); border-color: transparent; background: var(--good-soft); }
.conn[data-state="closed"] { color: #fff; border-color: transparent; background: var(--urgent); animation: conn-blink 1.2s ease-in-out infinite; }
@keyframes conn-blink { 50% { opacity: .55; } }
.user-chip { display: flex; align-items: center; gap: 7px; font-size: 12px; padding-left: 10px; border-left: 1px solid var(--border); }
.user-role { font-family: var(--mono); font-size: 10px; color: var(--dim); }

.views { flex: 1; min-height: 0; }
.view { display: none; height: 100%; }
.view.is-active { display: block; }

.page { height: 100%; overflow: auto; padding: 18px 20px 40px; }
.page--cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 14px; align-content: start; }
.page-head { margin-bottom: 14px; max-width: 900px; }
/* карточка во всю ширину сетки настроек (Источники — длинная таблица) */
.card--full { grid-column: 1 / -1; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }

/* ----------------------------------------------------------------- инбокс */
.inbox { height: 100%; display: grid; grid-template-columns: 290px minmax(0, 1fr) 330px; }
.conv-list, .side { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.conv-list { border-right: 1px solid var(--border); }
.side { border-left: 1px solid var(--border); }
.panel-head {
  flex: none; height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  border-bottom: 1px solid var(--border-soft); font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--dim); font-weight: 600;
}
.panel-head .filter { margin-left: auto; width: 170px; padding: 4px 7px; font-size: 11px; text-transform: none; letter-spacing: 0; }
.conv-items { flex: 1; overflow: auto; }
/* Поиск: разделы «Чаты» / «Сообщения» в списке и строка поиска в чате. */
.search-head {
  padding: 6px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim);
  background: var(--panel-2); border-bottom: 1px solid var(--border-soft); font-weight: 600;
}
.hit-item .conv-preview.hit-text { white-space: normal; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hit-item .conv-time { font-size: 9.5px; }
mark { background: #F5C451; color: #1A1200; border-radius: 2px; padding: 0 1px; }
.find-bar {
  flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 14px;
  border-bottom: 1px solid var(--border-soft); background: var(--panel-2);
}
.find-bar .filter { flex: 1; padding: 5px 8px; font-size: 12px; }
.find-count { font-size: 11px; color: var(--dim); font-family: var(--mono); min-width: 70px; text-align: right; }

.conv-item {
  display: flex; gap: 9px; padding: 10px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; position: relative;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.is-active { background: var(--panel-3); }
.conv-item.is-escalated::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--amber); }
.conv-item.is-escalated[data-urgency="high"]::before { background: var(--urgent); }
.ch-badge {
  flex: none; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff; position: relative;
}
.ch-badge[data-ch="telegram"] { background: #229ED9; }
.ch-badge[data-ch="whatsapp"] { background: #25D366; }
.ch-badge[data-ch="max"] { background: #7C4DFF; }
.ch-badge svg { width: 15px; height: 15px; }
.ch-avatar { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
/* поверх фото — метка канала в углу, чтобы не терять, откуда группа */
.ch-badge.has-avatar::after {
  content: ''; position: absolute; left: -2px; bottom: -2px; width: 9px; height: 9px; border-radius: 50%;
  background: inherit; box-shadow: 0 0 0 2px var(--panel);
}
.conv-unread {
  position: absolute; top: -4px; right: -5px; min-width: 15px; height: 15px; border-radius: 20px;
  background: var(--urgent); color: #fff; font-size: 9px; font-weight: 700; display: grid; place-items: center;
  padding: 0 4px; font-family: var(--mono);
}
.conv-meta { min-width: 0; flex: 1; }
.conv-top { display: flex; gap: 6px; align-items: baseline; }
.conv-name { font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { margin-left: auto; font-family: var(--mono); font-size: 10px; color: var(--dim); flex: none; }
.conv-sub { font-size: 11px; color: var(--dim); }
.conv-preview { font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv-flags { display: flex; gap: 4px; margin-top: 4px; }
.flag { font-size: 9.5px; font-family: var(--mono); padding: 1px 5px; border-radius: 4px; background: var(--panel-3); color: var(--dim); }
.flag--urgent { background: var(--urgent-soft); color: #FF98A2; }
.flag--amber { background: var(--amber-soft); color: var(--amber); }
.flag--good { background: var(--good-soft); color: var(--good); }

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-empty { margin: auto; text-align: center; color: var(--dim); }
.thread-body { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.thread-head {
  flex: none; height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 14px;
  border-bottom: 1px solid var(--border); background: var(--panel);
}
.thread-who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.thread-name { font-weight: 600; }
.thread-sub { font-size: 11px; color: var(--dim); }
.thread-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.viewers { font-size: 11px; color: var(--amber); font-family: var(--mono); }

.thread-log { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.log-wrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.day-sep { align-self: center; position: relative; margin: 6px 0 2px; }
.day-sep span, .day-float span {
  display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--panel-3); color: var(--dim); white-space: nowrap;
}
.day-float {
  position: absolute; top: 8px; left: 50%; transform: translate(-50%, -6px); z-index: 3;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.day-float span { box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.day-float.is-on { opacity: 1; transform: translate(-50%, 0); }
.bubble {
  max-width: 76%; padding: 8px 11px; border-radius: 10px; font-size: 13px; position: relative;
  white-space: pre-wrap; word-break: break-word;
}
.bubble--in { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border-soft); border-bottom-left-radius: 3px; }
.bubble--out { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 3px; }
.bubble--ai { align-self: flex-end; background: #1E4C8A; border-bottom-right-radius: 3px; }
/* Синие пузыри (агент и сотрудник) — белым в обеих темах: в дневной var(--text)
   тёмный и на синем не читается (14.10). */
.bubble--out, .bubble--ai { color: #fff; }
.bubble--out .doc-chip, .bubble--ai .doc-chip { color: #fff; background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .3); }
/* ответы сотрудников — пастельный фон своего цвета (opColor в inbox.js), текст чёрный в обеих темах */
.bubble--op { background: var(--op-bg); color: #111; }
.bubble.bubble--op .who, .bubble--op .time { opacity: .65; }
.bubble.bubble--op .doc-chip { color: #111; background: rgba(0, 0, 0, .06); border-color: rgba(0, 0, 0, .15); }
.bubble.bubble--op .quote, .bubble.bubble--op .ref-card { border-left-color: rgba(0, 0, 0, .35); background: rgba(0, 0, 0, .05); color: #111; }
.bubble.bubble--op .fwd { color: rgba(0, 0, 0, .6); }
.bubble.bubble--op .mention { background: rgba(0, 0, 0, .08); color: #111; }
.bubble--system { align-self: center; background: var(--panel-3); color: var(--dim); font-size: 11.5px; max-width: 90%; }
.bubble .who { display: block; font-size: 10px; opacity: .8; margin-bottom: 3px; font-weight: 600; }
.bubble .time { display: block; font-family: var(--mono); font-size: 9.5px; opacity: .7; margin-top: 4px; text-align: right; }
.bubble[data-status="pending"] { opacity: .65; }
.bubble[data-status="failed"] { background: var(--urgent-soft); border: 1px solid #5B2730; color: #FFC3C9; }
/* не ушло из-за связи — агент дошлёт сам: жёлтая рамка, не тревога */
.bubble[data-status="retrying"] { outline: 2px dashed var(--amber); outline-offset: -2px; }
.bubble[data-status="retrying"] .time { color: var(--amber); }
.bubble.bubble--op[data-status="retrying"] .time { color: #7A5300; }
:root[data-theme="light"] .bubble[data-status="failed"] { border-color: #E9A3AA; color: #8A1220; }
.sys-pill {
  align-self: center; display: inline-flex; align-items: center; gap: 7px; font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 20px; padding: 4px 11px; color: var(--dim);
}
.doc-chip { font-family: var(--mono); font-size: 10.5px; background: var(--route); color: #04121F; border-radius: 4px; padding: 1px 5px; font-weight: 600; }

/* Цитаты: в пузыре — на что ответили; над полем ввода — на что отвечает сотрудник. */
.quote {
  display: block; border-left: 3px solid var(--route); background: rgba(127, 127, 127, .12);
  border-radius: 4px; padding: 3px 8px; margin: 2px 0 5px; font-size: 11.5px; cursor: pointer; white-space: normal;
}
.quote b { display: block; font-size: 10.5px; }
.quote-text { display: block; opacity: .85; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.bubble--out .quote, .bubble--ai .quote { border-left-color: #fff; background: rgba(255, 255, 255, .14); }
.bubble.is-flash, .sys-pill.is-flash { outline: 2px solid var(--amber); outline-offset: 2px; }
.composer-quote {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-top: 1px solid var(--border);
  background: var(--panel-2);
}
.composer-quote .quote-body { flex: 1; min-width: 0; border-left: 3px solid var(--route); padding-left: 8px; font-size: 12px; }
.composer-quote .quote-body b { display: block; font-size: 10.5px; color: var(--route); }
.composer-quote .quote-body span { display: block; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-menu {
  position: fixed; z-index: 1000; min-width: 190px; padding: 4px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); display: flex; flex-direction: column;
}
.ctx-menu[hidden] { display: none; }
.ctx-menu button {
  background: none; border: 0; color: var(--text); text-align: left; padding: 7px 10px; border-radius: 5px;
  font: inherit; font-size: 12.5px; cursor: pointer;
}
.ctx-menu button:hover { background: var(--panel-3); }
.ctx-menu hr { border: 0; border-top: 1px solid var(--border-soft); margin: 4px 2px; }
.ctx-menu button.danger { color: var(--urgent); }
/* Правка и удаление отправленного (администратор). */
.bubble.is-editing { max-width: 90%; width: 520px; }
.bubble .edit-text {
  display: block; width: 100%; margin: 4px 0 6px; resize: vertical; font: inherit; font-size: 13px;
  background: rgba(0, 0, 0, .25); color: #fff; border: 1px solid rgba(255, 255, 255, .35); border-radius: 6px; padding: 6px 8px;
}
.bubble .edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.bubble--deleted {
  align-self: flex-end; background: transparent; border: 1px dashed var(--border); color: var(--dim);
  border-bottom-right-radius: 3px;
}
.bubble--deleted .deleted-text { text-decoration: line-through; opacity: .75; }
.bubble .fwd { display: block; font-size: 11.5px; color: var(--dim); margin: 1px 0 4px; }
.bubble .fwd b { font-weight: 600; }
.bubble--deleted .deleted-text.dim { text-decoration: none; font-style: italic; }

.composer { flex: none; border-top: 1px solid var(--border); padding: 10px 14px; display: flex; gap: 10px; background: var(--panel); }
.composer textarea { flex: 1; resize: vertical; min-height: 38px; max-height: 160px; }
.composer-side { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.composer-hint { font-size: 10px; color: var(--dim); font-family: var(--mono); }

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); }
.btn--primary { background: var(--route); color: #04121F; border-color: transparent; font-weight: 600; }
.btn--primary:hover { filter: brightness(1.08); background: var(--route); }
.btn--danger { background: var(--urgent-soft); color: #FF98A2; border-color: #5B2730; }
.btn--ghost { background: transparent; }
.btn--sm { padding: 4px 8px; font-size: 11.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------------------------------------------------- правая панель разбора */
.side-body { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.side-block { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 10px; }
.side-block h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); font-weight: 600; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 8px; font-size: 12px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; word-break: break-word; }
.kv dd.empty { color: #4E5E6B; }
.meter { height: 5px; border-radius: 3px; background: var(--panel-3); overflow: hidden; margin: 6px 0; }
.meter i { display: block; height: 100%; background: var(--good); }
.meter[data-low="1"] i { background: var(--amber); }
.notes { margin: 6px 0 0; padding-left: 16px; font-size: 11.5px; color: var(--dim); }
.notes li { margin-bottom: 2px; }
.stub-warn { font-size: 11px; color: var(--amber); background: var(--amber-soft); border-radius: 5px; padding: 6px 8px; }

/* -------------------------------------------------------------- эскалации */
.esc-list { display: flex; flex-direction: column; gap: 10px; max-width: 1000px; }
.esc {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--amber);
  border-radius: var(--radius); padding: 12px;
}
.esc[data-urgency="high"] { border-left-color: var(--urgent); background: linear-gradient(90deg, rgba(255, 75, 92, .06), var(--panel) 40%); }
.esc[data-status="resolved"], .esc[data-status="discarded"] { border-left-color: var(--border); opacity: .72; }
.esc-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.esc-reason { font-weight: 600; }
.esc-sla { font-family: var(--mono); font-size: 11px; color: var(--good); margin-left: auto; }
.esc-sla[data-over="1"] { color: var(--urgent); font-weight: 600; }
.esc-src { margin: 9px 0; padding: 9px 11px; background: var(--panel-2); border-radius: 6px; font-size: 12.5px; white-space: pre-wrap; }
.esc-draft { margin-top: 8px; }
.esc-draft textarea { width: 100%; min-height: 62px; resize: vertical; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 8px 10px; font: inherit; }
.esc-actions { display: flex; gap: 7px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.esc-actions label { font-size: 11.5px; color: var(--dim); display: inline-flex; align-items: center; gap: 5px; }

/* --------------------------------------------------------------- таблицы */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left; padding: 8px 10px; background: var(--panel-2); color: var(--dim);
  font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 0; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.table tbody tr:hover { background: var(--panel-2); }
.table .num { font-family: var(--mono); font-size: 11.5px; color: var(--route); cursor: pointer; }
.table .mono { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.table select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 3px 5px; font: inherit; font-size: 11.5px; }
.tag { font-size: 10.5px; font-family: var(--mono); padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.tag--routine { background: rgba(58, 160, 255, .14); color: var(--route); }
.tag--emergency { background: var(--urgent-soft); color: #FF98A2; }
.tag--ai { background: rgba(124, 77, 255, .16); color: #C0A9FF; }
.tag--operator { background: var(--good-soft); color: var(--good); }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn { background: transparent; border: 0; color: var(--dim); padding: 5px 11px; cursor: pointer; font-size: 12px; }
.seg-btn.is-active { background: var(--panel-3); color: var(--text); }
.seg-count { display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 3px; border-radius: 8px; background: var(--panel-3); color: var(--dim); font-size: 11px; line-height: 16px; text-align: center; }
.seg-count[hidden] { display: none; }

/* ------------------------------------------------------------- настройки */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 9px; }
.stat { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 9px 11px; }
.stat b { display: block; font-size: 20px; font-family: var(--mono); font-weight: 500; }
.stat span { font-size: 11px; color: var(--dim); }
.stat[data-tone="urgent"] b { color: var(--urgent); }
.stat[data-tone="amber"] b { color: var(--amber); }
.stat[data-tone="good"] b { color: var(--good); }

.form { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.form--row { flex-direction: row; flex-wrap: wrap; align-items: center; }
.form label { font-size: 12px; color: var(--dim); display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.form label span { flex: 1; }
.form input[type="number"] { width: 92px; }
.form input[type="text"], .form textarea { flex: 2; min-width: 160px; }
.form textarea { resize: vertical; }
.form-actions { display: flex; gap: 8px; align-items: center; }
.saved { font-size: 11px; color: var(--good); }

/* ----------------------------------------------------------------- тосты */
.toasts { position: fixed; right: 14px; top: 58px; display: flex; flex-direction: column; gap: 7px; z-index: 40; }
.toast {
  background: var(--panel-3); border: 1px solid var(--border); border-left: 3px solid var(--route);
  border-radius: 6px; padding: 9px 12px; font-size: 12.5px; max-width: 340px;
  box-shadow: 0 12px 30px -12px #000; animation: toast-in .16s ease-out;
}
.toast[data-tone="urgent"] { border-left-color: var(--urgent); }
.toast[data-tone="amber"] { border-left-color: var(--amber); }
.toast[data-tone="good"] { border-left-color: var(--good); }
.toast b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); margin-bottom: 2px; }
.toast--msg { cursor: pointer; position: relative; padding-right: 26px; transition: opacity .2s; }
.toast--msg:hover { background: var(--panel-2); }
.toast--msg b { text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--text); }
.toast--msg .toast-text { display: block; overflow-wrap: anywhere; }
.toast-x { position: absolute; top: 4px; right: 4px; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 12px; padding: 2px 5px; }
.toast-x:hover { color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* Узкие экраны: панель разбора убираем, она выезжает поверх по кнопке ℹ️. */
.m-only, .m-side { display: none !important; }
@media (max-width: 1200px) {
  .inbox { grid-template-columns: 250px minmax(0, 1fr); position: relative; }
  .side { display: none; }
  .m-side { display: inline-flex !important; }
  .inbox.is-side .side {
    display: flex; position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 100%); z-index: 30;
    box-shadow: -14px 0 30px -12px rgba(0, 0, 0, .55);
  }
  .side .panel-head .m-close { margin-left: auto; }
  /* шапка не шире экрана: разделы прокручиваются, второстепенное прячем */
  .topbar { gap: 10px; }
  .brand-name, .channels, .online, .user-role { display: none; }
  .tabs { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { flex: none; }
  .topbar-right { flex: none; }
  .thread-head { min-width: 0; }
  .thread-who { flex: 1 1 auto; }
  .thread-name, .thread-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .thread-actions { min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
  .thread-actions .btn { flex: none; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* Привязка источника к организации из 1С */
.bind { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.bind-results { display: flex; gap: 5px; flex-wrap: wrap; width: 100%; margin-top: 5px; }
tr[data-verified="0"] { background: rgba(255, 75, 92, .05); }
tr[data-verified="0"] td:first-child { border-left: 2px solid var(--urgent); }

/* Голосовые: плеер внутри пузыря */
.media-audio { display: block; width: 280px; max-width: 100%; height: 36px; margin: 2px 0 4px; }
.media-video { display: block; width: 200px; height: 200px; border-radius: 50%; object-fit: cover; margin: 2px 0 4px; background: #000; }

/* Сортировка списков */
.sort-box { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); margin-left: 10px; }
.sort-select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 12px; }
@media (max-width: 640px) { .sort-box { margin: 8px 0 0; } }

/* Фото в сообщении: превью, по клику — целиком в новой вкладке */
.media-img { display: block; max-width: 320px; max-height: 320px; width: auto; height: auto; border-radius: 8px; object-fit: contain; background: rgba(0,0,0,.15); cursor: zoom-in; margin: 2px 0 4px; }

.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; box-shadow: 0 8px 40px rgba(0,0,0,.5); cursor: default; }
.lightbox-close { position: absolute; top: 14px; right: 18px; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 50%; width: 38px; height: 38px; font-size: 18px; cursor: pointer; }
.lightbox-close:hover { background: rgba(255,255,255,.25); }

/* ------------------------------------- закрепления, общий чат, онлайн (15.10) */
.list-tools {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 4px 8px;
  border-bottom: 1px solid var(--border-soft);
}
.list-hint { margin-left: auto; font-size: 10.5px; }
.pin-mark { font-size: 10px; flex: none; }
.conv-item--team { background: var(--panel-2); border-bottom: 2px solid var(--border); }
.ch-badge--team { background: #2F8F6B; font-size: 14px; }
/* архив чатов (16.10) — только у администраторов */
.conv-item--archive { background: var(--panel-2); }
.ch-badge--archive { background: #6B7280; font-size: 14px; }
.archive-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-weight: 600;
  background: var(--panel-2); border-bottom: 2px solid var(--border); cursor: pointer;
}
.archive-head .dim { font-weight: 400; font-size: 10.5px; margin-left: auto; }
#btnPinConv.is-on { background: var(--amber-soft); border-color: var(--amber); }

.pin-bar {
  flex: none; max-height: 98px; overflow: auto; border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2); padding: 4px 14px;
}
.pin-row { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 0; cursor: pointer; min-width: 0; }
.pin-row:hover .pin-text { color: var(--text); }
.pin-row b { flex: none; font-weight: 600; }
.pin-text { flex: 1; min-width: 0; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-row .btn { flex: none; padding: 0 6px; }

.bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.mention { background: var(--amber-soft); color: var(--amber); border-radius: 3px; padding: 0 2px; font-weight: 600; }
.bubble--out .mention { background: rgba(255, 255, 255, .2); color: #fff; }
.mention.is-me { background: var(--amber); color: #1A1200; }
.bubble.is-mention { box-shadow: inset 3px 0 0 var(--amber); }
.ref-card {
  display: block; margin: 2px 0 5px; padding: 5px 8px; border-left: 3px solid var(--route);
  background: rgba(58, 160, 255, .12); border-radius: 4px; cursor: pointer; font-size: 12px; white-space: normal;
}
.ref-card:hover { background: rgba(58, 160, 255, .22); }
.ref-card b { display: block; font-size: 10.5px; }
.ref-card .ref-text { display: block; opacity: .85; }
.bubble--out .ref-card { border-left-color: #fff; background: rgba(255, 255, 255, .14); }

.composer--team, .composer--main { position: relative; }
/* Внутренняя заметка в чате партнёра: видна только сотрудникам */
.note-mode { flex: none; padding: 6px 14px; font-size: 12px; background: var(--amber-soft); color: var(--amber); border-top: 1px solid var(--border); }
.composer.is-note { background: var(--amber-soft); }
.bubble--note {
  align-self: center; max-width: min(560px, 92%); background: var(--amber-soft); border: 1px dashed var(--amber);
  color: var(--text); position: relative; padding-right: 26px;
}
.bubble--note .who { color: var(--amber); }
.bubble--note .note-del { position: absolute; top: 4px; right: 6px; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 11px; }
.bubble--note .note-del:hover { color: var(--urgent); }
/* опоздавшее сообщение: написано раньше, чем дошло (обрыв связи) */
.time .late { color: var(--amber); }
.conv-at { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 8px; background: var(--amber); color: #1A1200; font-size: 11px; font-weight: 700; }

.mention-box {
  position: absolute; left: 14px; bottom: calc(100% + 4px); min-width: 260px; max-width: 360px; z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35); padding: 4px;
}
.mention-item { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 5px; cursor: pointer; font-size: 12.5px; }
.mention-item .dim { margin-left: auto; font-size: 11px; }
.mention-item.is-active, .mention-item:hover { background: var(--panel-3); }

.online-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--border); display: inline-block; }
.online-dot.is-on { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.online-row { display: flex; align-items: center; gap: 9px; padding: 6px 4px; border-radius: 6px; cursor: pointer; }
.online-row:hover { background: var(--panel-3); }
.online-row.is-off { opacity: .6; }
.online-meta { min-width: 0; display: flex; flex-direction: column; }
.online-meta b { font-size: 12.5px; font-weight: 600; }
.online-meta .dim { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-note { font-size: 11px; margin: 0 2px; }
#iridaPreview { margin-top: 10px; }
#iridaPreview .kv { grid-template-columns: 130px 1fr; margin-bottom: 10px; }
#iridaPreview .warn { color: var(--urgent, #f87171); margin: 6px 0; }
#iridaPreview .ok { color: var(--good, #4ade80); margin: 8px 0 0; }

/* почта сотрудника в таблице «Сотрудники» (для чата поддержки, 16.10) */
.input-sm {
  width: 200px; padding: 3px 6px; font-size: 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
}

/* картинки к сообщению: скрепка, Ctrl+V, перетаскивание (16.10) */
.att-clip { flex: none; align-self: flex-end; padding: 6px 8px; font-size: 16px; line-height: 1; }
.att-thumbs { flex: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; background: var(--panel); border-top: 1px solid var(--border); }
.att-thumbs + .composer { border-top: 0; }
.att-thumb { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-thumb button {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .65); color: #fff; font-size: 13px; line-height: 18px; cursor: pointer;
}
.is-drop .thread-log, .is-drop.team-log, .is-drop #teamLog { outline: 2px dashed var(--route); outline-offset: -6px; }
.team-imgs { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 4px; }
.team-imgs .media-img { max-width: 240px; max-height: 220px; }

/* постраничный вывод под списками эскалаций и обращений */
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 1000px; margin-top: 14px; font-size: 13px; }
.pager[hidden] { display: none; }
.pager-btn { min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: inherit; cursor: pointer; }
.pager-btn:hover:not(:disabled) { background: var(--panel-3); }
.pager-btn.is-active { background: var(--route); border-color: var(--route); color: #fff; }
.pager-btn:disabled { opacity: .4; cursor: default; }
.pager-gap { padding: 0 4px; color: var(--dim); }
.pager-info { margin-left: 10px; color: var(--dim); }
.pager-size { margin-left: auto; color: var(--dim); display: inline-flex; align-items: center; gap: 6px; }

/* фильтры журнала */
.jfilters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0 0 12px; font-size: 12px; color: var(--dim); }
.jfilters label { display: inline-flex; align-items: center; gap: 6px; }
.jfilters input[type="date"], .jfilters input[type="search"], .jfilters select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 12.5px; }
.jfilters select { max-width: 220px; }
.jfilters .jf-grow { flex: 1 1 200px; }
.jfilters .jf-grow input { flex: 1; min-width: 120px; }
.jfilters [hidden] { display: none; }
.jf-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 10px; background: var(--panel-3); color: var(--text); }
.jf-chip button { border: 0; background: none; color: var(--dim); cursor: pointer; font-size: 14px; line-height: 1; }
.table .conv-link { color: var(--route); cursor: pointer; }
@media (max-width: 640px) {
  .jfilters label:not(.jf-check) { flex: 1 1 100%; }
  .jfilters label select, .jfilters label input[type="search"] { flex: 1; width: 0; min-width: 0; max-width: none; }
}

/* Настройки → условия обработки ИИ */
.air-pick { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; font-size: 12px; color: var(--dim); }
.air-pick label { display: inline-flex; align-items: center; gap: 8px; }
.air-pick select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font: inherit; font-size: 13px; max-width: 460px; }
.air-pick .filter { width: 220px; }
.air-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-size: 12px; }
.air-chip { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 12px; padding: 2px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.air-chip.is-active { border-color: var(--route); color: var(--route); }
.air-form { margin-top: 14px; }
.air-form .air-row { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 12px; align-items: start; font-size: 12.5px; color: var(--text); }
.air-form .air-row > span small { display: block; margin-top: 2px; font-size: 11px; line-height: 1.35; }
.air-form .air-row textarea { width: 100%; min-width: 0; }
.air-form .air-row input[type="text"] { width: 100%; }
.air-form .air-row input[type="checkbox"] { justify-self: start; }
.air-own-body { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.air-own-body textarea, .air-own-body input[type="text"] { flex: 1 1 260px; }
.air-own-body select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 12.5px; }
.air-own-body :disabled { opacity: .55; }
.air-fields { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.air-form .air-check { display: inline-flex; gap: 5px; align-items: center; justify-content: flex-start; color: var(--text); font-size: 12.5px; }
.air-head { font-size: 13px; padding: 8px 0 4px; border-bottom: 1px solid var(--border-soft); }
.air-general pre { white-space: pre-wrap; font-family: var(--mono); font-size: 11.5px; color: var(--dim); background: var(--panel-2); padding: 10px; border-radius: 6px; margin: 6px 0 0; }
.air-general summary { cursor: pointer; font-size: 12px; }
@media (max-width: 760px) { .air-form .air-row { grid-template-columns: 1fr; gap: 4px; } .air-pick select, .air-pick .filter { max-width: 100%; width: 100%; } .air-pick label { width: 100%; } }

/* Настройки → источники: фильтр и поиск */
.ptools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 10px 0; }
.ptools .filter { flex: 1 1 220px; max-width: 360px; }

/* Реакции сотрудников под пузырём (👀 смотрю, ✅ готово) — только в агенте */
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; white-space: normal; }
.react {
  font: inherit; font-size: 11px; line-height: 1; padding: 3px 7px; border-radius: 10px; cursor: pointer;
  background: rgba(127, 127, 127, .16); border: 1px solid transparent; color: inherit;
}
.react:hover { background: rgba(127, 127, 127, .28); }
.react.is-mine { border-color: currentColor; font-weight: 600; }
.bubble--out .react, .bubble--ai .react { background: rgba(255, 255, 255, .18); }
.bubble.bubble--op .react { background: rgba(0, 0, 0, .07); }
.bubble.bubble--op .react:hover { background: rgba(0, 0, 0, .14); }

/* Закрытые группы: строка в списке и окно управления */
.conv-item--group .ch-badge { font-size: 14px; }
.group-modal { position: fixed; inset: 0; z-index: 900; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.group-modal-box {
  background: var(--panel); color: var(--text); border: 1px solid var(--border-soft); border-radius: 10px;
  width: 560px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .4);
}
.group-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.group-modal-head h3 { margin: 0; font-size: 15px; }
.group-modal-body { padding: 12px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.group-modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border-soft); }
.group-list-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; background: var(--panel-2); }
.group-list-row .grow { flex: 1; min-width: 0; }
.group-list-row .dim { display: block; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-members { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 10px; max-height: 320px; overflow: auto; }
.group-members label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.group-modal input[type="text"] {
  width: 100%; box-sizing: border-box; margin-top: 4px; padding: 7px 9px; font: inherit; font-size: 13px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
}
.group-modal input[type="text"]:focus { outline: none; border-color: var(--route); }
.group-modal label { font-size: 12px; color: var(--dim); }
.group-members label { color: var(--text); }

/* «Переслать»: выбор сообщений и окно выбора чата */
.fwd-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 14px;
  border-top: 1px solid var(--border-soft); background: var(--panel-2); font-size: 13px;
}
.fwd-bar .fwd-hint { flex: 1; min-width: 160px; font-size: 12px; }
.bubble.is-pickable { cursor: pointer; }
.bubble.is-picked { outline: 2px solid var(--route); outline-offset: 2px; }
.bubble.is-picked::after {
  content: '✓'; position: absolute; top: -8px; right: -8px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--route); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.bubble.is-unpickable { opacity: .45; }
.fwd-list { display: flex; flex-direction: column; gap: 3px; max-height: 300px; overflow: auto; }
.fwd-row {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px; border: 1px solid transparent;
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.fwd-row:hover { border-color: var(--border); }
.fwd-row.is-on { border-color: var(--route); background: var(--panel-3); }
.fwd-row .grow { flex: 1; min-width: 0; }
.fwd-row .dim { display: block; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-modal textarea {
  width: 100%; box-sizing: border-box; margin-top: 4px; padding: 7px 9px; font: inherit; font-size: 13px; resize: vertical;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
}
.group-modal textarea:focus { outline: none; border-color: var(--route); }
.fwd-note { margin: 0; font-size: 12px; }
.bubble .fwd--link { cursor: pointer; text-decoration: underline dotted; }

/* ------------------------------------------------------------- телефон
 * Флагманы (390–430 px по ширине): один экран за раз — список чатов, переписка
 * (кнопка «←»), разбор и заявка поверх (ℹ️). Меню сообщения — долгим нажатием.
 * Поля ввода — 16 px: с меньшим шрифтом iPhone приближает страницу при вводе. */
@media (max-width: 820px) {
  .m-only { display: inline-flex !important; }
  .app { height: 100dvh; }

  .topbar {
    height: auto; flex-wrap: wrap; gap: 4px 8px; padding: 6px 10px 0;
    padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
  }
  .brand-name, .channels, .online, #userName, .user-role, .list-hint { display: none; }
  .topbar-right { gap: 4px; }
  .topbar-right .icon-btn { font-size: 17px; padding: 6px; }
  .user-chip { padding-left: 4px; border-left: 0; }
  .tabs { order: 3; flex: 1 1 100%; margin: 0 -10px; padding: 2px 6px 6px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { flex: none; padding: 8px 11px; font-size: 13.5px; }

  .inbox { grid-template-columns: minmax(0, 1fr); }
  .conv-list { display: flex; border-right: 0; }
  .thread { display: none; }
  .inbox.is-chat .conv-list { display: none; }
  .inbox.is-chat .thread { display: flex; }
  .inbox.is-side .side { width: 100%; box-shadow: none; }
  .panel-head { height: 44px; }
  .panel-head .filter { width: auto; flex: 1; font-size: 16px; padding: 6px 9px; }
  .conv-item { padding: 12px 10px; -webkit-touch-callout: none; }
  .conv-item .ch-badge { width: 38px; height: 38px; border-radius: 11px; font-size: 13px; }
  .conv-item .ch-badge svg { width: 19px; height: 19px; }
  .conv-name { font-size: 14.5px; }

  .thread-head { height: auto; min-height: 48px; padding: 6px 8px; gap: 4px 6px; flex-wrap: wrap; }
  .thread-who { flex: 1; min-width: 0; }
  .thread-who > div { min-width: 0; }
  .thread-name, .thread-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .thread-head .thread-actions { order: 3; flex: 1 1 100%; margin-left: 0; gap: 5px; overflow-x: auto; scrollbar-width: none; }
  .thread-head .thread-actions:empty { display: none; }
  .thread-head .thread-actions .btn { padding: 6px 9px; font-size: 12.5px; white-space: nowrap; flex: none; }
  #btnSide { order: -1; }
  #teamSide { order: 2; }
  #threadViewers { display: none; }
  .m-back { font-size: 20px; line-height: 1; padding: 6px 10px; }
  .thread-log { padding: 10px 8px; }
  .bubble { max-width: 88%; -webkit-touch-callout: none; }
  .media-img { max-width: 100%; }

  .composer { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); gap: 6px; align-items: flex-end; }
  .composer textarea { font-size: 16px; min-height: 44px; resize: none; }
  .composer-hint { display: none; }
  .composer .btn--primary { padding: 11px 12px; }
  .att-clip { padding: 10px 8px; }
  .composer-quote, .fwd-bar, .find-bar { padding-left: 8px; padding-right: 8px; }
  .fwd-bar .fwd-hint { display: none; }

  .filter, .find-bar .filter, .form input, .form select, .form textarea,
  .group-modal input[type="text"], .group-modal textarea, .login-card input { font-size: 16px; }
  .ctx-menu { min-width: 220px; }
  .ctx-menu button { padding: 11px 14px; font-size: 14.5px; }

  .toasts { left: 10px; right: 10px; top: calc(56px + env(safe-area-inset-top)); }
  .toast { max-width: none; }
  .page { padding: 12px 10px calc(40px + env(safe-area-inset-bottom)); }
  .page--cols { grid-template-columns: minmax(0, 1fr); }
  .group-modal { padding: 0; align-items: stretch; }
  .group-modal-box { width: 100%; max-height: none; height: 100dvh; border-radius: 0; border: 0; }
  .group-modal-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .lightbox { padding: 8px; }
}
