:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #e3e5e9; --text: #1d2129; --muted: #6b7280;
  --accent: #2563eb; --accent-soft: #e8efff; --in: #ffffff; --out: #dcf3e4; --note: #fff6d6;
  --danger: #dc2626; --ok: #16a34a; --warn: #d97706; --brown: #8b5a2b; --side: #1f2937;
  --who0: #e1efff; --who1: #fde7ea; --who2: #efe6ff; --who3: #ffeedd; --who4: #dff5f5; --who5: #f3f0d8; --who6: #f6e3f7; --who7: #e6e9f2;
  color-scheme: light;
}
:root[data-theme="dark"] { --bg: #111418; --panel: #1a1e24; --line: #2b313a; --text: #e6e8eb; --muted: #9aa3ae;
  --accent: #5b8cff; --accent-soft: #1f2a44; --in: #222831; --out: #17352a; --note: #3a3218; --brown: #b07d4f; --side: #0b0d10;
  --who0: #1f3350; --who1: #43252c; --who2: #32294f; --who3: #453220; --who4: #17403f; --who5: #3a3a1e; --who6: #452649; --who7: #2c3240;
  color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--accent); }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--panel); width: 100%; }
textarea { resize: vertical; }
label { display: block; margin: 8px 0; color: var(--muted); font-size: 14px; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
label.chk { display: flex; align-items: center; gap: 6px; }
label.chk input { width: auto; margin: 0; }
.muted { color: var(--muted); }
.pos { font-size: .82em; font-weight: normal; opacity: .7; white-space: nowrap; }  /* должность рядом с именем сотрудника */
.err { color: var(--danger); min-height: 1.2em; margin-top: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }

.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login h1 { margin: 0; }
.login button { width: 100%; margin-top: 12px; padding: 10px; }

.app { display: flex; height: 100%; }
.side { width: 60px; background: var(--side); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 6px; }
.side .brand { color: #fff; font-weight: 700; margin-bottom: 10px; }
.side .nav { width: 42px; height: 42px; border: 0; background: transparent; font-size: 19px; border-radius: 12px; padding: 0; transition: background .12s; }
.side .nav.active, .side .nav:hover { background: rgba(255,255,255,.12); }
.side .nav { position: relative; }
.side .nav .badge { position: absolute; top: -2px; right: -2px; padding: 0 5px; font-size: 12px; }
.settings { max-width: 440px; margin-top: 16px; }
.settings.wide { max-width: 760px; }
.settings textarea { width: 100%; resize: vertical; font-size: 14px; }
.settings-title { margin: 28px 0 0; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; }
.aibox { max-height: 38vh; overflow-y: auto; margin-bottom: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.aihead { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.aihead .grow { flex: 1; }
.aihead button { padding: 0 6px; font-size: 13px; }
.aicards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 6px; }
.aicard { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.aicard b { font-size: 13px; color: var(--accent); }
.aicard .txt { flex: 1; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.aicard .row { display: flex; gap: 4px; }
.aicard .row button { flex: 1; padding: 2px 6px; font-size: 13px; }
button.on { border-color: var(--accent); background: var(--accent-soft); }
.grow { flex: 1; }
.view { flex: 1; min-width: 0; }

.chats { display: flex; height: 100%; }
.list { flex: none; width: 340px; margin: 8px 0 8px 8px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--panel);
  box-shadow: 0 2px 10px rgba(0,0,0,.06); display: flex; flex-direction: column; }
.filters { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.filters button { border-radius: 10px; transition: background .12s, border-color .12s; }
.filters button:hover { background: var(--accent-soft); }
.filters .grouping button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#q, .filters select { border-color: transparent; border-radius: 12px; background: var(--bg); transition: background .12s, border-color .12s; }
#q:hover, .filters select:hover { border-color: var(--line); }
#q:focus, .filters select:focus { outline: 0; border-color: var(--accent); background: var(--panel); }
.filters .row { display: flex; gap: 6px; }
.filter-body { display: grid; gap: 8px; }
#filterFold { display: inline-flex; align-items: center; flex: none; }
.filters label.chk { margin: 0; }
.convs { overflow-y: auto; flex: 1; padding: 0 8px 8px 4px; }
.filters .find-row { justify-content: space-between; align-items: center; }
.filters .find-row button { padding: 3px 10px; font-size: 13px; }
.rm-list { display: grid; gap: 8px; max-height: 55vh; overflow-y: auto; }
.rm-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 4px; }
.rm-top, .rm-line { display: flex; align-items: center; gap: 6px; }
.rm-row button { padding: 2px 8px; font-size: 13px; flex: none; }
.rm-name { min-width: 0; word-break: break-word; }
.rm-id { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.bc-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.bc-tools select { width: auto; flex: 1 1 130px; }
.bc-tools input { flex: 2 1 160px; width: auto; }
.bc-tools button { padding: 3px 8px; font-size: 13px; }
.bc-list { max-height: 34vh; overflow-y: auto; min-height: 90px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; }
.bc-list label.chk { margin: 0; padding: 5px 0; color: var(--text); cursor: pointer; }
.bc-list label.bc-group { position: sticky; top: 0; z-index: 1; background: var(--panel); font-weight: 600; border-bottom: 1px solid var(--line); }
.bc-list label.bc-chat { padding-left: 14px; }
.bc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.find-result { margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.filters .grouping button { padding: 4px 8px; font-size: 13px; white-space: nowrap; }
.filters .grouping #byFolders, .filters .grouping #byCompanies { flex: 1; }
.folder-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.folder-row label.chk { margin: 0; white-space: nowrap; }
/* иконки чатов стоят в один столбец у левого края, текст вплотную к ним на любом уровне вложенности */
.conv { margin: 2px 0; padding: 10px 12px 10px 4px; border-radius: 14px; cursor: pointer; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px;
  transition: background .12s, box-shadow .12s; }
.conv > .ava { grid-row: 1 / span 2; align-self: center; }
.conv > .top, .conv > .meta { grid-column: 2; }
.ava { position: relative; flex: none; display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; overflow: hidden; font-size: 24px; line-height: 1; user-select: none; }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ava-btn { flex: none; display: inline-flex; padding: 0; border: 0; border-radius: 50%; background: none; }
.ava-btn:hover .ava { box-shadow: 0 0 0 2px var(--accent); }
.ava-preview { display: grid; place-items: center; margin: 12px 0; }
.ava-preview .ava { width: 112px; height: 112px; font-size: 64px; }
/* наведение подсвечивает, выбор добавляет рамку: и чат, и группа выглядят одинаково */
.conv:hover { background: var(--accent-soft); }
.conv.active { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.conv.active .name { color: var(--accent); }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.conv .top .meta { flex: none; flex-wrap: nowrap; }
.conv .tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 13px; }
.badge.quiet { background: var(--muted); }
.readonly-bar { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 14px; text-align: center; }  /* чат без уведомлений: непрочитанное видно, но не зовёт */
.tag.draft { color: var(--danger); border-color: var(--danger); }
.tag { border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.st-new { color: var(--ok); } .st-open { color: var(--accent); } .st-pending { color: var(--warn); } .st-closed { color: var(--muted); }
/* шаг 36px: высота 34 и зазор 2. Внешняя тень закрывает зазоры и углы, иначе под закреплёнными группами просвечивают чаты */
.group { position: sticky; top: calc(var(--d, 0) * 36px + 2px); z-index: calc(5 - var(--d, 0)); width: 100%; min-height: 34px; margin: 2px 0; display: flex; align-items: center;
  gap: 6px; padding: 4px 12px 4px calc(4px + var(--d, 0) * 12px);
  background: var(--bg); color: var(--text); border: 0; border-radius: 12px; box-shadow: 0 0 0 2px var(--panel);
  font-size: 15px; line-height: 22px; font-weight: 600; text-align: left; cursor: pointer; transition: background .12s, box-shadow .12s; }
.group:hover { background: var(--accent-soft); }
.group.has-active { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--panel), inset 0 0 0 1.5px var(--accent); }
.group:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.group .arrow { width: 10px; color: var(--muted); }
.group .ava { width: 26px; height: 26px; font-size: 16px; }
.group .ava[data-gkey]:hover { box-shadow: 0 0 0 2px var(--accent); }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.dot-new { background: var(--ok); }
.dot-pending { background: var(--brown); }
.group .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group .count { color: var(--muted); font-weight: 400; flex: 1 0 auto; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat .empty { margin: auto; color: var(--muted); }
.chat-head { padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; gap: 4px 8px; align-items: center; flex-wrap: wrap; }
.chat-head .who { flex: 1; min-width: 160px; }
.chat-head .who b { font-size: 16px; }
/* на широком экране поля стоят в одной строке с названием чата, на узком переносятся под него */
.chat-tools { display: none; flex: 1 1 480px; min-width: 0; gap: 4px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.chat-head.tools-open .chat-tools { display: flex; }
.chat-tools input, .chat-tools select { flex: 1 1 90px; width: auto; min-width: 0; max-width: 170px; height: 28px; padding: 0 6px; font-size: 13px; }
.chat-tools button { height: 28px; padding: 0 8px; font-size: 13px; }
.tools-btn { flex: none; width: 28px; height: 28px; padding: 0; font-size: 18px; line-height: 1; color: var(--muted); }
.tools-btn:hover { color: var(--accent); }
.chat-head.internal .chat-tools > :not(#membersBtn) { display: none; }
.group-internal .title { color: var(--accent); }
.new-chat { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 7px 12px; }
.new-chat button { font-size: 13px; }
.direct-user { display: block; width: 100%; padding: 7px 0 !important; text-align: left; color: var(--text) !important; border-bottom: 1px solid var(--line) !important; }
.direct-user:last-child { border-bottom: 0 !important; }
.group-member { padding: 5px 0; }
.group-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.group-row button { padding: 2px 8px; font-size: 13px; }
.msgs { flex: 1; overflow-y: auto; padding: 34px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--in); align-self: flex-start; position: relative; word-wrap: break-word; }
.msg.out { background: var(--out); align-self: flex-end; }
/* заливка бледная, чтобы текст читался, поэтому авторов различает ещё и яркая полоска слева */
.msg.in[class*="who"] { border-left-width: 4px; }
.msg.in.who0 { background: var(--who0); border-left-color: #2563eb; } .msg.in.who1 { background: var(--who1); border-left-color: #e11d48; }
.msg.in.who2 { background: var(--who2); border-left-color: #7c3aed; } .msg.in.who3 { background: var(--who3); border-left-color: #ea580c; }
.msg.in.who4 { background: var(--who4); border-left-color: #0d9488; } .msg.in.who5 { background: var(--who5); border-left-color: #a16207; }
.msg.in.who6 { background: var(--who6); border-left-color: #c026d3; } .msg.in.who7 { background: var(--who7); border-left-color: #64748b; }
.msg.note { background: var(--note); align-self: center; max-width: 85%; border-style: dashed; }
.msg .txt { white-space: pre-wrap; }
.msg .foot { font-size: 12px; color: var(--muted); display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 2px; }
/* панель стоит над сообщением; отступ внутри неё, иначе курсор по дороге к кнопкам уходил бы с сообщения */
.msg .actions { position: absolute; bottom: 100%; right: 8px; display: none; gap: 2px; padding-bottom: 3px;
  width: max-content; white-space: nowrap; }
.msg:hover .actions { display: flex; }
.msg.in .actions { right: auto; left: 8px; }
.rxwrap { position: relative; display: inline-flex; }
.rxbar { position: absolute; top: 100%; left: 0; z-index: 2; display: none; gap: 2px; padding: 3px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.msg.out .rxbar { left: auto; right: 0; }
.rxwrap:hover .rxbar, .rxwrap:focus-within .rxbar { display: flex; }
.rxbar button { border: 0; background: none; padding: 1px 3px !important; font-size: 16px !important; }
.rxs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rx { font-size: 13px; padding: 0 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
button.rx.mine { border-color: var(--accent); background: var(--accent-soft); }
span.rx { cursor: default; }
.gone { font-size: 13px; color: var(--muted); }
.msg .actions:focus-within { display: flex; }
.msg .actions button { padding: 0 6px; font-size: 13px; }
.msg .actions .callbtn { position: relative; display: inline-flex; align-items: center; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.msg .actions .callbtn:hover, .msg .actions .callbtn:focus-within { border-color: var(--accent); }
.msg .actions .callbtn select { position: absolute; inset: 0; height: 100%; padding: 0; border: 0; font-size: 13px; opacity: 0; cursor: pointer; }
.msg.flash { outline: 2px solid var(--accent); }
.msg.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.msgs.selecting .msg { cursor: pointer; user-select: none; }
.msgs.selecting .msg.note { opacity: .5; cursor: default; }
.msgs.selecting .actions { display: none !important; }
.selbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.fwd-list { max-height: 45vh; overflow-y: auto; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; min-height: 60px; }
.fwd-list label.chk { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--line); color: var(--text); cursor: pointer; }
.fwd-list label.chk:last-child { border-bottom: 0; }
.fwd-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: pre-wrap; overflow: hidden; max-height: 4.5em; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.atts img { max-width: 220px; max-height: 180px; border-radius: 8px; cursor: zoom-in; display: block; }
.atts video { max-width: min(340px, 100%); max-height: 300px; border-radius: 8px; display: block; background: #000; }
.atts video.round { width: 220px; height: 220px; max-height: none; border-radius: 50%; object-fit: cover; cursor: pointer; }
.atts img.sticker { max-width: 170px; max-height: 170px; border: 0; background: none; }
.atts video.gif { max-width: 280px; max-height: 280px; border-radius: 8px; display: block; }
.picker { margin-bottom: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.pick-body { max-height: 190px; overflow-y: auto; margin-top: 6px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 2px; }
.emoji-grid button { border: 0; background: none; padding: 3px 0; font-size: 20px; line-height: 1.3; }
.emoji-grid button:hover { background: var(--panel); }
.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.st-item { position: relative; display: block; }
.st-item > button:first-child, .st-add { width: 100%; height: 84px; padding: 3px; display: grid; place-items: center; overflow: hidden; }
.st-item img, .st-item video { max-width: 100%; max-height: 76px; }
.st-add { font-size: 26px; color: var(--muted); }
.st-del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0; line-height: 1; font-size: 14px; }
.atts audio { width: 280px; max-width: 100%; height: 40px; display: block; }
.file { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: var(--panel); font-size: 14px; text-decoration: none; color: var(--text); }
.file.purged { border-style: dashed; color: var(--muted); }
.mon { max-width: 760px; margin-top: 16px; }
.mon-disk { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--panel); margin-bottom: 16px; }
.mon-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.mon-bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin-bottom: 6px; }
.mon-bar i { display: block; height: 100%; background: var(--ok); }
.mon-bar.warn i { background: var(--warn); }
.mon-bar.bad i { background: var(--danger); }
.mon-tbl td:nth-child(2) { white-space: nowrap; font-weight: 600; }
.mon-preview { margin: 10px 0; min-height: 1.2em; }
.mon-period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 12px; }
.mon-period label { display: flex; align-items: center; gap: 6px; margin: 0; }
.mon-period .seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.mon-cards { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.mon-card { flex: 1 1 220px; display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--panel); }
.mon-card b { font-size: 17px; }
.mon h4 { margin: 20px 0 8px; }
.mon-scroll { overflow-x: auto; }
.mon-tbl.num td:not(:first-child), .mon-tbl.num th:not(:first-child) { text-align: right; white-space: nowrap; }
button.primary.danger-fill { background: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.failed { color: var(--danger); }

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 12px; }
.composer .replybox, .composer .pending { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.composer .replybox .quote { flex: 1; margin: 0; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.inputrow { display: flex; gap: 8px; align-items: flex-end; }
.inputbar { flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 2px; padding: 3px 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 21px; }
.inputbar:focus-within { border-color: var(--accent); }
.composer.note .inputbar { background: var(--note); }
.inputbar button { flex: none; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; background: none; font-size: 18px; line-height: 1; opacity: .7; }
.inputbar button:hover, .inputbar button.on, .composer.note #noteBtn { opacity: 1; background: var(--accent-soft); }
.inputbar textarea { display: block; flex: 1; min-width: 0; width: auto; min-height: 34px; max-height: 40vh; padding: 7px 4px; border: 0; border-radius: 0; background: none; line-height: 20px; resize: none; overflow-y: hidden; outline: none; }
.composer .send { flex: none; width: 42px; height: 42px; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.dropzone { position: absolute; inset: 0; background: rgba(37,99,235,.12); border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 18px; z-index: 5; pointer-events: none; }

.page { padding: 20px 24px; overflow-y: auto; }
.page header { display: flex; justify-content: space-between; align-items: center; }
.page h2 { margin: 0; }
.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 12px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--bg); }
.tbl td.actions { white-space: nowrap; text-align: right; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; }

dialog { border: 0; padding: 0; background: transparent; max-width: 560px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .card { max-height: 88vh; overflow-y: auto; }
dialog h3 { margin-top: 0; }
dialog .btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.perms { display: grid; gap: 2px; }
.hint { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90%; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 40; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }

@media (max-width: 800px) {
  .side { width: 48px; } .side .nav { width: 38px; height: 38px; }
  .list { width: 100%; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
  .chats.open .list { display: none; }
  .chats:not(.open) .chat { display: none; }
  .msg { max-width: 90%; }
  .page { padding: 16px; }
  .tbl { display: block; overflow-x: auto; }
}
.mobile-back, .menu-btn, .side-shade { display: none; }
@media (max-width: 800px) {
  .mobile-back { display: inline-block; }
  .msg .actions { max-width: calc(100vw - 48px); flex-wrap: wrap; white-space: normal; }
  .msgs { padding-top: 54px; }  /* панель может занять две строки и не должна обрезаться у первого сообщения */
  .composer .row { flex-wrap: wrap; }
  .inputbar { padding: 3px 4px; gap: 0; }
  .inputbar button { width: 30px; }  /* на узком экране место важнее: тексту остаётся больше ширины */
  .inputbar textarea { padding: 5px 4px; font-size: 17px; line-height: 24px; }
  .side { position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; width: 56px; overflow-y: auto; transform: translateX(-100%);
    transition: transform .18s; }
  .side .nav { flex: none; }
  .app.side-open .side { transform: none; }
  .side-shade { position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.4); }
  .app.side-open .side-shade { display: block; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; position: relative; flex: none; min-width: 38px; }
  .menu-btn .badge { position: absolute; top: -5px; right: -5px; padding: 0 5px; font-size: 12px; }
  .page header { flex-wrap: wrap; gap: 8px; }
  .page header h2 { flex: 1; min-width: 0; font-size: 19px; }
  .tools-btn { width: 40px; height: 40px; font-size: 18px; }
  .chat-head { flex-wrap: wrap; }
  .chat-head .who { min-width: 0; flex: 1 1 0; }
  .chat-tools { flex-basis: 100%; }
  .chat-tools input, .chat-tools select { max-width: none; }

  /* На телефоне крупнее только текст, размеры кнопок и панелей те же, что на компьютере */
  .group { font-size: 19px; }  /* строка 22px из общих стилей: высота группы задаёт шаг закрепления */
  .conv { padding-block: 13px; gap: 4px; }
  .conv > .ava { width: 48px; height: 48px; font-size: 28px; }
  .conv .name { font-size: 17px; }
  .conv .meta { font-size: 15px; }
  .tag { padding: 1px 8px; font-size: 14px; }
  .badge { font-size: 14px; }
  .chat-head .who b { font-size: 18px; }
  .msg { padding: 10px 13px; }
  .msg .txt { font-size: 17px; line-height: 1.4; }
  .msg .foot { font-size: 14px; }
  .quote { font-size: 15px; }
  .file { font-size: 16px; }
}
