/* Kira: интерфейс в духе Telegram Web. Светлая и тёмная темы через переменные. */

:root {
  --accent: #3390ec;
  --accent-hover: #2b7fd4;
  --accent-soft: rgba(51, 144, 236, .12);
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --bg-3: #e9ecef;
  --border: #e4e6e9;
  --text: #0f1419;
  --text-2: #5f6b77;
  --text-3: #8a96a3;
  --rail: #f7f8fa;
  --hover: #f1f3f5;
  --active: #3390ec;
  --active-text: #ffffff;
  --bubble: #ffffff;
  --bubble-shadow: 0 1px 2px rgba(16, 35, 47, .15);
  --chat-bg: #b8cfa6;
  --chat-bg-2: #dfe8c6;
  --chat-bg-3: #9fc3b1;
  --chip: rgba(0, 0, 0, .22);
  --good: #31a24c;
  --danger: #e53935;
  --link: #2481cc;
  --code-bg: rgba(0, 0, 0, .06);
  --quote-bg: rgba(51, 144, 236, .08);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .18);
  --radius: 12px;
  --bubble-radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --accent: #8774e1;
  --accent-hover: #7a66d8;
  --accent-soft: rgba(135, 116, 225, .16);
  --bg: #212121;
  --bg-2: #181818;
  --bg-3: #2c2c2c;
  --border: #303030;
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --text-3: #7f7f7f;
  --rail: #1a1a1a;
  --hover: #2c2c2c;
  --active: #8774e1;
  --bubble: #212121;
  --bubble-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --chat-bg: #0f0f0f;
  --chat-bg-2: #1c1b26;
  --chat-bg-3: #13201c;
  --chip: rgba(255, 255, 255, .12);
  --link: #8ab4f8;
  --code-bg: rgba(255, 255, 255, .08);
  --quote-bg: rgba(135, 116, 225, .14);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8774e1;
    --accent-hover: #7a66d8;
    --accent-soft: rgba(135, 116, 225, .16);
    --bg: #212121;
    --bg-2: #181818;
    --bg-3: #2c2c2c;
    --border: #303030;
    --text: #f1f1f1;
    --text-2: #aaaaaa;
    --text-3: #7f7f7f;
    --rail: #1a1a1a;
    --hover: #2c2c2c;
    --active: #8774e1;
    --bubble: #212121;
    --bubble-shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --chat-bg: #0f0f0f;
    --chat-bg-2: #1c1b26;
    --chat-bg-3: #13201c;
    --chip: rgba(255, 255, 255, .12);
    --link: #8ab4f8;
    --code-bg: rgba(255, 255, 255, .08);
    --quote-bg: rgba(135, 116, 225, .14);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: var(--text); }
[hidden] { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- кнопки и поля ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer; white-space: nowrap; text-decoration: none !important;
  color: var(--text);
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; height: 44px; font-weight: 600; }
.btn-icon {
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-2); flex: none;
}
.btn-icon:hover { background: var(--hover); color: var(--text); }
.btn-icon svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn svg { width: 18px; height: 18px; }

.input {
  height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-2); outline: none; min-width: 0;
}
.input:focus { border-color: var(--accent); background: var(--bg); }

.search {
  position: relative; display: flex; align-items: center;
}
.search svg {
  position: absolute; left: 12px; width: 18px; height: 18px; fill: none;
  stroke: var(--text-3); stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
.search input {
  width: 100%; height: 40px; border-radius: 22px; border: 2px solid transparent;
  background: var(--bg-2); padding: 0 14px 0 40px; outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--bg); }

.segmented { display: inline-flex; background: var(--bg-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text-2); font-size: 14px;
}
.segmented button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 500; }

/* Переключатель «сотрудник» */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 36px; height: 20px; border-radius: 10px; background: var(--bg-3); position: relative;
  transition: background .15s; flex: none; border: 1px solid var(--border);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.badge-bot {
  display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 9px;
  background: rgba(242, 157, 75, .16); color: #b86b12; font-size: 11px; font-weight: 600; vertical-align: middle;
}
.badge-internal {
  display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600;
  letter-spacing: .02em; vertical-align: middle; white-space: nowrap;
}

/* ---------- вход ---------- */

.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100%;
  background: var(--bg-2); padding: 16px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--bg); border-radius: 20px; padding: 36px 28px 28px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08); text-align: center;
}
.login-logo { color: var(--accent); }
.login-logo svg { width: 84px; height: 84px; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
.login-card p { margin: 0 0 24px; }
.login-card form { text-align: left; display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.field input {
  height: 48px; border-radius: 12px; border: 1px solid var(--border); padding: 0 14px;
  background: var(--bg); outline: none; font-size: 16px;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.form-error { color: var(--danger); font-size: 14px; }

/* ---------- каркас ---------- */

.layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.rail {
  width: 76px; flex: none; background: var(--rail); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 2px;
}
.rail-logo { color: var(--accent); margin-bottom: 10px; display: block; }
.rail-logo svg { width: 40px; height: 40px; display: block; }
.rail-item {
  position: relative; width: 64px; padding: 8px 0 6px; border-radius: 12px; border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
  color: var(--text-2); font-size: 11px; text-decoration: none !important;
}
.rail-item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-item:hover { background: var(--hover); color: var(--text); }
.rail-item.on { color: var(--accent); background: var(--accent-soft); }
.rail-item.on svg { stroke-width: 2.1; }
.rail-badge {
  position: absolute; top: 3px; right: 9px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; font-weight: 600;
}
.rail-spacer { flex: 1; }
.rail-form { margin: 0; }
.view { flex: 1; min-width: 0; display: flex; overflow: hidden; }

/* ---------- раздел «Чаты» ---------- */

.chats-layout { display: flex; flex: 1; min-width: 0; }
.sidebar {
  width: 380px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--border);
  background: var(--bg); min-height: 0;
}
.sidebar-head { padding: 10px 12px; display: flex; gap: 8px; align-items: center; }
.sidebar-head .search { flex: 1; }
.sidebar-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px 8px; }
.sidebar-tools .btn { gap: 4px; padding: 0 10px; color: var(--text-2); }
.sidebar-tools .btn svg { width: 16px; height: 16px; }
.sidebar-tools .btn:disabled { opacity: .45; cursor: default; }
#unread-filter b { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
#unread-filter b:empty { display: none; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.chat-item {
  display: flex; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 12px;
  cursor: pointer; color: inherit; text-decoration: none !important;
}
.chat-item:hover { background: var(--hover); }
.chat-item.on { background: var(--active); color: var(--active-text); }
.chat-item.on .chat-item-sub, .chat-item.on .chat-item-time { color: rgba(255,255,255,.85); }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-row { display: flex; align-items: baseline; gap: 8px; }
.chat-item-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--text-3); flex: none; }
.chat-item-sub { flex: 1; min-width: 0; color: var(--text-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-sub b { font-weight: 500; color: var(--text); }
.chat-item.on .chat-item-sub b { color: #fff; }
.unread {
  flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent);
  color: #fff; font-size: 12px; font-weight: 600; line-height: 22px; text-align: center;
}
.chat-item.on .unread { background: #fff; color: var(--accent); }
.chat-item.removed:not(.on) .avatar { filter: grayscale(1); opacity: .6; }
.chat-item.removed:not(.on) .chat-item-title { color: var(--text-2); }
.removed-badge {
  flex: none; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 8px;
  background: var(--bg-3); color: var(--text-2);
}
.chat-item.on .removed-badge { background: rgba(255,255,255,.2); color: #fff; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--text-2); }

.avatar {
  flex: none; width: 54px; height: 54px; border-radius: 50%; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 19px; user-select: none; position: relative;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.md { width: 42px; height: 42px; font-size: 16px; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; }
.c0 { background: linear-gradient(#ff885e, #ff516a); }
.c1 { background: linear-gradient(#ffcd6a, #ffa85c); }
.c2 { background: linear-gradient(#82b1ff, #665fff); }
.c3 { background: linear-gradient(#a0de7e, #54cb68); }
.c4 { background: linear-gradient(#53edd6, #28c9b7); }
.c5 { background: linear-gradient(#72d5fd, #2a9ef1); }
.c6 { background: linear-gradient(#e0a2f3, #d669ed); }

/* Лента */
.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--chat-bg); }
.chat-pane::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 15% 20%, var(--chat-bg-2) 0, transparent 45%),
    radial-gradient(circle at 85% 30%, var(--chat-bg-3) 0, transparent 40%),
    radial-gradient(circle at 60% 85%, var(--chat-bg-2) 0, transparent 45%);
  opacity: .9;
}
.chat-pane::after {
  /* лёгкий узор поверх градиента */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M18 22l10-4-3 12zM70 16c5 0 8 3 8 8M96 60l8 8m0-8l-8 8M20 84a6 6 0 1 0 12 0 6 6 0 1 0-12 0M60 70h14l-7 12zM88 100c4-6 10-6 14 0M40 46l6 6 10-12'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .chat-pane::after { filter: invert(1); opacity: .05; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chat-pane::after { filter: invert(1); opacity: .05; } }

.chat-head {
  position: relative; z-index: 2; height: 58px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 8px 0 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.chat-head .back { display: none; margin-left: -8px; }
.chat-head-body { flex: 1; min-width: 0; }
.chat-head-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.staff-toggle.on { color: var(--accent); background: var(--accent-soft); }
.filter-bar {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 12px; font-size: 13px; background: var(--accent-soft); color: var(--text); border-bottom: 1px solid var(--border);
}
:root .filter-bar { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.link-btn { border: 0; background: none; padding: 0; color: var(--link); cursor: pointer; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }
.chat-search-bar {
  position: relative; z-index: 2; display: flex; gap: 8px; align-items: center; padding: 8px 12px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.chat-search-bar .search { flex: 1; }
.search-results {
  position: absolute; z-index: 3; top: 58px; right: 0; width: min(420px, 100%); bottom: 0;
  background: var(--bg); border-left: 1px solid var(--border); display: flex; flex-direction: column;
}
.search-results-list { flex: 1; overflow-y: auto; }
.search-hit { display: block; padding: 10px 16px; border-bottom: 1px solid var(--border); color: inherit; cursor: pointer; text-decoration: none !important; }
.search-hit:hover { background: var(--hover); }
.search-hit-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.search-hit-text { color: var(--text-2); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.search-hit mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; }

.messages {
  position: relative; z-index: 1; flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 12px 16px 16px; overscroll-behavior: contain;
}
.messages-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; }
.chat-foot {
  position: relative; z-index: 2; flex: none; text-align: center; padding: 10px; font-size: 13px;
  color: var(--text-2); background: var(--bg); border-top: 1px solid var(--border);
}
.empty-pane { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; z-index: 1; }
.chip {
  display: inline-block; padding: 4px 12px; border-radius: 14px; background: var(--chip); color: #fff;
  font-size: 14px; font-weight: 500;
}
.day-sep { text-align: center; margin: 10px 0 8px; }
.loader-row { text-align: center; padding: 8px; }
.spinner {
  display: inline-block; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Сообщение */
.msg { display: flex; align-items: flex-end; gap: 8px; margin-top: 2px; padding-left: 0; }
.msg.first { margin-top: 8px; }
.msg-avatar { width: 34px; flex: none; align-self: flex-end; }
.msg-avatar .avatar { visibility: hidden; cursor: pointer; }
.msg.last .msg-avatar .avatar { visibility: visible; }
.bubble {
  position: relative; max-width: min(480px, calc(100% - 50px)); min-width: 64px; background: var(--bubble);
  border-radius: var(--bubble-radius); box-shadow: var(--bubble-shadow); padding: 6px 10px 6px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.first .bubble { border-top-left-radius: var(--bubble-radius); }
.msg:not(.first) .bubble { border-top-left-radius: 6px; }
.msg:not(.last) .bubble { border-bottom-left-radius: 6px; }
.msg.last .bubble { border-bottom-left-radius: 4px; }
.msg.highlight .bubble { animation: flash 2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--bubble-shadow); } }
.msg-name {
  display: none; font-size: 14px; font-weight: 600; margin-bottom: 2px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg.first .msg-name { display: block; }
.msg-name .badge-internal { margin-left: 6px; }
.n0 { color: #e17076; } .n1 { color: #f29d4b; } .n2 { color: #7c71e8; } .n3 { color: #4fae4e; }
.n4 { color: #3aa9a7; } .n5 { color: #3d95d9; } .n6 { color: #c661d6; }
.msg-text { white-space: pre-wrap; }
.msg-text code, .msg-text pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px;
  background: var(--code-bg); border-radius: 5px;
}
.msg-text code { padding: 1px 4px; }
.msg-text pre { padding: 8px 10px; margin: 4px 0; overflow-x: auto; white-space: pre; }
.msg-text blockquote {
  margin: 4px 0; padding: 4px 10px; border-left: 3px solid var(--accent); background: var(--quote-bg); border-radius: 4px;
}
.spoiler { background: var(--text-3); color: transparent; border-radius: 4px; cursor: pointer; transition: all .2s; }
.spoiler.shown { background: transparent; color: inherit; }
.msg-meta {
  float: right; margin: 6px 0 -4px 10px; font-size: 12px; color: var(--text-3); white-space: nowrap;
  line-height: 1; position: relative; top: 4px; user-select: none;
}
.msg-meta a { color: inherit; }
.msg-fwd { font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.reply {
  display: flex; gap: 8px; margin: 2px 0 4px; padding: 4px 8px; border-radius: 6px; background: var(--quote-bg);
  border-left: 3px solid var(--accent); cursor: pointer; font-size: 14px; max-width: 100%; overflow: hidden;
}
.reply img { width: 34px; height: 34px; object-fit: cover; border-radius: 4px; flex: none; }
.reply-body { min-width: 0; }
.reply-name { color: var(--accent); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-text { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Медиа */
.media { margin: -6px -10px 4px; border-radius: var(--bubble-radius) var(--bubble-radius) 0 0; overflow: hidden; position: relative; background: var(--bg-3); }
.msg:not(.first) .media { border-top-left-radius: 6px; }
.msg.first .msg-name + .media, .msg-fwd + .media, .reply + .media { margin-top: 4px; border-radius: 0; }
.media img, .media video { display: block; width: 100%; height: 100%; object-fit: cover; }
.media.photo img { cursor: zoom-in; }
.bubble:not(.media-only) .media:not(.sticker):not(.round) { max-width: calc(100% + 20px) !important; }
.bubble.sticker-wrap .msg-name, .bubble.round-wrap .msg-name { display: none !important; }
.bubble.media-only { padding: 0; background: transparent; box-shadow: none; }
.bubble.media-only .media { margin: 0; border-radius: var(--bubble-radius); }
.bubble.media-only .msg-meta {
  position: absolute; right: 8px; bottom: 8px; top: auto; margin: 0; padding: 3px 7px; border-radius: 10px;
  background: rgba(0,0,0,.45); color: #fff; float: none;
}
.bubble.media-only .msg-name { padding: 6px 10px 0; background: var(--bubble); border-radius: var(--bubble-radius) var(--bubble-radius) 0 0; }
.bubble.media-only .msg-name + .media { border-top-left-radius: 0; border-top-right-radius: 0; }
.media-blur img { filter: blur(24px); transform: scale(1.1); }
.media.pending { height: 120px !important; aspect-ratio: auto !important; width: 260px !important; }
.media-placeholder {
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px;
  color: var(--text-2); font-size: 13px; text-align: center; padding: 12px; height: 100%;
}
.media-placeholder svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.sticker { width: 180px; height: 180px; background: transparent; margin: 0; }
.sticker img, .sticker video { object-fit: contain; }
.sticker .tgs { width: 100%; height: 100%; }
.round { width: 220px; height: 220px; border-radius: 50% !important; margin: 0; }
.bubble.sticker-wrap .msg-meta, .bubble.round-wrap .msg-meta { position: static; float: none; display: inline-block; margin: 4px 0 0; padding: 3px 7px; border-radius: 10px; background: var(--chip); color: #fff; }
.voice audio, .audio audio { width: 100%; min-width: 240px; height: 40px; display: block; margin: 2px 0; }
.file {
  display: flex; align-items: center; gap: 10px; padding: 4px 0; color: inherit; text-decoration: none !important;
  min-width: 220px;
}
.file-icon {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.file-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.file-icon.off { background: var(--bg-3); color: var(--text-3); }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.file-sub { font-size: 13px; color: var(--text-2); }
.poll-q { font-weight: 600; margin-bottom: 2px; }
.poll-kind { font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.poll-opt { padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 4px; font-size: 14px; }
.geo { display: block; min-width: 240px; }
.geo-map {
  height: 120px; margin: -6px -10px 6px; border-radius: var(--bubble-radius) var(--bubble-radius) 0 0;
  background: linear-gradient(135deg, #cfe3c4, #b8d6e8); display: flex; align-items: center; justify-content: center;
}
.geo-map svg { width: 40px; height: 40px; fill: var(--danger); }

.jump-down {
  position: absolute; z-index: 4; right: 20px; bottom: 60px; width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,.2); cursor: pointer; color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
}
.jump-down svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.jump-down b {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%); min-width: 22px; height: 22px;
  padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; line-height: 22px;
}

/* ---------- страницы со статистикой и таблицами ---------- */

.page { flex: 1; overflow-y: auto; background: var(--bg-2); }
.page-inner { max-width: 1180px; margin: 0 auto; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; margin: 0; flex: 1; min-width: 200px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .grow { flex: 1; }
.card { background: var(--bg); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card + .card, .grid + .card, .card + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; flex: 1; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi-label { font-size: 13px; color: var(--text-2); }
.kpi-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; line-height: 1.1; }
.kpi-sub { font-size: 13px; color: var(--text-3); margin-top: 4px; }
.charts { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.chart-box { position: relative; height: 220px; }
.two-col { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-weight: 500; color: var(--text-2); font-size: 13px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--bg);
}
table.data th.num { text-align: right; }
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data th:first-child, table.data td:first-child { padding-left: 18px; }
table.data th:last-child, table.data td:last-child { padding-right: 18px; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover td { background: var(--hover); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-sub { font-size: 12px; color: var(--text-3); }
.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar-cell i { display: block; height: 6px; border-radius: 3px; background: var(--accent); opacity: .75; }

.date-nav { display: inline-flex; align-items: center; gap: 4px; }
.btn-icon:disabled { opacity: .35; cursor: default; background: transparent; }
.range-title { font-size: 18px; font-weight: 600; }
.delta { font-weight: 600; color: var(--text-2); }
.delta.up { color: var(--good); }
.delta.down { color: var(--danger); }
#stats-body { transition: opacity .15s; }
#stats-body.loading { opacity: .5; }
.list-section { padding: 10px 10px 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.hit { align-items: flex-start; }
.hit .chat-item-sub { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hit mark, .chat-item mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; }
.chat-item.on mark { background: rgba(255,255,255,.25); color: #fff; }
.date-nav input { width: 150px; }

/* Сотрудники и лента пользователя */
.staff-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.people-list { padding: 8px; position: sticky; top: 0; }
.person {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  color: inherit; text-decoration: none !important;
}
.person:hover { background: var(--hover); }
.person.on { background: var(--accent-soft); }
.person .who-name { flex: 1; }
.person .count { font-variant-numeric: tabular-nums; font-weight: 600; }
.person.zero { opacity: .55; }
.feed { padding: 0; overflow: hidden; }
.feed-group { border-bottom: 1px solid var(--border); }
.feed-group:last-child { border-bottom: 0; }
.feed-chat {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--bg);
  position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--border);
}
.feed-chat a { font-weight: 600; color: var(--text); }
.feed-body { padding: 8px 16px 12px; background: var(--bg-2); }
.feed .msg { max-width: 780px; }
.msg-goto {
  align-self: center; flex: none; display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px;
  border-radius: 15px; font-size: 13px; color: var(--accent); background: var(--bg); border: 1px solid var(--border);
  opacity: .55; transition: opacity .15s, background .15s; text-decoration: none !important; white-space: nowrap;
}
.msg-goto svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.msg:hover .msg-goto, .msg-goto:focus-visible { opacity: 1; }
.msg-goto:hover { background: var(--accent-soft); border-color: var(--accent); }
@media (hover: none) { .msg-goto { opacity: 1; } .msg-goto span { display: none; } .msg-goto { width: 34px; padding: 0; justify-content: center; } }
.empty-card { text-align: center; padding: 40px 20px; color: var(--text-2); }
.empty-card svg { width: 48px; height: 48px; fill: none; stroke: var(--text-3); stroke-width: 1.5; margin-bottom: 8px; }

.profile { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.profile-body { flex: 1; min-width: 200px; }
.profile h1 { margin: 0 0 2px; font-size: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 16px; background: var(--bg-2);
  color: var(--text); font-size: 13px; text-decoration: none !important;
}
.chip-link:hover { background: var(--hover); }
.chip-link b { color: var(--text-2); font-weight: 500; }

/* Рассылка и история */
.bc-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; }
.textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 140px; line-height: 1.45; background: var(--bg); width: 100%; font: inherit; }
.bc-filters { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.bc-filters .field .input { min-width: 180px; height: 38px; }
.bc-count { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.bc-count .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.bc-count.has .dot { background: var(--good); }
.bc-count.none .dot { background: var(--danger); }
.bc-recipients .card-head { margin-bottom: 6px; }
.bc-chats { max-height: 520px; overflow-y: auto; margin: 0 -10px; }
.bc-chat { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.bc-chat:hover { background: var(--hover); }
.bc-chat input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.bc-chat-body { display: flex; flex-direction: column; min-width: 0; }
.bc-preview { white-space: pre-wrap; background: var(--bg-2); border-radius: 12px; padding: 10px 14px; font-size: 15px; max-height: 300px; overflow-y: auto; overflow-wrap: anywhere; }
.modal.modal-wide { max-width: 560px; }
.lang-badge { display: inline-flex; height: 18px; align-items: center; padding: 0 6px; border-radius: 9px; font-size: 11px; font-weight: 700; }
.lang-ru { background: rgba(51, 144, 236, .14); color: #2a6fc0; }
.lang-test { background: rgba(242, 157, 75, .18); color: #b86b12; }
.input-sm.input-na { background: var(--bg-2); color: var(--text-3); border-style: dashed; cursor: not-allowed; }
.lang-eng { background: rgba(155, 89, 215, .14); color: #8343c4; }
.badge-status { display: inline-flex; height: 20px; align-items: center; padding: 0 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-status.ok { background: rgba(49, 162, 76, .12); color: var(--good); }
.badge-status.err { background: rgba(229, 57, 53, .1); color: var(--danger); }
.badge-status.wait { background: var(--accent-soft); color: var(--accent); }
.badge-status.del { background: var(--bg-3); color: var(--text-2); }
.err-text { color: var(--danger); }
.hist-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.hist-list { padding: 6px; max-height: calc(100vh - 140px); overflow-y: auto; position: sticky; top: 0; }
.hist-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px; border-radius: 10px; cursor: pointer; }
.hist-item:hover { background: var(--hover); }
.hist-item.on { background: var(--accent-soft); }
.hist-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hist-text { margin: 4px 0; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hist-detail { min-width: 0; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.hist-detail .card + .card { margin-top: 0; }
.hist-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.hist-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.hist-stats div { background: var(--bg-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.hist-stats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.hist-stats span { font-size: 12px; color: var(--text-2); }
.reply-link { display: block; color: inherit; font-size: 14px; max-width: 360px; }
.reply-link span { color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.log-row { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.log-row:last-child { border-bottom: 0; }
@media (max-width: 900px) {
  .bc-grid, .hist-layout { grid-template-columns: minmax(0, 1fr); }
  .hist-list { position: static; max-height: 300px; }
  .hist-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Удаления бота */
.rm-table tr.rm-pending td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.rm-table .who-name a { color: var(--text); font-weight: 600; }
.rm-reason-cell { min-width: 220px; max-width: 420px; }
.rm-reason-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
  .rm-table thead { display: none; }
  .rm-table, .rm-table tbody { display: block; }
  .rm-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
  table.data.rm-table td { display: block; padding: 0 !important; border: 0; max-width: none; min-width: 0; }
  .rm-table td:first-child, .rm-table td.rm-reason-cell { grid-column: 1 / -1; }
  .rm-table td[data-label]:not(:first-child)::before { content: attr(data-label); display: block; font-size: 12px; color: var(--text-3); margin-bottom: 2px; }
  .rm-table tr.rm-pending td:first-child { box-shadow: none; }
  .rm-table tr.rm-pending { box-shadow: inset 3px 0 0 var(--danger); }
  .rm-reason-line { white-space: normal; }
}

/* Настройка чатов */
.add-card { padding: 14px 18px; }
.add-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.add-row .field { flex: 1; min-width: 200px; max-width: 360px; }
.add-row .input { width: 100%; height: 38px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.add-result { margin-top: 10px; font-size: 14px; padding: 8px 12px; border-radius: 8px; background: var(--bg-2); }
.add-result.ok { background: rgba(49, 162, 76, .1); color: var(--good); }
.add-result.warn { background: rgba(242, 157, 75, .14); color: #b86b12; }
.add-result.error { background: rgba(229, 57, 53, .08); color: var(--danger); }
.input-sm { height: 32px; padding: 0 8px; font-size: 14px; background: var(--bg); max-width: 190px; }
.setup-table td { vertical-align: middle; }
.input-sm.input-resp { max-width: 240px; }
.setup-table .who-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-icon-sm { width: 28px; height: 28px; font-size: 14px; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.kind-supplier { border-color: var(--accent); color: var(--accent); }
.kind-test { border-color: #f29d4b; color: #c26a10; }
.suggest {
  display: block; margin-top: 4px; border: 0; background: none; padding: 0; cursor: pointer; text-align: left;
  font-size: 12px; color: var(--accent); font-weight: 600;
}
.suggest span { font-weight: 400; color: var(--text-2); }
.suggest:hover { text-decoration: underline; }
.suggest-note { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.setup-warn { font-size: 12px; color: #c26a10; margin-top: 3px; }
.row-removed td { opacity: .6; }
tr.row-flash td { animation: rowflash 1.4s ease-out; }
@keyframes rowflash { 0%, 30% { background: var(--accent-soft); } 100% { background: transparent; } }

/* Доступ */
.count-badge { display: inline-flex; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; }
.seg-sm { flex-wrap: nowrap; }
.seg-sm button { padding: 4px 9px; font-size: 13px; white-space: nowrap; }
.modal { max-height: calc(100dvh - 32px); overflow-y: auto; }
.modal.modal-sections { max-width: 640px; }
.modal-sections td { padding-top: 6px !important; padding-bottom: 6px !important; }
.ok-text { color: var(--good); }
.tg-links { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bc-chat.disabled { opacity: .5; cursor: default; }
.tg-list { max-height: 360px; margin: 0; }
table.data th.center, table.data td.center { text-align: center; }
.page-head .segmented { flex: none; }
.access-grid { grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); align-items: start; }
.form-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.show-sm { display: none; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.form-grid .field .input { height: 42px; background: var(--bg); width: 100%; }
.pw-field { display: flex; gap: 8px; }
.pw-field .input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: rgba(229, 57, 53, .08); border-color: var(--danger); }
.modal-body { padding: 24px 20px 20px; }

/* ---------- модальные окна ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.45); display: flex; align-items: center;
  justify-content: center; padding: 16px; animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg); border-radius: 16px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg);
  overflow: hidden; position: relative;
}
.modal-close { position: absolute; top: 8px; right: 8px; }
.user-card-top { text-align: center; padding: 28px 20px 16px; }
.user-card-top h3 { margin: 12px 0 2px; font-size: 20px; }
.user-card-rows { border-top: 1px solid var(--border); }
.user-card-row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.user-card-row:last-child { border-bottom: 0; }
.user-card-row .grow { flex: 1; }
.user-card-row a { font-weight: 500; }

.lightbox {
  position: fixed; inset: 0; z-index: 110; background: rgba(0,0,0,.9); display: flex; align-items: center;
  justify-content: center; animation: fade .15s; cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; box-shadow: 0 0 40px rgba(0,0,0,.5); }
.lightbox .btn-icon { position: absolute; top: 12px; right: 12px; color: #fff; }
.lightbox .btn-icon:hover { background: rgba(255,255,255,.12); }
.lightbox-dl { position: absolute; top: 18px; right: 64px; color: #fff; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 120; background: rgba(0,0,0,.8);
  color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; animation: fade .2s;
}

/* ---------- мобильная версия ---------- */

@media (max-width: 900px) {
  .two-col, .access-grid { grid-template-columns: minmax(0, 1fr); }
  .staff-layout { grid-template-columns: 1fr; }
  .people-list { position: static; }
  .sidebar { width: 320px; }
}

@media (max-width: 720px) {
  .layout { flex-direction: column-reverse; }
  .rail {
    width: 100%; height: auto; flex-direction: row; justify-content: space-around; border-right: 0;
    border-top: 1px solid var(--border); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .rail-logo, .rail-spacer { display: none; }
  .rail { overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .rail-item { width: auto; flex: 1 0 64px; padding: 6px 0 4px; }
  .rail-form { flex: 1 0 64px; display: flex; }
  .rail-form .rail-item { width: 100%; }
  .view { flex: 1; min-height: 0; }
  .sidebar { width: 100%; border-right: 0; }
  .chats-layout .chat-pane { display: none; }
  .chats-layout.has-chat .sidebar { display: none; }
  .chats-layout.has-chat .chat-pane { display: flex; }
  .chat-head .back { display: inline-flex; }
  .messages { padding: 8px 8px 12px; }
  .bubble { max-width: calc(100% - 44px); }
  .page-inner { padding: 16px 16px 32px; }
  .page-head h1 { font-size: 20px; }
  .kpi-value { font-size: 24px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .date-nav input { width: 140px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .search-results { top: 58px; width: 100%; border-left: 0; }
  .file-name { max-width: 180px; }
  .hide-sm { display: none; }
  /* Настройка чатов на телефоне: строка таблицы превращается в карточку */
  .setup-table thead { display: none; }
  .setup-table, .setup-table tbody { display: block; }
  .setup-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
  table.data.setup-table td { display: block; padding: 0 !important; border: 0; }
  .setup-table td:first-child { grid-column: 1 / -1; }
  .setup-table td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--text-3); margin-bottom: 3px; }
  .setup-table td.center { text-align: left; }
  .setup-table .input-sm { max-width: none; width: 100%; }
  .show-sm { display: block; }
  .voice audio, .audio audio { min-width: 200px; }
}
