/* Раздел «Чаты» */
body.chat-app { overflow: hidden; }
.app {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  height: 100%;
}

/* ---------- Левая колонка ---------- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.side-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 8px 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--band); color: var(--band-text);
}
.me-btn {
  display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;
  padding: 4px 6px 4px 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer;
  border-radius: var(--radius-m);
}
.me-btn .avatar { --c: #fff; background: rgba(255, 255, 255, .14); color: #fff; }
.me-btn .who { min-width: 0; }
.me-btn .who strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-btn .who span { display: block; font-size: 13px; color: var(--band-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-head .icon-btn { color: var(--band-muted); position: relative; }
.side-head .icon-btn:hover { background: rgba(255, 255, 255, .1); }
.side-head .icon-btn .badge { position: absolute; top: 0; right: -2px; min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px; }
.head-admin { display: none; }
@media (max-width: 760px) { .head-admin:not([hidden]) { display: inline-grid; } }

.search {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 12px 8px; padding: 0 12px;
  background: var(--paper); border-radius: var(--radius-m);
  color: var(--muted);
}
.search svg { width: 18px; height: 18px; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 0; font-size: 16px; outline: none; color: var(--text); }
.search:focus-within { box-shadow: 0 0 0 2px var(--ink); }

.tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 10px 11px; margin-bottom: -1px;
  border: 0; border-bottom: 2.5px solid transparent;
  background: transparent; color: var(--muted); font-weight: 600; cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab .badge { min-width: 20px; height: 20px; font-size: 11px; }

.notify-banner {
  display: flex; gap: 8px; align-items: center;
  margin: 10px 12px 0; padding: 8px 6px 8px 12px;
  border-radius: var(--radius-m); background: var(--warn-soft); font-size: 13px; color: var(--warn);
}
.notify-banner > span:first-child svg { width: 20px; height: 20px; display: block; }
.notify-banner #notify-text { flex: 1; }
.notify-banner .btn { flex: none; }
.notify-banner .icon-btn { width: 30px; height: 30px; }
.notify-banner .icon-btn svg { width: 16px; height: 16px; }

.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 0; }
.list-group { padding: 14px 16px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }

.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 14px; border: 0; background: transparent; text-align: left; cursor: pointer; color: inherit;
}
.item:hover { background: var(--surface-2); }
.item.active { background: var(--ink-soft); }
.item .body { flex: 1; min-width: 0; }
.item .row { display: flex; align-items: center; gap: 8px; }
.item .name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { font-size: 12px; color: var(--muted); flex: none; }
.item .preview { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .preview b { font-weight: 500; color: var(--text); }
.item .preview.typing { color: var(--ok); font-style: italic; }
.item.unread .name { color: var(--ink); }
.item .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .muted-icon { display: inline-grid; color: var(--muted); }
.item .muted-icon svg { width: 15px; height: 15px; }
.item .snippet { font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .snippet b { color: var(--text); font-weight: 500; }

.side-foot {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.side-foot .btn { padding: 10px 8px; font-size: 14px; }
.side-foot .btn svg { width: 20px; height: 20px; }
.side-foot .btn span { display: inline-flex; }
@media (max-width: 760px) { .side-foot { padding-bottom: 10px; } }

/* ---------- Правая колонка: переписка ---------- */
.conv { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.conv-empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 360px; }
.conv-empty .big, .pane-empty .big { display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 50%; background: var(--ink-soft); color: var(--ink); }
.conv-empty .big svg, .pane-empty .big svg { width: 36px; height: 36px; }
.conv-empty h2 { color: var(--text); font-size: 19px; margin: 0 0 6px; }
.conv-empty p { margin: 0 0 18px; }

#chat-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.conv-head {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
  min-height: 62px;
}
.conv-head .back { display: none; margin-left: -8px; }
.conv-head .title-btn { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 4px 0; color: inherit; }
.conv-head .titles { min-width: 0; }
.conv-head h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .sub.typing, .conv-head .sub.online { color: var(--ok); }
.conv-head > .icon-btn { color: var(--ink); }

.pinned-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.pinned-bar .pin-icon { color: var(--ink); display: grid; }
.pinned-bar .pin-icon svg { width: 18px; height: 18px; }
.pinned-text { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; border: 0; background: transparent; padding: 4px 0; cursor: pointer; text-align: left; color: inherit; border-left: 3px solid var(--signal); padding-left: 10px; }
.pinned-text strong { font-size: 12.5px; color: var(--ink); }
.pinned-text span { font-size: 13.5px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-bar .icon-btn { width: 32px; height: 32px; color: var(--muted); }
.pinned-bar .icon-btn svg { width: 16px; height: 16px; }

.messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px 16px 16px; }
.messages-inner { max-width: 860px; min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; justify-content: flex-end; }
.day { align-self: center; margin: 14px 0 8px; padding: 4px 12px; border-radius: 999px; background: var(--chip-bg-hover); font-size: 13px; color: var(--ink); font-weight: 500; }
.load-more { align-self: center; margin: 6px 0 10px; }

.msg { position: relative; display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; max-width: min(80%, 640px); }
.msg.cont { margin-top: 3px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.cont > .avatar, .msg.mine > .avatar { visibility: hidden; }
.msg.mine > .avatar { display: none; }
.direct .msg > .avatar { display: none; }
.bubble-wrap { display: flex; flex-direction: column; min-width: 0; }
.msg.mine .bubble-wrap { align-items: flex-end; }

.bubble {
  position: relative; min-width: 0; max-width: 100%;
  padding: 8px 12px 6px;
  background: var(--surface);
  border-radius: 4px var(--radius-l) var(--radius-l) var(--radius-l);
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
}
.msg.cont .bubble { border-top-left-radius: var(--radius-l); }
.msg.mine .bubble { background: var(--mine); border-radius: var(--radius-l) 4px var(--radius-l) var(--radius-l); }
.msg.mine.cont .bubble { border-top-right-radius: var(--radius-l); }
.msg.selected .bubble { box-shadow: 0 0 0 2px var(--signal); }
.msg.flash .bubble { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--signal); } 100% { box-shadow: 0 1px 1px rgba(0, 0, 0, .06); } }

.msg-more {
  position: absolute; top: 2px; right: -34px; width: 30px; height: 30px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: var(--surface); color: var(--muted); cursor: pointer; opacity: 0;
  box-shadow: var(--shadow); transition: opacity .12s;
}
.msg.mine .msg-more { right: auto; left: -34px; }
.msg-more svg { width: 18px; height: 18px; }
.msg:hover .msg-more, .msg-more:focus-visible { opacity: 1; }
@media (pointer: coarse) { .msg-more { display: none; } }

.author { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; font-size: 13px; font-weight: 600; color: var(--c); }
.author .role-tag { font-size: 11px; padding: 0 6px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.text a { color: var(--r-admin); }
.text.deleted { color: var(--muted); font-style: italic; }
.fwd { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.fwd svg { width: 14px; height: 14px; }
.fwd b { font-weight: 600; color: var(--ink); }
.quote {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; min-width: 0;
  margin: 2px 0 6px; padding: 4px 10px; border: 0; border-left: 3px solid var(--ink); border-radius: 6px;
  background: var(--chip-bg); text-align: left; cursor: pointer; color: inherit;
}
.quote strong { font-size: 12.5px; color: var(--ink); }
.quote span { font-size: 13.5px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stamp { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.stamp svg { width: 16px; height: 16px; }
.stamp .read { color: var(--r-admin); }
.stamp .edited { font-style: italic; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; cursor: pointer; color: inherit;
}
.reaction span { font-size: 12px; font-weight: 600; color: var(--muted); }
.reaction.mine { border-color: var(--ink); background: var(--ink-soft); }
.reaction.mine span { color: var(--ink); }

.files { display: grid; gap: 6px; margin: 4px 0 2px; }
.file-img { display: block; border-radius: var(--radius-m); overflow: hidden; background: var(--paper); max-width: 320px; }
.file-img img { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.file-video { display: block; max-width: 320px; width: 100%; border-radius: var(--radius-m); background: #000; }
.file-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; min-width: 220px; max-width: 360px;
  border-radius: var(--radius-m); background: var(--chip-bg);
  color: var(--text); text-decoration: none;
}
.file-card:hover { background: var(--chip-bg-hover); }
.file-card .info { min-width: 0; flex: 1; }
.file-card .fname { display: block; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fsize { display: block; font-size: 12.5px; color: var(--muted); }
.file-card .dl { width: 22px; height: 22px; color: var(--muted); flex: none; }

/* Голосовые */
.voice { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 2px 0; }
.voice-play { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; background: var(--btn); color: #fff; cursor: pointer; }
.voice-play svg { width: 18px; height: 18px; }
.voice-mid { flex: 1; min-width: 0; display: grid; gap: 4px; }
.voice-bar { height: 6px; border-radius: 3px; background: var(--chip-bg-hover); cursor: pointer; overflow: hidden; }
.voice-fill { height: 100%; width: 0; background: var(--ink); border-radius: 3px; }
.voice-time { font-size: 12px; color: var(--muted); }

/* Звонок в истории */
.msg.call-row { align-self: center; max-width: 100%; margin: 10px 0; }
.call-pill {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 6px 8px 6px 14px; border-radius: 999px; background: var(--surface); box-shadow: 0 1px 1px rgba(0, 0, 0, .06); font-size: 14px;
}
.call-pill .call-ico { display: grid; color: var(--ok); }
.call-pill .call-ico svg { width: 18px; height: 18px; }
.call-pill.missed .call-ico, .call-pill.missed > span:nth-child(2) { color: var(--danger); }
.call-pill .call-dur, .call-pill .call-time { color: var(--muted); font-size: 12.5px; }

.to-bottom {
  position: absolute; right: 22px; bottom: 96px; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 0; border-radius: 999px;
  background: var(--btn); color: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- Поле ввода ---------- */
.composer {
  padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer-inner { max-width: 860px; margin: 0 auto; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none;
  min-height: 44px; max-height: 160px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 22px;
  background: var(--paper); font-size: 16px; line-height: 1.4; outline: none;
}
.composer textarea:focus { border-color: var(--ink); background: var(--surface); }
.composer .icon-btn { width: 44px; height: 44px; color: var(--muted); }
.composer .send { background: var(--btn); color: #fff; }
.composer .send:hover { background: var(--btn-hover); }
.composer .send:disabled { opacity: .4; }
.composer .mic { color: var(--ink); background: var(--ink-soft); }

.compose-ctx { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; padding: 4px 4px 4px 10px; border-left: 3px solid var(--ink); background: var(--chip-bg); border-radius: 6px; }
.compose-ctx .ctx-icon { color: var(--ink); display: grid; }
.compose-ctx .ctx-icon svg { width: 18px; height: 18px; }
.compose-ctx .ctx-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.compose-ctx strong { font-size: 13px; color: var(--ink); }
.compose-ctx .ctx-body span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-ctx .icon-btn { width: 32px; height: 32px; }
.compose-ctx .icon-btn svg { width: 16px; height: 16px; }

.recorder { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.recorder .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e0453a; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.recorder .rec-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.recorder .rec-hint { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recorder .icon-btn:first-child { color: var(--danger); }
.readonly-note { text-align: center; color: var(--muted); font-size: 14px; padding: 10px; }

.pending-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: flex; align-items: center; gap: 6px; max-width: 260px;
  padding: 5px 4px 5px 10px; border-radius: 999px;
  background: var(--ink-soft); color: var(--ink); font-size: 13px;
}
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip small { color: var(--muted); flex: none; }
.chip button { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; flex: none; }
.chip button:hover { background: var(--chip-bg-hover); }
.chip button svg { width: 14px; height: 14px; }
.progress { height: 4px; border-radius: 2px; background: var(--ink-soft); overflow: hidden; margin-bottom: 8px; }
.progress div { height: 100%; width: 0; background: var(--ink); transition: width .2s; }

.drop-overlay {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 20;
  display: grid; place-items: center;
  background: var(--paper); opacity: .94;
  border: 3px dashed var(--ink); border-radius: var(--radius-l);
  margin: 10px; color: var(--ink); font-size: 18px; font-weight: 600; pointer-events: none;
}

/* ---------- Меню действий с сообщением ---------- */
.menu-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 90; background: var(--overlay); display: flex; align-items: flex-end; }
.menu-backdrop.float { background: transparent; display: block; }
.menu {
  width: 100%; background: var(--surface); border-radius: var(--radius-l) var(--radius-l) 0 0;
  padding: 8px 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); box-shadow: var(--shadow-lg);
}
.menu-backdrop.float .menu { border-radius: var(--radius-l); padding: 6px 0; }
.menu-reactions { display: flex; justify-content: space-around; padding: 4px 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-reactions button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; font-size: 22px; cursor: pointer; }
.menu-backdrop.float .menu-reactions button { width: 28px; height: 32px; font-size: 18px; }
.menu-reactions button:hover, .menu-reactions button.on { background: var(--ink-soft); }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 18px; border: 0; background: transparent; text-align: left; cursor: pointer; font-size: 15px; color: inherit; }
.menu-item:hover { background: var(--surface-2); }
.menu-item svg { width: 20px; height: 20px; color: var(--muted); }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }

/* ---------- Списки в окнах ---------- */
.member-list { margin-bottom: 8px; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.member-row .body { min-width: 0; flex: 1; }
.member-row .name { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.member-row .meta { font-size: 13px; color: var(--muted); }
.profile-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.profile-head strong { display: block; font-size: 18px; margin-bottom: 4px; }
.profile-photo-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.profile-photo-actions .btn span { display: inline-flex; }
dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 20px; font-size: 14px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.section-title { font-size: 15px; font-weight: 600; margin: 20px 0 10px; }
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.quick-actions .btn span { display: inline-flex; }
.inline-form { display: flex; gap: 8px; }
.muted-text { color: var(--muted); font-size: 14px; }
.files-link { margin-top: 10px; }
.files-link span { display: inline-flex; }
.steps-list { padding-left: 20px; margin: 0 0 12px; display: grid; gap: 6px; }

/* ---------- Телефон: один экран за раз ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="list"] .conv { display: none; }
  .app[data-view="chat"] .sidebar { display: none; }
  .conv-head .back { display: inline-grid; }
  .conv-head { padding-left: 12px; }
  .messages { padding: 10px 10px 14px; }
  .msg { max-width: 88%; }
  .to-bottom { right: 14px; }
}

/* ---------- «Вас обслуживают»: закреплённые люди для точек, поставщиков, клиентов ---------- */
.service-strip { margin: 10px 12px 0; padding: 8px 4px 6px; border-radius: var(--radius-m); background: var(--ink-soft); }
.ss-head { display: flex; align-items: baseline; gap: 8px; padding: 0 8px 6px; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.ss-head .ss-area { font-weight: 500; color: var(--muted); }
.ss-list { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.ss-list::-webkit-scrollbar { display: none; }
.ss-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px; flex: none;
  width: 84px; padding: 4px 2px; border: 0; border-radius: var(--radius-m);
  background: transparent; color: inherit; cursor: pointer; text-align: center;
}
.ss-item:hover { background: var(--chip-bg-hover); }
.ss-item .ss-name { max-width: 100%; font-size: 12.5px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ss-item .ss-title { max-width: 100%; font-size: 11px; color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.welcome-lead { margin-top: 0; }
.welcome-list .member-row .icon-btn { color: var(--ink); background: var(--ink-soft); width: 38px; height: 38px; margin-left: 4px; }
.welcome-list .member-row .icon-btn svg { width: 20px; height: 20px; }

/* Служебные сообщения в чате */
.call-pill.system { max-width: min(560px, 100%); padding: 6px 14px; font-size: 13.5px; color: var(--muted); text-align: center; flex-wrap: wrap; border-radius: var(--radius-l); }
.call-pill.system .call-ico { color: var(--ink); }
