/* Chat Layout */
.chat-page {
  padding: 2rem 0 4rem;
}

.chat-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  min-height: 78vh;
  align-items: start;
}

@media (max-width: 820px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }
  .chat-sidebar {
    max-height: 40vh;
    overflow-y: auto;
  }
}

/* Sidebar — Conversation List */
.chat-sidebar {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 78vh;
  box-shadow: var(--shadow);
}

.chat-sidebar-header {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(6, 182, 212, 0.06);
  flex-shrink: 0;
}

.chat-sidebar-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-sidebar-header h3 svg {
  color: var(--accent);
}

.chat-sidebar-search {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-sidebar-search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--trans);
}

.chat-sidebar-search input:focus {
  border-color: var(--accent);
}

.chat-sidebar-search input::placeholder {
  color: var(--muted);
}

.chat-conv-list {
  overflow-y: auto;
  flex: 1;
}

.chat-conv-list::-webkit-scrollbar {
  width: 4px;
}
.chat-conv-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Single conversation row */
.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background var(--trans);
  position: relative;
}

.chat-conv-item:hover {
  background: var(--surface);
}

.chat-conv-item.active {
  background: rgba(6, 182, 212, 0.1);
  border-left: 3px solid var(--accent);
}

.chat-conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
}

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

.chat-conv-info {
  flex: 1;
  min-width: 0;
}

.chat-conv-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.chat-conv-preview {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.15rem;
}

.chat-conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  flex-shrink: 0;
}

.chat-conv-time {
  font-size: 0.7rem;
  color: var(--muted);
}

.chat-unread-badge {
  background: var(--accent);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 0.1rem 0.45rem;
  min-width: 18px;
  text-align: center;
}

/* New conversation button */
.chat-new-btn {
  margin: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: linear-gradient(45deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--trans);
  flex-shrink: 0;
}

.chat-new-btn:hover {
  opacity: 0.88;
  color: #fff;
}

/* Empty state in sidebar */
.chat-conv-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Main Chat Window */
.chat-window {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  height: 78vh;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Chat header bar */
.chat-window-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: rgba(6, 182, 212, 0.06);
  flex-shrink: 0;
}

.chat-window-header .chat-conv-avatar {
  width: 38px;
  height: 38px;
  font-size: 0.9rem;
}

.chat-window-title {
  flex: 1;
}

.chat-window-title h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.chat-window-title span {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Message area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Date separator */
.chat-date-sep {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-date-sep::before,
.chat-date-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Individual message bubble */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.chat-msg.sent {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg.received {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-msg-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chat-msg-sender {
  font-weight: 600;
  color: var(--accent);
}

.chat-msg-bubble {
  padding: 0.65rem 0.95rem;
  border-radius: 1.1rem;
  font-size: 0.875rem;
  line-height: 1.55;
  word-wrap: break-word;
  word-break: break-word;
  position: relative;
}

.chat-msg.sent .chat-msg-bubble {
  background: linear-gradient(135deg, var(--accent), #0891b2);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.chat-msg.received .chat-msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 0.25rem;
}

.chat-msg-time {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.2rem;
  padding: 0 0.25rem;
}

.chat-msg.sent .chat-msg-time {
  color: rgba(148, 163, 184, 0.8);
}

/* Read receipt tick */
.chat-read-tick {
  font-size: 0.65rem;
  margin-left: 0.2rem;
}
.chat-read-tick.read {
  color: var(--accent);
}
.chat-read-tick.unread {
  color: var(--muted);
}

/* Empty message state */
.chat-msg-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  padding: 2rem;
  gap: 0.8rem;
}

.chat-msg-empty svg {
  opacity: 0.3;
}

.chat-msg-empty p {
  font-size: 0.88rem;
}

/* Message Input Area */
.chat-input-area {
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg3);
  flex-shrink: 0;
}

.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 0.7rem;
}

.chat-input-wrap {
  flex: 1;
  position: relative;
}

.chat-input-wrap textarea {
  width: 100%;
  background: var(--bg2);          /* explicit dark — avoids browser-default white */
  -webkit-appearance: none;         /* prevent WebKit overriding background         */
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 140px;
  line-height: 1.5;
  transition: border-color var(--trans);
  overflow-y: auto;
}

.chat-input-wrap textarea:focus {
  border-color: var(--accent);
}

.chat-input-wrap textarea::placeholder {
  color: var(--muted);
}

.chat-send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.1rem;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.84rem;
  font-weight: 600;
  transition:
    opacity var(--trans),
    transform var(--trans);
  flex-shrink: 0;
  min-height: 44px;
}

.chat-send-btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

.chat-send-btn:active {
  transform: translateY(0);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Char count hint */
.chat-char-hint {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: right;
  margin-top: 0.25rem;
}

.chat-char-hint.warn {
  color: var(--warning);
}

/* No-conversation placeholder */
.chat-no-conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  padding: 3rem;
  gap: 1rem;
}

.chat-no-conv svg {
  opacity: 0.25;
}

.chat-no-conv h3 {
  font-size: 1.1rem;
  color: var(--text);
  opacity: 0.7;
}

.chat-no-conv p {
  font-size: 0.88rem;
}

/* New Conversation Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close {
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  transition: color var(--trans);
}

.modal-close:hover {
  color: var(--text);
}

/* User picker list inside modal */
.user-pick-list {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.user-pick-list::-webkit-scrollbar {
  width: 4px;
}
.user-pick-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.user-pick-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--trans);
  text-decoration: none;
  color: var(--text);
}

.user-pick-item:last-child {
  border-bottom: none;
}

.user-pick-item:hover {
  background: var(--surface);
}

.user-pick-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}

.user-pick-name {
  font-size: 0.88rem;
  font-weight: 600;
}

.user-pick-email {
  font-size: 0.75rem;
  color: var(--muted);
}

.user-pick-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.modal-search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--trans);
}

.modal-search:focus {
  border-color: var(--accent);
}

.modal-search::placeholder {
  color: var(--muted);
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  height: 20px;
  flex-shrink: 0;
}

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBounce 1.2s ease infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Toast notifications */
.chat-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.1rem;
  font-size: 0.83rem;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  max-width: 320px;
  animation: toastIn 0.3s ease;
}

.chat-toast.success {
  border-left: 3px solid var(--success);
}
.chat-toast.error {
  border-left: 3px solid var(--danger);
}

@keyframes toastIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Nav badge (unread count in navbar) */
.nav-chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  padding: 0 3px;
  margin-left: 3px;
  vertical-align: super;
  line-height: 1;
}

/* Loading skeleton (message area while polling) */
.chat-skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.skel-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    rgba(255, 255, 255, 0.06) 50%,
    var(--surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Page-level heading */
.chat-page-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.chat-page-title h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
}

.chat-page-title .badge {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent);
  border: 1px solid rgba(6, 182, 212, 0.35);
  border-radius: 20px;
  padding: 0.2rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FILE UPLOAD — Attach button, hidden input, file preview strip
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Hide the raw browser file picker completely ─────────────────────── */
#chatFileInput {
  display: none !important;
  /* The attach button triggers chatFileInput.click() via JS;
     the native <input type="file"> must never be visible.              */
}

/* ── 2. Attach (paperclip) button ────────────────────────────────────────── */
.chat-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: color var(--trans), border-color var(--trans), background var(--trans);
}

.chat-attach-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: rgba(6, 182, 212, 0.4);
  background: rgba(6, 182, 212, 0.06);
}

.chat-attach-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── 3. File preview strip — HIDDEN by default ───────────────────────────── */
/*      JS adds .active to reveal it when a file is staged / uploading.      */
.chat-file-preview {
  display: none;                    /* ← key fix: hide until JS adds .active */
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.5rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.chat-file-preview.active {
  display: flex;                    /* shown only when a file is staged       */
}

/* File type icon / thumbnail */
.chat-file-preview-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: calc(var(--radius-sm) - 2px);
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  overflow: hidden;
}

.chat-file-preview-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* Text info block */
.chat-file-preview-info {
  flex: 1;
  min-width: 0;
}

.chat-file-preview-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-file-preview-size {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Upload progress bar */
.chat-upload-progress {
  margin-top: 0.35rem;
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.chat-upload-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* Status text ("Uploading…" / "Ready") */
.chat-file-preview-progress {
  font-size: 0.74rem;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Remove (✕) button */
.chat-file-remove-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 50%;
  color: var(--danger);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background var(--trans), border-color var(--trans);
  line-height: 1;
}

.chat-file-remove-btn:hover {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.5);
}
