/* ===== СТРАНИЦА ЧАТА — LAYOUT ===== */

#page-chat.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.content:has(#page-chat.active) {
  overflow: hidden;
}

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  border: 0.5px solid var(--color-border-tertiary);
  background: var(--color-background-primary);
}

/* ===== ЛЕВАЯ ПАНЕЛЬ — СПИСОК ДИАЛОГОВ ===== */

.chat-sidebar {
  width: 272px;
  min-width: 272px;
  display: flex;
  flex-direction: column;
  background: var(--color-background-secondary);
  border-right: 0.5px solid var(--color-border-tertiary);
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
  border-bottom: 0.5px solid var(--color-border-tertiary);
  flex-shrink: 0;
}

.chat-new-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 5px;
  border-radius: var(--border-radius-sm);
  font-size: 15px;
  display: flex;
  align-items: center;
  transition: background 0.12s, color 0.12s;
}
.chat-new-btn:hover {
  background: var(--color-background-tertiary);
  color: var(--color-primary);
}

.chat-search-wrap {
  padding: 10px 12px;
  flex-shrink: 0;
}

.chat-search-input {
  width: 100%;
  padding: 7px 12px;
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: 20px;
  font-size: 12px;
  background: var(--color-background-primary);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
}
.chat-search-input:focus { border-color: var(--color-primary); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 0; }

/* Элемент разговора */
.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  cursor: pointer;
  border-radius: 10px;
  margin: 1px 6px;
  transition: background 0.12s;
  position: relative;
}
.chat-conv-item:hover  { background: rgba(0,0,0,0.04); }
.chat-conv-item.active { background: rgba(37,99,235,0.09); }

/* Аватар */
.chat-conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  user-select: none;
}

.chat-online-dot {
  width: 10px;
  height: 10px;
  background: #22c55e;
  border: 2px solid var(--color-background-secondary);
  border-radius: 50%;
  position: absolute;
  bottom: 0;
  right: 0;
}

.chat-conv-info { flex: 1; min-width: 0; }

.chat-conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 3px;
}

.chat-conv-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conv-time {
  font-size: 10px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-conv-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.chat-conv-last {
  font-size: 11px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-unread-badge {
  background: var(--color-primary);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
}

/* ===== ПРАВАЯ ЧАСТЬ ===== */

.chat-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  user-select: none;
  gap: 0;
}

.chat-active-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ===== ЗАГОЛОВОК ЧАТА ===== */

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 0.5px solid var(--color-border-tertiary);
  background: var(--color-background-primary);
  flex-shrink: 0;
}

.chat-header-avatar-wrap { position: relative; flex-shrink: 0; }

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  user-select: none;
}

.chat-header-info { flex: 1; }

.chat-header-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.chat-header-sub {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 1px;
}
.chat-header-sub.online { color: #22c55e; }

.chat-header-actions { display: flex; gap: 4px; }

/* ===== СПИСОК СООБЩЕНИЙ ===== */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #f0f4f8;
  min-height: 0;
}

/* Разделитель даты */
.chat-date-sep {
  align-self: center;
  font-size: 11px;
  color: var(--color-text-secondary);
  background: rgba(255,255,255,0.8);
  padding: 3px 12px;
  border-radius: 10px;
  margin: 8px 0;
  backdrop-filter: blur(4px);
}

/* Системное сообщение */
.chat-msg-system {
  align-self: center;
  font-size: 11px;
  color: var(--color-text-secondary);
  background: rgba(255,255,255,0.8);
  padding: 3px 12px;
  border-radius: 10px;
  margin: 4px 0;
}

/* Обёртка сообщения */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 70%;
  animation: chatMsgIn 0.18s ease;
}

@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.outgoing {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg.incoming { align-self: flex-start; }

/* Аватар в сообщении */
.chat-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-bottom: 18px;
  user-select: none;
}

.chat-msg-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.chat-msg.outgoing .chat-msg-body { align-items: flex-end; }
.chat-msg.incoming .chat-msg-body { align-items: flex-start; }

/* Имя отправителя (только в группе) */
.chat-msg-sender-name {
  font-size: 10px;
  font-weight: 600;
  padding: 0 6px;
  margin-bottom: 1px;
}

/* Пузырь текстового сообщения */
.chat-bubble {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  max-width: 100%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.chat-msg.outgoing .chat-bubble {
  background: var(--color-primary);
  color: #fff;
  border-radius: 16px 4px 16px 16px;
}

.chat-msg.incoming .chat-bubble {
  background: #fff;
  color: var(--color-text-primary);
  border-radius: 4px 16px 16px 16px;
  border: 0.5px solid var(--color-border-tertiary);
}

/* Файловая карточка */
.chat-bubble-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px !important;
  min-width: 190px;
  cursor: pointer;
  transition: opacity 0.12s;
}
.chat-bubble-file:hover { opacity: 0.88; }

.chat-file-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.22);
}
.chat-msg.incoming .chat-file-icon {
  background: var(--color-background-secondary);
  color: var(--color-primary);
}
.chat-file-icon.file-image  { background: rgba(255,255,255,0.22); }
.chat-msg.incoming .chat-file-icon.file-image { background: rgba(22,163,74,0.1); color: var(--color-success); }
.chat-file-icon.file-pdf    { background: rgba(255,255,255,0.22); }
.chat-msg.incoming .chat-file-icon.file-pdf   { background: rgba(220,38,38,0.1);  color: var(--color-danger); }

.chat-file-info { flex: 1; min-width: 0; }

.chat-file-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-file-size { font-size: 10px; opacity: 0.7; margin-top: 2px; }

/* Карточка локации */
.chat-bubble-location {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px !important;
  min-width: 210px;
  cursor: pointer;
  transition: opacity 0.12s;
}
.chat-bubble-location:hover { opacity: 0.88; }

.chat-location-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.22);
}
.chat-msg.incoming .chat-location-icon {
  background: rgba(220,38,38,0.1);
  color: var(--color-danger);
}

.chat-location-address { font-size: 12px; font-weight: 500; }
.chat-location-coords  { font-size: 10px; opacity: 0.65; margin-top: 2px; font-family: monospace; }

/* Метка времени */
.chat-msg-time {
  font-size: 10px;
  color: var(--color-text-secondary);
  padding: 0 4px;
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.chat-read-check { color: var(--color-primary); }

/* ===== ВВОД СООБЩЕНИЯ ===== */

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-top: 0.5px solid var(--color-border-tertiary);
  background: var(--color-background-primary);
  flex-shrink: 0;
}

.chat-tool-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 7px;
  border-radius: 50%;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.chat-tool-btn:hover {
  background: var(--color-background-tertiary);
  color: var(--color-primary);
}

.chat-input {
  flex: 1;
  padding: 8px 14px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: 20px;
  font-size: 13px;
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.chat-input:focus {
  border-color: var(--color-primary);
  background: var(--color-background-primary);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.chat-send-btn:hover   { background: var(--color-primary-dark); transform: scale(1.06); }
.chat-send-btn:active  { transform: scale(0.94); }
.chat-send-btn:disabled{ background: var(--color-border-secondary); cursor: not-allowed; transform: none; }

/* ===== BADGE HA НАВ-ИКОНКЕ ЧАТА ===== */

.nav-chat-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 15px;
  height: 15px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  border: 1.5px solid var(--sidebar-bg);
}
