/* =====================================================
   chat.css — модуль чата ProgFit PWA
   Подключить в index.html после style.css
   ===================================================== */

/* --- FAB-кнопка открытия чата --- */
.chat-fab {
  position: fixed;
  bottom: 80px; /* над нижней nav-bar */
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary, #6366f1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(99,102,241,0.45);
  z-index: 800;
  transition: transform .15s, box-shadow .15s;
}
.chat-fab:hover  { transform: scale(1.08); }
.chat-fab:active { transform: scale(0.94); }
.chat-fab svg { width: 24px; height: 24px; fill: #fff; }

.chat-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-page, #f5f5f5);
  padding: 0 3px;
}
.chat-fab-badge.hidden { display: none; }

/* --- Оверлей --- */
.chat-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 900;
  align-items: flex-end;
  justify-content: center;
}
.chat-overlay.open { display: flex; }

/* --- Панель --- */
.chat-panel {
  background: var(--bg-card, #fff);
  width: 100%;
  max-width: 500px;
  height: 92dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Шапка --- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border, #f0f0f0);
  flex-shrink: 0;
}
.chat-back-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  color: var(--text-secondary, #888);
  padding: 0 6px 0 0;
  line-height: 1;
  display: none;
}
.chat-back-btn.visible { display: block; }

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary, #1a1a1a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-sub {
  font-size: 12px;
  color: var(--text-secondary, #888);
  margin-top: 1px;
}
.chat-close-btn {
  background: var(--bg-secondary, #f5f5f5);
  border: none;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 16px;
  color: var(--text-secondary, #666);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-close-btn:hover { background: var(--border, #ebebeb); }

/* --- Список диалогов --- */
.chat-screen { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.chat-screen.active { display: flex; }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 12px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background .12s;
}
.conv-item:hover { background: var(--bg-secondary, #f8f8f8); }
.conv-item:active { background: var(--bg-secondary, #f0f0f0); }

.conv-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--primary, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}
.conv-avatar .unread-dot {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card, #fff);
  padding: 0 3px;
}

.conv-body { flex: 1; min-width: 0; }
.conv-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary, #1a1a1a);
}
.conv-preview {
  font-size: 13px;
  color: var(--text-secondary, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.conv-time {
  font-size: 11px;
  color: var(--text-secondary, #aaa);
  flex-shrink: 0;
}

/* --- Экран сообщений --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border, #e0e0e0); border-radius: 3px; }

/* Разделитель даты */
.msg-date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary, #aaa);
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-date-sep::before,
.msg-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border, #f0f0f0);
}

/* Пузыри */
.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 74%;
  gap: 2px;
}
.msg-row.out { align-self: flex-end; align-items: flex-end; }
.msg-row.in  { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.out .msg-bubble {
  background: var(--primary, #6366f1);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.in .msg-bubble {
  background: var(--bg-secondary, #f2f2f7);
  color: var(--text-primary, #1a1a1a);
  border-bottom-left-radius: 4px;
}

/* Файл-вложение */
.msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.07);
  text-decoration: none;
  font-size: 13px;
  max-width: 220px;
}
.msg-row.out .msg-file { background: rgba(255,255,255,0.22); color: #fff; }
.msg-row.in  .msg-file { color: var(--text-primary, #1a1a1a); }
.msg-file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Мета (время + статус) */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-secondary, #aaa);
  padding: 0 3px;
}
.msg-tick { font-size: 12px; }
.msg-tick.read { color: var(--primary, #6366f1); }

/* Индикатор печатает */
.typing-row {
  align-self: flex-start;
  display: none;
}
.typing-row.show { display: flex; }
.typing-bubble {
  background: var(--bg-secondary, #f2f2f7);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary, #aaa);
  animation: tBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .18s; }
.typing-dot:nth-child(3) { animation-delay: .36s; }
@keyframes tBounce {
  0%,60%,100% { transform: translateY(0); }
  30%         { transform: translateY(-5px); }
}

/* --- Шаблоны тренера --- */
.chat-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 14px 4px;
  border-top: 1px solid var(--border, #f0f0f0);
}
.chat-tpl {
  background: var(--bg-secondary, #f2f2f7);
  border: 1px solid var(--border, #e5e5ea);
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary, #555);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.chat-tpl:hover { background: var(--border, #e5e5ea); }

/* --- Превью файла --- */
.chat-file-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 0;
  font-size: 13px;
  color: var(--text-secondary, #555);
}
.chat-file-preview.show { display: flex; }
.chat-file-preview-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #ef4444;
  font-size: 18px;
  padding: 0;
  line-height: 1;
}

/* --- Поле ввода --- */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 16px;
  border-top: 1px solid var(--border, #f0f0f0);
  background: var(--bg-card, #fff);
  flex-shrink: 0;
}
.chat-attach {
  background: none;
  border: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-secondary, #888);
  flex-shrink: 0;
}
.chat-attach:hover { background: var(--bg-secondary, #f5f5f5); }
#chat-file-input { display: none; }
#chat-video-input { display: none; }
.chat-input-wrap {
  flex: 1;
  background: var(--bg-secondary, #f2f2f7);
  border-radius: 18px;
  padding: 8px 14px;
  min-height: 36px;
  max-height: 110px;
  overflow-y: auto;
}
#chat-textarea {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary, #1a1a1a);
  line-height: 1.45;
  min-height: 20px;
}
#chat-textarea::placeholder { color: var(--text-secondary, #aaa); }

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary, #6366f1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s, transform .1s;
}
.chat-send:hover  { background: #4f46e5; }
.chat-send:active { transform: scale(0.93); }
.chat-send:disabled { background: var(--border, #d1d5db); cursor: default; }
.chat-send svg { width: 17px; height: 17px; fill: #fff; }

/* --- Пустые состояния / лоадер --- */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 24px;
  color: var(--text-secondary, #aaa);
}
.chat-empty-icon { font-size: 44px; }
.chat-empty-text { font-size: 14px; text-align: center; line-height: 1.5; }
.chat-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  font-size: 13px;
  color: var(--text-secondary, #aaa);
}

/* Десктоп — открывать по центру */
@media (min-width: 520px) {
  .chat-overlay { align-items: center; }
  .chat-panel {
    border-radius: 20px;
    height: 85vh;
    max-height: 680px;
    margin: 0;
  }
  .chat-fab { bottom: 32px; right: 32px; }
}
