/* ═══════════════════════════════════════════════════════════════════════
   Chat System — Getskills2
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Hide page scrollbar when chat panel is open ────────────────────── */
body.chat-panel-open { overflow: hidden; }

/* ─── Chat toggle button (header) ────────────────────────────────────── */
.chat-btn-wrap { position: relative; }

.chat-btn {
  background: none; border: none; color: var(--text-inverse);
  font-size: 18px; padding: 6px 8px; cursor: pointer; position: relative;
  opacity: 0.85; transition: opacity 0.15s;
}
.chat-btn:hover { opacity: 1; }

.chat-badge {
  position: absolute; top: 2px; right: 0;
  background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px; line-height: 1;
}
.chat-badge.chat-hidden { display: none; }

/* ─── Chat panel (side drawer — desktop) ─────────────────────────────── */
.chat-panel {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  width: 380px;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.chat-panel.chat-open { transform: translateX(0); }

/* ─── Panel header ───────────────────────────────────────────────────── */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  flex-shrink: 0;
}
.chat-header-title {
  font-weight: 600; font-size: 15px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.chat-header-actions { display: flex; gap: 4px; }
.chat-header-btn {
  background: none; border: none; color: var(--text-secondary);
  font-size: 16px; padding: 6px 8px; cursor: pointer; border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.chat-header-btn:hover { background: var(--bg); color: var(--text); }

/* Members button with count badge */
.chat-members-btn { position: relative; }
.chat-members-count {
  position: absolute; top: 1px; right: 0;
  background: var(--secondary); color: #fff;
  font-size: 9px; font-weight: 700;
  min-width: 14px; height: 14px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px; line-height: 1;
}

/* Back button (in conversation view) */
.chat-back-btn {
  background: none; border: none; color: var(--text-secondary);
  font-size: 15px; padding: 4px 8px 4px 0; cursor: pointer;
}
.chat-back-btn:hover { color: var(--text); }

/* ─── Conversation list ──────────────────────────────────────────────── */
.chat-conv-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
}

.chat-conv-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.chat-conv-search input {
  width: 100%; padding: 7px 12px;
  border: 1px solid var(--border); border-radius: 20px;
  font-size: 13px; background: var(--bg);
  outline: none; transition: border-color 0.15s;
  font-family: var(--font-body);
}
.chat-conv-search input:focus { border-color: var(--primary); }
.chat-conv-search input::placeholder { color: var(--text-light); }

.chat-conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  cursor: pointer; transition: background 0.12s;
  border-bottom: 1px solid #f3f4f6;
  position: relative;
}
.chat-conv-item:hover { background: #f9fafb; }
.chat-conv-item.chat-conv-active { background: #eff6ff; }

.chat-conv-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 14px;
  flex-shrink: 0; text-transform: uppercase;
}
.chat-conv-avatar.chat-group-avatar {
  background: var(--secondary); font-size: 16px;
}

.chat-conv-body { flex: 1; min-width: 0; }
.chat-conv-name {
  font-weight: 600; font-size: 13px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
.chat-conv-name .chat-teacher-tag {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  background: var(--primary); color: #fff;
  padding: 1px 5px; border-radius: 3px;
  flex-shrink: 0;
}
.chat-conv-preview {
  font-size: 12px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-conv-meta {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 4px; flex-shrink: 0;
}
.chat-conv-time {
  font-size: 11px; color: var(--text-light);
}
.chat-conv-unread {
  background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

.chat-conv-empty {
  padding: 40px 20px; text-align: center;
  color: var(--text-light); font-size: 13px;
}

/* ─── Conversation view (messages) ───────────────────────────────────── */
.chat-messages-wrap {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}

.chat-messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 12px 14px;
  display: flex; flex-direction: column;
  gap: 2px;
}

/* Date separator */
.chat-date-sep {
  text-align: center; padding: 8px 0;
  font-size: 11px; color: var(--text-light); font-weight: 600;
  position: relative;
}
.chat-date-sep::before, .chat-date-sep::after {
  content: ''; position: absolute; top: 50%;
  width: calc(50% - 50px); height: 1px; background: var(--border);
}
.chat-date-sep::before { left: 0; }
.chat-date-sep::after { right: 0; }

/* Message bubble */
.chat-msg {
  display: flex; gap: 8px; max-width: 85%;
  padding: 2px 0;
}
.chat-msg.chat-msg-mine { flex-direction: row-reverse; align-self: flex-end; }

.chat-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 11px;
  flex-shrink: 0; margin-top: 2px; text-transform: uppercase;
}
.chat-msg-mine .chat-msg-avatar { display: none; }

.chat-msg-content {
  background: #f0f2f5; border-radius: 14px;
  padding: 8px 14px;
  max-width: 100%;
}
.chat-msg-mine .chat-msg-content {
  background: #d6edfb; color: var(--text);
  border-radius: 14px 14px 4px 14px;
}
.chat-msg:not(.chat-msg-mine) .chat-msg-content {
  border-radius: 14px 14px 14px 4px;
}

.chat-msg-sender {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 2px;
}
.chat-msg-mine .chat-msg-sender { display: none; }

.chat-msg-text {
  font-size: 13px; line-height: 1.45;
  word-wrap: break-word; white-space: pre-wrap;
}
.chat-msg-mine .chat-msg-text { color: var(--text); }

.chat-msg-time {
  font-size: 10px; color: var(--text-light);
  margin-top: 2px; text-align: right;
}
.chat-msg-mine .chat-msg-time { color: var(--text-light); }

.chat-msg-edited {
  font-size: 10px; font-style: italic; color: var(--text-light);
}
.chat-msg-mine .chat-msg-edited { color: var(--text-light); }

/* System message */
.chat-msg-system {
  text-align: center; padding: 4px 0;
  font-size: 11px; color: var(--text-light); font-style: italic;
  align-self: center; max-width: 100%;
}

/* Deleted message */
.chat-msg-deleted .chat-msg-text {
  color: var(--text-light); font-style: italic;
}

/* File message */
.chat-msg-file {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: rgba(0,0,0,0.05);
  border-radius: 8px; cursor: pointer; transition: background 0.15s;
}
.chat-msg-file:hover { background: rgba(0,0,0,0.08); }
.chat-msg-mine .chat-msg-file { background: rgba(0,0,0,0.05); }
.chat-msg-mine .chat-msg-file:hover { background: rgba(0,0,0,0.08); }
.chat-msg-file i { font-size: 20px; flex-shrink: 0; }
.chat-msg-file-info { min-width: 0; }
.chat-msg-file-name {
  font-size: 12px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-msg-file-size { font-size: 10px; opacity: 0.7; }

/* Image preview in file message */
.chat-msg-img {
  max-width: 220px; max-height: 180px;
  border-radius: 8px; cursor: pointer;
  object-fit: cover;
}

/* Typing indicator */
.chat-typing {
  font-size: 12px; color: var(--text-light); font-style: italic;
  padding: 4px 14px; min-height: 20px;
}

/* ─── Message input area ─────────────────────────────────────────────── */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: flex; align-items: flex-end; gap: 8px;
  flex-shrink: 0;
  background: #fff;
}

.chat-input-field {
  flex: 1; min-height: 36px; max-height: 120px;
  padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 20px;
  font-size: 13px; font-family: var(--font-body);
  outline: none; resize: none;
  line-height: 1.4;
  overflow-y: auto;
  transition: border-color 0.15s;
}
.chat-input-field:focus { border-color: var(--primary); }
.chat-input-field::placeholder { color: var(--text-light); }

.chat-input-btn {
  background: none; border: none;
  color: var(--text-secondary); font-size: 18px;
  padding: 6px; cursor: pointer; border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.chat-input-btn:hover { color: var(--primary); background: #fce4ec; }

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

/* ─── New conversation button ────────────────────────────────────────── */
.chat-new-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 8px 12px;
  padding: 8px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
  font-family: var(--font-body);
}
.chat-new-btn:hover { background: var(--primary-dark); }
.chat-new-btn i { font-size: 12px; }

/* ─── Contact list (new conversation) ────────────────────────────────── */
.chat-contacts-list {
  flex: 1; overflow-y: auto;
}
.chat-contact-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid #f3f4f6;
}
.chat-contact-item:hover { background: #f9fafb; }
.chat-contact-item.selected { background: #eff6ff; }

.chat-contact-check {
  width: 18px; height: 18px; border-radius: 4px;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.chat-contact-item.selected .chat-contact-check {
  background: var(--primary); border-color: var(--primary);
  color: #fff; font-size: 10px;
}

.chat-contact-name {
  font-size: 13px; font-weight: 500; color: var(--text);
}
.chat-contact-type {
  font-size: 10px; color: var(--text-light);
  margin-left: auto;
}

/* ─── Exam block overlay ─────────────────────────────────────────────── */
.chat-exam-block {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.95);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; z-index: 5;
  padding: 24px;
}
.chat-exam-block i { font-size: 40px; color: var(--text-light); }
.chat-exam-block p {
  font-size: 14px; color: var(--text-secondary);
  text-align: center; line-height: 1.5;
}

/* ─── Loading ────────────────────────────────────────────────────────── */
.chat-loading {
  display: flex; align-items: center; justify-content: center;
  padding: 20px; color: var(--text-light); font-size: 13px;
}

/* ─── Conversation info header (inside message view) ─────────────────── */
.chat-conv-info {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; flex: 1;
}
.chat-conv-info-name {
  font-weight: 600; font-size: 14px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-conv-info-count {
  font-size: 11px; color: var(--text-light);
}

/* ─── Scroll to bottom FAB ───────────────────────────────────────────── */
.chat-scroll-bottom {
  position: absolute; bottom: 70px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-card); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; color: var(--text-secondary);
  transition: opacity 0.2s; z-index: 2;
}
.chat-scroll-bottom:hover { background: var(--bg); }

/* ─── Member kick button ─────────────────────────────────────────────── */
.chat-member-kick {
  background: none; border: none;
  color: var(--text-light); font-size: 14px;
  padding: 6px 8px; cursor: pointer; border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.chat-member-kick:hover { color: var(--error); background: #fef2f2; }

/* ─── Invite pills zone (scrollable) ─────────────────────────────────── */
.chat-invite-chips-wrap {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  max-height: 100px;
  overflow-y: auto;
  flex-shrink: 0;
}
.chat-invite-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 6px 3px 9px;
  border-radius: 14px; font-size: 11.5px; font-weight: 500;
  white-space: nowrap; line-height: 1.3;
}
/* Existing members: neutral grey */
.chat-chip-existing {
  background: #f0f2f5; color: var(--text);
}
/* Newly added: blue highlight */
.chat-chip-new {
  background: #dbeafe; color: #1d4ed8;
}
.chat-invite-chip-x {
  background: none; border: none;
  color: var(--text-light); font-size: 9px;
  padding: 2px; cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s;
}
.chat-invite-chip-x:hover { color: var(--error); }
/* Existing member without remove button: no extra padding */
.chat-chip-existing:not(:has(.chat-invite-chip-x)) {
  padding-right: 9px;
}

/* ─── Context menu (messages + conversation kebab) ───────────────────── */
.chat-context-menu {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.16);
  z-index: 10001;
  min-width: 150px;
  overflow: hidden;
  animation: chatMenuIn 0.12s ease-out;
}
@keyframes chatMenuIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.chat-ctx-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  font-size: 13px; color: var(--text);
  cursor: pointer; transition: background 0.12s;
  white-space: nowrap;
}
.chat-ctx-item:hover { background: #f3f4f6; }
.chat-ctx-item i { width: 16px; text-align: center; font-size: 13px; color: var(--text-secondary); }
.chat-ctx-danger { color: var(--error); }
.chat-ctx-danger i { color: var(--error); }
.chat-ctx-danger:hover { background: #fef2f2; }

/* ─── Muted indicator on conversation item ───────────────────────────── */
.chat-conv-muted {
  font-size: 11px; color: var(--text-light);
}
.chat-conv-muted i { font-size: 10px; }

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .chat-panel {
    width: 100%; top: 0;
    border-radius: 0; box-shadow: none;
  }
  .chat-panel .chat-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  .chat-input-area {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .chat-msg { max-width: 90%; }
  .chat-context-menu {
    position: fixed !important;
    bottom: 0 !important; left: 0 !important; right: 0 !important;
    top: auto !important;
    border-radius: 16px 16px 0 0;
    min-width: auto; width: 100%;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    animation: chatMenuSlideUp 0.2s ease-out;
  }
  @keyframes chatMenuSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .chat-ctx-item { padding: 14px 20px; font-size: 15px; }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .chat-panel { width: 340px; }
}
