/* ═══════════ Чат ═══════════ */

#panel-chat {
  height: calc(100vh - 132px);
  min-height: 420px;
}

.ch-layout {
  display: flex;
  gap: 14px;
  height: 100%;
}

.ch-list {
  width: 300px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--bg2, #fff);
  border: 1px solid var(--border, #e3e6ec);
  border-radius: 10px;
  overflow: hidden;
}

.ch-list-header {
  padding: 10px;
  border-bottom: 1px solid var(--border, #e3e6ec);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ch-search {
  flex: 1 1 100%;
  padding: 7px 10px;
  border: 1px solid var(--border2, #d7dbe3);
  border-radius: 6px;
  background: var(--bg3, #f4f6fa);
  color: var(--text, #1c2333);
  font-size: 12px;
}

.ch-search::placeholder { color: var(--text3, #8a93a6); }

.ch-btn {
  flex: 1 1 auto;
  padding: 7px 10px;
  border: 1px solid var(--border2, #d7dbe3);
  border-radius: 6px;
  background: var(--bg3, #f4f6fa);
  color: var(--text2, #4b5565);
  font-size: 11px;
  cursor: pointer;
  text-align: center;
}

.ch-btn:hover { border-color: var(--accent, #2f6fed); color: var(--accent, #2f6fed); }
.ch-btn.primary { background: var(--accent, #2f6fed); border-color: var(--accent, #2f6fed); color: #fff; }
.ch-btn.primary:hover { opacity: 0.9; color: #fff; }

.ch-conv-list {
  flex: 1;
  overflow-y: auto;
}

.ch-conv {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border2, #eef0f4);
}

.ch-conv:hover { background: var(--bg3, #f4f6fa); }
.ch-conv.active { background: color-mix(in srgb, var(--accent, #2f6fed) 10%, transparent); }

.ch-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent, #2f6fed);
  position: relative;
}

.ch-avatar .ch-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg2, #fff);
  background: #cbd2dc;
}

.ch-avatar .ch-dot.online { background: #2ecc71; }

.ch-conv-main {
  flex: 1;
  min-width: 0;
}

.ch-conv-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #1c2333);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-conv-preview {
  font-size: 11px;
  color: var(--text2, #4b5565);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.ch-conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.ch-conv-time { font-size: 10px; color: var(--text3, #8a93a6); }

.ch-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent, #2f6fed);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}

.ch-badge.show { display: inline-flex; }

/* ── Окно чата ── */
.ch-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg2, #fff);
  border: 1px solid var(--border, #e3e6ec);
  border-radius: 10px;
  overflow: hidden;
  min-width: 0;
}

.ch-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ch-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3, #8a93a6);
  font-size: 14px;
}

.ch-window-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #e3e6ec);
  flex-shrink: 0;
}

.ch-title { font-size: 14px; font-weight: 700; color: var(--text, #1c2333); }
.ch-subtitle { font-size: 11px; color: var(--text2, #4b5565); margin-top: 1px; }
.ch-subtitle .online { color: #2ecc71; }

.ch-window-actions { display: flex; gap: 6px; }

.ch-icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border2, #d7dbe3);
  border-radius: 6px;
  background: var(--bg3, #f4f6fa);
  color: var(--text2, #4b5565);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.ch-icon-btn:hover { border-color: var(--accent, #2f6fed); color: var(--accent, #2f6fed); }
.ch-icon-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ── Сообщения ── */
.ch-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg, #f7f8fb);
}

.ch-load-more {
  text-align: center;
  padding: 4px 0;
}

.ch-load-more button {
  border: none;
  background: none;
  color: var(--accent, #2f6fed);
  font-size: 11px;
  cursor: pointer;
}

.ch-msg { display: flex; max-width: 78%; }

.ch-msg.mine { align-self: flex-end; justify-content: flex-end; }
.ch-msg.theirs { align-self: flex-start; }

.ch-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg3, #f4f6fa);
  border: 1px solid var(--border2, #e3e6ec);
  min-width: 0;
}

.ch-msg.mine .ch-bubble {
  background: var(--accent, #2f6fed);
  border-color: var(--accent, #2f6fed);
  color: #fff;
}

.ch-sender {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent, #2f6fed);
  margin-bottom: 2px;
}

.ch-msg.mine .ch-sender { display: none; }

.ch-body {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.ch-body.deleted { font-style: italic; opacity: 0.6; }

.ch-quote {
  border-left: 3px solid var(--accent, #2f6fed);
  background: color-mix(in srgb, var(--accent, #2f6fed) 8%, transparent);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 6px;
  min-width: 0;
}

.ch-quote.deleted { border-left-color: var(--text3, #8a93a6); }

.ch-quote-sender {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent, #2f6fed);
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-quote-body {
  font-size: 12px;
  color: var(--text2, #4b5565);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-msg.mine .ch-quote {
  background: rgba(255, 255, 255, 0.12);
  border-left-color: rgba(255, 255, 255, 0.6);
}

.ch-msg.mine .ch-quote-sender,
.ch-msg.mine .ch-quote-body { color: #fff; }

.ch-msg.meta { align-self: center; max-width: 90%; }
.ch-msg.meta .ch-bubble {
  background: transparent;
  border: none;
  color: var(--text3, #8a93a6);
  font-size: 11px;
  padding: 2px 8px;
}

.ch-msg-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 10px;
  opacity: 0.75;
}

.ch-msg.mine .ch-msg-footer { color: #eef; }
.ch-msg.theirs .ch-msg-footer { color: var(--text3, #8a93a6); }

.ch-edited { font-style: italic; }

.ch-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}

.ch-actions button {
  border: none;
  background: none;
  color: inherit;
  opacity: 0.8;
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
}

.ch-actions button:hover { opacity: 1; text-decoration: underline; }

/* ── Реакции ── */
.ch-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }

.ch-reaction {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border2, #d7dbe3);
  background: var(--bg2, #fff);
  font-size: 12px;
  cursor: pointer;
}

.ch-msg.mine .ch-reaction { border-color: rgba(255,255,255,0.4); background: rgba(255,255,255,0.15); }

.ch-reaction.mine { border-color: var(--accent, #2f6fed); }

.ch-reaction .cnt { font-size: 11px; color: var(--text2, #4b5565); }
.ch-msg.mine .ch-reaction .cnt { color: #fff; }

/* ── Вложения ── */
.ch-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: min(300px, 100%);
  margin-top: 6px;
}

.ch-image-tile {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border2, #d7dbe3);
  border-radius: 7px;
  background: var(--bg2, #fff);
  cursor: pointer;
}

.ch-images-1 { grid-template-columns: minmax(0, 1fr); max-width: 300px; }
.ch-images-3 .ch-image-tile:first-child { grid-row: span 2; }
.ch-image-tile:hover { border-color: var(--accent, #2f6fed); }
.ch-image-preview { width: 100%; height: 100%; display: block; object-fit: cover; opacity: 0; transition: opacity .15s ease; }
.ch-image-preview.loaded { opacity: 1; }
.ch-image-preview.failed { opacity: .35; }
.ch-msg.mine .ch-image-tile { border-color: rgba(255,255,255,.45); }

.ch-attachments { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }

.ch-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg2, #fff);
  border: 1px solid var(--border2, #d7dbe3);
  font-size: 12px;
  cursor: pointer;
  color: var(--text, #1c2333);
  max-width: 260px;
}

.ch-msg.mine .ch-attachment { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.4); color: #fff; }

.ch-attachment:hover { border-color: var(--accent, #2f6fed); }
.ch-attachment .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-attachment .size { font-size: 10px; opacity: 0.7; flex-shrink: 0; }

/* ── typing ── */
.ch-typing {
  padding: 0 16px 4px;
  font-size: 11px;
  color: var(--text2, #4b5565);
  min-height: 16px;
}

/* ── Ввод ── */
.ch-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border, #e3e6ec);
  flex-shrink: 0;
}

.ch-file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
  flex-shrink: 0;
}

.ch-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg3, #f4f6fa);
  border: 1px solid var(--border2, #d7dbe3);
  font-size: 11px;
  max-width: 220px;
}

.ch-file-chip .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-file-chip .size { font-size: 10px; opacity: 0.7; flex-shrink: 0; }
.ch-file-chip .x { cursor: pointer; color: var(--text3, #8a93a6); font-weight: 700; flex-shrink: 0; }

.ch-input {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  resize: none;
  padding: 9px 12px;
  border: 1px solid var(--border2, #d7dbe3);
  border-radius: 8px;
  background: var(--bg3, #f7f8fb);
  color: var(--text, #1c2333);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.ch-input::placeholder { color: var(--text3, #8a93a6); }

.ch-input:focus { border-color: var(--accent, #2f6fed); }

.ch-send {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: var(--accent, #2f6fed);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ch-send svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.ch-send:hover { opacity: 0.9; }

.ch-editing-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--border, #e3e6ec);
  background: color-mix(in srgb, var(--accent, #2f6fed) 8%, transparent);
  font-size: 12px;
  flex-shrink: 0;
}

.ch-editing-bar b { color: var(--accent, #2f6fed); }
.ch-editing-bar .cancel { margin-left: auto; cursor: pointer; color: var(--text3, #8a93a6); text-decoration: underline; }

.ch-reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--border, #e3e6ec);
  background: color-mix(in srgb, var(--accent, #2f6fed) 8%, transparent);
  font-size: 12px;
  flex-shrink: 0;
}

.ch-reply-bar b { color: var(--accent, #2f6fed); flex-shrink: 0; }
.ch-reply-bar .reply-sender { font-weight: 700; color: var(--text, #1c2333); flex-shrink: 0; }
.ch-reply-bar .reply-excerpt { color: var(--text2, #4b5565); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ch-reply-bar .cancel { margin-left: auto; cursor: pointer; color: var(--text3, #8a93a6); text-decoration: underline; flex-shrink: 0; }

/* ── Список результатов поиска ── */
.ch-search-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ch-search-item {
  padding: 8px 10px;
  border: 1px solid var(--border2, #e3e6ec);
  border-radius: 8px;
  background: var(--bg2, #fff);
  cursor: pointer;
  font-size: 12px;
}

.ch-search-item:hover { border-color: var(--accent, #2f6fed); }
.ch-search-item .conv { font-weight: 700; color: var(--accent, #2f6fed); }
.ch-search-item .snippet { color: var(--text2, #4b5565); margin-top: 2px; }
.ch-search-empty { color: var(--text3, #8a93a6); text-align: center; padding: 20px; font-size: 12px; }

/* ── Модалки ── */
#ch-members-modal .modal-content {
  width: min(650px, calc(100vw - 24px));
  min-width: 0;
  max-width: calc(100vw - 24px);
  height: min(calc(100vh - 32px), 620px);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#ch-members-modal .modal-header,
#ch-members-modal .admin-modal-actions {
  flex-shrink: 0;
}

#ch-members-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

#ch-members-body .ch-member-list {
  max-height: min(42vh, 360px);
  overflow-y: auto;
  padding-right: 4px;
}

#ch-members-body .ch-member-row .nm {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#ch-members-body .ch-member-row .ch-btn,
#ch-members-body .ch-member-row select {
  flex: 0 0 auto;
}

#ch-members-body .ch-group-name-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  margin-top: 12px;
}

#ch-members-body .ch-group-name-row .auth-inp {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  margin-bottom: 0;
}

#ch-members-body .ch-group-name-row .ch-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

#ch-members-body .ch-group-name-view {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  min-height: 36px;
  flex-shrink: 0;
  line-height: 1.4;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border2, #e3e6ec);
  border-radius: 8px;
  background: var(--bg3, #f4f6fa);
}

#ch-members-body .ch-group-name-view .label {
  color: var(--text3, #8a93a6);
  font-size: 11px;
  flex: 0 0 auto;
}

#ch-members-body .ch-group-name-view .value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.ch-member-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }

.ch-modal-hint {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--border2, #e3e6ec);
  border-radius: 8px;
  background: var(--bg3, #f4f6fa);
  color: var(--text2, #5b6472);
  font-size: 12px;
  line-height: 1.45;
}

.ch-member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border2, #e3e6ec);
  border-radius: 8px;
  background: var(--bg3, #f4f6fa);
}

.ch-member-row .nm { flex: 1; font-size: 12px; font-weight: 600; }
.ch-member-row select {
  padding: 4px 6px;
  border: 1px solid var(--border2, #d7dbe3);
  border-radius: 6px;
  background: var(--bg2, #fff);
  font-size: 11px;
}

.ch-pick-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.ch-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--border2, #e3e6ec);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.ch-pick-row:hover { border-color: var(--accent, #2f6fed); }
.ch-pick-row.selected { border-color: var(--accent, #2f6fed); background: color-mix(in srgb, var(--accent, #2f6fed) 8%, transparent); }
.ch-pick-row .chk { width: 16px; height: 16px; }

.ch-react-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0;
  justify-content: center;
}

.ch-react-grid button {
  font-size: 22px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border2, #e3e6ec);
  border-radius: 10px;
  background: var(--bg3, #f4f6fa);
  cursor: pointer;
}

.ch-react-grid button:hover { border-color: var(--accent, #2f6fed); transform: scale(1.08); }

.ch-reaction-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--border2, #d7dbe3);
  background: var(--bg2, #fff);
  font-size: 11px;
  cursor: pointer;
}

/* ── Галерея ── */
.ch-gallery-open { overflow: hidden; }
.ch-gallery-modal {
  position: fixed;
  z-index: 1100;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 72px;
  background: rgba(8, 12, 22, .88);
}

.ch-gallery-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(92vw, 1200px);
  height: min(86vh, 900px);
  touch-action: pan-y;
}

.ch-gallery-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 12px 50px rgba(0,0,0,.4);
}

.ch-gallery-close,
.ch-gallery-nav {
  position: absolute;
  z-index: 1;
  border: 0;
  color: #fff;
  background: rgba(255,255,255,.12);
  cursor: pointer;
}

.ch-gallery-close {
  top: 16px;
  right: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
}

.ch-gallery-nav {
  top: 50%;
  width: 44px;
  height: 64px;
  margin-top: -32px;
  border-radius: 8px;
  font-size: 42px;
  line-height: 50px;
}

.ch-gallery-nav.prev { left: 18px; }
.ch-gallery-nav.next { right: 18px; }
.ch-gallery-close:hover,
.ch-gallery-nav:hover:not(:disabled) { background: rgba(255,255,255,.25); }
.ch-gallery-nav:disabled { opacity: .25; cursor: default; }
.ch-gallery-counter { position: absolute; bottom: 18px; color: #fff; font-size: 12px; opacity: .8; }

/* ── Tablet / Mobile ── */
@media (max-width: 860px) {
  .ch-list { width: 240px; min-width: 200px; }
  .ch-msg { max-width: 86%; }
}

@media (max-width: 640px) {
  #panel-chat { height: calc(100vh - 96px); }
  .ch-layout { flex-direction: column; }
  .ch-list { width: 100%; min-width: 0; max-height: 180px; }
  .ch-conv-list { max-height: 180px; }
  .ch-msg { max-width: 92%; }
  .ch-file-preview { padding: 6px 10px 0; }
  .ch-input-row { padding: 8px 10px; }
  .ch-gallery-modal { padding: 44px 12px; }
  .ch-gallery-stage { width: 100%; height: 82vh; }
  .ch-gallery-nav { width: 34px; height: 50px; font-size: 32px; line-height: 38px; }
  .ch-gallery-nav.prev { left: 6px; }
  .ch-gallery-nav.next { right: 6px; }
  .ch-gallery-close { top: 8px; right: 10px; }
  #ch-members-modal .modal-content { width: calc(100vw - 16px); max-width: calc(100vw - 16px); height: calc(100vh - 16px); max-height: calc(100vh - 16px); padding: 16px; }
  #ch-members-body .ch-group-name-row { flex-direction: column; }
  #ch-members-body .ch-group-name-row .auth-inp,
  #ch-members-body .ch-group-name-row .ch-btn { width: 100%; }
}
