/* ============================================================
   МЕССЕНДЖЕР (Стиль Telegram)
   ============================================================ */

[hidden] {
  display: none !important;
}

.tg-body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tg-body .footer {
  margin-top: 0;
  padding: 12px;
  flex-shrink: 0;
  border-top: none;
}

.tg-layout {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: calc(var(--nav-h) + 20px) 20px 20px;
  gap: 20px;
  min-height: 0;
  overflow: hidden;
}

/* ---------- Сайдбар ---------- */
.tg-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: rgba(20, 12, 35, 0.6);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(10px);
  min-height: 0;
}

.tg-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.tg-search {
  flex: 1;
  background: rgba(10, 7, 16, 0.6);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.tg-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
}

.tg-new-chat {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.15);
  color: var(--purple-bright);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.tg-new-chat:hover {
  background: rgba(139, 92, 246, 0.3);
}

.tg-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.tg-chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  color: var(--text);
}
.tg-chat-item:hover,
.tg-chat-item.active {
  background: rgba(139, 92, 246, 0.15);
}
.tg-chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  overflow: hidden;
}
.tg-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tg-chat-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tg-chat-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  margin-bottom: 2px;
}
.tg-chat-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tg-chat-name .badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(139, 92, 246, 0.2);
  color: var(--purple-bright);
}
.tg-chat-last-msg {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-chat-time {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: 8px;
}

/* ---------- Окно чата ---------- */
.tg-chat-window {
  flex: 1;
  background: rgba(20, 12, 35, 0.4);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(10px);
  position: relative;
  min-height: 0;
}

.tg-empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 16px;
  height: 100%;
}
.tg-empty-icon {
  font-size: 48px;
  background: rgba(139, 92, 246, 0.1);
  padding: 20px;
  border-radius: 50%;
  border: 1px dashed var(--border);
}

.tg-active-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  min-height: 0;
}

.tg-chat-header {
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  background: rgba(20, 12, 35, 0.8);
  flex-shrink: 0;
}
.tg-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}
.tg-chat-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.tg-chat-title {
  font-size: 16px;
  font-weight: 600;
  display: block;
}
.tg-chat-status {
  font-size: 13px;
  color: var(--purple-bright);
}
.tg-settings-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: background 0.2s;
}
.tg-settings-btn:hover {
  background: rgba(139, 92, 246, 0.15);
  color: var(--text);
}

.tg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.tg-messages::-webkit-scrollbar {
  width: 6px;
}
.tg-messages::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.3);
  border-radius: 10px;
}

/* Пузыри сообщений */
.tg-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}
.tg-msg-row.mine {
  align-self: flex-end;
  align-items: flex-end;
}
.tg-msg-row.other {
  align-self: flex-start;
  align-items: flex-start;
}
.tg-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
}
.tg-msg-bubble img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 8px;
  display: block;
}
.tg-msg-row.mine .tg-msg-bubble {
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.tg-msg-row.other .tg-msg-bubble {
  background: rgba(28, 17, 48, 0.8);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.tg-msg-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  margin-left: 4px;
}
.tg-msg-row.mine .tg-msg-time {
  color: rgba(255, 255, 255, 0.7);
}

/* Карточки постов (Канал) — переименованные классы */
.tg-channel-post {
  background: rgba(28, 17, 48, 0.6);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 20px;
  max-width: 90%;
  align-self: flex-start;
  margin-bottom: 8px;
}
.tg-post-head {
  font-size: 13px;
  color: var(--purple-bright);
  font-weight: 600;
  margin-bottom: 6px;
}
.tg-post-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  margin-bottom: 12px;
}
.tg-post-image {
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}
.tg-post-image img {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
  display: block;
}
.tg-post-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid rgba(167, 139, 250, 0.1);
  padding-top: 12px;
}
.tg-post-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: color 0.2s;
  padding: 4px 8px;
  border-radius: 100px;
}
.tg-post-btn:hover {
  color: var(--text);
  background: rgba(139, 92, 246, 0.1);
}
.tg-post-btn.active {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
}
.tg-post-btn.dislike.active {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
}

/* Поле ввода */
.tg-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: rgba(20, 12, 35, 0.8);
  flex-shrink: 0;
}
.tg-input-form {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(10, 7, 16, 0.6);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 6px 4px 16px;
  transition: border-color 0.3s ease;
}
.tg-input-form:focus-within {
  border-color: rgba(167, 139, 250, 0.5);
}
.tg-input-form input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 10px 0;
}
.tg-attach-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}
.tg-attach-btn:hover {
  color: var(--purple-bright);
}
.tg-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--purple-bright);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 0.2s,
    background 0.2s;
  flex-shrink: 0;
}
.tg-send-btn:hover {
  transform: scale(1.05);
  background: #a855f7;
}

.tg-subscriber-notice,
.tg-block-notice {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 12px;
  background: rgba(10, 7, 16, 0.6);
  border-radius: 12px;
  border: 1px dashed var(--border);
}

/* ---------- Модалки ---------- */
.tg-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.tg-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 3, 12, 0.8);
  backdrop-filter: blur(5px);
}
.tg-modal-window {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: riseIn 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
  max-height: 85vh;
}
.tg-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tg-modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}
.tg-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}
.tg-modal-close:hover {
  color: var(--text);
}

.tg-modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tg-tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}
.tg-tab.active {
  color: var(--purple-bright);
  border-bottom-color: var(--purple-bright);
}

.tg-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-height: 0;
}
.tg-avatar-upload {
  display: flex;
  justify-content: center;
  cursor: pointer;
}
.tg-avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.1);
  border: 2px dashed rgba(167, 139, 250, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--purple-bright);
  overflow: hidden;
  transition: all 0.2s;
}
.tg-avatar-upload:hover .tg-avatar-preview {
  border-color: var(--purple-bright);
  background: rgba(139, 92, 246, 0.2);
}
.tg-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tg-modal-input {
  width: 100%;
  background: rgba(10, 7, 16, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.tg-modal-input:focus {
  border-color: var(--purple-bright);
}
.tg-modal-search-wrap {
  position: relative;
}
.tg-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 10;
}
.tg-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.tg-search-item:hover {
  background: rgba(139, 92, 246, 0.15);
}
.tg-search-item .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--purple-bright);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.tg-search-item .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tg-search-item .info {
  display: flex;
  flex-direction: column;
}
.tg-search-item .name {
  font-size: 14px;
  font-weight: 600;
}
.tg-search-item .id {
  font-size: 12px;
  color: var(--muted);
}

.tg-selected-members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tg-member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 100px;
  font-size: 13px;
  color: var(--text);
}
.tg-member-chip .chip-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--purple-bright);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  overflow: hidden;
}
.tg-member-chip .chip-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tg-member-chip .remove-member {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.tg-member-chip .remove-member:hover {
  color: #f87171;
}

.tg-modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}
.tg-btn-primary {
  background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
  color: #fff;
  border: none;
  border-radius: 100px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}
.tg-btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.tg-btn-danger {
  width: 100%;
  background: rgba(248, 113, 113, 0.1);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
}
.tg-btn-danger:hover {
  background: rgba(248, 113, 113, 0.2);
  border-color: #f87171;
}

/* Кнопка "Добавить участника" */
.open-add-member-btn {
  align-self: flex-start;
  padding: 8px 16px;
  font-size: 13px;
}

/* Список участников в настройках */
.tg-settings-members-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tg-settings-member {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(10, 7, 16, 0.4);
  border-radius: 12px;
}
.tg-settings-member .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--purple-bright);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.tg-settings-member .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tg-settings-member .info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.tg-settings-member .name {
  font-size: 14px;
  font-weight: 600;
}
.tg-settings-member .role {
  font-size: 11px;
  color: var(--purple-bright);
}
.tg-settings-member .menu-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tg-settings-member .menu-btn:hover {
  background: rgba(139, 92, 246, 0.2);
  color: var(--text);
}

/* Выпадающее меню (3 точки) */
.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 100;
  min-width: 180px;
  overflow: hidden;
}
.dropdown-menu button {
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dropdown-menu button:hover {
  background: rgba(139, 92, 246, 0.15);
}
.dropdown-menu button.danger {
  color: #f87171;
}
.dropdown-menu button.danger:hover {
  background: rgba(248, 113, 113, 0.15);
}

/* Модалка комментариев */
.tg-comments-window {
  max-width: 500px;
  height: 80vh;
}
.tg-comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tg-comment-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tg-comment-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tg-comment-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--purple-bright);
}
.tg-comment-time {
  font-size: 11px;
  color: var(--muted);
}
.tg-comment-text {
  font-size: 14px;
  color: var(--text);
  background: rgba(139, 92, 246, 0.1);
  padding: 8px 12px;
  border-radius: 0 12px 12px 12px;
  display: inline-block;
  word-break: break-word;
}
.tg-comments-input {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: rgba(10, 7, 16, 0.8);
}

/* ---------- Адаптив ---------- */
@media (max-width: 768px) {
  .tg-layout {
    padding: calc(var(--nav-h) + 10px) 10px 10px;
    gap: 0;
  }
  .tg-sidebar {
    width: 100%;
    border-radius: 16px;
  }
  .tg-chat-window {
    display: none;
    border-radius: 16px;
  }
  .tg-layout.chat-open .tg-sidebar {
    display: none;
  }
  .tg-layout.chat-open .tg-chat-window {
    display: flex;
  }
  .tg-back-btn {
    display: block;
  }
  .tg-channel-post {
    max-width: 100%;
  }
}
