/* ==========================================================================
   Chat-Private Stylesheet (Messenger Warm Coffee Theme)
   Strictly < 1000 lines (Panels & Responsive split into panels.css)
   ========================================================================== */

@import url("panels.css");

:root {
  /* Messenger Palette */
  --bg-sidebar: #ffffff;
  --bg-details: #ffffff;
  --bg-chat-theme: #f6dfc8; /* Warm coffee/latte tone matching screenshot */
  --bg-chat-overlay: rgba(246, 223, 200, 0.94);
  --bubble-self: #593014; /* Deep roasted coffee brown */
  --bubble-self-text: #ffffff;
  --bubble-peer: #ffffff; /* Clean white */
  --bubble-peer-text: #1c1e21;
  --text-main: #050505;
  --text-secondary: #65676b;
  --text-muted: #8a8d91;
  --accent-blue: #0084ff;
  --accent-pill-active: #e7f3ff;
  --accent-coffee: #794a28;
  --caramel-soft: #a86c3d;
  --bg-coffee-soft: #fcf8f4;
  --border-light: #e4e6eb;
  --input-bg: #f0f2f5;
  --hover-bg: #f2f2f2;
  --active-chat-bg: #eaf3ff;
  --online-green: #31a24c;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius-bubble: 18px;
  --radius-pill: 20px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
  --shadow-floating: 0 4px 16px rgba(0, 0, 0, 0.16);
}

.hidden {
  display: none !important;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  font-family: var(--font-family);
  background-color: var(--bg-sidebar);
  color: var(--text-main);
  overflow: hidden;
  user-select: text;
}

.messenger-container {
  display: flex;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-sidebar);
}

/* CENTER CHAT MAIN */
.messenger-chat-main {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-chat-theme);
  min-width: 0;
}

.chat-header {
  height: 60px;
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mobile-back-btn {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #593014;
  padding: 4px;
}

.header-avatar-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.header-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.header-meta {
  min-width: 0;
}

.meta-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-title {
  font-size: 16px;
  font-weight: 700;
  color: #2b180a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-icon-subtle {
  background: transparent;
  border: none;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.6;
}

.btn-icon-subtle:hover {
  opacity: 1;
}

.meta-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #7b583f;
}

.online-badge {
  background: rgba(49, 162, 76, 0.15);
  color: #1a7431;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background-color: transparent;
  color: #593014;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.header-action-btn:hover {
  background-color: rgba(89, 48, 20, 0.08);
}

.header-action-btn.active {
  color: #593014;
  background-color: rgba(89, 48, 20, 0.12);
}

/* Chat Viewport & Messages */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.theme-backdrop-illustration {
  position: absolute;
  inset: 0;
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.25) 0%, rgba(246, 223, 200, 0.85) 100%),
    url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M60 20c-15 0-25 10-25 25 0 20 25 45 25 45s25-25 25-45c0-15-10-25-25-25zm0 35c-5.5 0-10-4.5-10-10s4.5-10 10-10 10 4.5 10 10-4.5 10-10 10z' fill='%23593014' fill-opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
}

.messages-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  z-index: 2;
}

/* History Pagination Spinner & Start Badge */
.history-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 6px;
  width: 100%;
}

.history-spinner.hidden {
  display: none !important;
}

.spinner-dot {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(89, 48, 20, 0.15);
  border-top-color: #593014;
  border-radius: 50%;
  animation: spinHistory 0.65s linear infinite;
}

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

.conversation-start-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px auto 8px;
  padding: 5px 14px;
  border-radius: 16px;
  background-color: rgba(89, 48, 20, 0.08);
  color: #593014;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  width: fit-content;
  user-select: none;
}

.conversation-start-badge.hidden {
  display: none !important;
}

/* Network Status Bar (Messenger Style: Offline / Reconnected Banner) */
.network-status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  background-color: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fde68a;
  transition: all 0.25s ease;
  z-index: 40;
  user-select: none;
}

.network-status-bar.online {
  background-color: #d1fae5;
  color: #065f46;
  border-bottom: 1px solid #a7f3d0;
}

.network-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #f59e0b;
  flex-shrink: 0;
  animation: unreadDotPulse 1.4s infinite;
}

.network-status-bar.online .network-status-dot {
  background-color: #10b981;
  animation: none;
}

.network-status-bar.hidden {
  display: none !important;
}

/* Unread Messages Separator (Zalo / Messenger Style) */
.unread-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px 0 12px;
  gap: 12px;
  width: 100%;
  user-select: none;
}

.unread-sep-line {
  flex: 1;
  height: 1px;
  background-color: rgba(220, 38, 38, 0.45);
}

.unread-sep-badge {
  font-size: 12px;
  font-weight: 600;
  color: #dc2626;
  background-color: #fff1f2;
  border: 1px solid rgba(220, 38, 38, 0.3);
  padding: 3px 14px;
  border-radius: 12px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(220, 38, 38, 0.08);
}

/* Floating Unread Pill (Top Right of Chat Area) */
.unread-floating-pill {
  position: absolute;
  top: 72px;
  right: 20px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  background: #ffffff;
  color: #dc2626;
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  animation: unreadPillSlide 0.25s ease-out;
}

.unread-floating-pill:hover {
  background: #fff1f2;
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.2);
  transform: translateY(-1px);
}

.unread-floating-pill:active {
  transform: translateY(0);
}

.unread-floating-pill.hidden {
  display: none !important;
}

.unread-pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef4444;
  animation: unreadDotPulse 1.4s infinite;
}

.unread-pill-icon {
  stroke: #dc2626;
  stroke-width: 2.5;
  transition: transform 0.2s;
}

.unread-floating-pill:hover .unread-pill-icon {
  transform: translateY(-2px);
}

@keyframes unreadDotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

@keyframes unreadPillSlide {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 70%;
  position: relative;
  margin-bottom: 2px;
}

.message-row.peer { align-self: flex-start; }
.message-row.self { align-self: flex-end; flex-direction: row-reverse; }

.bubble-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.message-bubble {
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: filter 0.15s ease;
}

.message-row.self .message-bubble {
  background-color: var(--bubble-self);
  color: var(--bubble-self-text);
  border-radius: 18px 18px 4px 18px;
}

.message-row.peer .message-bubble {
  background-color: var(--bubble-peer);
  color: var(--bubble-peer-text);
  border-radius: 18px 18px 18px 4px;
}

.bubble-text { white-space: pre-wrap; }

.sender-label {
  font-size: 11px;
  font-weight: 600;
  color: #7b583f;
  margin-bottom: 3px;
}

.bubble-reply-quote {
  background-color: rgba(0, 0, 0, 0.08);
  border-left: 3px solid rgba(255, 255, 255, 0.6);
  padding: 5px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  cursor: pointer;
}

.message-row.peer .bubble-reply-quote {
  background-color: rgba(89, 48, 20, 0.06);
  border-left: 3px solid #593014;
}

.reply-quote-sender {
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 2px;
  opacity: 0.85;
}

.reply-quote-snippet {
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.7;
}

.message-row.self .bubble-meta { color: rgba(255, 255, 255, 0.75); }
.message-row.peer .bubble-meta { color: rgba(0, 0, 0, 0.45); }
.message-row.status-pending .message-bubble { opacity: 0.75; }
.message-row.status-pending .bubble-meta::after { content: " 🕒"; font-size: 10px; }

.btn-msg-reply {
  background: transparent;
  border: none;
  font-size: 12px;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  padding: 0 2px;
}
.btn-msg-reply:hover { opacity: 1; }

.bubble-image {
  max-width: 100%;
  max-height: 320px;
  min-height: 60px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
  background-color: rgba(89, 48, 20, 0.05);
}

.bubble-video {
  max-width: 100%;
  max-height: 300px;
  border-radius: 12px;
  display: block;
}

/* Audio Player */
.bubble-audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  min-width: 180px;
}

.audio-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background-color: rgba(255, 255, 255, 0.25);
  color: inherit;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.message-row.peer .audio-play-btn {
  background-color: #593014;
  color: #ffffff;
}

.audio-timeline {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.audio-progress {
  flex: 1;
  height: 4px;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.message-row.peer .audio-progress {
  background-color: rgba(0, 0, 0, 0.1);
}

.audio-progress-bar {
  height: 100%;
  width: 0%;
  background-color: currentColor;
}

.audio-duration {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

/* Floating Scroll to Bottom Button */
.btn-scroll-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: #ffffff;
  color: #593014;
  border: none;
  box-shadow: var(--shadow-floating);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.btn-scroll-bottom:hover { transform: translateX(-50%) scale(1.05); }
.btn-scroll-bottom.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
}

/* Flash highlight */
@keyframes flashHighlight {
  0% { transform: scale(1); filter: brightness(1.3); }
  50% { transform: scale(1.02); filter: brightness(1.6); }
  100% { transform: scale(1); filter: brightness(1); }
}
.flash-highlight .message-bubble { animation: flashHighlight 1.5s ease-out; }

/* Reply & Recording Banners */
.reply-banner {
  background-color: rgba(255, 255, 255, 0.95);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 9;
}
.reply-banner.hidden { display: none; }
.reply-bar-accent { width: 4px; height: 36px; background-color: #593014; border-radius: 2px; }
.reply-content { flex: 1; min-width: 0; }
.reply-header { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: #593014; }
.reply-header .btn-close { background: none; border: none; cursor: pointer; font-size: 14px; color: var(--text-secondary); }
.reply-preview-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.recording-bar {
  background-color: #ffffff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border-light);
  z-index: 9;
}
.recording-bar.hidden { display: none; }
.rec-pulse-dot { width: 12px; height: 12px; border-radius: 50%; background-color: #ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }
.rec-status { font-size: 14px; font-weight: 600; color: var(--text-main); }
.rec-timer { font-size: 14px; font-weight: 700; color: #ef4444; }
.rec-actions { margin-left: auto; display: flex; gap: 8px; }
.btn-rec-cancel, .btn-rec-send { padding: 6px 14px; border-radius: 18px; border: none; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-rec-cancel { background-color: #f0f2f5; color: #ef4444; }
.btn-rec-send { background-color: #593014; color: #ffffff; }

/* Chat Footer / Input area */
.chat-footer {
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.footer-left-actions { display: flex; align-items: center; gap: 4px; }
.footer-tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: transparent;
  color: #593014;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.footer-tool-btn:hover { background-color: rgba(89, 48, 20, 0.08); }
.gif-btn { font-weight: 800; font-size: 12px; letter-spacing: -0.5px; }

.messenger-input-pill {
  flex: 1;
  background-color: var(--input-bg);
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  padding: 8px 12px 8px 16px;
  min-height: 38px;
  border: 1px solid transparent;
}
.messenger-input-pill:focus-within { border-color: rgba(89, 48, 20, 0.2); }
.messenger-input-pill textarea {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 20px;
  resize: none;
  max-height: 100px;
  color: var(--text-main);
}
.messenger-input-pill textarea::placeholder { color: var(--text-secondary); }

.btn-emoji-inside {
  background: transparent;
  border: none;
  color: #593014;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
}
.btn-emoji-inside:hover { opacity: 1; }

.btn-footer-action {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background-color: transparent;
  color: #593014;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  transition: transform 0.15s ease;
}
.btn-footer-action:hover { transform: scale(1.15); }
.btn-footer-action:active { transform: scale(0.9); }

/* Modals (Agora, Lightbox) */
.video-modal {
  position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.92);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
}
.video-modal.hidden { display: none; }
.video-container { width: 100%; height: 100%; position: relative; display: flex; align-items: center; justify-content: center; }
.remote-video { width: 100%; height: 100%; background-color: #111; position: relative; }
.remote-video > div { width: 100% !important; height: 100% !important; }
.local-video {
  position: absolute; top: 20px; right: 20px; width: 140px; height: 190px;
  border-radius: 12px; overflow: hidden; border: 2px solid #ffffff; box-shadow: var(--shadow-md); z-index: 10;
}
.local-video > div { width: 100% !important; height: 100% !important; }
.call-status-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #ffffff; gap: 12px;
}
.call-avatar { width: 80px; height: 80px; border-radius: 50%; background-color: #333; display: flex; align-items: center; justify-content: center; font-size: 36px; }
.call-controls { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); display: flex; gap: 16px; z-index: 10; }
.call-btn {
  width: 52px; height: 52px; border-radius: 50%; border: none; font-size: 22px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: var(--shadow-md);
}
.btn-toggle { background-color: rgba(255, 255, 255, 0.2); color: #fff; }
.btn-toggle.disabled { background-color: #ef4444; }
.btn-hangup { background-color: #ef4444; color: #fff; }

.incoming-dialog {
  position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px); z-index: 999; display: flex; align-items: center; justify-content: center;
}
.incoming-dialog.hidden { display: none; }
.incoming-card {
  background-color: #ffffff; padding: 30px 40px; border-radius: 20px;
  text-align: center; box-shadow: var(--shadow-floating); color: var(--text-main);
}
.caller-avatar {
  width: 64px; height: 64px; border-radius: 50%; background-color: #31a24c; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 28px; margin: 0 auto 16px auto; animation: pulse 1s infinite;
}
.incoming-actions { display: flex; gap: 14px; margin-top: 20px; justify-content: center; }
.btn-call-reject, .btn-call-accept { padding: 10px 24px; border-radius: 20px; border: none; font-weight: 600; cursor: pointer; }
.btn-call-reject { background-color: #ef4444; color: #fff; }
.btn-call-accept { background-color: #31a24c; color: #fff; }

.lightbox {
  position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.92);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; user-select: none;
}
.lightbox.hidden { display: none; }
.lightbox-toolbar {
  position: absolute; top: 16px; right: 20px; z-index: 1010;
  display: flex; align-items: center; gap: 8px;
}
.lightbox-btn {
  background: rgba(255, 255, 255, 0.15); color: #fff; border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%; width: 40px; height: 40px; font-size: 20px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; backdrop-filter: blur(8px); transition: background 0.2s, transform 0.15s;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.3); transform: scale(1.05); }
.lightbox-btn:active { transform: scale(0.95); }
.lightbox-btn-close { font-size: 26px; }
.lightbox-canvas {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  cursor: grab;
}
.lightbox-canvas.dragging { cursor: grabbing; }
.lightbox-content {
  max-width: 90vw; max-height: 90vh; border-radius: 8px; object-fit: contain;
  transition: transform 0.05s linear; will-change: transform;
  pointer-events: auto;
}
