/* ==========================================================================
   WhatsApp Web - Authentic Pixel-Perfect Design System
   ========================================================================== */

:root {
  --app-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* WhatsApp Web Dark Theme (Exact Official Values) */
  --bg-app: #111b21;
  --bg-panel: #111b21;
  --bg-sidebar: #111b21;
  --bg-header: #202c33;
  --bg-chat: #0b141a;
  --bg-input: #2a3942;
  --bg-input-bar: #202c33;
  --bg-active-chat: #2a3942;
  --bg-hover-chat: #202c33;
  --bg-message-in: #202c33;
  --bg-message-out: #005c4b;
  --bg-reply-in: rgba(0, 0, 0, 0.22);
  --bg-reply-out: rgba(0, 0, 0, 0.18);
  --bg-badge: #00a884;
  --bg-dropdown: #233138;
  --bg-modal: #222e35;
  --bg-date-pill: #182229;

  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-muted: #667781;
  --text-badge: #111b21;
  --text-link: #53bdeb;
  --text-quote-in: #53bdeb;
  --text-quote-out: #25d366;
  --text-date-pill: #8696a0;

  --border-color: rgba(134, 150, 160, 0.15);
  --border-subtle: #202c33;

  --accent-green: #00a884;
  --accent-green-hover: #02906f;
  --accent-blue-tick: #53bdeb;
  --accent-gray-tick: #8696a0;
  --accent-red: #ea4335;

  --shadow-bubble: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --shadow-md: 0 2px 5px 0 rgba(11, 20, 26, 0.26), 0 2px 10px 0 rgba(11, 20, 26, 0.16);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.45);

  --doodle-bg: url("../img/whatsapp-doodle-dark.svg");
}

/* Light Theme Variables */
body.light-theme {
  --bg-app: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-header: #f0f2f5;
  --bg-chat: #efeae2;
  --bg-input: #ffffff;
  --bg-input-bar: #f0f2f5;
  --bg-active-chat: #f0f2f5;
  --bg-hover-chat: #f5f6f6;
  --bg-message-in: #ffffff;
  --bg-message-out: #d9fdd3;
  --bg-reply-in: #f5f6f6;
  --bg-reply-out: #cef5c6;
  --bg-badge: #25d366;
  --bg-dropdown: #ffffff;
  --bg-modal: #ffffff;
  --bg-date-pill: #ffffff;

  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;
  --text-badge: #ffffff;
  --text-link: #027eb5;
  --text-quote-in: #027eb5;
  --text-quote-out: #008069;
  --text-date-pill: #54656f;

  --border-color: rgba(11, 20, 26, 0.1);
  --border-subtle: #f0f2f5;

  --accent-green: #008069;
  --accent-green-hover: #017560;
  --accent-blue-tick: #53bdeb;
  --accent-gray-tick: #8696a0;

  --shadow-bubble: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --shadow-md: 0 2px 5px 0 rgba(11, 20, 26, 0.12), 0 2px 10px 0 rgba(11, 20, 26, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.18);

  --doodle-bg: url("../img/whatsapp-doodle-light.svg");
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--app-font);
  background-color: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(134, 150, 160, 0.2);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(134, 150, 160, 0.4);
}

/* Root App Layout */
#app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

.app-window {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* ==========================================================================
   SIDEBAR (Left Panel)
   ========================================================================== */
.sidebar {
  width: 400px;
  min-width: 320px;
  max-width: 460px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  z-index: 20;
}

/* Sidebar Header */
.sidebar-header {
  height: 60px;
  background-color: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.avatar-wrapper {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #374248;
}

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

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #25d366;
  border: 2px solid var(--bg-header);
}

/* WAHA Status Pill */
.waha-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s;
}

.waha-status-badge:hover {
  opacity: 0.85;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-connected {
  background: rgba(0, 168, 132, 0.15);
  color: #00a884;
}
.status-connected .status-dot {
  background-color: #00a884;
  box-shadow: 0 0 6px #00a884;
}

.status-qr {
  background: rgba(255, 188, 56, 0.15);
  color: #ffbc38;
}
.status-qr .status-dot {
  background-color: #ffbc38;
  animation: pulseDot 1.4s infinite;
}

.status-disconnected {
  background: rgba(234, 67, 53, 0.15);
  color: #ea4335;
}
.status-disconnected .status-dot {
  background-color: #ea4335;
}

@keyframes pulseDot {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.icon-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

body.light-theme .icon-btn:hover {
  background-color: rgba(0, 0, 0, 0.06);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Search Bar Area */
.sidebar-search-area {
  padding: 8px 12px 10px 12px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  background-color: var(--bg-header);
  border-radius: 8px;
  padding: 0 12px;
  height: 36px;
  gap: 12px;
  transition: background-color 0.2s, box-shadow 0.2s;
}

.search-box:focus-within {
  background-color: var(--bg-input);
  box-shadow: 0 0 0 1px var(--accent-green);
}

.search-box svg {
  width: 17px;
  height: 17px;
  fill: var(--text-secondary);
  flex-shrink: 0;
}

.search-input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  color: var(--text-primary);
  font-size: 14px;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.clear-search-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: none;
  font-size: 14px;
}

/* Filter Chips */
.filter-chips {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-chip {
  background-color: var(--bg-header);
  color: var(--text-secondary);
  border: none;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.filter-chip:hover {
  background-color: var(--bg-hover-chat);
  color: var(--text-primary);
}

.filter-chip.active {
  background-color: #0a332c;
  color: #00a884;
  font-weight: 500;
}

body.light-theme .filter-chip.active {
  background-color: #e7fce3;
  color: #008069;
}

/* Chat List */
.chat-list {
  flex: 1;
  overflow-y: auto;
  background-color: var(--bg-sidebar);
}

.chat-item {
  display: flex;
  align-items: center;
  height: 72px;
  padding: 0 16px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  position: relative;
  gap: 15px;
  user-select: none;
}

.chat-item:hover {
  background-color: var(--bg-hover-chat);
}

.chat-item.active {
  background-color: var(--bg-active-chat);
}

.chat-avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background-color: #2a3942;
  position: relative;
}

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

.chat-info {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-bottom: 1px solid var(--border-color);
  gap: 3px;
}

.chat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.chat-title {
  font-size: 16.5px;
  font-weight: 400;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-time {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: 8px;
}

.chat-row-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-last-msg {
  font-size: 13.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-last-msg .status-tick {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.unread-badge {
  background-color: var(--bg-badge);
  color: var(--text-badge);
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  margin-left: 6px;
  flex-shrink: 0;
}

.pin-icon {
  width: 14px;
  height: 14px;
  fill: var(--text-secondary);
  margin-left: 4px;
}

/* ==========================================================================
   CHAT WINDOW (Right Panel)
   ========================================================================== */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-chat);
  position: relative;
  height: 100%;
  overflow: hidden;
}

/* Authentic WhatsApp Vector Doodle Background Pattern */
.chat-window::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: var(--doodle-bg);
  background-repeat: repeat;
  background-size: 412px 412px;
  pointer-events: none;
  opacity: 0.9;
  z-index: 0;
}

/* Empty State Window */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 20px;
  background-color: var(--bg-header);
  border-bottom: 6px solid var(--accent-green);
  z-index: 1;
}

.empty-state-img {
  width: 320px;
  max-width: 80%;
  margin-bottom: 28px;
  opacity: 0.9;
}

.empty-state-title {
  font-size: 32px;
  font-weight: 300;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.empty-state-desc {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 460px;
  line-height: 20px;
}

.empty-state-lock {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 40px;
  font-size: 13px;
  color: var(--text-muted);
}

.empty-state-lock svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Active Chat Header */
.chat-header {
  height: 60px;
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  min-width: 0;
}

.chat-header-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-header-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-status {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Messages Scroll Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 7% 12px 7%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  z-index: 1;
}

/* Date Pill */
.date-pill-wrapper {
  display: flex;
  justify-content: center;
  margin: 10px 0 8px 0;
}

.date-pill {
  background-color: var(--bg-date-pill);
  color: var(--text-date-pill);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 7.5px;
  box-shadow: var(--shadow-bubble);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  user-select: none;
}

/* Encryption notice pill */
.encryption-notice {
  background-color: #182229;
  border-radius: 8px;
  padding: 7px 14px;
  margin: 8px auto 14px auto;
  max-width: 520px;
  font-size: 12.5px;
  color: #ffd279;
  text-align: center;
  line-height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-bubble);
}

body.light-theme .encryption-notice {
  background-color: #ffeecd;
  color: #54656f;
}

/* ==========================================================================
   AUTHENTIC MESSAGE BUBBLES
   ========================================================================== */
.message-row {
  display: flex;
  margin-bottom: 2px;
  position: relative;
  width: 100%;
}

.message-row.is-first {
  margin-top: 8px;
}

.message-row.outgoing {
  justify-content: flex-end;
}

.message-row.incoming {
  justify-content: flex-start;
}

/* Message Bubble Container */
.message-bubble {
  display: flex;
  flex-direction: column;
  width: fit-content;
  max-width: 65%;
  min-width: 70px;
  padding: 6px 7px 8px 9px;
  border-radius: 7.5px;
  font-size: 14.2px;
  line-height: 19px;
  position: relative;
  box-shadow: var(--shadow-bubble);
  word-wrap: break-word;
  transition: transform 0.2s, box-shadow 0.2s;
}

.message-bubble.has-media {
  padding: 3px 3px 6px 3px;
  max-width: 336px;
  width: min(336px, calc(100vw - 80px));
}

.message-bubble.has-media-only {
  padding: 3px;
  max-width: 336px;
  width: fit-content;
}

.message-bubble.has-document {
  max-width: 336px;
  width: min(336px, calc(100vw - 80px));
  padding: 4px 4px 6px 4px;
}

.message-bubble.highlight-pulse {
  animation: bubblePulse 1.6s ease;
}

@keyframes bubblePulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(0, 168, 132, 0.8); }
  30% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(0, 168, 132, 0.4); }
  100% { transform: scale(1); box-shadow: var(--shadow-bubble); }
}

/* Bubble Colors & Tails */
.message-row.outgoing .message-bubble {
  background-color: var(--bg-message-out);
  color: var(--text-primary);
}

.message-row.incoming .message-bubble {
  background-color: var(--bg-message-in);
  color: var(--text-primary);
}

.message-row.outgoing.has-tail .message-bubble {
  border-top-right-radius: 0;
}

.message-row.incoming.has-tail .message-bubble {
  border-top-left-radius: 0;
}

/* SVG Tails */
.bubble-tail {
  position: absolute;
  top: 0;
  width: 8px;
  height: 13px;
  pointer-events: none;
}

.bubble-tail.tail-in {
  left: -8px;
  color: var(--bg-message-in);
}

.bubble-tail.tail-out {
  right: -8px;
  color: var(--bg-message-out);
}

/* Group Sender Header */
.message-sender-name {
  font-size: 12.8px;
  font-weight: 600;
  margin-bottom: 3px;
  cursor: pointer;
  line-height: 16px;
}

/* Quoted / Replied Box inside Bubble */
.message-quote {
  background-color: var(--bg-reply-in);
  border-left: 4px solid var(--text-quote-in);
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 5px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: opacity 0.15s;
}

.message-row.outgoing .message-quote {
  background-color: var(--bg-reply-out);
  border-left-color: var(--text-quote-out);
}

.message-quote:hover {
  opacity: 0.85;
}

.quote-author {
  font-weight: 600;
  color: var(--text-quote-in);
  font-size: 12px;
}

.message-row.outgoing .quote-author {
  color: var(--text-quote-out);
}

.quote-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

/* Text Content Wrapper with Snug Fit */
.bubble-text-wrap {
  position: relative;
  display: inline;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bubble-meta-spacer {
  display: inline-block;
  width: 58px;
  height: 11px;
  pointer-events: none;
}

/* Timestamp & Ticks */
.message-meta {
  position: absolute;
  right: 7px;
  bottom: 5px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-secondary);
  user-select: none;
  white-space: nowrap;
}

.status-tick {
  width: 16px;
  height: 16px;
}

.status-tick.read {
  color: var(--accent-blue-tick);
}

.status-tick.delivered,
.status-tick.sent {
  color: var(--accent-gray-tick);
}

.status-tick.pending {
  color: var(--text-secondary);
  animation: tickClockPulse 1.2s infinite ease-in-out;
}

@keyframes tickClockPulse {
  0%, 100% {
    opacity: 0.55;
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
}

.status-tick.failed {
  color: #ea4335 !important;
}

/* Button Spinner for Send Button */
.icon-btn.is-sending {
  pointer-events: none;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2.2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #00a884;
  border-radius: 50%;
  animation: spinLoader 0.75s infinite linear;
}

@keyframes spinLoader {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Media Uploading Overlay (WhatsApp Style) */
.media-upload-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 20, 26, 0.58);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  z-index: 4;
}

.media-upload-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #00a884;
  border-radius: 50%;
  animation: spinLoader 0.85s infinite linear;
}

.media-upload-label {
  font-size: 11.5px;
  font-weight: 500;
  color: #ffffff;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* Document Upload Spinner */
.doc-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spinLoader 0.8s infinite linear;
}

/* Hover Chevron Button */
.bubble-actions-trigger {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  transition: opacity 0.15s ease;
  z-index: 5;
}

.message-bubble:hover .bubble-actions-trigger {
  opacity: 1;
}

.bubble-actions-trigger:hover {
  color: var(--text-primary);
}

/* Floating Quick Reactions on Hover */
.quick-reactions-bar {
  position: absolute;
  top: -32px;
  display: none;
  background-color: var(--bg-dropdown);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 2px 6px;
  gap: 4px;
  box-shadow: var(--shadow-md);
  z-index: 20;
}

.message-row.outgoing .quick-reactions-bar {
  right: 8px;
}

.message-row.incoming .quick-reactions-bar {
  left: 8px;
}

.message-row:hover .quick-reactions-bar {
  display: flex;
}

.reaction-btn {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.15s;
  padding: 2px 4px;
  border-radius: 12px;
}

.reaction-btn:hover {
  transform: scale(1.3);
  background: rgba(255, 255, 255, 0.1);
}

/* Displayed Reactions Pill */
.message-reactions {
  position: absolute;
  bottom: -10px;
  background-color: var(--bg-header);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1px 6px;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 3px;
  box-shadow: var(--shadow-bubble);
  cursor: pointer;
  z-index: 2;
}

.message-row.outgoing .message-reactions {
  right: 12px;
}

.message-row.incoming .message-reactions {
  left: 12px;
}

/* ==========================================================================
   MEDIA ELEMENTS (Image, Voice Note, Document)
   ========================================================================== */

/* Media: Image Card */
.media-image-card {
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  width: 100%;
  max-width: 100%;
  position: relative;
  background: rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-image-card img {
  width: 100%;
  height: auto;
  max-height: 380px;
  display: block;
  object-fit: cover;
  border-radius: 5px;
  transition: transform 0.2s ease;
}

.media-image-card:hover img {
  transform: scale(1.015);
}

.media-caption-text {
  padding: 6px 8px 3px 6px;
  font-size: 14.2px;
  line-height: 19px;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

/* Image overlay meta when no caption */
.media-overlay-meta {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(11, 20, 26, 0.65);
  backdrop-filter: blur(4px);
  padding: 2px 7px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.95);
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.media-overlay-meta .status-tick {
  width: 15px;
  height: 14px;
}

.media-overlay-meta .status-tick.read {
  color: #53bdeb;
}

/* Media: Voice Note / Audio Player (Sleek WhatsApp PTT) */
.voice-note-container {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  min-width: 270px;
  max-width: 320px;
}

.voice-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}

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

.voice-mic-badge {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background-color: #25d366;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-mic-badge svg {
  width: 10px;
  height: 10px;
  fill: #111b21;
}

.voice-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.voice-play-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-pause-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.15s;
}

.play-pause-btn:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.08);
}

.play-pause-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Waveform Scrubber */
.waveform-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  cursor: pointer;
  position: relative;
}

.wave-bar {
  flex: 1;
  background-color: var(--text-secondary);
  border-radius: 2px;
  height: 10px;
  transition: background-color 0.15s;
}

.wave-bar.active {
  background-color: var(--accent-green);
}

.voice-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-secondary);
}

.playback-speed-badge {
  background: rgba(255, 255, 255, 0.12);
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

/* Media: Document Card */
.document-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 4px;
  text-decoration: none;
  color: inherit;
  transition: background-color 0.15s;
  min-width: 230px;
}

.document-card:hover {
  background: rgba(0, 0, 0, 0.3);
}

.doc-icon-wrapper {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background-color: #25d366;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.doc-icon-wrapper svg {
  width: 20px;
  height: 20px;
  fill: #ffffff;
}

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

.doc-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ==========================================================================
   INPUT BAR & CONTROLS
   ========================================================================== */
.replying-banner {
  background-color: var(--bg-input-bar);
  border-top: 1px solid var(--border-color);
  padding: 8px 16px;
  display: none;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 10;
}

.replying-banner.active {
  display: flex;
}

.replying-content {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.reply-accent-bar {
  width: 4px;
  height: 38px;
  border-radius: 2px;
  background-color: var(--accent-green);
  flex-shrink: 0;
}

.replying-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.replying-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-green);
}

.replying-snippet {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;
}

.close-reply-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.close-reply-btn:hover {
  color: var(--text-primary);
}

/* Chat Input Bar (Bottom) */
.chat-input-bar {
  min-height: 62px;
  background-color: var(--bg-input-bar);
  border-top: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.input-actions-left {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 3px;
}

.input-field-wrapper {
  flex: 1;
  background-color: var(--bg-input);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  min-height: 42px;
  max-height: 120px;
  position: relative;
}

.message-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary);
  line-height: 20px;
  max-height: 100px;
  overflow-y: auto;
}

.message-textarea::placeholder {
  color: var(--text-secondary);
}

.input-actions-right {
  display: flex;
  align-items: center;
  margin-bottom: 3px;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: none;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.send-btn.has-text {
  background-color: var(--accent-green);
  color: #ffffff;
}

.send-btn.has-text:hover {
  background-color: var(--accent-green-hover);
}

.send-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Voice Recorder Live Mode */
.voice-recorder-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 42px;
  background-color: var(--bg-input-bar);
}

.voice-recorder-bar.recording {
  display: flex;
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #ea4335;
  animation: pulseDot 1s infinite;
}

.recording-timer {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.recording-waveforms {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.rec-wave {
  width: 3px;
  background-color: var(--accent-green);
  border-radius: 2px;
  animation: waveMotion 1s infinite alternate ease-in-out;
}

@keyframes waveMotion {
  0% { height: 4px; }
  100% { height: 18px; }
}

.recording-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rec-cancel-btn {
  background: none;
  border: none;
  color: #ea4335;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rec-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--accent-green);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Attachment Radial / Popover Menu */
.attachment-popover {
  position: absolute;
  bottom: 74px;
  left: 20px;
  background-color: var(--bg-dropdown);
  border-radius: 14px;
  padding: 10px;
  display: none;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  border: 1px solid var(--border-color);
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.attachment-popover.active {
  display: flex;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.attachment-opt {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s;
  color: var(--text-primary);
  font-size: 14px;
}

.attachment-opt:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.opt-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.opt-circle svg {
  width: 20px;
  height: 20px;
  fill: #ffffff;
}

.opt-circle.purple { background-color: #bf59cf; }
.opt-circle.pink { background-color: #ec407a; }
.opt-circle.blue { background-color: #5157ae; }
.opt-circle.orange { background-color: #e54238; }

/* Emoji Picker Popup */
.emoji-picker-popover {
  position: absolute;
  bottom: 74px;
  left: 16px;
  width: 340px;
  height: 360px;
  background-color: var(--bg-dropdown);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  border: 1px solid var(--border-color);
  overflow: hidden;
  animation: popIn 0.2s ease;
}

.emoji-picker-popover.active {
  display: flex;
}

.emoji-tabs {
  display: flex;
  justify-content: space-around;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-header);
}

.emoji-tab-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background-color 0.15s;
}

.emoji-tab-btn:hover, .emoji-tab-btn.active {
  background-color: rgba(255, 255, 255, 0.1);
}

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.emoji-item {
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: transform 0.15s, background-color 0.15s;
}

.emoji-item:hover {
  transform: scale(1.25);
  background-color: rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   DRAWERS (Slide-in Panels)
   ========================================================================== */
.drawer {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: var(--bg-sidebar);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.1, 0.9, 0.2, 1);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  height: 108px;
  background-color: var(--bg-header);
  display: flex;
  align-items: flex-end;
  padding: 16px 20px;
  gap: 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 19px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.drawer-back-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.drawer-back-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
}

/* Settings Form */
.settings-section {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-green);
}

.form-input {
  background-color: var(--bg-header);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--accent-green);
}

.btn-primary {
  background-color: var(--accent-green);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.15s;
}

.btn-primary:hover {
  background-color: var(--accent-green-hover);
}

.btn-secondary {
  background-color: var(--bg-header);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.btn-secondary:hover {
  background-color: var(--bg-hover-chat);
}

/* ==========================================================================
   MODALS (Attachment Preview, Lightbox, QR)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-modal);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  animation: modalScale 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 500;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.preview-media-box {
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  overflow: hidden;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-media-box img {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.caption-input-box {
  width: 100%;
}

.caption-input-box input {
  width: 100%;
  background-color: var(--bg-header);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Lightbox Fullscreen */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.lightbox-overlay.active {
  display: flex;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
}

.lightbox-close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
}

.lightbox-close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
  }
  .chat-window {
    display: none;
  }
  .app-container.chat-open .sidebar {
    display: none;
  }
  .app-container.chat-open .chat-window {
    display: flex;
  }
  .mobile-back-btn {
    display: flex !important;
  }
}

.mobile-back-btn {
  display: none;
}

/* Refresh Button Spin Animation */
.rotating svg {
  animation: spin 0.6s linear infinite;
}

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

/* Floating Scroll-to-Bottom Button */
.scroll-bottom-btn {
  position: absolute;
  bottom: 78px;
  right: 22px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  transition: background 0.15s, transform 0.15s, opacity 0.2s;
  z-index: 25;
}

.scroll-bottom-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  transform: scale(1.06);
}

.scroll-bottom-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.scroll-unread-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--accent-green);
  border: 2px solid var(--bg-panel);
}

/* Single Room Mode */
.app-window.is-single-room .sidebar-search-area,
.app-window.is-single-room #new-chat-btn,
.app-window.is-single-room #settings-btn,
.app-window.is-single-room #mobile-back-btn {
  display: none !important;
}

@media (max-width: 768px) {
  .app-window.is-single-room .sidebar {
    display: none !important;
  }
  .app-window.is-single-room .chat-window {
    display: flex !important;
  }
}
