/* ============================================
   Chat — лента сообщений, пузыри, реакции
   ============================================ */

.message {
  display: flex;
  gap: 10px;
  max-width: 72%;
  margin-bottom: 4px;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.own {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-on-gradient);
  background: var(--aion-gradient);
  flex-shrink: 0;
  margin-top: 16px;
  overflow: hidden;
}
.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.message.own .message-avatar { display: none; }

.message-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-silver);
  margin-bottom: 3px;
  padding: 0 4px;
}
.message.own .message-sender { display: none; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  position: relative;
  max-width: 100%;
}

.message:not(.own) .message-bubble {
  background: var(--bg-surface);
  border-top-left-radius: 4px;
}

.message.own .message-bubble {
  background: var(--aion-gradient);
  color: var(--text-on-gradient);
  border-top-right-radius: 4px;
  box-shadow: var(--shadow-glow-strong);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}
.message.own .message-time {
  text-align: right;
}

/* Дата-разделитель */
.date-separator {
  display: flex;
  justify-content: center;
  margin: 16px 0 12px;
}
.date-separator span {
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: var(--radius-full);
}

/* Непрочитанные */
.unread-separator {
  display: flex;
  justify-content: center;
  margin: 12px 0;
}
.unread-separator span {
  background: var(--aion-gradient);
  color: var(--text-on-gradient);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: var(--radius-full);
}

/* Реакции */
.message-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  background: var(--reaction-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.reaction-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.reaction-chip.active {
  background: var(--reaction-active-bg);
  border-color: var(--accent-solid);
  color: var(--text-primary);
}

/* Reply-блок внутри сообщения */
.reply-block {
  background: rgba(192, 192, 192, 0.06);
  border-left: 3px solid var(--accent-silver);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}
.reply-block b {
  color: var(--accent-silver);
  display: block;
  font-size: 12px;
  margin-bottom: 2px;
}

/* Вложение — изображение */
.message-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 4px;
  display: block;
  object-fit: cover;
}

/* Вложение — файл */
.message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(192, 192, 192, 0.06);
  border-radius: var(--radius-md);
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.15s;
}
.message-file:hover { background: rgba(192, 192, 192, 0.1); }

.file-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.file-info {
  min-width: 0;
}
.file-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-size {
  font-size: 11px;
  color: var(--text-muted);
}

/* Аудио-сообщение */
.message-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
}
.audio-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--aion-gradient);
  color: var(--text-on-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: var(--shadow-glow-strong);
}
.audio-waveform-mini {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  flex: 1;
  min-width: 60px;
}
.audio-waveform-mini bar {
  flex: 1;
  height: 60%;
  background: var(--accent-solid);
  border-radius: 2px;
  opacity: 0.6;
}
.audio-duration {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}

/* Прогресс загрузки */
.upload-progress {
  height: 3px;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}
.upload-progress > div {
  height: 100%;
  background: var(--aion-gradient);
  transition: width 0.3s;
}

/* Статус отправки */
.message.sending { opacity: 0.6; }
.message.error .message-bubble::after {
  content: ' ❌';
  color: var(--status-error);
}

/* Ссылки и упоминания в тексте */
.text-entity-link,
.text-entity-mention,
.text-entity-hashtag {
  color: var(--accent-silver);
  text-decoration: underline;
  text-decoration-color: rgba(192, 192, 192, 0.3);
  text-underline-offset: 2px;
  cursor: pointer;
}
.message.own .text-entity-link,
.message.own .text-entity-mention,
.message.own .text-entity-hashtag {
  color: #fff;
  text-decoration-color: rgba(255, 255, 255, 0.4);
}

.text-entity-code {
  font-family: var(--font-mono);
  background: rgba(192, 192, 192, 0.12);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.text-entity-pre {
  font-family: var(--font-mono);
  background: rgba(192, 192, 192, 0.08);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  margin: 4px 0;
  font-size: 13px;
}

.spoiler {
  background: var(--text-muted);
  color: transparent;
  cursor: pointer;
  border-radius: 3px;
  padding: 0 3px;
  transition: all 0.2s;
}
.spoiler.revealed {
  background: transparent;
  color: inherit;
}

/* Посты канала — без аватара и подписи */
.channel-post .message-avatar { display: none; }
.channel-post .message-sender { display: none; }
.channel-post .message { max-width: 100%; }
.channel-post .message-bubble {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
}

/* ============================================
   Строка чата в левой панели (chat-list)
   ============================================ */

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.chat-item:hover {
  background: var(--bg-hover);
}
.chat-item.active {
  background: var(--bg-active);
}
.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--aion-gradient);
}

.chat-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.chat-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-last {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-row .badge {
  flex-shrink: 0;
}

/* Бот-бейдж */
.badge-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--accent-silver);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
/* ============================================
   Сообщения бота — кнопки и карточки метрик
   ============================================ */

.bot-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.bot-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  background: var(--aion-gradient);
  color: var(--text-on-gradient);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-glow-strong);
}
.bot-action:hover {
  background: var(--aion-gradient-hover);
  transform: translateY(-1px);
}
.bot-action.secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-line2);
  box-shadow: none;
}
.bot-action.secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  transform: none;
}

.metric-card {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}
.metric-value.positive { color: var(--status-online); }
.metric-value.negative { color: var(--accent-silver); }

.metric-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ============================================
   Посты канала — большие карточки без аватара
   ============================================ */

.message.channel-post {
  display: block;
  max-width: 100%;
  width: 100%;
  margin-bottom: 8px;
}

.message.channel-post .message-avatar,
.message.channel-post .message-sender {
  display: none;
}

.message.channel-post .message-body {
  width: 100%;
  max-width: 100%;
}

.post-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s;
}
.post-card:hover {
  border-color: var(--border-medium);
}

.post-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin: 0;
}

.post-text {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  flex-wrap: wrap;
  line-height: 1.3;
}

.post-meta-tag {
  color: var(--accent-silver);
  font-weight: 600;
}

.post-actions {
  display: flex;
  gap: 6px;
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.post-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--bg-hover);
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.post-action:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}
.post-action.active {
  background: var(--aion-gradient);
  color: var(--text-on-gradient);
}
.post-action .icon {
  width: 12px;
  height: 12px;
}

/* ============================================
   Типы чатов — мелкие отличия в шапке
   ============================================ */

.right-panel[data-chat-type="channel"] .chat-subtitle {
  color: var(--accent-silver);
}

.right-panel[data-chat-type="bot"] .chat-subtitle {
  color: var(--status-online);
}

.right-panel[data-chat-type="group"] .chat-subtitle {
  color: var(--text-secondary);
}

/* ============================================
   Универсальный рендер сообщений из API
   ============================================ */

.message-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 6px;
    display: block;
    object-fit: cover;
    transition: opacity 0.2s;
}

/* Пустые состояния внутри ленты и панелей */
.messages-container .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 240px;
    text-align: center;
    color: var(--text-muted);
}

.right-tab-content .empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
/* ============================================
   Индикатор статуса отправки (часики / ошибка)
   ============================================ */

.msg-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 4px;
    vertical-align: -2px;
    flex-shrink: 0;
    opacity: 0.6;
}

    .msg-status .icon {
        width: 12px;
        height: 12px;
        stroke-width: 2.4;
    }

/* В своих сообщениях (на градиенте) — светлее и заметнее */
.message.own .msg-status {
    opacity: 0.85;
    color: rgba(255, 255, 255, 0.9);
}

    .message.own .msg-status .icon {
        stroke: rgba(255, 255, 255, 0.9);
    }

/* Часики — крутятся, пока сообщение отправляется */
.msg-status.sending .icon {
    animation: msgSpin 1.2s linear infinite;
    transform-origin: center;
}

@keyframes msgSpin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Ошибка — красная, заметная */
.msg-status.error {
    opacity: 1;
}

    .msg-status.error .icon {
        stroke: var(--status-error);
    }

.message.own .msg-status.error .icon {
    stroke: var(--status-error);
}

/* Посты канала — выравнивание чуть иное */
.post-text .msg-status {
    margin-left: 6px;
    vertical-align: middle;
}
/* ============================================
   Reply-панель (обновлённая)
   ============================================ */

.reply-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-line);
    border-left: 3px solid var(--accent-solid);
}

.reply-bar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.reply-bar-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reply-bar .reply-user {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-silver);
    display: block;
}

.reply-bar .reply-text {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Превью вложения (обновлённое)
   ============================================ */

.attachment-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-line);
}

    .attachment-preview .attach-icon {
        width: 40px;
        height: 40px;
        border-radius: var(--radius-md);
        background: var(--bg-hover);
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--accent-silver);
        flex-shrink: 0;
    }

        .attachment-preview .attach-icon .icon {
            width: 20px;
            height: 20px;
        }

    .attachment-preview .attach-body {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .attachment-preview .attach-name {
        font-size: 13px;
        font-weight: 600;
        color: var(--text-primary);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .attachment-preview .attach-size {
        font-size: 11px;
        color: var(--text-muted);
    }

    .attachment-preview .attach-caption {
        background: transparent;
        border: none;
        color: var(--text-primary);
        font-size: 12px;
        outline: none;
        width: 100%;
        margin-top: 2px;
        padding: 0;
    }

        .attachment-preview .attach-caption::placeholder {
            color: var(--text-muted);
        }

    .attachment-preview .upload-progress {
        height: 3px;
        background: var(--bg-hover);
        border-radius: var(--radius-full);
        overflow: hidden;
        margin-top: 4px;
    }

        .attachment-preview .upload-progress > div {
            height: 100%;
            background: var(--aion-gradient);
            transition: width 0.3s;
        }
/* ============================================
   Галочки статуса (отправлено / доставлено / прочитано)
   ============================================ */

.msg-status.sent .icon,
.msg-status.delivered .icon {
    stroke: rgba(255, 255, 255, 0.65);
}

.msg-status.read .icon {
    stroke: #FFFFFF;
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.4));
}

/* На обычных (не своих) сообщениях не показываем — они только для своих */
.message:not(.own) .msg-status {
    display: none;
}

/* Индикатор «печатает…» — пульсация */
.typing-bar {
    padding: 6px 20px;
    font-size: 12px;
    font-style: italic;
    color: var(--accent-silver);
    background: var(--bg-app);
    animation: typingPulse 1.4s ease-in-out infinite;
}

@keyframes typingPulse {
    0%, 100% {
        opacity: 0.7;
    }

    50% {
        opacity: 1;
    }
}