/* ================================================================
   Рабочий инструмент: спокойный, без обводок, с воздухом.
   Разделяем плоскостями и отступами, а не рамками.
   Шрифт Onest — с настоящей кириллицей (у Archivo её не было вовсе).
   ================================================================ */

:root, :root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]        { color-scheme: dark; }
:root[data-theme="auto"]        { color-scheme: light dark; }

:root {
  --bg:        light-dark(#f7f7f9, #0f1014);
  --panel:     light-dark(#ffffff, #1d1e25);
  --surface:   light-dark(#f1f1f4, #272935);
  --surface-2: light-dark(#e8e8ed, #32343f);
  --hover:     light-dark(#f4f4f7, #24252d);
  /* Холст под облаками. В тёмной теме он ЗАМЕТНО темнее карточек:
     тени на чёрном не работают, разделять может только светлота. */
  --canvas:    light-dark(#e8eaf1, #131419);

  /* Колонка слева тёмная всегда, но в тёмной теме она самая тёмная из всего. */
  --side:        light-dark(#16171b, #0d0e11);
  --side-2:      light-dark(#1f2026, #191a20);
  --side-active: light-dark(#272932, #23242c);
  --side-tile:   light-dark(#24252c, #212229);
  --side-text:   #e9eaee;
  --side-muted:  #9ea1ac;

  --text:  light-dark(#15161a, #eceef3);
  --muted: light-dark(#63656e, #9a9daa);
  --faint: light-dark(#73757e, #7e8190);

  /* Разделители почти не видны: линия нужна только там, где без неё теряется структура. */
  --line: light-dark(#e9e9ee, #24242b);

  --accent:      light-dark(#4353c4, #7d8af0);
  --accent-hover:light-dark(#3a49b3, #8f9bf5);
  --accent-soft: light-dark(#eef0fb, #1c1e33);
  --on-accent:   #ffffff;

  --ok:          light-dark(#177d57, #43c48f);
  --danger:      light-dark(#c03f2e, #f08573);
  --danger-soft: light-dark(#fdeeec, #2b1815);

  --scroll:       light-dark(#d5d6dc, #2e2e36);
  --scroll-hover: light-dark(#bcbdc6, #3f3f4a);

  /* Глубина мягкая и многослойная — она заменяет рамки.
     ВАЖНО: light-dark() умеет только цвета, поэтому по теме меняем ЦВЕТ тени,
     а саму тень собираем обычным способом. Иначе правило молча отваливается. */
  --sh-1: light-dark(rgba(18, 19, 26, .085), rgba(0, 0, 0, .45));
  --sh-2: light-dark(rgba(18, 19, 26, .10),  rgba(0, 0, 0, .50));
  --sh-3: light-dark(rgba(18, 19, 26, .16),  rgba(0, 0, 0, .62));

  --lift-1: 0 1px 1px var(--sh-1), 0 2px 6px var(--sh-1);
  --lift-2: 0 1px 2px var(--sh-1), 0 8px 24px var(--sh-2);
  --lift-3: 0 2px 8px var(--sh-2), 0 20px 56px var(--sh-3);

  --sans: 'Onest', 'Segoe UI', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, monospace;

  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -.003em;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 2px; }
code, pre { font-family: var(--mono); }

/* ---------- полоса прокрутки ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
.sidebar { scrollbar-color: #35363f transparent; }
.bots::-webkit-scrollbar-thumb { background: #35363f; background-clip: content-box; }
.bots::-webkit-scrollbar-thumb:hover { background: #454652; background-clip: content-box; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll); border-radius: 99px;
  border: 4px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* ================= вход и приглашение ================= */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.gate-card {
  width: 100%; max-width: 396px;
  background: var(--panel);
  border-radius: var(--r-lg);
  padding: 40px 36px 34px;
  box-shadow: var(--lift-2);
}
.gate-card h1 { margin: 0 0 7px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.gate-card p.sub { margin: 0 0 28px; color: var(--muted); font-size: 14px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 11px 13px;
  border: 0; border-radius: var(--r-sm);
  background: var(--surface);
  transition: box-shadow .16s, background .16s;
}

.btn {
  border: 0; border-radius: var(--r-sm);
  background: var(--accent); color: var(--on-accent);
  padding: 11px 16px; cursor: pointer; width: 100%;
  font-size: 14px; font-weight: 500;
  transition: background .16s, transform .08s, opacity .16s;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--surface); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.slim { width: auto; padding: 8px 13px; font-size: 13.5px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger); opacity: .88; }

.note { margin-top: 16px; font-size: 13px; color: var(--muted); }
.error {
  background: var(--danger-soft); color: var(--danger);
  padding: 11px 13px; border-radius: var(--r-sm);
  font-size: 13.5px; margin-bottom: 16px;
}
.hidden { display: none !important; }

/* ================= каркас ================= */
.app { display: grid; grid-template-columns: 268px 1fr; height: 100dvh; background: var(--bg); }
/* Страница ровно в экран. Без этого на телефоне body (height:100%) оказывается ниже
   .app (100dvh, растёт при скрытой адресной строке), и палец двигает всю страницу
   вместо переписки: приходилось сперва «зацепиться» за ленту. overscroll-behavior
   держит жест внутри ленты и списка — докрутили до края, страница не едет следом. */
body:has(.app) { height: 100dvh; overflow: hidden; overscroll-behavior: none; }
.stream, .bots { overscroll-behavior: contain; }

/* ---------- боковая колонка ---------- */
.sidebar {
  background: var(--side);
  color: var(--side-text);
  display: flex; flex-direction: column; min-width: 0;
  /* min-height: 0 — иначе строка сетки .app растягивается под длинный список комнат,
     страница уезжает целиком, а список так и не получает свою прокрутку (у .main
     это уже стояло, у боковой панели — нет; всплыло на 40 комнатах). */
  min-height: 0;
}
.brand {
  padding: 20px 20px 14px;
  font-size: 15px; font-weight: 600; letter-spacing: -.015em;
  display: flex; align-items: center; gap: 9px;
}
.brand .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.side-label { padding: 8px 20px 5px; font-size: 12.5px; color: var(--side-muted); }

.bots { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 10px; }

.room {
  display: flex; gap: 10px; align-items: center;
  width: 100%; text-align: left;
  padding: 7px 10px;
  border: 0; background: transparent; color: var(--side-text);
  border-radius: var(--r-sm); cursor: pointer; margin-bottom: 1px;
  transition: background .13s;
}
.room:hover { background: var(--side-2); }
.room.active { background: var(--side-active); }
.room .ava {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--side-tile); display: grid; place-items: center;
  font-size: 14px; flex: none;
}
.room .meta { min-width: 0; flex: 1; }
.room .nm { font-size: 13.5px; line-height: 1.3; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room .sb { font-size: 12px; line-height: 1.3; color: var(--side-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room .live { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: none; animation: blip 1.4s ease-in-out infinite; }
/* Правый край строки комнаты: время последнего сообщения, под ним состояние —
   бот отвечает (зелёная точка), счётчик новых или метка «есть новое». */
.room .side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-height: 28px; justify-content: center; }
.room .when { font-size: 10.5px; color: var(--side-muted); line-height: 1; white-space: nowrap; }
.room .badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.room .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
/* Точки состояния стоят в строке имени, перед текстом. */
.room .nm .live, .room .nm .dot { display: inline-block; vertical-align: middle; margin: -2px 7px 0 0; width: 8px; height: 8px; }
@keyframes blip { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }
.empty-side { padding: 14px 20px; font-size: 13px; color: var(--side-muted); }

.me { position: relative; padding: 12px; display: flex; gap: 10px; align-items: center; }
.me .ava {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--side-tile); color: var(--side-text);
  display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none;
}
.me .meta { min-width: 0; flex: 1; }
.me .nm { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .rl { font-size: 12px; color: var(--side-muted); }
.icon-btn {
  background: transparent; border: 0; color: var(--side-muted);
  cursor: pointer; padding: 6px; border-radius: var(--r-sm); font-size: 15px;
  transition: background .13s, color .13s;
}
.icon-btn:hover { background: var(--side-2); color: var(--side-text); }
/* Кнопка «назад» живёт в светлой шапке чата, а не в тёмной колонке. */
#backBtn { color: var(--muted); }
#backBtn:hover { background: var(--surface); color: var(--text); }

.popup {
  position: absolute; bottom: 52px; right: 12px;
  background: var(--panel); border-radius: var(--r-md); padding: 5px;
  box-shadow: var(--lift-3); min-width: 196px; z-index: 30;
}
.popup button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 9px 11px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 13.5px; color: var(--text);
}
.popup button:hover { background: var(--hover); }
.popup-label { font-size: 12px; color: var(--faint); padding: 8px 11px 4px; }
.popup-sep { height: 1px; background: var(--line); margin: 5px 9px; }
.seg { display: flex; flex-direction: column; padding: 0 5px; }
.seg button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 7px 8px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 13.5px; color: var(--muted);
}
.seg button:hover { background: var(--hover); color: var(--text); }
.seg button::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--surface-2); flex: none;
}
.seg button.on { color: var(--text); font-weight: 500; }
.seg button.on::before { background: var(--accent); }

/* ================= переписка ================= */
.main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--panel);
}

.chat-head {
  padding: 16px 26px; display: flex; align-items: center; gap: 12px;
  background: var(--panel); position: relative; z-index: 1;
}
.chat-head .ava {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--surface); display: grid; place-items: center;
  font-size: 16px; flex: none;
}
.chat-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.012em; }
.chat-head .sub { font-size: 12.5px; color: var(--muted); }
.badge {
  font-size: 12px; padding: 4px 10px; border-radius: 99px;
  background: var(--surface); color: var(--muted);
}

/* Серой остаётся только лента: на ней белые облака видны сразу,
   а шапка и поле ввода стоят на белом и не сливаются с кнопками. */
.stream {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px 26px 16px;
  background: var(--canvas);
}
.stream-inner { max-width: 780px; margin: 0 auto; }

.day { text-align: center; font-size: 12px; color: var(--faint); margin: 20px 0 14px; }
.earlier { display: flex; justify-content: center; padding: 2px 0 12px; }

.msg { display: flex; gap: 11px; padding: 5px 0; }
.msg .ava {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 600;
  background: var(--surface); color: var(--muted);
}
.msg.bot .ava { background: var(--accent-soft); color: var(--accent); font-size: 14px; }
.msg.mine .ava { background: var(--accent-soft); color: var(--accent); }
.msg.err .ava { background: var(--danger-soft); color: var(--danger); }

.msg .body { min-width: 0; max-width: 74%; display: flex; flex-direction: column; align-items: flex-start; }
.msg .who { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-bottom: 4px; padding: 0 2px; }
.msg .who span { color: var(--faint); font-size: 12px; margin-left: 7px; }

/* Облако без рамки: отделяется плоскостью, а не контуром. */
.msg .text {
  overflow-wrap: anywhere;
  background: var(--panel);
  box-shadow: var(--lift-1);
  padding: 11px 15px;
  border-radius: 4px var(--r-lg) var(--r-lg) var(--r-lg);
}
.msg.mine { flex-direction: row-reverse; }
.msg.mine .body { align-items: flex-end; }
.msg.mine .who { text-align: right; }
.msg.mine .text {
  background: var(--accent); color: var(--on-accent);
  box-shadow: var(--lift-1);
  border-radius: var(--r-lg) 4px var(--r-lg) var(--r-lg);
}
.msg.mine .text a { color: var(--on-accent); text-decoration: underline; }
.msg.mine .text code { background: rgba(255, 255, 255, .17); color: var(--on-accent); }
.msg.mine .text pre { background: rgba(0, 0, 0, .18); color: var(--on-accent); }
.msg.mine .text ul li::marker { color: rgba(255, 255, 255, .55); }
.msg.mine .text h4 { color: rgba(255, 255, 255, .8); }
.msg.err .text { background: var(--danger-soft); color: var(--danger); }

.msg .text b { font-weight: 600; }
.msg .text code { background: var(--surface); padding: 1.5px 5px; border-radius: 5px; font-size: 12.5px; }
.msg .text pre {
  background: var(--surface); padding: 12px 14px; border-radius: var(--r-sm);
  overflow-x: auto; white-space: pre; margin: 9px 0; font-size: 12.5px; line-height: 1.55;
}
.msg .text ul, .msg .text ol { margin: 7px 0; padding-left: 21px; }
.msg .text li { margin: 3px 0; }
.msg .text ul li::marker { color: var(--faint); }
.msg .text h4 { margin: 14px 0 6px; font-size: 14px; font-weight: 600; color: var(--text); }
.msg .text h4:first-child { margin-top: 0; }
.msg .text hr { border: 0; border-top: 1px solid var(--line); margin: 13px 0; }
.msg .text a { overflow-wrap: anywhere; }

.typing { display: flex; gap: 11px; padding: 6px 0 2px; align-items: center; font-size: 13.5px; color: var(--muted); }
.typing .ava { width: 28px; height: 28px; border-radius: 50%; background: var(--surface); flex: none; }
.typing .dots span {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted); margin-left: 3px;
  animation: bounce 1.25s ease-in-out infinite;
}
.typing .dots span:nth-child(2) { animation-delay: .16s; }
.typing .dots span:nth-child(3) { animation-delay: .32s; }
@keyframes bounce { 0%, 65%, 100% { transform: none; opacity: .4 } 30% { transform: translateY(-4px); opacity: 1 } }
.typing .think-t { color: var(--faint); font-variant-numeric: tabular-nums; }
/* Плашка-приглашение к уведомлениям при открытии приложения. */
.push-cta {
  position: fixed; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  max-width: 460px; margin: 0 auto; z-index: 55;
  background: var(--panel); box-shadow: var(--lift-3); border-radius: var(--r-md);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 11px;
}
.push-cta-t { font-size: 14px; line-height: 1.4; }
.push-cta-b { display: flex; gap: 8px; }
.push-cta-b .btn { flex: 1; }
/* Просмотр картинки поверх чата. */
.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .86);
  display: grid; place-items: center; padding: 64px 16px 16px; cursor: zoom-out;
}
.lightbox img {
  max-width: 100%; max-height: calc(100dvh - 80px); object-fit: contain;
  border-radius: var(--r-md); box-shadow: 0 20px 60px rgba(0, 0, 0, .5); cursor: default;
}
.lightbox .lb-bar {
  position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px;
  display: flex; align-items: center; gap: 8px; color: #fff; cursor: default;
}
.lightbox .lb-name { flex: 1; font-size: 13.5px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .btn.ghost { background: rgba(255, 255, 255, .12); color: #fff; }
.lightbox .btn.ghost:hover { background: rgba(255, 255, 255, .22); }

/* ---------- поле ввода ---------- */
.composer { padding: 14px 26px 20px; background: var(--panel); position: relative; z-index: 1; }
.composer-inner { max-width: 780px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: var(--r-md);
  padding: 12px 15px; background: var(--panel); box-shadow: var(--lift-1);
  max-height: 200px; min-height: 46px;
  transition: box-shadow .16s, background .16s;
}
.composer textarea::placeholder { color: var(--faint); }
.composer .send {
  border: 0; border-radius: var(--r-md);
  background: var(--accent); color: var(--on-accent);
  height: 46px; padding: 0 20px; cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background .16s, transform .08s;
}
.composer .send:hover:not(:disabled) { background: var(--accent-hover); }
.composer .send:active:not(:disabled) { transform: translateY(1px); }
.composer .send:disabled { opacity: .5; cursor: default; }
.composer .hint { max-width: 780px; margin: 9px auto 0; font-size: 12px; color: var(--faint); }
/* Скрепка слева от поля — той же высоты, что поле и кнопка. */
.composer .attach {
  flex: none; width: 46px; height: 46px; border: 0; border-radius: var(--r-md);
  background: var(--panel); box-shadow: var(--lift-1); font-size: 18px; cursor: pointer;
  transition: background .16s;
}
.composer .attach:hover { background: var(--surface); }
.composer.drop .composer-inner { outline: 2px dashed var(--accent); outline-offset: 5px; border-radius: var(--r-md); }
/* Полка с прикреплёнными картинками над полем ввода. */
.attach-strip { max-width: 780px; margin: 0 auto 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.attach-strip .thumb {
  position: relative; width: 72px; height: 72px; border-radius: var(--r-sm); overflow: hidden;
  background: var(--surface); box-shadow: var(--lift-1);
}
.attach-strip .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-strip .thumb button {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; padding: 0;
}
/* Картинки в сообщении: уменьшенные, по клику — файл целиком. */
.msg .pics { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg .pics img {
  display: block; width: auto; height: auto; max-width: min(320px, 100%); max-height: 320px;
  border-radius: var(--r-md); box-shadow: var(--lift-1); background: var(--surface);
}
.msg.mine .pics { justify-content: flex-end; }
/* Файлы в сообщении и на полке перед отправкой: значок, имя, размер. */
.msg .files { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; max-width: 100%; }
.msg .file {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 9px 13px; border-radius: var(--r-md); background: var(--panel); box-shadow: var(--lift-1);
  color: inherit; text-decoration: none; transition: background .13s;
}
.msg .file:hover { background: var(--surface); }
.msg .file .fname, .attach-strip .fchip .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .file .fsize, .attach-strip .fchip .fsize { color: var(--muted); font-size: 12px; flex: none; }
.attach-strip .fchip {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; max-width: 280px;
  padding: 0 6px 0 10px; border-radius: 99px; background: var(--surface); box-shadow: var(--lift-1); font-size: 13px;
}
.attach-strip .fchip button {
  width: 20px; height: 20px; border: 0; border-radius: 50%; padding: 0; flex: none;
  background: rgba(0, 0, 0, .35); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
}
/* Зона броска — окно комнаты целиком: рамка и подпись поверх, пока тащат файлы. */
#chat { position: relative; }
#chat.drop::after {
  content: 'Отпустите, чтобы прикрепить'; position: absolute; inset: 10px; z-index: 5; pointer-events: none;
  display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: var(--r-md);
  background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 500;
}
.readonly-bar {
  max-width: 780px; margin: 0 auto; font-size: 13.5px; color: var(--muted);
  text-align: center; padding: 12px; background: var(--panel);
  box-shadow: var(--lift-1); border-radius: var(--r-md);
}

.blank { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 40px; }
.blank h3 { margin: 0 0 7px; color: var(--text); font-size: 16px; font-weight: 600; }
.blank div { font-size: 13.5px; max-width: 380px; }

/* ================= окна ================= */
.overlay {
  position: fixed; inset: 0;
  background: light-dark(rgba(22, 23, 30, .32), rgba(0, 0, 0, .6));
  backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 26px; z-index: 40;
  animation: fade .15s ease both;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--panel); border-radius: var(--r-lg);
  width: 100%; max-width: 880px; max-height: 88dvh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--lift-3);
  animation: pop .2s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.995) } to { opacity: 1; transform: none } }
.modal-head { padding: 18px 24px 16px; display: flex; align-items: center; gap: 14px; }
.modal-head h2 { margin: 0; flex: 1; font-size: 16px; font-weight: 600; letter-spacing: -.015em; }

.modal.dialog { max-width: 440px; }
.modal.dialog .modal-body { font-size: 14px; color: var(--muted); padding-top: 0; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; }
.dlg-actions .btn { min-width: 104px; }

.tabs { display: flex; gap: 3px; padding: 0 20px; box-shadow: inset 0 -1px 0 var(--line); }
.tab {
  border: 0; background: transparent; padding: 10px 14px 12px; cursor: pointer;
  color: var(--muted); font-size: 14px; position: relative;
  transition: color .13s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 500; }
.tab.active::after {
  content: ''; position: absolute; left: 10px; right: 10px; bottom: 0;
  height: 2px; border-radius: 2px 2px 0 0; background: var(--accent);
}
.modal-body { padding: 20px 24px 28px; overflow-y: auto; }
.modal-body h4 { margin: 28px 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.modal-body h4:first-child { margin-top: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 12.5px; color: var(--faint); font-weight: 400;
  padding: 8px 11px;
}
td { padding: 7px 11px; vertical-align: middle; box-shadow: inset 0 1px 0 var(--line); }
tbody tr:hover td { background: var(--hover); }
td code { font-size: 12.5px; color: var(--muted); background: var(--surface); padding: 1.5px 6px; border-radius: 5px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
/* Кнопки действий у бота — квадратные иконки; подпись во всплывающем title. */
.icon-act {
  position: relative; width: 32px; height: 32px; flex: none; padding: 0;
  display: inline-grid; place-items: center;
  border: 0; border-radius: var(--r-sm); background: var(--surface);
  color: var(--muted); cursor: pointer; transition: background .13s, color .13s;
}
.icon-act:hover { background: var(--surface-2); color: var(--text); }
.icon-act svg { width: 18px; height: 18px; display: block; }
.act-badge {
  position: absolute; top: -4px; right: -4px; min-width: 15px; height: 15px;
  padding: 0 3px; border-radius: 99px; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 600; line-height: 15px; text-align: center;
}

.pill {
  font-size: 12px; padding: 3px 9px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.pill.grey { background: var(--surface); color: var(--muted); }
.pill.off { background: var(--danger-soft); color: var(--danger); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; padding: 10px 12px; border: 0; border-radius: var(--r-sm);
  background: var(--surface);
  transition: box-shadow .16s, background .16s;
}
.form-grid textarea { font-size: 13.5px; line-height: 1.65; resize: vertical; }
.form-grid input::placeholder, .form-grid textarea::placeholder { color: var(--faint); }

.access-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.access-chip {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 99px; padding: 6px 13px 6px 10px; font-size: 13.5px;
  background: var(--surface); cursor: pointer;
  white-space: nowrap; hyphens: none; word-break: keep-all; flex: none;
  transition: background .13s, color .13s;
}
/* Название показывается целиком: чип занимает столько, сколько нужно тексту, а
   длинные просто уходят на следующую строку сетки. Прятать лишнее с многоточием
   нельзя — в части браузеров ширина названия внутри inline-flex считалась
   меньше текста, и «aivio» превращалось в «a.» при пустом чипе. */
.access-chip .chip-name, .access-chip .chip-from { flex: none; overflow: visible; }
.access-chip .chip-from {
  font-size: 11.5px; color: var(--faint); margin-left: 2px;
}
.access-chip:has(input:checked) .chip-from { color: var(--accent); opacity: .75; }
.access-chip:hover { background: var(--surface-2); }

/* Панель «Запреты»: строка на инструмент — галочка, название с кодом маски, подсказка.
   Строки с пометкой «нужно для AIVIO» подсвечены, чтобы не закрыть боту дорогу в
   платформу одним лишним кликом. */
.deny-section { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 16px 0 6px; }
.deny-row {
  display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: baseline;
  padding: 7px 10px; border-radius: var(--r-sm); cursor: pointer; transition: background .13s;
}
.deny-row:hover { background: var(--surface); }
.deny-row input { margin: 0; align-self: center; }
.deny-row .deny-title { font-size: 13.5px; }
.deny-row .deny-title code { font-size: 11.5px; color: var(--faint); margin-left: 6px; }
.deny-row .deny-hint { grid-column: 2; font-size: 12px; color: var(--muted); }
.deny-row.warn .deny-hint { color: var(--ok); }
.deny-row:has(input:checked) .deny-title { color: var(--accent); }
.access-chip:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.access-chip input[type=checkbox] { accent-color: var(--accent); }

/* Доступ к ботам: строка на бота, в каждой переключатель «Нет · Читает · Пишет».
   Чем больше прав — тем больше цвета: серый → светлый акцент → акцент.
   Радиокнопки: состояние живёт в разметке, стрелки клавиатуры работают сами. */
.acc-list { display: flex; flex-direction: column; gap: 6px; }
.acc-row {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 7px 7px 9px; border-radius: var(--r-md);
  background: var(--surface);
  transition: background .13s;
}
.acc-row:hover { background: var(--surface-2); }
.acc-tile {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: var(--panel); display: grid; place-items: center; font-size: 17px;
  transition: background .13s;
}
.acc-name {
  flex: 1; min-width: 0; font-size: 14px; font-weight: 500; line-height: 1.3;
  color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  transition: color .13s;
}
.acc-name small {
  display: block; font-size: 12px; font-weight: 400; color: var(--faint);
  overflow: hidden; text-overflow: ellipsis;
}
.acc-row:has(input:not([value=none]):checked) .acc-tile { background: var(--accent-soft); }
.acc-row:has(input:not([value=none]):checked) .acc-name { color: var(--text); }
.acc-status { font-size: 12px; color: var(--ok); flex: none; }
.acc-status:empty { display: none; }
.acc-status.bad { color: var(--danger); }
.acc-seg {
  display: inline-flex; flex: none; gap: 2px; padding: 3px;
  border-radius: 9px; background: var(--panel); box-shadow: var(--lift-1);
}
.acc-seg label {
  position: relative; padding: 5px 12px; border-radius: 6px;
  font-size: 12.5px; line-height: 1.4; color: var(--muted);
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: background .13s, color .13s;
}
.acc-seg label:hover { color: var(--text); background: var(--surface); }
.acc-seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.acc-seg label:has(input:checked) { color: var(--text); background: var(--surface-2); font-weight: 500; }
.acc-seg label.read:has(input:checked) { color: var(--accent); background: var(--accent-soft); }
.acc-seg label.write:has(input:checked) { color: var(--on-accent); background: var(--accent); }
.acc-seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

.copy-box { display: flex; gap: 8px; margin-top: 12px; }
.copy-box input {
  flex: 1; padding: 10px 12px; border: 0; border-radius: var(--r-sm);
  background: var(--accent-soft); color: var(--accent); font-size: 13px;
}
details summary { font-size: 13.5px; color: var(--muted); }

/* Фокус — мягкое кольцо, без жёстких контуров. */
.field input:focus, .composer textarea:focus,
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus,
.copy-box input:focus {
  outline: none;
  background: var(--panel);
  box-shadow: 0 0 0 2px var(--accent);
}
.btn:focus-visible, .tab:focus-visible, .room:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

#backBtn { display: none; }

/* ================= телефон ================= */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app.show-list .sidebar { display: flex; }
  .app.show-list .main { display: none; }
  #backBtn { display: inline-block; }

  .main { border-radius: 0; box-shadow: none; }
  .form-grid { grid-template-columns: 1fr; }
  .stream, .composer { padding-left: 15px; padding-right: 15px; }
  .chat-head { padding: 13px 15px; gap: 10px; }
  .chat-head h2, .chat-head .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .composer { padding-bottom: 15px; }
  .composer .send { padding: 0 16px; }

  .msg { gap: 9px; }
  .msg .body { max-width: 84%; }
  .msg .text { padding: 9px 12px; }

  .overlay { padding: 0; }
  .modal { max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .modal.dialog { height: auto; max-height: none; border-radius: var(--r-lg); margin: 16px; }
  .overlay:has(.dialog) { padding: 16px; place-items: center; }
  .modal-head { padding: 16px; }
  .modal-body { padding: 18px 16px 30px; }
  .tabs { padding: 0 12px; }
  table { min-width: 520px; }
  .copy-box { flex-direction: column; }
  .copy-box .btn { width: 100%; }

  /* Строка доступа на телефоне: имя сверху, переключатель на всю ширину снизу. */
  .acc-row { flex-wrap: wrap; row-gap: 8px; }
  .acc-seg { width: 100%; order: 3; }
  .acc-seg label { flex: 1; text-align: center; }
  .acc-status { order: 2; }

  /* Телефон: размеры настольной вёрстки (13–14,5 px) на экране с руки читаются
     мелко. Базовый текст 16 px, как в мессенджерах; поля ввода тоже 16 px — иначе
     iOS при фокусе приближает страницу. Остальное подтянуто пропорционально. */
  body { font-size: 16px; }
  .btn { font-size: 15px; }
  .btn.slim { font-size: 14.5px; padding: 9px 14px; }
  .icon-btn { font-size: 18px; padding: 8px; }
  .error, .note, .readonly-bar, .empty-side { font-size: 14.5px; }
  .field label { font-size: 14px; }
  .field input, .form-grid input, .form-grid select, .form-grid textarea { font-size: 16px; }
  .gate-card p.sub { font-size: 15px; }

  .brand { font-size: 17px; }
  .side-label { font-size: 13.5px; }
  .room { padding: 9px 10px; gap: 11px; }
  .room .ava { width: 34px; height: 34px; border-radius: 8px; font-size: 17px; }
  .room .nm { font-size: 15.5px; }
  .room .sb { font-size: 13.5px; }
  .room .when { font-size: 12px; }
  .room .side { min-height: 34px; }
  .room .badge { min-width: 20px; height: 20px; font-size: 12px; }
  .me .ava { width: 34px; height: 34px; font-size: 13px; }
  .me .nm { font-size: 15px; }
  .me .rl { font-size: 13px; }
  .popup button { font-size: 15px; padding: 11px 12px; }

  .chat-head .ava { width: 36px; height: 36px; font-size: 18px; }
  .chat-head h2 { font-size: 17px; }
  .chat-head .sub { font-size: 13.5px; }
  .day { font-size: 13px; }
  .msg .ava { width: 32px; height: 32px; font-size: 12.5px; }
  .msg .who { font-size: 13.5px; }
  .msg .who span { font-size: 13px; }
  .msg .text { padding: 10px 13px; line-height: 1.5; }
  .msg .file { font-size: 15px; }
  .typing { font-size: 14.5px; }
  .composer textarea { font-size: 16px; min-height: 48px; padding: 12px 14px; }
  .composer .send { height: 48px; font-size: 15px; }
  .composer .attach { width: 48px; height: 48px; font-size: 20px; }
  .composer .hint { display: none; } /* подсказка про Enter на экранной клавиатуре бессмысленна и съедала четыре строки */
  .attach-strip .fchip { font-size: 14px; height: 40px; }

  .tab { font-size: 15px; }
  .icon-act { width: 36px; height: 36px; }
  .icon-act svg { width: 20px; height: 20px; }
  table { font-size: 14.5px; }
  .pill { font-size: 13px; }
  .access-chip { font-size: 14.5px; padding: 7px 14px 7px 11px; }
  .deny-row .deny-title { font-size: 15px; }
  .deny-row .deny-hint { font-size: 13px; }
  .deny-section { font-size: 12.5px; }
  .emoji-grid button { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Поле «Значок» с пикером: кнопка внутри поля справа, сетка значков под полем.
   Сетка — та же плоскость, что у всплывающих меню (.popup): без обводок, тень. */
.emoji-field { position: relative; }
.form-grid .emoji-field input { padding-right: 44px; }
.emoji-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; font-size: 18px; line-height: 1;
  padding: 4px 6px; border-radius: var(--r-sm); cursor: pointer;
  transition: background .13s;
}
.emoji-btn:hover { background: var(--hover); }
.emoji-pop {
  position: fixed; z-index: 60; max-height: 320px; overflow-y: auto;
  overscroll-behavior: contain; /* докрутили сетку до конца — страница под ней не едет */
  padding: 6px 8px 8px; background: var(--panel); border-radius: var(--r-md);
  box-shadow: var(--lift-3);
}
.emoji-pop .popup-label { padding: 8px 4px 4px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; }
.emoji-grid button {
  border: 0; background: transparent; font-size: 21px; line-height: 1;
  padding: 7px 0; border-radius: var(--r-sm); cursor: pointer;
  transition: background .1s, transform .1s;
}
.emoji-grid button:hover { background: var(--hover); transform: scale(1.12); }
.emoji-foot { display: flex; justify-content: flex-end; padding: 8px 2px 2px; }

