/* ============ Токены ============ */
:root {
  color-scheme: light;
  --font: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
  /* Фирменные цвета «Все оптика»: чёрный и золото с логотипа. */
  --bg: #ffffff;
  --bg-2: #f7f6f3;
  --bg-3: #eeebe4;
  --hover: #f8f6f1;
  --border: #e8e4db;
  --border-2: #d6d0c3;
  --text: #1a1814;
  --text-2: #5d584e;
  --text-3: #8e887b;
  --accent: #f0b030; /* золото очков на логотипе */
  --accent-hover: #e2a01f;
  --accent-grad: linear-gradient(180deg, #f7c84c 0%, #eca826 100%);
  --accent-soft: #fcf2d8;
  --accent-text: #8a5d00; /* бронза: на белом контраст выше 5:1, в отличие от чистого золота */
  --on-accent: #1a1814;
  --focus-ring: rgba(240, 176, 48, 0.3);
  --mention-bg: #fff8e1;
  --mention-line: #f0b030;
  --chip-bg: #f6ecd2;
  --chip-text: #7a5200;
  --chip-me: #ffd97a;
  --chip-me-text: #5a3d00;
  --flash: #fff0b3;
  --danger: #d93f4c;
  --danger-soft: #fdebed;
  --online: #1fb47a;
  --offline: #b5b0a5;
  --code-bg: #f5f3ee;
  --code-text: #b4235a;
  --shadow: 0 12px 32px rgba(26, 20, 8, 0.16), 0 2px 8px rgba(26, 20, 8, 0.06);
  --brand-dark: #121110; /* фирменный чёрный: экран входа и загрузки в обеих темах */
  --side-bg: #f6f4ef;
  --side-bg-2: #ece9e1;
  --side-text: #3d3a33;
  --side-text-2: #8a8478;
  --side-strong: #1a1814;
  --side-hover: rgba(26, 24, 20, 0.06);
  --side-hover-2: rgba(26, 24, 20, 0.1);
  --side-field: rgba(26, 24, 20, 0.04);
  --side-active: #f0b030;
  --side-active-text: #1a1814;
  --side-line: rgba(26, 24, 20, 0.09);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141311;
    --bg-2: #1b1a17;
    --bg-3: #27251f;
    --hover: #1c1a17;
    --border: #2b2823;
    --border-2: #3d3930;
    --text: #efebe3;
    --text-2: #b3ac9f;
    --text-3: #807a6e;
    --accent: #f0b030;
    --accent-hover: #f6c04f;
    --accent-soft: #2d2512;
    --accent-text: #f3c14f;
    --focus-ring: rgba(240, 176, 48, 0.25);
    --mention-bg: #2a2312;
    --mention-line: #e0a32a;
    --chip-bg: #3a2f14;
    --chip-text: #f5d27a;
    --chip-me: #5c4610;
    --chip-me-text: #ffe29a;
    --flash: #3d3313;
    --danger: #f0616d;
    --danger-soft: #3b1e24;
    --online: #2fcf8f;
    --offline: #5f5a50;
    --code-bg: #221f1a;
    --code-text: #ff9fbd;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.35);
    --side-bg: #0b0a09;
    --side-bg-2: #171512;
    --side-text: #c9c3b6;
    --side-text-2: #7f796d;
    --side-strong: #ffffff;
    --side-hover: rgba(255, 255, 255, 0.06);
    --side-hover-2: rgba(255, 255, 255, 0.14);
    --side-field: rgba(255, 255, 255, 0.05);
    --side-line: rgba(240, 176, 48, 0.14);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141311;
  --bg-2: #1b1a17;
  --bg-3: #27251f;
  --hover: #1c1a17;
  --border: #2b2823;
  --border-2: #3d3930;
  --text: #efebe3;
  --text-2: #b3ac9f;
  --text-3: #807a6e;
  --accent: #f0b030;
  --accent-hover: #f6c04f;
  --accent-soft: #2d2512;
  --accent-text: #f3c14f;
  --focus-ring: rgba(240, 176, 48, 0.25);
  --mention-bg: #2a2312;
  --mention-line: #e0a32a;
  --chip-bg: #3a2f14;
  --chip-text: #f5d27a;
  --chip-me: #5c4610;
  --chip-me-text: #ffe29a;
  --flash: #3d3313;
  --danger: #f0616d;
  --danger-soft: #3b1e24;
  --online: #2fcf8f;
  --offline: #5f5a50;
  --code-bg: #221f1a;
  --code-text: #ff9fbd;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.35);
  --side-bg: #0b0a09;
  --side-bg-2: #171512;
  --side-text: #c9c3b6;
  --side-text-2: #7f796d;
  --side-strong: #ffffff;
  --side-hover: rgba(255, 255, 255, 0.06);
  --side-hover-2: rgba(255, 255, 255, 0.14);
  --side-field: rgba(255, 255, 255, 0.05);
  --side-line: rgba(240, 176, 48, 0.14);
}

/* ============ База ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.center { text-align: center; justify-content: center; }
.sr-only { position: fixed; opacity: 0; pointer-events: none; }
.ico { width: 18px; height: 18px; flex: none; }
kbd {
  font: 11px var(--font);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid currentColor;
  opacity: 0.6;
}
code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1px 5px;
  border-radius: 5px;
}
pre {
  margin: 6px 0;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
}
pre code { background: none; color: var(--text); padding: 0; font-size: 13px; }
blockquote {
  margin: 4px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border-2);
  color: var(--text-2);
}
mark { background: var(--chip-me); color: inherit; border-radius: 3px; padding: 0 1px; }

.boot-screen { height: 100vh; display: grid; place-items: center; background: var(--brand-dark); }
.boot-logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: url(/logo.png) center / contain no-repeat;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; transform: scale(0.94); } }

/* ============ Кнопки и поля ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: var(--bg);
  color: var(--text);
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--hover); border-color: var(--text-3); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent-grad); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.danger-outline:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent-text); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.sm .ico { width: 15px; height: 15px; }
.btn.big { height: 44px; font-size: 15px; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm .ico { width: 16px; height: 16px; }
.icon-btn.emoji { font-size: 16px; line-height: 1; }
.icon-btn[data-danger]:hover { color: var(--danger); background: var(--danger-soft); }

input:not([type=checkbox]):not([type=radio]):not([type=file]), textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--bg);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
input:disabled { background: var(--bg-2); color: var(--text-3); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span:first-child { font-size: 13px; font-weight: 600; color: var(--text-2); }
.hint { font-size: 12.5px; color: var(--text-3); }
.input-prefix {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-2); border-radius: 8px; padding-left: 10px;
  color: var(--text-3); background: var(--bg);
}
.input-prefix:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.input-prefix input { border: 0 !important; box-shadow: none !important; padding-left: 0 !important; background: transparent !important; color: var(--text); }
.search-input input { color: var(--text); }
.search-input {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border-2); border-radius: 8px;
  padding-left: 10px; color: var(--text-3); background: var(--bg);
}
.search-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.search-input input { border: 0 !important; box-shadow: none !important; padding-left: 0 !important; background: transparent !important; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.check > span { display: flex; flex-direction: column; }
.form-error {
  background: var(--danger-soft); color: var(--danger);
  padding: 9px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 12px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-2); font-size: 13px;
}
.chip:hover { border-color: var(--accent); }
.chip .ico { width: 13px; height: 13px; }
.chip.ghost { background: transparent; color: var(--text-3); }
.tag {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  padding: 1px 6px; border-radius: 5px;
  background: var(--bg-3); color: var(--text-2); vertical-align: 1px;
}
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; margin-left: auto;
}
.empty { padding: 28px 20px; text-align: center; color: var(--text-3); }
.list-loading { padding: 20px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ============ Аватары ============ */
.avatar {
  --s: 36px;
  position: relative; flex: none;
  width: var(--s); height: var(--s);
  border-radius: 50%;
  background: var(--c, #8e8da0);
  color: #fff;
  display: inline-grid; place-items: center;
  font-size: calc(var(--s) * 0.38); font-weight: 650; letter-spacing: 0.02em;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.bot { background: linear-gradient(135deg, #f7b733, #fc4a1a); }
.avatar.bot .ico, .avatar.all .ico { width: 55%; height: 55%; }
.avatar.all { background: var(--accent); color: var(--on-accent); }
.avatar .presence {
  position: absolute; right: -2px; bottom: -2px;
  width: max(9px, calc(var(--s) * 0.3)); height: max(9px, calc(var(--s) * 0.3));
  border-radius: 50%;
  background: var(--offline);
  border: 2px solid var(--ring, var(--bg));
}
.avatar .presence.on { background: var(--online); }
[data-user] { cursor: pointer; }

/* ============ Экран входа ============ */
.auth {
  min-height: 100vh; min-height: 100dvh; overflow-y: auto;
  display: grid; place-items: center; padding: 24px 16px;
  /* Чёрный фон с золотым свечением — как на логотипе. */
  background:
    radial-gradient(1000px 560px at 12% -12%, rgba(240, 176, 48, 0.28), transparent 60%),
    radial-gradient(900px 520px at 108% 112%, rgba(114, 68, 8, 0.45), transparent 60%),
    var(--brand-dark);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 18px;
  padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.auth-logo { width: 56px; height: 56px; margin-bottom: 12px; }
.auth h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.auth-sub { margin: 0 0 20px; color: var(--text-2); }
.auth-form { text-align: left; }
.auth-note { margin: 14px 0 0; text-align: center; font-size: 13px; color: var(--text-3); }
.auth-tabs { display: flex; background: var(--bg-2); border-radius: 10px; padding: 3px; margin-bottom: 20px; }
.auth-tabs button { flex: 1; height: 34px; border: 0; border-radius: 8px; background: transparent; font-weight: 600; color: var(--text-2); }
.auth-tabs button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }

/* ============ Каркас ============ */
.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) auto;
  height: 100vh; height: 100dvh;
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; background: var(--bg); }
.panel {
  width: 400px; min-height: 0;
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg); position: relative;
}

.main.dragging::after, .panel.dragging::after {
  content: "Отпустите, чтобы прикрепить файлы";
  position: absolute; inset: 10px; z-index: 30;
  display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--accent-text); font-weight: 650; font-size: 17px;
  pointer-events: none;
}

/* ============ Боковая панель ============ */
.sidebar {
  --ring: var(--side-bg);
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; min-height: 0;
}
.ws-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 10px 16px; }
.ws-logo { width: 32px; height: 32px; border-radius: 50%; }
.ws-name { flex: 1; min-width: 0; font-weight: 700; font-size: 16px; color: var(--side-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: var(--side-hover); color: var(--side-strong);
}
.side-icon-btn:hover { background: var(--side-hover-2); }
.side-icon-btn.sm { width: 24px; height: 24px; background: transparent; color: var(--side-text-2); }
.side-icon-btn.sm:hover { background: var(--side-hover); color: var(--side-strong); }
.side-icon-btn.sm .ico { width: 16px; height: 16px; }
.side-search {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 8px; padding: 0 10px; height: 34px;
  border: 1px solid var(--side-line); border-radius: 8px;
  background: var(--side-field); color: var(--side-text-2); text-align: left;
}
.side-search span { flex: 1; }
.side-search:hover { color: var(--side-strong); border-color: var(--side-text-2); }
.side-search .ico { width: 16px; height: 16px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; scrollbar-color: var(--side-hover-2) transparent; }
.side-nav { padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--side-line); }
.side-section { margin-top: 14px; }
.side-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 4px 10px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--side-text-2);
}
.side-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; height: 32px; padding: 0 8px 0 10px;
  border: 0; border-radius: 7px; background: transparent;
  color: var(--side-text); text-decoration: none; text-align: left; font-size: 14.5px;
}
.side-item:hover { background: var(--side-hover); color: var(--side-strong); }
.side-item.active { background: var(--accent-grad); color: var(--side-active-text); font-weight: 600; --ring: var(--side-active); }
.side-item.unread { color: var(--side-strong); font-weight: 700; }
.side-item.muted:not(.active) { opacity: 0.55; }
.side-item.subtle { color: var(--side-text-2); }
.side-item .side-ico { width: 16px; height: 16px; opacity: 0.85; }
.side-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-label .status-emoji { margin-left: 5px; font-size: 13px; }
.side-you { font-size: 11px; font-weight: 600; opacity: 0.6; margin-left: 4px; }
.side-mute { width: 13px; height: 13px; opacity: 0.6; }
.notif-hint {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin: 8px 0 0; padding: 9px 10px;
  border: 1px dashed var(--side-text-2); border-radius: 8px;
  background: transparent; color: var(--side-text); font-size: 13px; text-align: left;
}
.notif-hint:hover { background: var(--side-hover); color: var(--side-strong); }
.notif-hint .ico { width: 16px; height: 16px; color: var(--accent); }
.side-foot { display: flex; align-items: center; gap: 6px; padding: 10px 10px 12px; border-top: 1px solid var(--side-line); }
.me-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  padding: 6px; border: 0; border-radius: 9px; background: transparent; color: var(--side-strong); text-align: left;
}
.me-btn:hover { background: var(--side-hover); }
.me-meta { display: flex; flex-direction: column; min-width: 0; }
.me-name { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: 12px; color: var(--side-text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ Шапка чата ============ */
.chat-header {
  display: flex; align-items: center; gap: 8px;
  min-height: 60px; padding: 8px 12px 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-titles { flex: 1; min-width: 0; cursor: pointer; }
.chat-name { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 16.5px; }
.chat-name .avatar { margin-right: 2px; }
.chat-name-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-ico { color: var(--text-3); width: 18px; height: 18px; }
.muted-ico { width: 15px; height: 15px; color: var(--text-3); }
.chat-sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-actions { display: flex; align-items: center; gap: 2px; }
.members-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text-2); font-weight: 600; font-size: 13px;
}
.members-btn:hover { background: var(--hover); color: var(--text); }
.members-btn .ico { width: 16px; height: 16px; }
.only-mobile { display: none; }

/* ============ Лента сообщений ============ */
.msg-scroll { flex: 1; overflow-y: auto; position: relative; overscroll-behavior: contain; }
.msg-list { padding: 8px 0 12px; }
.chat-start { padding: 36px 24px 20px; }
.chat-start h2 { margin: 12px 0 6px; font-size: 24px; letter-spacing: -0.01em; }
.chat-start p { margin: 0 0 4px; color: var(--text-2); max-width: 640px; }
.chat-start-ico {
  width: 64px; height: 64px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text);
}
.chat-start-ico .ico { width: 30px; height: 30px; }

.day-sep, .new-sep, .thread-sep {
  position: relative; display: flex; justify-content: center; margin: 14px 0 6px;
}
.day-sep::before, .new-sep::before, .thread-sep::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--border);
}
.day-sep span {
  position: relative; padding: 2px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); font-size: 12.5px; font-weight: 650; color: var(--text-2);
}
.new-sep::before { border-color: var(--danger); }
.new-sep { justify-content: flex-end; padding-right: 16px; }
.new-sep span {
  position: relative; padding: 0 8px; background: var(--bg); color: var(--danger);
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.thread-sep { justify-content: flex-start; padding-left: 20px; margin: 4px 0 8px; }
.thread-sep span { position: relative; padding-right: 10px; background: var(--bg); font-size: 12.5px; color: var(--text-3); }

.msg {
  position: relative;
  display: grid; grid-template-columns: 38px minmax(0, 1fr); column-gap: 12px;
  padding: 6px 20px 6px 20px;
  transition: background 0.4s;
}
.msg.compact { padding-top: 1px; padding-bottom: 1px; }
.msg:hover, .msg.menu-open { background: var(--hover); }
.msg.mentioned { background: var(--mention-bg); box-shadow: inset 3px 0 var(--mention-line); }
.msg.pinned { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.msg.flash { background: var(--flash); }
.msg.editing { background: var(--accent-soft); }
.msg-gutter { padding-top: 2px; }
.msg-hover-time { display: block; visibility: hidden; font-size: 11px; color: var(--text-3); text-align: right; padding-top: 3px; }
.msg.compact:hover .msg-hover-time { visibility: visible; }
.msg-body { min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-author { font-weight: 700; color: var(--text); }
.msg-author[data-user]:hover { text-decoration: underline; }
.msg-head .status-emoji { font-size: 14px; margin-left: -4px; }
.msg-time { font-size: 12px; color: var(--text-3); }
.pin-mark { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--accent-text); }
.pin-mark .ico { width: 12px; height: 12px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-text.jumbo { font-size: 34px; line-height: 1.25; }
.msg-text.deleted { color: var(--text-3); font-style: italic; }
.edited { font-size: 12px; color: var(--text-3); }
.mention {
  padding: 0 3px; border-radius: 4px;
  background: var(--chip-bg); color: var(--chip-text); font-weight: 600;
}
.mention.me, .mention.all { background: var(--chip-me); color: var(--chip-me-text); }
.mention[data-user]:hover { text-decoration: underline; }

.msg.system { grid-template-columns: 38px minmax(0, 1fr); padding-top: 3px; padding-bottom: 3px; color: var(--text-2); font-size: 14px; }
.msg.system .msg-gutter { display: grid; justify-items: end; padding-top: 1px; }
.sys-ico { width: 16px; height: 16px; color: var(--text-3); }
.msg.system .msg-author { font-weight: 650; }

.msg-actions {
  position: absolute; top: -16px; right: 16px; z-index: 5;
  display: none; align-items: center; gap: 1px; padding: 2px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.msg:hover .msg-actions, .msg.menu-open .msg-actions { display: flex; }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.file-img { display: block; flex: none; line-height: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--bg-2); }
/* Без процентов в max-width: иначе рамка считается по исходной ширине и справа остаётся пустое поле. */
.file-img img { display: block; width: auto; height: auto; max-width: min(360px, 70vw); max-height: 280px; }
.file-card {
  display: flex; align-items: center; gap: 10px;
  min-width: 220px; max-width: 360px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  color: var(--text); text-decoration: none;
}
.file-card:hover { border-color: var(--accent); }
.file-ico { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); flex: none; }
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12px; color: var(--text-3); }
.file-dl { color: var(--text-3); }

.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.reaction {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-2); font-size: 13px;
}
.reaction:hover { border-color: var(--text-3); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.r-emoji { font-size: 15px; line-height: 1; }
.r-count { font-weight: 650; font-size: 12.5px; }
.reaction.add { color: var(--text-3); opacity: 0; transition: opacity 0.12s; }
.reaction.add .ico { width: 15px; height: 15px; }
.msg:hover .reaction.add { opacity: 1; }

.thread-summary {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px; padding: 4px 10px 4px 4px;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; font-size: 13px; max-width: 100%;
}
.thread-summary:hover { background: var(--bg); border-color: var(--border); }
.ts-avatars { display: flex; }
.ts-avatars .avatar { border: 2px solid var(--bg); margin-left: -6px; }
.ts-avatars .avatar:first-child { margin-left: 0; }
.ts-count { font-weight: 700; color: var(--accent-text); }
.ts-last { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts-open { display: none; color: var(--text-3); }
.thread-summary:hover .ts-open { display: inline; }
.thread-summary:hover .ts-last { display: none; }

.msg-edit { margin-top: 4px; }
.msg-edit textarea { resize: none; min-height: 40px; }
.msg-edit-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.msg-edit-bar .muted { flex: 1; }

.jump-latest {
  position: absolute; right: 24px; bottom: 120px; z-index: 10;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg); color: var(--accent-text);
  font-weight: 600; font-size: 13px; box-shadow: var(--shadow);
}
.jump-latest .ico { width: 15px; height: 15px; }

/* ============ Поле ввода ============ */
.composer-wrap { padding: 0 20px 14px; }
.composer { position: relative; }
.composer-box {
  border: 1px solid var(--border-2); border-radius: 12px; background: var(--bg);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.composer textarea {
  display: block; border: 0 !important; box-shadow: none !important; background: transparent !important;
  resize: none; padding: 12px 14px 4px; min-height: 44px; max-height: 40vh; line-height: 1.45;
}
.composer-tools { display: flex; align-items: center; gap: 2px; padding: 4px 6px 6px; }
.composer-spacer { flex: 1; }
.send-btn {
  display: inline-grid; place-items: center; width: 36px; height: 32px;
  border: 0; border-radius: 8px; background: var(--accent-grad); color: var(--on-accent);
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { background: var(--bg-3); color: var(--text-3); cursor: default; }
.send-btn .ico { width: 16px; height: 16px; }
.composer-meta { display: flex; align-items: center; gap: 12px; min-height: 20px; padding: 3px 4px 0; font-size: 12px; color: var(--text-3); }
.typing { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.typing.on { color: var(--text-2); font-weight: 550; }
.composer-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }
.composer-hint b { font-weight: 600; color: var(--text-2); }
.chan-link { font-weight: 600; text-decoration: none; }
.chan-link:hover { text-decoration: underline; }
.composer-files { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 10px 0; }
.att {
  display: flex; align-items: center; gap: 8px; max-width: 260px;
  padding: 6px 6px 6px 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-2);
}
.att.error { border-color: var(--danger); background: var(--danger-soft); }
.att img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.att-ico { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); }
.att-meta { display: flex; flex-direction: column; min-width: 0; }
.att-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-sub { font-size: 12px; color: var(--text-3); }
.att-x { display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); }
.att-x:hover { background: var(--bg-3); color: var(--text); }
.att-x .ico { width: 14px; height: 14px; }
.mention-pop {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 20;
  max-height: 300px; overflow-y: auto; padding: 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.mention-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.mention-item.active, .mention-item:hover { background: var(--accent-soft); }
.mi-name { font-weight: 600; }
.mi-nick { color: var(--text-3); font-size: 13px; }

/* ============ Правая панель ============ */
.panel-head { display: flex; align-items: center; gap: 8px; min-height: 60px; padding: 8px 10px 8px 18px; border-bottom: 1px solid var(--border); }
.panel-titles { flex: 1; min-width: 0; }
.panel-title { font-weight: 700; font-size: 16px; }
.panel-sub { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.panel .composer-wrap { padding: 0 14px 12px; }
.panel .composer-hint { display: none; }
.panel .msg { padding-left: 14px; padding-right: 14px; }
.panel .msg-actions { right: 10px; }
.panel-search { padding: 12px 14px; border-bottom: 1px solid var(--border); }

.info-section { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.info-section h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 14px; }
.info-section h3 .btn { margin-left: auto; }
.info-title { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 700; }
.info-title .ico { color: var(--text-3); }
.info-topic { margin: 8px 0 4px; white-space: pre-wrap; }
.info-person { display: flex; gap: 12px; align-items: center; }
.info-name { font-weight: 700; font-size: 16px; }
.member-list { display: flex; flex-direction: column; gap: 2px; margin: 0 -8px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.member:hover { background: var(--hover); }
.member-meta { flex: 1; min-width: 0; }
.danger-zone { display: flex; flex-wrap: wrap; gap: 8px; border-bottom: 0; }
.hook { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.hook-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.hook-head b { flex: 1; }
.hook-head .ico { width: 15px; height: 15px; color: #f59e0b; }
.copy-row { display: flex; align-items: center; gap: 6px; }
.copy-row input { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.hook-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; font-size: 11.5px; padding: 5px 8px; }

.result-list { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; }
.info-section .result-list { padding: 0; }
.result-count { padding: 0 2px; }
.result {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); cursor: pointer;
}
.result:hover, .result:focus-visible { border-color: var(--accent); outline: none; }
.result-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 4px; }
.result-text { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 9em; overflow: hidden; }

.profile { text-align: center; padding-bottom: 20px; }
.profile-cover { height: 96px; background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 45%, #1a1814)); }
.profile-avatar { margin-top: -52px; --ring: var(--bg); }
.profile-avatar .avatar { border: 4px solid var(--bg); --s: 104px; }
.profile-name { margin: 10px 18px 2px; font-size: 21px; }
.profile-title { color: var(--text-2); }
.profile-status { display: inline-block; margin-top: 8px; padding: 4px 12px; border-radius: 999px; background: var(--bg-2); font-size: 13.5px; }
.profile-presence { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--text-3); }
.profile-presence i { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); }
.profile-presence.on i { background: var(--online); }
.profile-presence.on { color: var(--online); }
.profile .btn-row { margin: 16px 0 6px; }
.profile-fields { text-align: left; margin: 12px 18px 0; display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; font-size: 14px; }
.profile-fields dt { color: var(--text-3); }
.profile-fields dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

/* ============ Сотрудники ============ */
.people { flex: 1; overflow-y: auto; }
.people-top { position: sticky; top: 0; z-index: 2; padding: 14px 20px; background: var(--bg); border-bottom: 1px solid var(--border); }
.people-top .search-input { max-width: 520px; }
.people-list { padding: 4px 20px 24px; }
.people-group h3 { margin: 18px 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); }
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.person {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.person:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); }
.person-meta { flex: 1; min-width: 0; }
.person-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-title { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-status { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.join-view, .empty-main { flex: 1; display: grid; place-items: center; padding: 24px; text-align: center; }
.join-card { max-width: 420px; }
.join-card .chat-start-ico { margin: 0 auto 12px; }
.join-card h2 { margin: 0 0 6px; }
.empty-main img { width: 64px; height: 64px; opacity: 0.9; }
.empty-main h2 { margin: 12px 0 4px; }

/* ============ Модальные окна, меню, тосты ============ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(14, 11, 4, 0.5); backdrop-filter: blur(2px);
  animation: fade 0.12s ease-out;
}
.modal {
  width: 100%; max-width: 480px; max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px; box-shadow: var(--shadow);
  animation: rise 0.16s ease-out;
}
.modal.wide { max-width: 620px; }
.modal-head { display: flex; align-items: center; padding: 16px 14px 8px 22px; }
.modal-head h2 { flex: 1; margin: 0; font-size: 18px; }
.modal-body { padding: 8px 22px 6px; overflow-y: auto; }
.modal-text { margin: 0 0 12px; color: var(--text-2); }
.modal-text .quote-preview { margin-top: 12px; max-height: 160px; overflow: hidden; white-space: pre-wrap; color: var(--text); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; }
.modal-foot-inline { display: flex; justify-content: flex-end; padding: 12px 0 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

.picker .picker-chips { margin: 0 0 8px; }
.picker-list { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; margin-top: 8px; }
.picker-list.tall { max-height: 420px; }
.pick {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left;
}
.pick:hover { background: var(--hover); }
.pick.on { background: var(--accent-soft); }
.pick-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-meta > span:first-child { font-weight: 600; }
.pick-check { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--border-2); display: grid; place-items: center; color: transparent; }
.pick-check .ico { width: 14px; height: 14px; }
.pick.on .pick-check { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.browse-list { display: flex; flex-direction: column; margin-top: 10px; max-height: 420px; overflow-y: auto; }
.browse-item { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--border); }
.browse-ico { width: 36px; height: 36px; border-radius: 9px; background: var(--bg-2); display: grid; place-items: center; color: var(--text-2); flex: none; }
.browse-meta { flex: 1; min-width: 0; }
.browse-name { font-weight: 650; }
.browse-meta .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.qs-list { display: flex; flex-direction: column; gap: 2px; margin: 10px 0 8px; min-height: 120px; }
.qs-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.qs-item.active { background: var(--accent-soft); }
.qs-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qs-item .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qs-ico { width: 22px; display: grid; place-items: center; color: var(--text-3); }
.qs-ico .ico { width: 16px; height: 16px; }
.modal .hint { display: block; margin-bottom: 14px; }

.avatar-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.avatar-edit .btn-row { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.status-row { display: flex; gap: 8px; }
.emoji-input { width: 56px !important; text-align: center; flex: none; }

.popover {
  position: fixed; z-index: 200;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  animation: fade 0.1s ease-out;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 36px); gap: 2px; padding: 8px; }
.emoji-btn { width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; font-size: 20px; line-height: 1; }
.emoji-btn:hover { background: var(--bg-3); transform: scale(1.12); }
.menu { min-width: 260px; padding: 6px; }
.menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; }
.menu-item:hover { background: var(--hover); }
.menu-item .ico { width: 16px; height: 16px; color: var(--text-3); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .ico { color: var(--danger); }

#toast-root { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: 10px; max-width: min(480px, calc(100vw - 32px));
  background: #1a1814; color: #fff; font-size: 14px; box-shadow: var(--shadow);
  animation: rise 0.16s ease-out; transition: opacity 0.3s, transform 0.3s;
}
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }
.conn-banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 250;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; background: #f59e0b; color: #1a1814; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow);
}
.conn-banner .ico { width: 16px; height: 16px; }

/* ============ Адаптив ============ */
@media (max-width: 1100px) {
  .panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: var(--shadow); }
  .app { grid-template-columns: 250px minmax(0, 1fr); }
}
@media (max-width: 800px) {
  body { font-size: 15.5px; }
  .app { grid-template-columns: 1fr; position: relative; }
  .sidebar, .main { grid-column: 1; grid-row: 1; }
  .main { display: none; }
  .app.chat-open .main { display: flex; }
  .app.chat-open .sidebar { display: none; }
  .panel { position: fixed; inset: 0; width: auto; z-index: 60; border-left: 0; }
  .only-mobile { display: inline-grid; }
  .chat-header { padding-left: 6px; }
  .msg { padding-left: 12px; padding-right: 12px; column-gap: 10px; }
  .msg-actions { right: 8px; }
  .composer-wrap { padding: 0 10px 10px; }
  .composer-hint { display: none; }
  .side-search kbd { display: none; }
  .people-top, .people-list { padding-left: 16px; padding-right: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .jump-latest { right: 14px; bottom: 110px; }
  .emoji-grid { grid-template-columns: repeat(7, 36px); }
  .file-img img { max-width: 72vw; }
}

/* ============ Сотрудники: состояние и администрирование ============ */
.state-tag {
  display: inline-block; margin-top: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; vertical-align: 1px;
}
.person-name .state-tag { margin: 0 0 0 4px; padding: 0 7px; font-size: 11px; }
.state-tag.blocked { background: var(--danger-soft); color: var(--danger); }
.state-tag.deleted { background: var(--bg-3); color: var(--text-3); }
.state-tag.owner { background: var(--accent-soft); color: var(--accent-text); }
.person.is-blocked { opacity: 0.6; }
.admin-tools { margin: 14px 18px 0; padding: 12px; border: 1px dashed var(--border-2); border-radius: 12px; }
.admin-tools-title { font-size: 11.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); }
.admin-tools .btn-row { margin-top: 8px; }
.cred-card {
  margin: 0 0 12px; padding: 12px 14px; white-space: pre-wrap; font-size: 13.5px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
}
.chat-header .btn.primary.sm { flex: none; }

/* ============ Markdown в сообщениях ============ */
.md-h { font-weight: 750; line-height: 1.3; margin: 6px 0 2px; }
.md-h1 { font-size: 1.45em; }
.md-h2 { font-size: 1.25em; }
.md-h3 { font-size: 1.1em; }
.md-list { margin: 2px 0; padding-left: 22px; white-space: normal; }
.md-list li { white-space: pre-wrap; margin: 1px 0; }
.result-text .md-h1, .result-text .md-h2 { font-size: 1.1em; }

/* ============ Просмотр картинок ============ */
.file-img { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 400;
  display: flex; flex-direction: column;
  background: rgba(8, 7, 5, 0.92); color: #fff;
  animation: fade 0.12s ease-out;
}
.lb-bar { display: flex; align-items: center; gap: 4px; padding: 10px 12px; flex: none; }
.lb-name { flex: 1; min-width: 0; padding-left: 6px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.85; }
.lb-zoom { min-width: 52px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; opacity: 0.85; }
.lb-btn {
  display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 8px;
  border: 0; border-radius: 9px; background: transparent; color: #fff; font-size: 20px; text-decoration: none;
}
.lb-btn:hover { background: rgba(255, 255, 255, 0.14); }
.lb-btn .ico { width: 20px; height: 20px; }
.lb-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; display: grid; place-items: center; cursor: grab; touch-action: none; }
.lb-stage.dragging { cursor: grabbing; }
.lb-img { max-width: none; max-height: none; transform-origin: center center; user-select: none; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 64px; border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, 0.1); color: #fff; font-size: 34px; line-height: 1;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.2); }
.lb-nav.prev { left: 12px; }
.lb-nav.next { right: 12px; }
.lb-hint { flex: none; padding: 6px 12px 12px; text-align: center; font-size: 12px; opacity: 0.55; }
@media (max-width: 800px) {
  .lb-hint, .lb-name { display: none; }
  .lb-btn { min-width: 34px; padding: 0 4px; }
}
/* ============ Блоки кода ============ */
.code-block { position: relative; margin: 6px 0; }
.code-block pre { margin: 0; max-height: 480px; overflow: auto; }
.code-copy {
  position: absolute; top: 6px; right: 6px; z-index: 1;
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg);
  color: var(--text-2); font-size: 12px; opacity: 0; transition: opacity 0.12s;
}
.code-copy .ico { width: 13px; height: 13px; }
.code-block:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--text); border-color: var(--text-3); }
@media (hover: none) { .code-copy { opacity: 1; } }

/* ============ Справочник должностей ============ */
.pos-add, .pos-row { display: grid; grid-template-columns: 1fr minmax(0, 260px) auto auto; gap: 8px; align-items: center; }
.pos-add { grid-template-columns: 1fr minmax(0, 260px) auto; margin: 4px 0 12px; }
.pos-row.no-role { grid-template-columns: 1fr auto auto; }
.pos-add.no-role { grid-template-columns: 1fr auto; }
.pos-list { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.pos-row select, .pos-add select, .field select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border-2); border-radius: 8px; background: var(--bg); color: var(--text);
}
.pos-count { min-width: 52px; text-align: right; }
@media (max-width: 800px) {
  .pos-add, .pos-row { grid-template-columns: 1fr; }
}
/* ============ Полоска закреплённых сообщений ============ */
.pin-bar {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 6px 12px 6px 20px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.pin-bar-ico { width: 16px; height: 16px; color: var(--accent); flex: none; }
.pin-bar-body { flex: 1; min-width: 0; cursor: pointer; padding: 2px 0; border-left: 2px solid var(--accent); padding-left: 10px; }
.pin-bar-title { font-size: 12.5px; font-weight: 700; color: var(--accent-text); }
.pin-bar-text { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-bar-text b { color: var(--text); font-weight: 600; }
.pin-bar-body:hover .pin-bar-text { color: var(--text); }

/* ============ Карточки документов ============ */
.file-card { cursor: pointer; }
.file-card .file-ico {
  width: 40px; height: 40px; font-size: 11px; font-weight: 800; letter-spacing: 0.02em; color: #fff;
}
.file-ico.kind-pdf { background: #d93f4c; }
.file-ico.kind-doc { background: #2b6cde; }
.file-ico.kind-xls { background: #1f9254; }
.file-ico.kind-ppt { background: #e0702b; }
.file-ico.kind-txt { background: #6f6a60; }
.file-ico.kind-zip { background: #8e6bc9; }
.file-ico.kind-other { background: var(--bg-3); color: var(--text-2); }
.file-dl {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none;
  border-radius: 8px; color: var(--text-3);
}
.file-dl:hover { background: var(--bg-3); color: var(--text); }
.file-dl .ico, .file-dl-ico { width: 18px; height: 18px; color: var(--text-3); }

/* ============ Просмотр документов ============ */
.dv-stage { position: relative; flex: 1; min-height: 0; display: flex; padding: 0 16px 16px; }
.dv-frame { flex: 1; width: 100%; border: 0; border-radius: 8px; background: #fff; }
.dv-status { margin: auto; text-align: center; font-size: 15px; line-height: 1.8; opacity: 0.9; }
.dv-status .btn { margin-top: 12px; }
/* ============ Статусы присутствия ============ */
.avatar .presence.idle { background: var(--bg); box-shadow: inset 0 0 0 2px var(--online); }
.avatar .presence.away { background: #f0a020; }
.avatar .presence.dnd { background: var(--danger); }
.avatar .presence.dnd::after { content: ""; position: absolute; left: 22%; right: 22%; top: calc(50% - 1px); height: 2px; border-radius: 1px; background: #fff; }
.presence-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--offline); position: relative; }
.presence-dot.on { background: var(--online); }
.presence-dot.idle { box-shadow: inset 0 0 0 2px var(--online); background: transparent; }
.presence-dot.away { background: #f0a020; }
.presence-dot.dnd { background: var(--danger); }
.presence-dot.dnd::after { content: ""; position: absolute; left: 2px; right: 2px; top: 4px; height: 2px; border-radius: 1px; background: #fff; }
.menu-sub { display: block; margin-top: 1px; font-weight: 400; }
.menu-item.checked { background: var(--accent-soft); }
.menu-item.checked .ico { color: var(--accent-text); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }
.hint.warn { padding: 8px 10px; margin-bottom: 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }

/* ============ Цитаты, пересланные, выбор ============ */
.msg-quote {
  display: flex; flex-direction: column; gap: 1px; max-width: 560px;
  margin: 2px 0 4px; padding: 4px 10px; border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0; background: var(--bg-2); cursor: pointer; font-size: 13px;
}
.msg-quote:hover { background: var(--bg-3); }
.msg-quote b { font-weight: 650; color: var(--accent-text); }
.msg-quote span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-quote.deleted span { font-style: italic; color: var(--text-3); }
.msg-quote.static { cursor: default; margin-bottom: 12px; }
.msg-fwd { margin: 2px 0; padding: 2px 0 2px 12px; border-left: 3px solid var(--border-2); }
.fwd-head { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-bottom: 2px; font-size: 12.5px; color: var(--text-3); }
.fwd-head .ico { width: 13px; height: 13px; }
.fwd-head b { color: var(--text-2); font-weight: 600; }
.msg.selectable { grid-template-columns: 22px 38px minmax(0, 1fr); cursor: pointer; user-select: none; }
.msg.selected, .msg.selected:hover { background: var(--accent-soft); }
.sel-box {
  align-self: start; margin-top: 9px; width: 18px; height: 18px; display: grid; place-items: center;
  border: 2px solid var(--border-2); border-radius: 5px; background: var(--bg); color: transparent;
}
.msg.compact .sel-box { margin-top: 4px; }
.sel-box .ico { width: 12px; height: 12px; stroke-width: 3; }
.msg.selected .sel-box { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.select-bar {
  display: flex; align-items: center; gap: 8px; margin: 0 20px 14px; padding: 10px 12px;
  border: 1px solid var(--border-2); border-radius: 12px; background: var(--bg-2);
}
.select-count { flex: 1; min-width: 0; font-weight: 600; }

/* ============ Поле ввода: форматирование, ответ, запись, отложенная отправка ============ */
.composer-fmt { display: flex; align-items: center; gap: 1px; padding: 4px 6px 0; flex-wrap: wrap; }
.fmt-btn {
  display: inline-grid; place-items: center; min-width: 28px; height: 26px; padding: 0 5px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-3); font-size: 14px; line-height: 1;
}
.fmt-btn:hover { background: var(--hover); color: var(--text); }
.fmt-btn .ico { width: 15px; height: 15px; }
.fmt-btn code { font-family: var(--mono); font-size: 13px; background: none; color: inherit; padding: 0; }
.fmt-sep { width: 1px; height: 16px; margin: 0 4px; background: var(--border); }
.composer-reply {
  display: flex; align-items: center; gap: 8px; margin: 8px 8px 0; padding: 6px 6px 6px 10px;
  border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; background: var(--bg-2);
}
.composer-reply[hidden] { display: none; }
.composer-reply > .ico { width: 16px; height: 16px; color: var(--accent-text); flex: none; }
.reply-body { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.reply-body b { font-weight: 650; }
.reply-body span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 12px 12px 4px; }
.rec-bar[hidden] { display: none; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: rec-pulse 1s ease-in-out infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 650; min-width: 38px; }
@keyframes rec-pulse { 50% { opacity: 0.25; } }
.send-group { display: inline-flex; align-items: stretch; gap: 1px; }
.send-group .send-btn { border-radius: 8px 0 0 8px; }
.send-more {
  display: inline-grid; place-items: center; width: 26px; height: 32px;
  border: 0; border-radius: 0 8px 8px 0; background: var(--accent-grad); color: var(--on-accent);
}
.send-more:hover:not(:disabled) { background: var(--accent-hover); }
.send-more:disabled { background: var(--bg-3); color: var(--text-3); cursor: default; }
.send-more .ico { width: 14px; height: 14px; }
.side-draft { display: inline-flex; color: inherit; opacity: 0.7; }
.side-draft .ico { width: 13px; height: 13px; }

/* ============ Голосовые, архив, сохранённое ============ */
.voice {
  display: flex; align-items: center; gap: 8px; width: min(420px, 100%); padding: 6px 10px 6px 8px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg-2);
}
.voice-ico { width: 18px; height: 18px; color: var(--accent-text); flex: none; }
.voice audio { flex: 1; min-width: 0; height: 34px; }
.files-zip {
  display: inline-flex; align-items: center; gap: 6px; flex-basis: 100%;
  font-size: 13px; color: var(--accent-text); text-decoration: none;
}
.files-zip:hover { text-decoration: underline; }
.files-zip .ico { width: 14px; height: 14px; }
.icon-btn.saved-on, .icon-btn.saved-on:hover { color: var(--accent); }
.icon-btn.saved-on .ico { fill: currentColor; }
.panel-tabs { display: flex; gap: 4px; padding: 10px 14px 0; border-bottom: 1px solid var(--border); }
.panel-tabs .tab {
  padding: 7px 10px 9px; border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--text-3); font-weight: 600; margin-bottom: -1px;
}
.panel-tabs .tab:hover { color: var(--text); }
.panel-tabs .tab.on { color: var(--text); border-bottom-color: var(--accent); }
.sched-item { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.sched-item .result { border: 0; padding: 0; }
.sched-when { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--accent-text); }
.sched-when .ico { width: 14px; height: 14px; }
.sched-when .icon-btn { margin-left: auto; }
.time-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.help-steps li { margin: 6px 0; }
.nt-exceptions { display: flex; flex-direction: column; gap: 4px; }
.nt-exc { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.nt-exc-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dv-doc { flex: 1; overflow: auto; padding: 24px 32px; border-radius: 8px; background: var(--bg); color: var(--text); }
.dv-doc .msg-text { max-width: 860px; margin: 0 auto; font-size: 15px; line-height: 1.6; }
@media (max-width: 720px) {
  .composer-fmt { display: none; }
  .select-bar { margin: 0 10px 10px; flex-wrap: wrap; }
  .dv-doc { padding: 16px; }
}
.tone-row { display: flex; gap: 8px; align-items: center; }
.tone-row select { flex: 1; min-width: 0; }

/* ============ Курилка — база знаний ============ */
.wiki { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.wiki-nav { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg-2); }
.wiki-nav .search-input { margin: 12px 12px 6px; }
.wiki-tree { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.wiki-item {
  display: flex; align-items: center; gap: 7px; width: 100%; min-height: 32px; padding: 5px 8px;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-2); text-align: left; text-decoration: none; font-size: 14px;
}
.wiki-item > span:not(.wiki-twist):not(.wiki-n) { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wiki-item:hover { background: var(--hover); color: var(--text); }
.wiki-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 650; }
.wiki-item.folder { font-weight: 600; color: var(--text); }
.wiki-item.home { font-weight: 650; color: var(--text); margin-bottom: 4px; }
.wiki-ico { width: 15px; height: 15px; flex: none; opacity: 0.7; }
.wiki-twist { display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none; transform: rotate(-90deg); transition: transform 0.12s; cursor: pointer; }
.wiki-twist.open { transform: none; }
.wiki-twist .ico { width: 14px; height: 14px; }
.wiki-n { font-size: 12px; color: var(--text-3); font-weight: 500; }
.wiki-sub { margin-left: 12px; padding-left: 6px; border-left: 1px solid var(--border); }
.wiki-main { overflow-y: auto; min-width: 0; }

.wiki-page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; max-width: 1180px; margin: 0 auto; padding: 22px 32px 48px; }
.wiki-page.has-toc { grid-template-columns: minmax(0, 1fr) 220px; }
.wiki-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); margin-bottom: 6px; }
.wiki-crumbs a { color: var(--text-3); text-decoration: none; }
.wiki-crumbs a:hover { color: var(--accent-text); text-decoration: underline; }
.wiki-crumb-sep { opacity: 0.6; }
.wiki-head { display: flex; align-items: flex-start; gap: 12px; }
.wiki-head h1 { flex: 1; min-width: 0; margin: 0; font-size: 28px; line-height: 1.25; overflow-wrap: anywhere; }
.wiki-actions { display: flex; align-items: center; gap: 4px; flex: none; padding-top: 4px; }
.wiki-desc { margin: 8px 0 0; color: var(--text-2); font-size: 15px; }
.wiki-meta { margin: 8px 0 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-3); }
.wiki-draft { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-size: 14px; }
.wiki-draft > span { flex: 1; min-width: 180px; }
.wiki-draft .ico { width: 16px; height: 16px; }

.wiki-toc { position: sticky; top: 16px; align-self: start; max-height: calc(100vh - 140px); overflow-y: auto; padding-left: 14px; border-left: 2px solid var(--border); font-size: 13px; }
.wiki-toc-head { font-weight: 700; color: var(--text-2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; font-size: 11.5px; }
.wiki-toc a { display: block; padding: 3px 0; color: var(--text-3); text-decoration: none; line-height: 1.35; }
.wiki-toc a:hover { color: var(--accent-text); }
.wiki-toc a.lvl3 { padding-left: 12px; }
.wiki-toc a.lvl4, .wiki-toc a.lvl5, .wiki-toc a.lvl6 { padding-left: 24px; }

/* Статья */
.wiki-doc { white-space: normal; font-size: 15px; line-height: 1.65; color: var(--text); overflow-wrap: anywhere; }
.wiki-doc > :first-child { margin-top: 0; }
.wiki-doc p { margin: 0 0 12px; }
.wiki-doc h1, .wiki-doc h2, .wiki-doc h3, .wiki-doc h4, .wiki-doc h5, .wiki-doc h6 { position: relative; margin: 26px 0 10px; line-height: 1.3; scroll-margin-top: 16px; border-radius: 6px; transition: background 0.6s; }
.wiki-doc h1 { font-size: 24px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); }
.wiki-doc h2 { font-size: 20px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.wiki-doc h3 { font-size: 17px; }
.wiki-doc h4, .wiki-doc h5, .wiki-doc h6 { font-size: 15px; }
.wiki-doc h1.flash, .wiki-doc h2.flash, .wiki-doc h3.flash, .wiki-doc h4.flash { background: var(--flash); }
.wiki-anchor { margin-left: 8px; color: var(--text-3); text-decoration: none; opacity: 0; font-weight: 400; }
.wiki-doc :is(h1, h2, h3, h4, h5, h6):hover .wiki-anchor { opacity: 1; }
.wiki-doc ul, .wiki-doc ol { margin: 0 0 12px; padding-left: 26px; }
.wiki-doc li { margin: 3px 0; }
.wiki-doc li > ul, .wiki-doc li > ol { margin: 4px 0; }
.wiki-doc li.task { list-style: none; margin-left: -20px; }
.wiki-doc li.task input { margin: 0 6px 0 0; vertical-align: -2px; accent-color: var(--accent); }
.wiki-doc a { color: var(--accent-text); }
.wiki-doc a.wiki-file::before { content: ""; }
.wiki-badlink { color: var(--text-3); text-decoration: underline dotted; cursor: help; }
.wiki-doc hr { border: 0; border-top: 1px solid var(--border-2); margin: 22px 0; }
.wiki-doc blockquote { margin: 0 0 14px; padding: 10px 14px; border-left: 4px solid var(--border-2); border-radius: 0 8px 8px 0; background: var(--bg-2); color: var(--text-2); }
.wiki-doc blockquote > :last-child { margin-bottom: 0; }
.wiki-doc blockquote.is-info { border-left-color: #2f80ed; background: color-mix(in srgb, #2f80ed 10%, var(--bg)); }
.wiki-doc blockquote.is-success { border-left-color: var(--online); background: color-mix(in srgb, var(--online) 10%, var(--bg)); }
.wiki-doc blockquote.is-warning { border-left-color: var(--accent); background: var(--accent-soft); }
.wiki-doc blockquote.is-danger { border-left-color: var(--danger); background: var(--danger-soft); }
.wiki-doc code { font-family: var(--mono); font-size: 0.88em; padding: 1px 5px; border-radius: 5px; background: var(--code-bg); color: var(--code-text); }
.wiki-doc .code-block { margin: 0 0 14px; }
.wiki-doc pre { padding: 12px 14px; border-radius: 8px; background: var(--code-bg); border: 1px solid var(--border); overflow: auto; line-height: 1.5; }
.wiki-doc pre code { padding: 0; background: none; color: var(--text); font-size: 13px; white-space: pre; }
.wiki-doc mark { background: var(--chip-me); color: inherit; border-radius: 3px; padding: 0 2px; }
.wiki-table { margin: 0 0 14px; overflow-x: auto; }
.wiki-doc table { border-collapse: collapse; min-width: 50%; font-size: 14px; }
.wiki-doc th, .wiki-doc td { padding: 7px 11px; border: 1px solid var(--border-2); vertical-align: top; text-align: left; }
.wiki-doc th { background: var(--bg-2); font-weight: 650; }
.wiki-doc tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-2) 50%, transparent); }
.wiki-doc .file-img { display: inline-block; max-width: 100%; margin: 4px 0; vertical-align: top; }
.wiki-doc .file-img img { max-width: 100%; max-height: none; height: auto; }
.wiki-results { max-width: 900px; margin: 0 auto; padding: 22px 32px 40px; display: flex; flex-direction: column; gap: 8px; }
.wiki-results h2 { margin: 0 0 8px; font-size: 18px; }
.wiki-results .result { text-decoration: none; color: inherit; }
.wiki-results mark { background: var(--chip-me); color: inherit; border-radius: 3px; }
.wiki-missing { max-width: 640px; margin: 60px auto; padding: 0 24px; text-align: center; }

/* Редактор */
.wiki-editor { display: flex; flex-direction: column; max-width: 1400px; margin: 0 auto; padding: 18px 28px 24px; }
.wiki-edit-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.wiki-edit-head h2 { margin: 0; font-size: 20px; }
.wiki-toolbar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; flex-wrap: wrap; gap: 1px; padding: 6px; border: 1px solid var(--border-2); border-bottom: 0; border-radius: 10px 10px 0 0; background: var(--bg-2); }
.wiki-edit-panes { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border-2); border-radius: 0 0 10px 10px; min-height: 360px; }
.wiki-edit-panes textarea {
  border: 0 !important; border-right: 1px solid var(--border) !important; border-radius: 0 0 0 10px !important; box-shadow: none !important;
  resize: vertical; padding: 14px 16px; min-height: 360px; font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
}
.wiki-preview { padding: 14px 18px; overflow: auto; max-height: 75vh; }
.wiki-edit-foot { position: sticky; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 12px 0 2px; background: var(--bg); }
.wiki-tabs { gap: 2px; }
.wiki-tabs .tab { padding: 4px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); font-weight: 600; }
.wiki-tabs .tab.on { background: var(--bg); color: var(--text); }

/* История, корзина, импорт */
.wiki-revs { display: flex; flex-direction: column; gap: 4px; max-height: 32vh; overflow-y: auto; margin-bottom: 12px; }
.wiki-rev { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); text-align: left; color: var(--text); }
button.wiki-rev { flex-direction: column; align-items: flex-start; gap: 2px; }
button.wiki-rev:hover, .wiki-rev.on { border-color: var(--accent); }
.wiki-rev-view .wiki-doc { max-height: 46vh; overflow: auto; padding: 12px 14px; margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; }
.check.inline { display: inline-flex; margin: 0 18px 0 0; }
.wiki-import-log {
  max-height: 220px; overflow-y: auto; margin-top: 6px; padding: 10px 12px; border-radius: 8px;
  background: var(--code-bg); border: 1px solid var(--border); font-family: var(--mono); font-size: 12.5px; line-height: 1.6; white-space: pre-wrap;
}

@media (max-width: 1500px) {
  .wiki-page.has-toc { grid-template-columns: minmax(0, 1fr); }
  .wiki-toc { display: none; }
}
@media (max-width: 800px) {
  .wiki { grid-template-columns: minmax(0, 1fr); position: relative; }
  .wiki-nav { display: none; }
  .wiki.show-nav .wiki-nav { display: flex; position: absolute; inset: 0; z-index: 5; }
  .wiki-page, .wiki-results { padding: 16px 16px 40px; }
  .wiki-head { flex-direction: column; gap: 8px; }
  .wiki-head h1 { font-size: 23px; }
  .wiki-editor { padding: 14px 12px 16px; }
  .wiki-edit-panes { grid-template-columns: 1fr; }
  .wiki-edit-panes[data-show="src"] .wiki-preview { display: none; }
  .wiki-edit-panes[data-show="preview"] textarea { display: none; }
  .wiki-edit-panes textarea { border-right: 0 !important; border-radius: 0 0 10px 10px !important; }
  .wiki-tabs { display: inline-flex; }
  .hide-mobile { display: none; }
}
/* Правка сообщения: вложения */
.edit-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.edit-file { display: flex; align-items: center; gap: 8px; max-width: 280px; padding: 5px 6px 5px 5px; border: 1px solid var(--border-2); border-radius: 10px; background: var(--bg); }
.edit-file img { width: 48px; height: 48px; object-fit: cover; border-radius: 7px; flex: none; background: var(--bg-2); }
.edit-file .file-ico { width: 48px; height: 48px; }
.edit-file-name { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-file.uploading { opacity: 0.6; }
.msg-edit-bar .btn.ghost { margin-right: auto; }
.msg-edit-bar .muted { flex: 1; }
/* Прочитано: ✓ — доставлено, ✓✓ серые — прочитали не все, ✓✓ цветные — прочитали все */
.msg-read {
  position: absolute; right: 14px; bottom: 4px; display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 4px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); font-size: 11.5px; line-height: 1;
}
.msg-read .ico { width: 15px; height: 15px; stroke-width: 2.2; }
.msg-read:hover { background: var(--bg-3); color: var(--text-2); }
.msg-read.all { color: var(--online); }
.msg:has(.msg-read) .msg-body { padding-right: 34px; }
.read-pop { min-width: 220px; max-height: 320px; overflow-y: auto; }
.read-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px; font-size: 12px; font-weight: 700; }
.read-head .ico { width: 14px; height: 14px; }
.read-row { display: flex; align-items: center; gap: 8px; padding: 4px 10px; font-size: 13.5px; }
/* Курилка: перетаскивание страниц и папок */
.wiki-item.dragging { opacity: 0.45; }
.wiki-item.drop-over { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent-text); }
.wiki-item.drop-bad { cursor: no-drop; }
.wiki-item[draggable="true"] { -webkit-user-drag: element; }
/* Устройства и сеансы */
.sess-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.sess-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.sess-row.current { border-color: var(--accent); background: var(--accent-soft); }
.sess-ico { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 9px; background: var(--bg-2); color: var(--text-2); }
.sess-ico .ico { width: 18px; height: 18px; }
.sess-meta { flex: 1; min-width: 0; }
.sess-device { font-weight: 600; overflow-wrap: anywhere; }

/* ============ Телефон и установленная веб-версия (iPhone «На экран Домой», Android «Установить») ============ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
/* Вырезы экрана в горизонтальном положении */
.app { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
@keyframes sheet-in { from { transform: translateY(100%); } }

@media (max-width: 800px) {
  /* iPhone увеличивает страницу при вводе в поле со шрифтом меньше 16px — приложения так не делают */
  input:not([type=checkbox]):not([type=radio]):not([type=file]), textarea, select { font-size: 16px; }
  /* Полоска «Домой» внизу экрана не перекрывает поле ввода и нижние кнопки */
  .composer-wrap { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .side-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .select-bar { margin-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .wiki-main, .people-list, .panel-scroll { padding-bottom: env(safe-area-inset-bottom); }
  #toast-root { bottom: calc(24px + env(safe-area-inset-bottom)); }
  .jump-latest { bottom: calc(110px + env(safe-area-inset-bottom)); }
}

/* Окна на узком экране — шторкой снизу, как в приложениях iPhone */
@media (max-width: 560px) {
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal {
    max-width: none; border-radius: 18px 18px 0 0;
    max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheet-in 0.2s ease-out;
  }
}

/* Меню сообщения на телефоне: шторка снизу (долгое нажатие), реакции сверху */
.popover.sheet {
  left: 0 !important; right: 0; top: auto !important; bottom: 0;
  max-height: 75dvh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 18px 18px 0 0; border-bottom: 0;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 0 0 100vmax rgba(14, 11, 4, 0.45);
  animation: sheet-in 0.18s ease-out;
}
.popover.sheet::before { content: ""; display: block; width: 38px; height: 5px; margin: 2px auto 8px; border-radius: 3px; background: var(--border-2); }
.popover.sheet .menu { min-width: 0; padding: 0; }
.popover.sheet .menu-item { padding: 13px 14px; font-size: 16px; }
.popover.sheet .menu-item .ico { width: 20px; height: 20px; }
.sheet-reactions { display: flex; justify-content: space-between; gap: 4px; padding: 2px 6px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.sheet-react { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--bg-2); font-size: 22px; line-height: 1; }
.sheet-react:active { transform: scale(0.92); }
.sheet-react.more .ico { width: 22px; height: 22px; color: var(--text-2); }

/* Сенсорный экран: панель действий «при наведении» не нужна (есть долгое нажатие), касание не выделяет текст */
@media (hover: none) and (pointer: coarse) {
  .msg:hover .msg-actions, .msg.menu-open .msg-actions { display: none; }
  .msg:hover:not(.mentioned):not(.pinned):not(.selected):not(.editing):not(.flash) { background: transparent; }
  .msg.menu-open { background: var(--hover); }
  .msg-list .msg { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .msg-list .msg .msg-edit { -webkit-user-select: text; user-select: text; }
  .icon-btn, .btn, .side-item, .menu-item { touch-action: manipulation; }
}
/* Установленная версия: кнопки и меню не выделяются как текст сайта */
@media (display-mode: standalone) {
  .sidebar, .chat-header, .composer-tools, .menu, .side-foot { -webkit-user-select: none; user-select: none; }
}
.ios-share { display: inline-block; padding: 0 4px; border: 1px solid var(--border-2); border-radius: 5px; font-size: 12px; }
