/* ═══════════════════════════════════════════════════════════
   Snake School Chat — два блока-карточки
   ═══════════════════════════════════════════════════════════ */

/* ── Panel ── */
#panel-chat { display: none !important; }
#panel-chat.active {
  display: flex !important;
  flex-direction: column;
  /* Уменьшаем реальную высоту через отступы: карточки не на весь экран */
  height: calc(100vh - 46px);
  overflow: hidden;
  padding: 20px 20px 40px !important;
  background: #e8f0e8;
  gap: 0;
  box-sizing: border-box;
}

/* Карточки заметно ниже экрана, с воздухом сверху и снизу */
#panel-chat.active .chat-layout {
  max-height: 74vh;
  height: 100%;
}
.content:has(#panel-chat.active) { padding:0 !important; overflow:hidden !important; }

/* ── Главный layout: два блока рядом ── */
.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
  gap: 12px;
}

/* ════════════════════════════════════════
   ЛЕВЫЙ БЛОК — список чатов (карточка)
   ════════════════════════════════════════ */
.chat-rooms-sidebar {
  width: 300px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,.08);
  overflow: hidden;
}

.chat-rooms-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  font-size: 20px;
  font-weight: 800;
  color: #111827;
  flex-shrink: 0;
}
.chat-rooms-title span { font-size:13px; color:#9ca3af; font-weight:400; }

/* Поиск */
.chat-search-wrap { padding: 0 14px 10px; flex-shrink: 0; }
.chat-search-row { position: relative; }
.chat-search-input {
  width: 100%;
  box-sizing: border-box;
  background: #f3f4f6;
  border: none;
  border-radius: 22px;
  padding: 9px 14px 9px 38px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  color: #111827;
}
.chat-search-input:focus { background: #f0fdf4; }
.chat-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
  z-index: 1;
}

/* Фильтры */
.chat-filters {
  display: flex; gap: 6px;
  padding: 0 14px 10px;
  flex-shrink: 0;
}
.chat-filter-btn {
  padding: 5px 16px;
  border-radius: 20px;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.chat-filter-btn.active { background:#16a34a; border-color:#16a34a; color:#fff; }
.chat-filter-btn:hover:not(.active) { background:#f0fdf4; border-color:#86efac; color:#16a34a; }

/* Список */
#chat-rooms-list {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #e5e7eb transparent;
}
.chat-room-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid #f9fafb;
}
.chat-room-item:hover { background: #f9fafb; }
.chat-room-item.active { background: #f0fdf4; border-left: 3px solid #16a34a; padding-left: 13px; }

.chat-room-avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: #fff;
  flex-shrink: 0; position: relative; overflow: hidden;
}
.chat-room-avatar img { width:100%;height:100%;object-fit:cover;border-radius:50%;display:block; }
.chat-online-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 12px; height: 12px;
  background: #16a34a; border: 2.5px solid #fff; border-radius: 50%;
  overflow: visible;
}

.chat-room-info { flex:1; min-width:0; }
.chat-room-name {
  font-size: 14px; font-weight: 700; color: #111827;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px;
}
.chat-room-last {
  font-size: 12px; color: #9ca3af;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-room-meta { display:flex; flex-direction:column; align-items:flex-end; gap:4px; flex-shrink:0; }
.chat-room-time { font-size: 11px; color: #9ca3af; }
.chat-unread-badge {
  background: #16a34a; color: #fff;
  font-size: 11px; font-weight: 800;
  line-height: 1;
  min-width: 20px; height: 20px;
  border-radius: 10px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}

/* ════════════════════════════════════════
   ПРАВЫЙ БЛОК — диалог (карточка)
   ════════════════════════════════════════ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,.08);
  overflow: hidden;
}

/* Шапка */
#chat-header {
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
}

/* Сообщения */
#chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 3px;
  scrollbar-width: thin; scrollbar-color: #ccc transparent;
  background: #f9fbf9;
}

.chat-empty-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; color: #9ca3af; padding: 40px 20px;
}

/* Строки сообщений */
.chat-msg-row {
  display: flex; align-items: flex-end; gap: 6px;
  animation: msgIn .15s ease; max-width: 75%;
}
@keyframes msgIn { from { opacity:0; transform:translateY(6px); } }
.chat-msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-row.theirs { align-self: flex-start; }

.chat-msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #fff;
  flex-shrink: 0; overflow: hidden;
}
.chat-msg-avatar img { width:100%;height:100%;object-fit:cover;border-radius:50%; }
.chat-msg-avatar-placeholder { width: 30px; flex-shrink: 0; }

.chat-msg-bubble { display:flex; flex-direction:column; max-width:100%; }
.chat-msg-name { font-size:11px; font-weight:700; color:#16a34a; margin-bottom:2px; padding-left:4px; }

.chat-msg-body {
  background: #fff;
  border-radius: 16px 16px 16px 4px;
  padding: 9px 13px;
  font-size: 14px; color: #111827; line-height: 1.5; word-break: break-word;
  box-shadow: 0 1px 3px rgba(0,0,0,.09);
  border: 1px solid #f0f0f0;
}
.mine .chat-msg-body {
  background: #16a34a; color: #fff;
  border-radius: 16px 16px 4px 16px;
  border-color: #16a34a;
  box-shadow: 0 1px 3px rgba(22,163,74,.25);
}

.chat-msg-time {
  font-size: 10px; color: rgba(0,0,0,.35);
  margin-top: 2px; padding: 0 4px;
  display: flex; align-items: center; gap: 3px;
}
.mine .chat-msg-time { color:rgba(255,255,255,.7); justify-content:flex-end; }
.chat-read-icon { width:15px; height:15px; }

/* Медиа */
.chat-img {
  max-width: 240px; max-height: 200px;
  border-radius: 10px; object-fit: cover; cursor: zoom-in; display: block;
}
.chat-file-link {
  display:inline-flex; align-items:center; gap:6px;
  color:#16a34a; text-decoration:none; font-size:13px; font-weight:600;
}
.mine .chat-file-link { color:#bbf7d0; }

/* Карточки */
.chat-card {
  border-radius: 12px; padding: 10px 13px;
  background: #f0fdf4; border: 1.5px solid #bbf7d0;
  cursor: pointer; transition: background .12s; min-width: 180px;
}
.chat-card:hover { background: #dcfce7; }
.chat-card-title { font-size:12px; font-weight:700; color:#166534; margin-bottom:4px; }
.chat-card-body  { font-size:13px; color:#111827; }
.mine .chat-card { background:rgba(255,255,255,.2); border-color:rgba(255,255,255,.35); }
.mine .chat-card-title { color:#bbf7d0; }
.mine .chat-card-body  { color:#fff; }

/* Typing */
#chat-typing-indicator {
  font-size:12px; color:#6b7280; font-style:italic;
  padding:4px 20px; min-height:18px;
  opacity:0; transition:opacity .25s;
  background:#f9fbf9; flex-shrink:0;
}

/* Поле ввода */
.chat-input-area {
  border-top: 1px solid #f0f0f0; padding: 10px 14px;
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; flex-shrink: 0;
}
#chat-text-input {
  flex:1; min-height:42px; max-height:120px; resize:none;
  border:1.5px solid #e5e7eb; border-radius:22px;
  padding:10px 16px; font-size:14px; font-family:inherit;
  outline:none; transition:border-color .15s; overflow-y:auto; background:#f9fafb;
}
#chat-text-input:focus { border-color:#86efac; background:#fff; }

.chat-input-btn {
  width:42px; height:42px; border-radius:50%; border:none;
  cursor:pointer; display:flex; align-items:center; justify-content:center;
  transition:background .15s, transform .1s; flex-shrink:0;
}
.chat-input-btn:active { transform:scale(.9); }
#chat-send-btn  { background:#16a34a; color:#fff; }
#chat-send-btn:hover { background:#15803d; }
#chat-file-btn  { background:#f3f4f6; color:#6b7280; }
#chat-file-btn:hover { background:#e5e7eb; }

/* Нет активного чата */
#chat-no-active {
  flex:1; display:flex; flex-direction:column;
  align-items:center; justify-content:center;
  background:#f9fbf9; color:#9ca3af; text-align:center;
  border-radius: 0 0 16px 16px;
}

/* Nav badge */
.chat-nav-badge {
  background: #16a34a;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  flex-shrink: 0;
}

/* Lightbox */
#chatImgLightbox {
  display:none; position:fixed; inset:0;
  background:rgba(0,0,0,.9); z-index:999;
  align-items:center; justify-content:center; cursor:zoom-out;
}
#chatImgLightbox.open { display:flex; }
#chatImgLightbox img { max-width:92vw; max-height:92vh; border-radius:8px; object-fit:contain; }
#chatImgLightbox button {
  position:absolute; top:14px; right:18px;
  background:rgba(255,255,255,.15); border:none; color:#fff;
  font-size:24px; cursor:pointer; width:36px; height:36px;
  border-radius:50%; display:flex; align-items:center; justify-content:center;
}

/* Кнопка "назад" в шапке чата — видна только на мобильной версии */
.chat-back-btn {
  display: none;
  width: 32px; height: 32px; flex-shrink: 0;
  align-items: center; justify-content: center;
  background: none; border: none; border-radius: 50%;
  color: #374151; cursor: pointer; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.chat-back-btn:active { background: #f3f4f6; }

@media (max-width:900px) {
  /* ── Мобильная версия чата: как в Telegram ──────────────────────────
     По умолчанию виден список чатов на всю ширину. При открытии диалога
     (класс .chat-mobile-open на .chat-layout, см. chat-module.js) список
     скрывается, а диалог занимает весь блок. Стрелка "назад" в шапке
     диалога возвращает к списку. ── */
  #panel-chat.active { height:calc(100vh - 46px); padding:8px !important; }

  /* На десктопе карточка чата специально пониже (max-height:74vh, см. выше)
     чтобы оставался "воздух" вокруг. На мобильной это же правило вылезало
     пустым отступом между полем ввода и клавиатурой — на телефоне чат
     должен занимать всю доступную высоту блока. */
  #panel-chat.active .chat-layout {
    max-height: none;
    height: 100%;
  }

  .chat-layout { position: relative; }

  .chat-rooms-sidebar {
    display: flex;
    width: 100%;
    min-width: 0;
  }
  .chat-main, #chat-no-active {
    display: none !important;
  }

  .chat-layout.chat-mobile-open .chat-rooms-sidebar {
    display: none !important;
  }
  .chat-layout.chat-mobile-open .chat-main {
    display: flex !important;
    width: 100%;
  }

  .chat-back-btn { display: flex; }
}
