/* messages.css — Direct messaging UI. Dark theme, Instagram DMs aesthetic. */

/* === Layout === */
.msg-page {
  display: flex;
  margin-top: 72px;
  height: calc(100vh - 72px);
  background: #0d0d0d;
  overflow: hidden;
}

/* === Sidebar (Conversation List) === */
.msg-sidebar {
  width: 340px;
  min-width: 280px;
  border-right: 1px solid #1e1e1e;
  display: flex;
  flex-direction: column;
  background: #111;
}

.msg-sidebar-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid #1e1e1e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.msg-sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.msg-new-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #8B5CF6;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.msg-new-btn:hover { background: #7C3AED; }

.msg-search {
  padding: 12px 16px;
  border-bottom: 1px solid #1e1e1e;
}

.msg-search input {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 9px 14px;
  color: #ccc;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.msg-search input::placeholder { color: #555; }
.msg-search input:focus { border-color: #8B5CF6; }

/* User search results dropdown */
.msg-user-results {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  margin-top: 8px;
  overflow: hidden;
  display: none;
}

.msg-user-results.active { display: block; }

.msg-user-results li {
  list-style: none;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
  color: #ccc;
  font-size: 0.875rem;
}

.msg-user-results li:hover { background: #222; }
.msg-user-results .user-name { font-weight: 600; color: #fff; }
.msg-user-results .user-role { font-size: 0.75rem; color: #888; }

/* Conversation list */
.msg-convo-list {
  flex: 1;
  overflow-y: auto;
}

.msg-convo-list::-webkit-scrollbar { width: 4px; }
.msg-convo-list::-webkit-scrollbar-track { background: transparent; }
.msg-convo-list::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

.msg-convo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 1px solid #161616;
  transition: background 0.15s;
  position: relative;
}

.msg-convo-item:hover { background: #161616; }

.msg-convo-item.active {
  background: #1a1a2e;
  border-left: 3px solid #8B5CF6;
}

.msg-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #8B5CF6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-convo-info {
  flex: 1;
  min-width: 0;
}

.msg-convo-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-convo-preview {
  font-size: 0.78rem;
  color: #777;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.msg-convo-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.msg-timestamp {
  font-size: 0.7rem;
  color: #555;
}

.msg-unread-badge {
  background: #8B5CF6;
  color: #fff;
  border-radius: 10px;
  padding: 2px 7px;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

.msg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #555;
  gap: 8px;
  padding: 20px;
  text-align: center;
}

.msg-empty-icon { font-size: 2rem; }
.msg-empty-text { font-size: 0.85rem; }

/* === Thread Panel === */
.msg-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.msg-thread-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #555;
  gap: 12px;
  text-align: center;
}

.msg-thread-empty .big-icon { font-size: 4rem; opacity: 0.2; }
.msg-thread-empty p { font-size: 0.9rem; max-width: 320px; line-height: 1.5; }

.msg-thread-header {
  padding: 16px 24px;
  border-bottom: 1px solid #1e1e1e;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #111;
}

.msg-thread-header .msg-avatar { width: 38px; height: 38px; font-size: 0.9rem; }

.msg-thread-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
}

.msg-thread-subtitle {
  font-size: 0.75rem;
  color: #777;
}

.msg-thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-thread-messages::-webkit-scrollbar { width: 4px; }
.msg-thread-messages::-webkit-scrollbar-track { background: transparent; }
.msg-thread-messages::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-bubble-wrap.sent { flex-direction: row-reverse; }

.msg-bubble-wrap .msg-avatar {
  width: 28px;
  height: 28px;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.msg-bubble-content { max-width: 65%; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.4;
  word-break: break-word;
}

.msg-bubble-wrap.received .msg-bubble {
  background: #1e1e1e;
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
}

.msg-bubble-wrap.sent .msg-bubble {
  background: #8B5CF6;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-bubble-time {
  font-size: 0.65rem;
  color: #555;
  margin-top: 3px;
  padding: 0 4px;
}

.msg-bubble-wrap.sent .msg-bubble-time { text-align: right; }

/* Input area */
.msg-input-area {
  padding: 16px 24px;
  border-top: 1px solid #1e1e1e;
  background: #111;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.msg-input {
  flex: 1;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 24px;
  padding: 12px 18px;
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.4;
}

.msg-input::placeholder { color: #555; }
.msg-input:focus { border-color: #8B5CF6; }

.msg-send-btn {
  background: #8B5CF6;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.msg-send-btn:hover { background: #7C3AED; transform: scale(1.05); }
.msg-send-btn:active { transform: scale(0.95); }

/* Loading indicator */
.msg-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  color: #555;
  font-size: 0.85rem;
}

.msg-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #333;
  border-top-color: #8B5CF6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  margin-right: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === Mobile === */
@media (max-width: 768px) {
  .msg-page { margin-top: 60px; height: calc(100vh - 60px); }

  .msg-sidebar {
    width: 100%;
    border-right: none;
  }

  .msg-sidebar.hidden-mobile {
    display: none;
  }

  .msg-thread {
    width: 100%;
  }

  .msg-thread.mobile-hidden {
    display: none;
  }

  .msg-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: #8B5CF6;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 4px 0;
    margin-bottom: 8px;
  }
}

/* === Search result avatar === */
.msg-user-results .msg-avatar { width: 32px; height: 32px; font-size: 0.75rem; flex-shrink: 0; }