/* =================================================== */
/* CometChat-Inspired Chat Screen                      */
/* =================================================== */

/* ─── CONVERSATION LIST ─── */
.cc-messages-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-app);
  animation: cc-fade-in 300ms ease;
}

.cc-messages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  flex-shrink: 0;
  background: var(--bg-surface);
}

.cc-messages-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0;
}

.cc-messages-actions {
  display: flex;
  gap: 4px;
}

.cc-messages-actions .btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
}

.cc-messages-actions .btn-icon:hover {
  background: var(--bg-surface);
  color: var(--primary);
  transform: scale(1.05);
}

/* Search */
.cc-search-bar {
  padding: 0 20px 12px;
  position: relative;
}

.cc-search-bar input {
  width: 100%;
  height: 42px;
  border-radius: 21px;
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  padding: 0 16px 0 42px;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--text-primary);
  outline: none;
  transition: all 0.25s;
  box-sizing: border-box;
}

.cc-search-bar input:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--primary-pale);
}

.cc-search-bar input::placeholder {
  color: var(--text-placeholder);
}

.cc-search-icon {
  position: absolute;
  left: 36px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  color: var(--text-muted);
  pointer-events: none;
  margin-top: -6px;
}

/* Tabs */
.cc-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--divider);
}

.cc-tab {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cc-tab:hover {
  color: var(--text-primary);
}

.cc-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Chat Rows */
.cc-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.cc-chat-list::-webkit-scrollbar {
  width: 4px;
}

.cc-chat-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.cc-chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  box-sizing: border-box;
}

.cc-chat-row:hover {
  background: var(--bg-sunken);
}

.cc-chat-row.unread {
  background: var(--primary-ghost);
}

.cc-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.cc-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.cc-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cc-avatar.group-avatar {
  border-radius: 12px;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 20px;
  border: none;
}

.cc-online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid var(--bg-app);
}

.cc-chat-info {
  flex: 1;
  min-width: 0;
}

.cc-chat-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cc-chat-name {
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cc-chat-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.cc-chat-row.unread .cc-chat-time {
  color: var(--primary);
  font-weight: 700;
}

.cc-chat-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.cc-chat-preview {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.cc-chat-row.unread .cc-chat-preview {
  color: var(--text-secondary);
  font-weight: 600;
}

.cc-unread-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

.cc-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
  text-align: center;
}

.cc-empty-icon {
  font-size: 56px;
  margin-bottom: 14px;
}

.cc-empty-state h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px;
}

.cc-empty-state p {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.cc-fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--text-inverse);
  border: none;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 100;
}

.cc-fab:hover {
  transform: translateY(-2px) scale(1.06);
}


/* ════════════════════════════════════ */
/* ─── CHAT VIEW                     ─── */
/* ════════════════════════════════════ */
.cc-chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background: var(--bg-app, #f8f9fb);
  position: fixed;
  inset: 0;
  z-index: 500;
  overflow: hidden;
}

/* Inline mode: when embedded inside a desktop split panel */
.cc-chat-page.cc-chat-page--inline {
  position: relative;
  inset: unset;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  flex: 1;
  min-height: 0;
  z-index: 1;
  background: transparent;
}

.cc-chat-page--inline .cc-chat-header {
  position: relative;
  z-index: 10;
  flex-shrink: 0;
  display: flex;
  min-height: 52px;
}


/* Header */
.cc-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  flex-shrink: 0;
  background: var(--bg-surface, #fff);
  border-bottom: 1px solid var(--border, #e5e7eb);
  z-index: 50;
}

.cc-header-back {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: all 0.15s;
  flex-shrink: 0;
}

.cc-header-back:hover {
  background: var(--bg-sunken, #f3f4f6);
}

.cc-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
}

.cc-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cc-header-avatar.group {
  border-radius: 10px;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 16px;
  border: none;
}

.cc-header-info {
  flex: 1;
  cursor: pointer;
  min-width: 0;
}

.cc-header-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cc-header-status {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 500;
  margin-top: 1px;
}

.cc-header-status.online {
  color: #22C55E;
  font-weight: 600;
}

.cc-header-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.cc-header-actions .btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  transition: all 0.15s;
}

.cc-header-actions .btn-icon:hover {
  background: var(--bg-sunken, #f3f4f6);
  color: var(--text-primary, #374151);
}

/* Messages Area */
.cc-messages {
  flex: 1;
  min-height: 0; /* CRITICAL: allows flex child to scroll properly */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.cc-messages::-webkit-scrollbar {
  width: 4px;
}

.cc-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

/* Date */
.cc-date-sep {
  text-align: center;
  margin: 16px auto 8px;
  padding: 3px 12px;
  background: var(--bg-sunken, #e5e7eb);
  border-radius: 8px;
  color: var(--text-muted, #6b7280);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  width: fit-content;
}

/* System */
.cc-system-msg {
  text-align: center;
  padding: 4px 12px;
  margin: 6px auto;
  background: var(--bg-sunken, #f3f4f6);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-muted, #9ca3af);
  width: fit-content;
}

/* ─── MESSAGE ROW ─── */
.cc-msg-row {
  display: flex;
  gap: 6px;
  max-width: 65%;
  margin-bottom: 2px;
}

.cc-msg-row.cc-mine {
  align-self: flex-end;
  justify-content: flex-end;
}

.cc-msg-row.cc-theirs {
  align-self: flex-start;
}

/* Sender avatar */
.cc-sender-ava {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  align-self: flex-end;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

.cc-sender-ava img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Bubble column */
.cc-bubble-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.cc-sender-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 2px;
  margin-bottom: 1px;
}

/* Reply bar */
.cc-reply-bar {
  background: var(--bg-sunken);
  border-left: 2px solid var(--primary);
  border-radius: 4px;
  padding: 3px 8px;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
}

.cc-reply-bar b {
  color: var(--text-primary);
}

/* ─── BUBBLE ─── */
.cc-bubble {
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: break-word;
  cursor: default;
  position: relative;
}

.cc-sent {
  background: var(--msg-out-bg);
  color: var(--msg-out-text);
  border-radius: var(--r-msg-out);
}

.cc-recv {
  background: var(--msg-in-bg);
  color: var(--msg-in-text);
  border-radius: var(--r-msg-in);
  border: 1px solid var(--border);
}

.cc-bubble-text {
  display: inline;
}

.cc-bubble-img {
  display: block;
  max-width: 200px;
  max-height: 160px;
  border-radius: 10px;
  object-fit: cover;
  cursor: pointer;
  margin-bottom: 2px;
}

.cc-bubble-vid {
  display: block;
  max-width: 200px;
  max-height: 160px;
  border-radius: 10px;
  margin-bottom: 2px;
}

.cc-bubble-aud {
  display: block;
  max-width: 180px;
  height: 32px;
  margin: 2px 0;
}

/* Meta (time + ticks) — inline float */
.cc-meta {
  float: right;
  margin-left: 8px;
  margin-top: 4px;
  font-size: 10px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.cc-sent .cc-meta {
  color: rgba(255, 255, 255, 0.5);
}

.cc-recv .cc-meta {
  color: rgba(0, 0, 0, 0.3);
}

.cc-ticks {
  font-size: 11px;
  letter-spacing: -2px;
  font-weight: bold;
  margin-left: 1px;
}

.cc-tick-read {
  color: #34B7F1; /* WhatsApp Blue */
}

.tick-read {
  color: #34B7F1; /* WhatsApp Blue */
}

.tick-pending {
  color: #94a3b8;
  font-size: 14px !important;
  margin-left: 2px;
}

/* Old chat.js tick classes */
.msg-ticks {
  font-size: 11px;
  letter-spacing: -2px;
  font-weight: bold;
  margin-left: 2px;
}

.msg-ticks.tick-read {
  color: #34B7F1 !important; /* WhatsApp Blue */
}

.msg-ticks.tick-delivered {
  color: rgba(255, 255, 255, 0.5);
}

.msg-ticks.tick-pending {
  color: #94a3b8;
  font-size: 14px !important;
}

.msg-edited-label {
  font-size: 10px;
  font-style: italic;
  opacity: 0.6;
  margin-right: 4px;
}

.msg-time-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
}

/* Reactions */
.cc-reacts {
  display: flex;
  gap: 2px;
  margin-top: 1px;
}

.cc-msg-row.cc-mine .cc-reacts {
  justify-content: flex-end;
}

.cc-reacts span {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1px 5px;
  font-size: 13px;
}

.cc-reacts span small {
  font-size: 10px;
  margin-left: 2px;
}

/* Typing */
.cc-typing {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f3f4f6;
  border-radius: 14px;
  width: fit-content;
  margin-top: 2px;
  align-self: flex-start;
}

.cc-typing.active {
  display: flex;
}

.cc-typing-dot {
  width: 5px;
  height: 5px;
  background: #94a3b8;
  border-radius: 50%;
  animation: cc-typing-bounce 1.4s infinite ease-in-out both;
}

.cc-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.cc-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.cc-typing-name {
  font-size: 11px;
  color: #9ca3af;
}

/* Scroll-to-bottom */
.cc-scroll-bottom {
  position: absolute;
  bottom: 68px;
  right: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 60;
  color: #6b7280;
}

.cc-scroll-bottom.visible {
  display: flex;
}

.cc-scroll-bottom:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}


/* ─── INPUT BAR ─── */
.cc-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  background: var(--bg-surface, #fff);
  border-top: 1px solid var(--border, #e5e7eb);
  position: relative;
  z-index: 100;
}

.cc-input-bar .btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  transition: color 0.15s;
  flex-shrink: 0;
}

.cc-input-bar .btn-icon:hover {
  color: #6366f1;
}

.cc-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--bg-sunken, #f3f4f6);
  border-radius: 20px;
  padding: 4px 14px;
  min-height: 38px;
  border: 1.5px solid transparent;
  transition: all 0.2s;
}

.cc-input-wrap:focus-within {
  background: var(--bg-surface, #fff);
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.06);
}

.cc-input-wrap textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  max-height: 100px;
  padding: 7px 0;
  line-height: 18px;
}

.cc-input-wrap textarea::placeholder {
  color: #9ca3af;
}

.cc-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #6366f1;
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  transition: transform 0.15s, opacity 0.15s;
}

.cc-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.cc-send-btn:active {
  transform: scale(0.9);
}

.cc-send-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* Recording */
.cc-recording-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  color: #EF4444;
  font-weight: 700;
  font-size: 13px;
  flex: 1;
  padding: 0 10px;
}

.cc-recording-indicator.active {
  display: flex;
}

.cc-recording-dot {
  width: 8px;
  height: 8px;
  background: #EF4444;
  border-radius: 50%;
  animation: cc-pulse-dot 1s infinite;
}

/* Emoji Picker */
.cc-emoji-picker {
  position: absolute;
  bottom: 58px;
  left: 12px;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  z-index: 200;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
}

.cc-emoji-picker button {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  border-radius: 6px;
  padding: 4px;
  transition: all 0.1s;
}

.cc-emoji-picker button:hover {
  background: #f3f4f6;
  transform: scale(1.1);
}

/* Context Menu */
.cc-context-menu {
  position: fixed;
  background: var(--bg-surface, #fff);
  backdrop-filter: blur(16px);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  min-width: 160px;
  z-index: 1000;
  border: 1px solid var(--border, #e5e7eb);
  overflow: hidden;
}

.cc-context-menu .cc-react-row {
  display: flex;
  padding: 8px 10px;
  gap: 6px;
  border-bottom: 1px solid #e5e7eb;
  justify-content: center;
}

.cc-context-menu .cc-react-row span {
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.1s;
  border-radius: 6px;
  padding: 3px;
}

.cc-context-menu .cc-react-row span:hover {
  transform: scale(1.2);
  background: #f3f4f6;
}

.cc-context-menu button {
  padding: 10px 16px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-primary, #374151);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
}

.cc-context-menu button:hover {
  background: var(--bg-sunken, #f3f4f6);
}

.cc-context-menu button.danger {
  color: #EF4444;
}


/* ─── ANIMATIONS ─── */
@keyframes cc-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes cc-msg-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cc-pop-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes cc-pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

@keyframes cc-typing-bounce {

  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}


/* ─── DARK MODE ─── */
[data-theme="dark"] .cc-chat-page {
  background: var(--bg-app);
}

[data-theme="dark"] .cc-chat-header {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] .cc-sent {
  background: #4f46e5;
}

[data-theme="dark"] .cc-recv {
  background: #1e293b;
  color: #e2e8f0;
}

[data-theme="dark"] .cc-recv .cc-meta {
  color: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .cc-date-sep {
  background: var(--bg-sunken);
  color: var(--text-muted);
}

[data-theme="dark"] .cc-system-msg {
  background: var(--bg-sunken);
}

[data-theme="dark"] .cc-typing {
  background: var(--bg-sunken);
}

[data-theme="dark"] .cc-input-bar {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] .cc-input-wrap {
  background: var(--bg-sunken);
}

[data-theme="dark"] .cc-input-wrap:focus-within {
  background: var(--bg-surface);
  border-color: rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .cc-input-wrap textarea {
  color: var(--text-primary);
}

[data-theme="dark"] .cc-send-btn {
  background: #6366f1;
}

[data-theme="dark"] .cc-context-menu {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] .cc-context-menu button {
  color: var(--text-primary);
}

[data-theme="dark"] .cc-emoji-picker {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] .cc-reacts span {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] .cc-scroll-bottom {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="dark"] .cc-messages-actions .btn-icon {
  background: var(--bg-sunken);
}

[data-theme="dark"] .cc-chat-row:hover {
  background: var(--bg-sunken);
}

[data-theme="dark"] .cc-unread-badge {
  background: #6366f1;
}

[data-theme="dark"] .cc-search-bar input {
  background: var(--bg-sunken);
}

[data-theme="dark"] .cc-tab.active {
  color: #818cf8;
  border-bottom-color: #818cf8;
}

[data-theme="dark"] .cc-fab {
  background: #6366f1;
}

[data-theme="dark"] .cc-online-dot {
  border-color: var(--bg-app);
}

[data-theme="dark"] .cc-reply-bar {
  background: rgba(99, 102, 241, 0.1);
}

[data-theme="dark"] .cc-tick-read,
[data-theme="dark"] .msg-ticks.tick-read {
  color: #34B7F1; /* WhatsApp Blue — consistent in dark mode */
}

[data-theme="dark"] .cc-header-back:hover {
  background: var(--bg-sunken);
}


[data-theme="dark"] .cc-header-actions .btn-icon:hover {
  background: var(--bg-sunken);
}

/* Chat Search Bar (Inside Chat Screen) */
.cc-chat-search {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--bg-sunken);
  border-radius: 12px;
  padding: 8px 14px;
  margin: 4px 14px 10px;
  border: 1px solid var(--border);
  animation: cc-fade-in 0.2s ease-out;
}

.cc-chat-search.active {
  display: flex !important;
}

.cc-chat-search input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  font-family: var(--font-body);
  color: var(--text-primary);
}

.cc-chat-search .cc-search-close {
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
}

.cc-context-menu button.danger {
  color: #EF4444 !important;
}

/* ─── TELEGRAM THEME ─── */
[data-theme="telegram"] .cc-chat-page {
  background: var(--bg-app);
}

[data-theme="telegram"] .cc-chat-header,
[data-theme="telegram"] .cc-input-bar {
  background: var(--bg-surface);
  border-color: var(--border);
}

[data-theme="telegram"] .cc-sent {
  background: var(--msg-out-bg);
  color: var(--msg-out-text);
}

[data-theme="telegram"] .cc-recv {
  background: var(--msg-in-bg);
  color: var(--msg-in-text);
}

[data-theme="telegram"] .cc-recv .cc-meta {
  color: var(--msg-time);
}

[data-theme="telegram"] .cc-sent .cc-meta {
  color: rgba(255,255,255,0.45);
}

[data-theme="telegram"] .cc-date-sep {
  background: rgba(0,0,0,0.3);
  color: rgba(255,255,255,0.7);
  backdrop-filter: blur(4px);
}

[data-theme="telegram"] .cc-input-wrap {
  background: var(--bg-sunken);
}

[data-theme="telegram"] .cc-input-wrap:focus-within {
  background: var(--bg-surface);
  border-color: rgba(91,155,213,0.3);
}

[data-theme="telegram"] .cc-send-btn {
  background: var(--primary);
}

[data-theme="telegram"] .cc-unread-badge {
  background: var(--primary);
}

[data-theme="telegram"] .cc-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

[data-theme="telegram"] .cc-fab {
  background: var(--primary);
  box-shadow: 0 4px 20px rgba(91,155,213,0.3);
}

[data-theme="telegram"] .cc-messages-actions .btn-icon:hover {
  background: var(--primary);
  color: #fff;
}

[data-theme="telegram"] .cc-search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,155,213,0.1);
}

[data-theme="telegram"] .cc-context-menu {
  background: var(--bg-elevated);
  border-color: var(--border);
}

[data-theme="telegram"] .cc-reacts span {
  background: var(--bg-elevated);
  border-color: var(--border);
}

[data-theme="telegram"] .cc-typing {
  background: var(--bg-sunken);
}

/* ─── OLD CHAT STYLE (chat.js) — USE CSS VARIABLES ─── */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--vh, 1vh) * 100);
  background: var(--bg-app);
  position: fixed;
  inset: 0;
  z-index: 500;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  backdrop-filter: blur(12px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 100;
}

.chat-input-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--bg-sunken);
  border-radius: 20px;
  padding: 4px 14px;
  min-height: 38px;
  border: 1.5px solid transparent;
  transition: all 0.2s;
}

.chat-input-wrapper:focus-within {
  border-color: rgba(99,102,241,0.25);
  background: var(--bg-surface);
}

.chat-input-wrapper textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  max-height: 100px;
  padding: 7px 0;
  line-height: 18px;
}

.chat-status {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.chat-status.online {
  color: var(--online);
  font-weight: 600;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary, #6366f1);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
  transition: transform 0.15s, opacity 0.15s;
}

.send-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

/* Message Bubbles — use CSS variables for theme-aware colors */
.msg-bubble-wrapper {
  display: flex;
  gap: 6px;
  max-width: 75%;
  margin-bottom: 2px;
  animation: cc-msg-in 0.2s ease-out;
}

.msg-bubble-wrapper.mine {
  align-self: flex-end;
  justify-content: flex-end;
}

.msg-bubble-wrapper.theirs {
  align-self: flex-start;
}

.msg-bubble {
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
  max-width: 100%;
}

.msg-sent {
  background: var(--msg-out-bg);
  color: var(--msg-out-text);
  border-radius: 16px 16px 4px 16px;
}

.msg-received {
  background: var(--msg-in-bg);
  color: var(--msg-in-text);
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--border);
}

.msg-date {
  text-align: center;
  padding: 4px 14px;
  background: var(--bg-sunken);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  width: fit-content;
  margin: 12px auto 6px;
}

.msg-content-text {
  display: inline;
}

.msg-reactions-bubble {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  justify-content: flex-end;
}

.msg-reactions-bubble span {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 14px;
  cursor: pointer;
}

/* Typing Indicator */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-sunken);
  border-radius: 14px;
  width: fit-content;
  margin-top: 4px;
  align-self: flex-start;
}

.typing-indicator.active {
  display: flex;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: cc-typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* Invite card in chat */
.invite-card {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border);
  border-radius: 16px !important;
  color: var(--text-primary) !important;
}

/* ─── SMOOTH PAGE TRANSITIONS ─── */
.anim-fade-in {
  animation: cc-fade-in 0.25s ease-out;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 400px) {
  .msg-bubble-wrapper {
    max-width: 85%;
  }
  .cc-msg-row {
    max-width: 80%;
  }
}