:root {
  --accent: #3a6ea5;
  --accent-dark: #2c5480;
  --bg-panel: #f7f8fa;
  --bubble-me: #3a6ea5;
  --bubble-them: #ffffff;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #eef1f4;
}

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef1f4;
}
.auth-card {
  background: #fff;
  padding: 2rem;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 360px;
}

/* ---------- Shell layout ---------- */
.chat-shell {
  display: flex;
  height: 100vh;
}

.chat-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e2e5e9;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #e2e5e9;
}
.me { display: flex; align-items: center; gap: 0.6rem; }
.me-name { font-weight: 600; }

.connection-banner {
  background: #fff3cd;
  color: #664d03;
  text-align: center;
  font-size: 0.8rem;
  padding: 0.35rem;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-me { background: var(--accent-dark); }
.avatar-group { background: #7a5ca8; }

.avatar-upload-label { cursor: pointer; position: relative; }
.avatar-upload-label:hover .avatar { filter: brightness(0.85); }

.conversation-list { overflow-y: auto; flex: 1; }
.conversation-item {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.7rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid #f0f1f3;
}
.conversation-item:hover { background: var(--bg-panel); }
.conversation-item.active { background: #e8f0fa; }
.conv-meta { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 0.92rem; }
.conv-preview {
  font-size: 0.82rem;
  color: #6c757d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-side { text-align: right; font-size: 0.72rem; color: #97a0a8; }
.unread-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 0.05rem 0.4rem;
  margin-top: 0.2rem;
}

/* ---------- Main panel ---------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
}
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #97a0a8;
}
.thread-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1.2rem;
  background: #fff;
  border-bottom: 1px solid #e2e5e9;
}
.message-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg-row { display: flex; }
.msg-row.me { justify-content: flex-end; }
.bubble {
  max-width: 60%;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.35;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}
.msg-row.me .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 3px; }
.msg-row.them .bubble { background: var(--bubble-them); color: #212529; border-bottom-left-radius: 3px; }
.bubble time {
  display: block;
  font-size: 0.68rem;
  opacity: 0.7;
  margin-top: 0.2rem;
}
.tick-slot { display: inline-block; margin-left: 0.3rem; }
.tick { font-size: 0.75rem; letter-spacing: -1px; }
.tick-sent { color: rgba(255,255,255,0.65); }
.tick-delivered { color: rgba(255,255,255,0.9); }
.tick-read { color: #53bdeb; } /* WhatsApp-style read-receipt blue */

.send-form {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 1.2rem;
  background: #fff;
  border-top: 1px solid #e2e5e9;
}

@media (max-width: 700px) {
  .chat-sidebar { width: 100%; position: absolute; inset: 0; z-index: 2; }
  .chat-sidebar.hide-mobile { display: none; }
  .chat-main { width: 100%; }
}

/* ---------- Search ---------- */
.search-panel {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #e2e5e9;
}
.search-results { margin-top: 0.5rem; max-height: 60vh; overflow-y: auto; }
.search-result {
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid #f0f1f3;
  cursor: pointer;
}
.search-result:hover { background: var(--bg-panel); }
.search-result-conv { font-weight: 600; font-size: 0.82rem; }
.search-result-body {
  font-size: 0.82rem;
  color: #6c757d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-empty { color: #97a0a8; font-size: 0.85rem; padding: 0.5rem 0.3rem; }

/* ---------- Message rows: sender label, forwarded, edited, deleted ---------- */
.sender-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.15rem;
}
.forwarded-label {
  font-size: 0.72rem;
  font-style: italic;
  opacity: 0.75;
  margin-bottom: 0.15rem;
}
.edited-label { font-size: 0.68rem; opacity: 0.7; }
.msg-body { white-space: pre-wrap; }

.msg-row.deleted .bubble-deleted {
  background: transparent;
  border: 1px dashed #c7cdd4;
  color: #97a0a8;
  box-shadow: none;
  max-width: 60%;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  font-size: 0.85rem;
}

.msg-row.highlight .bubble { animation: highlight-flash 2s ease; }
@keyframes highlight-flash {
  0%   { box-shadow: 0 0 0 3px #ffe08a; }
  100% { box-shadow: 0 1px 1px rgba(0,0,0,0.04); }
}

/* ---------- Hover-reveal message actions (edit / delete / forward) ---------- */
.msg-row { position: relative; }
.msg-actions {
  display: flex;
  gap: 0.2rem;
  opacity: 0;
  transition: opacity 0.15s;
  align-self: center;
  margin: 0 0.3rem;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-actions button {
  border: none;
  background: #fff;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 0.8rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  cursor: pointer;
}

.edit-box { margin-top: 0.2rem; }
.edit-box input { margin-bottom: 0.3rem; }
.edit-box-actions { display: flex; gap: 0.4rem; }

/* ---------- Attachments ---------- */
.attachment-image {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  margin-bottom: 0.3rem;
}
.attachment-file {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.3rem;
  text-decoration: none;
  color: inherit;
}
.msg-row.me .attachment-file { background: rgba(255,255,255,0.15); color: #fff; }
.attachment-icon { font-size: 1.2rem; }
.attachment-meta { display: flex; flex-direction: column; min-width: 0; }
.attachment-name {
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.attachment-size { font-size: 0.7rem; opacity: 0.75; }

/* ---------- Typing indicator ---------- */
.typing-indicator {
  padding: 0.2rem 1.2rem;
  font-size: 0.78rem;
  font-style: italic;
  color: #6c757d;
}

/* ---------- Attach button on the send form ---------- */
.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0;
}

/* ---------- New chat modal: 1:1 / group tabs ---------- */
.nav-pills .nav-link { cursor: pointer; }

/* ---------- Forward modal ---------- */
.forward-target {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.2rem;
  border-bottom: 1px solid #f0f1f3;
  cursor: pointer;
}

/* ---------- Emoji picker ---------- */
.emoji-picker {
  position: absolute;
  bottom: 60px;
  right: 1.2rem;
  background: #fff;
  border: 1px solid #e2e5e9;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.15rem;
  max-width: 260px;
  z-index: 5;
}
.emoji-option {
  border: none;
  background: none;
  font-size: 1.3rem;
  line-height: 1.6;
  border-radius: 6px;
  cursor: pointer;
  padding: 0.15rem;
}
.emoji-option:hover { background: var(--bg-panel); }
.chat-main { position: relative; }

/* ---------- Avatar camera badge (upload affordance) ---------- */
.avatar-upload-label { position: relative; display: inline-block; }
.avatar-camera-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--accent-dark);
  color: #fff;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  border: 2px solid #fff;
}

/* ---------- Icon spacing on auth pages ---------- */
.auth-card h1 i { margin-right: 0.3rem; }
.form-label i { width: 1.1rem; text-align: center; opacity: 0.7; }
.alert i { margin-right: 0.2rem; }

/* ---------- End-to-end encryption indicator ---------- */
.e2ee-badge {
  color: #53bdeb;
  font-size: 0.95rem;
  padding: 0.3rem;
}

/* ---------- Reactions ---------- */
.reaction-picker {
  position: absolute;
  background: #fff;
  border: 1px solid #e2e5e9;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 0.3rem 0.5rem;
  display: flex;
  gap: 0.2rem;
  z-index: 6;
}
.reaction-picker button {
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 50%;
  padding: 0.15rem 0.3rem;
  transition: transform 0.1s;
}
.reaction-picker button:hover { transform: scale(1.3); background: var(--bg-panel); }

.reaction-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.3rem;
}
.reaction-pill {
  background: rgba(0,0,0,0.06);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0.05rem 0.45rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.reaction-pill.mine { background: rgba(58,110,165,0.15); border-color: var(--accent); }
.msg-row.me .reaction-pill { background: rgba(255,255,255,0.2); color: #fff; }
.msg-row.me .reaction-pill.mine { border-color: #fff; }

/* ---------- Pagination ---------- */
.load-more-btn {
  display: block;
  margin: 0.5rem auto;
  background: #fff;
  border: 1px solid #e2e5e9;
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
}
.load-more-btn:hover { background: var(--bg-panel); }

/* ---------- Group read receipt text (replaces ticks for groups) ---------- */
.group-read-status {
  font-size: 0.68rem;
  opacity: 0.85;
  margin-left: 0.3rem;
}

/* ---------- Group members modal ---------- */
.member-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f0f1f3;
}
.member-row .member-info { flex: 1; min-width: 0; }
.member-row .member-name { font-weight: 600; font-size: 0.88rem; }
.member-row .member-email { font-size: 0.76rem; color: #6c757d; }
