/* Панель поддержки (AI-14352, ADR-220). Тот же язык, что у панели управления
 * (frontend/control/css/control.css): токены в :root, светлая и тёмная тема.
 * Телефон — равноправный экран: контролы 44 px, поля 16 px (iOS не зумит),
 * обращение — чат на всю видимую область над клавиатурой (--vv-top/--vvh из core.js). */
:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --text: #1b1b1a;
  --text-2: #52514e;
  --muted: #76756f;
  --border: #e3e2de;
  --accent: #2a78d6;
  --accent-soft: #e6f0fb;
  --good: #1a7f45;
  --good-soft: #e3f3e9;
  --warn: #a5650b;
  --warn-soft: #fbf0dc;
  --bad: #c93a3a;
  --bad-soft: #fbe7e7;
  --note: #fdf3d0;
  --note-border: #e6cf7a;
  --radius: 10px;
  --gap: 16px;
  --control-h: 36px;
  --field-font: 14px;
  --content-max: 960px;
  --desk-max: 1480px;
  --sheet-max: 560px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2376756f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1b1b1a;
    --surface-2: #242422;
    --text: #f1f0ec;
    --text-2: #c9c8c0;
    --muted: #9b9a92;
    --border: #2f2f2c;
    --accent: #5b9df0;
    --accent-soft: #1d2b3d;
    --good: #4cc27f;
    --good-soft: #17301f;
    --warn: #e0a54a;
    --warn-soft: #33270f;
    --bad: #ef7070;
    --bad-soft: #3a1c1c;
    --note: #33290c;
    --note-border: #6b5a1c;
  }
}
/* Телефон и планшет в портрете: палец, а не курсор. */
@media (max-width: 899px) {
  :root { --control-h: 44px; --field-font: 16px; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1 1 auto; }
.boot, .loading { color: var(--muted); padding: 40px 16px; text-align: center; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ── Кнопки и поля: одна высота, рамка, шрифт (правило UI 3) ─────── */
.btn {
  font: inherit; font-weight: 500; border-radius: 8px; padding: 0 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  height: var(--control-h); white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
a.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger-outline { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-ghost { background: transparent; }
.btn-icon { width: var(--control-h); padding: 0; flex: none; }
.btn-block { width: 100%; }
.input {
  font: inherit; font-size: var(--field-font); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 10px; height: var(--control-h); min-width: 0; width: 100%;
}
.input:disabled { background: var(--surface-2); color: var(--muted); }
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 72px; line-height: 1.4; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; text-overflow: ellipsis;
  background: var(--surface) var(--arrow) no-repeat right 12px center;
}
input[type="search"] { -webkit-appearance: none; appearance: none; }
.input:focus, .btn:focus-visible, .seg-btn:focus-visible, .tab:focus-visible, .q-item:focus-visible,
.pick:focus-visible, .thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; height: var(--control-h); }
.seg-btn {
  font: inherit; border: 0; background: transparent; color: var(--text-2); padding: 0 12px; height: 100%;
  border-radius: 7px; cursor: pointer; white-space: nowrap; flex: 1 1 0;
}
.seg-btn.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; min-width: 0; }
.field > span:first-child { color: var(--text-2); }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-error { color: var(--bad); background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.callout { padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.callout-warn { background: var(--warn-soft); color: var(--text); border: 1px solid var(--warn); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; min-height: var(--control-h); }
.check input { width: 20px; height: 20px; margin: 0; flex: none; }
.danger-zone { padding-top: 12px; border-top: 1px solid var(--border); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.empty { text-align: center; padding: 32px 16px; color: var(--text-2); }
.empty-title { font-weight: 600; font-size: 15px; color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 auto; max-width: 420px; }
.plain-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }

.chip {
  display: inline-block; font-size: 11.5px; line-height: 18px; padding: 0 7px; border-radius: 9px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap; font-weight: 500;
}
.chip-ok { background: var(--good-soft); color: var(--good); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-error { background: var(--bad-soft); color: var(--bad); }
.chip-info { background: var(--accent-soft); color: var(--accent); }
.count, .badge {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; text-align: center;
  font-size: 12px; line-height: 20px; font-weight: 600; background: var(--surface-2); color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.count-hot, .badge { background: var(--accent); color: #fff; }

.notice {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(var(--vv-top, 0px) + env(safe-area-inset-top, 0px) + 10px);
  max-width: calc(100vw - 32px); background: var(--good); color: #fff; padding: 9px 14px; border-radius: 10px;
  font-weight: 500; box-shadow: 0 6px 20px rgba(0,0,0,.2); text-align: center;
}

/* ── Вход ────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login > .muted { margin-top: -8px; }
.login .input, .login .btn { height: 44px; font-size: 16px; }
.login .btn { width: 100%; }

/* ── Шапка ───────────────────────────────────────────────────────── */
.top { background: var(--surface); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top, 0px); }
.top-row {
  max-width: var(--desk-max); margin: 0 auto; display: flex; align-items: center; gap: 4px 16px;
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tabs, .status-tabs { display: flex; gap: 4px; min-width: 0; }
.tab {
  white-space: nowrap; padding: 0 10px; height: 44px; display: inline-flex; align-items: center;
  color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.content { max-width: var(--content-max); margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); }
.view { display: flex; flex-direction: column; gap: var(--gap); }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.view-head > div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }

/* ── Очередь ─────────────────────────────────────────────────────── */
.tickets-view { max-width: var(--desk-max); margin: 0 auto; }
.toolbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 16px 10px; }
.status-tabs { border-bottom: 1px solid var(--border); margin: 0 -16px 10px; padding: 0 16px; }
.toolbar-row { display: flex; gap: 8px; align-items: center; }
.search-input { flex: 1 1 240px; max-width: 360px; }
.toolbar-filters { display: flex; gap: 8px; margin-left: auto; min-width: 0; }
.toolbar-filters .select { width: auto; max-width: 260px; }
.status-select, .filter-btn { display: none; }

.q-list { display: flex; flex-direction: column; }
.q-item {
  display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; color: var(--text);
  border-bottom: 1px solid var(--border); background: var(--surface); min-width: 0;
}
.q-item:hover { text-decoration: none; }
@media (hover: hover) { .q-item:hover { background: var(--surface-2); } }
.q-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.q-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; align-self: center; }
.q-num { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.q-subject { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.q-item.unread .q-subject { font-weight: 700; }
.q-who { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.q-preview {
  color: var(--muted); font-size: 13px; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 2px; }
.q-time { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.q-status { color: var(--muted); font-size: 12px; text-align: center; padding: 10px 16px 0; overflow-wrap: anywhere; }
.q-status:empty { display: none; }
.more-btn { display: flex; margin: 10px 16px 16px; width: calc(100% - 32px); }

/* ── Обращение ───────────────────────────────────────────────────── */
.pane { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; background: var(--bg); }
.pane-head { background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.pane-head-row { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 320px; }
.pane-titles { min-width: 0; flex: 1 1 auto; }
.pane-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-sub { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-controls { display: flex; gap: 8px; min-width: 0; }
.ctl { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ctl-label { color: var(--muted); font-size: 12px; }
.ctl .select { width: auto; }
.pane-error { flex-basis: 100%; }
.back-btn { display: none; }
.pane-body { flex: 1 1 auto; min-height: 0; display: flex; }
.pane-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.pane-aside { width: 300px; flex: none; overflow-y: auto; border-left: 1px solid var(--border); background: var(--surface); padding: 14px 16px; display: none; }

.chat { flex: 1 1 auto; min-height: 0; position: relative; }
.chat-log { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.chat-log > :first-child { margin-top: auto; }  /* короткая переписка прижата к полю ответа */
.msg { max-width: min(78%, 620px); padding: 8px 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); min-width: 0; }
.msg-user { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-staff { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--accent-soft); border-color: transparent; }
.msg-note { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--note); border: 1px dashed var(--note-border); }
.msg-label { font-size: 12px; font-weight: 600; color: var(--warn); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.4; }
.msg-time { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.msg-staff .msg-time, .msg-note .msg-time { text-align: right; }
.msg-system { align-self: center; text-align: center; color: var(--muted); font-size: 12.5px; padding: 2px 10px; max-width: 100%; overflow-wrap: anywhere; }
.msg-system .msg-time { margin: 0; white-space: nowrap; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-body + .thumbs { margin-top: 8px; }
.thumb { padding: 0; border: 0; background: var(--surface-2); border-radius: 8px; overflow: hidden; cursor: zoom-in; display: block; }
.thumb img { display: block; max-width: 100%; height: auto; max-height: 180px; object-fit: cover; }
.new-pill { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); box-shadow: 0 4px 14px rgba(0,0,0,.18); border-color: var(--accent); color: var(--accent); }
.drop-hint {
  position: absolute; inset: 8px; z-index: 5; border: 2px dashed var(--accent); border-radius: 12px; pointer-events: none;
  background: color-mix(in srgb, var(--accent-soft) 85%, transparent); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; text-align: center; padding: 16px;
}

/* Поле ответа */
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 16px; display: flex; flex-direction: column; gap: 8px; }
.composer-note { background: var(--note); }
.composer-text { min-height: var(--control-h); max-height: 180px; resize: none; font-size: max(15px, var(--field-font)); }
.composer-hint { color: var(--warn); font-size: 12.5px; }
.composer-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.composer-tools, .composer-send { display: flex; align-items: center; gap: 8px; min-width: 0; }
.composer-send { margin-left: auto; }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; }
.attach { position: relative; width: 72px; height: 72px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.attach img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-x {
  position: absolute; top: 0; right: 0; width: 44px; height: 44px; padding: 0; border: 0; cursor: pointer; background: none; color: #fff;
  display: flex; align-items: flex-start; justify-content: flex-end;
}
.attach-x .icon { width: 26px; height: 26px; padding: 4px; background: rgba(0,0,0,.6); border-radius: 0 0 0 8px; }
.attach-loading::after {
  content: ""; position: absolute; inset: 20px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Сведения об авторе */
.info { display: flex; flex-direction: column; gap: 18px; }
.info-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.info-block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: minmax(84px, 38%) minmax(0, 1fr); gap: 2px 10px; align-items: baseline; }
.kv-k { color: var(--text-2); font-size: 13px; }
.kv-v { overflow-wrap: anywhere; }
.info .field { margin-top: 4px; }

/* Выбор из частых вопросов */
.pick-list { display: flex; flex-direction: column; gap: 8px; }
.pick {
  font: inherit; text-align: left; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 44px; min-width: 0;
}
.pick:hover { border-color: var(--accent); }
.pick-q { font-weight: 600; overflow-wrap: anywhere; }
.pick-a {
  color: var(--text-2); font-size: 13px; white-space: pre-wrap; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3;
}

/* ── Частые вопросы ──────────────────────────────────────────────── */
.faq-list { display: flex; flex-direction: column; gap: 10px; }
.faq-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start;
}
.faq-draft { border-style: dashed; }
.faq-pos { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 20px; padding-top: 1px; }
.faq-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.faq-q { font-size: 15px; overflow-wrap: anywhere; }
.faq-a {
  color: var(--text-2); white-space: pre-wrap; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4;
}
.faq-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.faq-actions { display: flex; gap: 8px; }
.quote { border-left: 3px solid var(--border); padding-left: 10px; color: var(--text-2); overflow-wrap: anywhere; }

/* ── Шит: ширины контента на широком (правило 5), снизу на телефоне ─ */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: var(--sheet-max); outline: none;
  max-height: calc(var(--vvh, 100vh) - 32px); display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.sheet-head { padding: 16px 16px 8px; }
.sheet-head h2 { font-size: 17px; overflow-wrap: anywhere; }
.sheet-body { padding: 4px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
/* Кнопки шита — во всю ширину поровну (правило 1), три и больше — столбиком. */
.sheet-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; padding: 16px; }
.sheet-actions-stack { grid-auto-flow: row; }
.sheet-actions .btn { width: 100%; height: 44px; }

.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.94); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
}
.lightbox img { max-width: 100%; min-height: 0; flex: 0 1 auto; object-fit: contain; border-radius: 6px; }
.lightbox-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; max-width: 100%; }
.lightbox-name { color: #fff; opacity: .8; overflow-wrap: anywhere; font-size: 13px; }
.lightbox .btn { height: 44px; }

/* ── Широкий экран: очередь слева, обращение справа, прокрутка у каждой своя ── */
@media (min-width: 900px) {
  body[data-view="tickets"] .app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  body[data-view="tickets"] .main { flex: 1 1 auto; min-height: 0; }
  .tickets-view { height: 100%; display: flex; flex-direction: column; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .desk { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(320px, 30%) minmax(0, 1fr); }
  .queue-col { overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface); min-width: 0; }
  .ticket-col { display: flex; min-width: 0; min-height: 0; align-items: stretch; }
  .ticket-col > .empty { margin: auto; }
}
@media (min-width: 1200px) {
  .pane-aside { display: block; }
  .info-btn { display: none; }
  .desk { grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); }
}

/* ── Телефон: список и обращение по очереди ──────────────────────── */
@media (max-width: 899px) {
  .top-row { flex-wrap: wrap; padding-top: 4px; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -4px; }
  .who { max-width: 40vw; }
  .content { padding-top: 12px; }
  .view-head { flex-direction: column; align-items: stretch; }
  .view-head .btn { width: 100%; }

  .toolbar { padding: 10px 12px; position: sticky; top: 0; z-index: 4; }
  .status-tabs, .toolbar-filters { display: none; }
  .toolbar-row { flex-wrap: wrap; }
  .search-input { flex: 1 1 100%; max-width: none; }
  .status-select { display: block; flex: 1 1 0; }
  .filter-btn { display: inline-flex; flex: none; }
  .q-list { gap: 8px; padding: 10px 12px 0; }
  .q-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
  .q-top { align-items: flex-start; }
  .q-top .dot { align-self: flex-start; margin-top: 7px; }
  .q-subject { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; }
  .more-btn { margin: 10px 12px calc(16px + env(safe-area-inset-bottom, 0px)); width: calc(100% - 24px); }
  .queue-col { padding-bottom: env(safe-area-inset-bottom, 0px); }

  .ticket-col { display: none; }
  body.ticket-open { overflow: hidden; }
  body.ticket-open .top, body.ticket-open .toolbar, body.ticket-open .queue-col { display: none; }
  /* Чат занимает ровно видимую полосу: клавиатура iOS накрывает страницу, а не сжимает её. */
  body.ticket-open .ticket-col {
    display: flex; position: fixed; z-index: 10; left: 0; right: 0;
    top: var(--vv-top, 0px); height: var(--vvh, 100dvh); background: var(--bg);
  }
  .back-btn { display: inline-flex; }
  .pane-head { padding: calc(env(safe-area-inset-top, 0px) + 8px) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); gap: 8px; }
  .pane-head-row { flex-basis: 100%; gap: 8px; }
  .pane-controls { flex: 1 1 100%; }
  .ctl { flex: 1 1 0; }
  .ctl-label { display: none; }
  .ctl .select { width: 100%; }
  .chat-log { padding: 10px 12px; }
  .msg { max-width: 86%; }
  .composer { padding: 8px max(12px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }
  .kb-open .composer { padding-bottom: 8px; }
  /* Пока набирают ответ, статус и приоритет уступают место переписке. */
  .kb-open .pane-controls { display: none; }
  .composer-text { max-height: 120px; }
  /* 375: скрепка, частые вопросы и «Ответ/Заметка» в одну строку; 320 — переключатель уходит на свою. */
  .composer-tools { flex: 1 1 100%; flex-wrap: wrap; }
  .composer-tools .faq-btn { flex: 1 1 auto; padding: 0 8px; }
  .composer-tools .seg { flex: 1 1 auto; padding: 0; }  /* зона нажатия сегмента — все 44 px */
  .composer-tools .seg-btn { padding: 0 10px; }
  /* Кнопки отправки — во всю ширину поровну, главное действие справа. */
  .composer-send { flex: 1 1 100%; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
  .composer-send .btn { padding: 0 6px; min-width: 0; }

  .faq-card { grid-template-columns: auto minmax(0, 1fr); padding: 12px; }
  .faq-actions { grid-column: 1 / -1; }
  .faq-actions .btn:last-child { flex: 1 1 auto; }

  .sheet-backdrop { align-items: flex-end; padding: var(--vv-top, 0px) 0 var(--kb-inset, 0px); }
  .sheet { max-width: none; border-radius: 14px 14px 0 0; max-height: calc(var(--vvh, 100dvh) - 24px); }
  .sheet-actions { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .kb-open .sheet-actions { padding-bottom: 16px; }
}

/* Самые узкие телефоны: счётчик в списке статусов важнее подписи кнопки. */
@media (max-width: 359px) {
  .filter-text { display: none; }
  .filter-btn { min-width: 44px; padding: 0 10px; }
  .filter-btn .badge { margin-left: 0; }
  .composer-send .btn { font-size: 13px; }
}
