/* Disconnect banner */
.disconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #dc3545;
  color: #fff;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  overflow-x: hidden;
  max-width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

/* Doar pagina de chat are scroll intern (liste/mesaje); restul paginilor (contacts, admin) au scroll normal */
html:has(.app-shell), body:has(.app-shell) {
  overflow: hidden;
}

/* Layout */
.app-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - var(--nav-h, 56px));
  height: calc(100dvh - var(--nav-h, 56px));
}

.threads {
  border-right: 1px solid #e5e5e5;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.threadList {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.threadItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.threadItem:hover { background: #fafafa; }
.threadItem.active { background: #eef5ff; }

.threadAvatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.88rem;
  color: #fff;
  letter-spacing: 0.5px;
}

.threadBody {
  flex: 1;
  min-width: 0;
}


.threadName {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.threadPhone {
  font-size: 0.82rem;
  color: #666;
}
.threadPreview {
  font-size: 0.85rem;
  color: #555;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.threadTime {
  font-size: 0.72rem;
  color: #777;
  text-align: right;
  margin-top: 2px;
}

.threadMeta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.threadAgent {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 1px 5px;
  border-radius: 4px;
  background: #ede9fe;
  color: #5b21b6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channelBadge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: lowercase;
  background: #e9ecef;
  color: #555;
}
.channelBadge--whatsapp { background: #dcf7c5; color: #1a7a3c; }
.channelBadge--sms      { background: #dbeafe; color: #1d4ed8; }
.channelBadge--telegram { background: #dbeeff; color: #0063b2; }
.channelBadge--email    { background: #fef3c7; color: #92400e; }

/* WhatsApp 24h customer service window */
.waWindowBadge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 2px;
}
.waWindowBadge.open    { background: #dcf7c5; color: #1a7a3c; }
.waWindowBadge.warn    { background: #fef3c7; color: #92400e; }
.waWindowBadge.expired { background: #fee2e2; color: #b91c1c; }

.waWindowBanner {
  font-size: 0.85rem;
  padding: 6px 12px;
  border-top: 1px solid transparent;
}
.waWindowBanner.warn    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.waWindowBanner.expired { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* Assign modal user list */
.assignUserItem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
}
.assignUserItem:hover { background: #f5f5f5; }
.assignUserItem.assigned { background: #eef5ff; }

.assignUserName { font-size: 0.9rem; font-weight: 500; }
.assignUserSub  { font-size: 0.78rem; color: #888; }

.assignCheck {
  margin-left: auto;
  color: #0d6efd;
  font-size: 0.9rem;
  font-weight: 700;
}

.chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chatHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.messageList {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fbfbfb;
  -webkit-overflow-scrolling: touch;
}

.msgRow {
  display: flex;
  margin-bottom: 10px;
}

.msgRow.inbound { justify-content: flex-start; }
.msgRow.outbound { justify-content: flex-end; }

.bubble {
  max-width: min(720px, 85%);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #eee;
  background: white;
}

.msgRow.outbound .bubble {
  background: #d9fdd3;
  border-color: #d0fac9;
}

.msgRow.internal {
  justify-content: center;
}

.msgRow.internal .bubble {
  background: #fdf3e3;
  border-color: #e8c98a;
  border-style: dashed;
  max-width: min(720px, 90%);
}

.msgRow.internal .bubble::before {
  content: "📝 Internal note";
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #9a6700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.bubble .meta {
  margin-top: 6px;
  font-size: 0.72rem;
  color: #666;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.attachmentThumb {
  margin-top: 8px;
  cursor: pointer;
  border-radius: 10px;
  max-width: 260px;
  max-height: 200px;
  object-fit: cover;
  border: 1px solid #e6e6e6;
}

.attachmentAudio {
  display: block;
  margin-top: 8px;
  max-width: 260px;
}

/* "Save as": small round button over the bottom right corner of an image/video */
.attachmentMedia {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.attachmentMedia .attachmentThumb {
  display: block;
}

.attachmentSave {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.attachmentMedia:hover .attachmentSave,
.attachmentSave:focus-visible {
  opacity: 1;
}

.attachmentSave:hover {
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
}

/* Audio / documents: same button, inline next to the control */
.attachmentRow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.attachmentRow .attachmentAudio {
  margin-top: 0;
}

.attachmentSave--inline {
  position: static;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.06);
  color: #666;
  opacity: 0.7;
}

.attachmentSave--inline:hover {
  background: rgba(0, 0, 0, 0.12);
  color: #333;
  opacity: 1;
}

/* Touch screens have no hover: keep it visible but faint */
@media (hover: none) {
  .attachmentSave {
    opacity: 0.85;
  }
}

/* Navbar: quick actions always visible, the rest in the burger menu on mobile */
#mainNav .container-fluid {
  position: relative;
}

#mainNav .navbar-brand {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.navQuick {
  flex-shrink: 0;
}

#mainNav .navbar-toggler {
  padding: 2px 6px;
  font-size: 1rem;
  box-shadow: none;
}

.navBtnLabel {
  margin-left: 2px;
}

@media (min-width: 768px) {
  .navBtnLabel--mobile {
    display: none;
  }
}

@media (max-width: 767.98px) {
  /* Dropdown panel under the navbar, floats over the page instead of pushing it down */
  #navMenu {
    position: absolute;
    top: calc(100% + 4px);
    right: 8px;
    z-index: 1050;
    min-width: 220px;
    padding: 8px;
    background: #fff;
    border: 1px solid #e3e3e3;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  }

  #navMenu .navMenuItems {
    flex-direction: column;
    align-items: stretch !important;
    gap: 6px !important;
  }

  #navMenu .btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    font-size: 0.85rem;
    padding: 6px 10px;
  }

  #navMenu form .btn {
    justify-content: flex-start;
  }

  #navMenu .btn.d-none {
    display: none !important;
  }
}

/* Empty state: no conversation selected */
.chatEmpty {
  display: none;
}

.chat.noConversation > :not(.chatEmpty) {
  display: none !important;
}

.chat.noConversation .chatEmpty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  text-align: center;
  background: #fbfbfb;
}

.chatEmptyArt {
  width: 200px;
  max-width: 60%;
  height: auto;
  margin-bottom: 16px;
}

.chatEmptyTitle {
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
}

.chatEmptyText {
  margin-top: 4px;
  max-width: 320px;
  font-size: 0.9rem;
  color: #777;
}

/* File dragged over the chat pane */
.chat {
  position: relative;
}

.chat.dropActive::after {
  content: "Drop file to attach";
  position: absolute;
  inset: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed #0d6efd;
  border-radius: 12px;
  background: rgba(13, 110, 253, 0.08);
  color: #0d6efd;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
}

/* Emoji picker, opens above the composer */
.chatComposer {
  position: relative;
}

.emojiPopover {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 8px;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  overflow: hidden;
}

.emojiPopover.d-none {
  display: none;
}

.emojiPopover emoji-picker {
  --num-columns: 8;
  height: 340px;
  max-width: calc(100vw - 16px);
}

/* Selected file waiting to be sent, above the composer */
.attachPreview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 6px 10px;
  border: 1px solid #e6e6e6;
  border-radius: 10px;
  background: #f8f9fa;
}

.attachPreview.d-none {
  display: none;
}

.attachPreviewThumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.attachPreviewIcon {
  width: 44px;
  text-align: center;
  font-size: 26px;
  flex-shrink: 0;
}

.attachPreviewInfo {
  flex: 1;
  min-width: 0;
}

.attachPreviewName {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mediaContainer {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.mediaContainer img,
.mediaContainer video {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 12px;
}

.mediaContainer audio {
  width: 100%;
}

.mediaContainer .mediaPdf {
  width: 100%;
  height: 80vh;
  border: 0;
}

.text {
    white-space: pre-line;
}

.threadItem.unread .threadName,
.threadItem.unread .threadPreview {
    font-weight: 800;
}

.unreadBadge {
    display: inline-block;
    min-width: 18px;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 0.72rem;
    line-height: 1.2;
    background: #0d6efd;
    color: #fff;
    margin-left: 8px;
}

@media (max-width: 768px) {
  /* Navbar: wrap and shrink */
  .navbar .navbar-brand {
    font-size: 0.95rem;
    margin-right: 8px;
  }

  .navbar .navQuick {
    gap: 6px !important;
  }

  .navbar .btn {
    font-size: 0.78rem;
    padding: 3px 8px;
  }

  /* App shell: single column */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    width: 100%;
  }

  /* Default mobile: show threads full height, hide chat */
  .threads {
    width: 100%;
    height: calc(100vh - var(--nav-h, 56px));
    height: calc(100dvh - var(--nav-h, 56px));
    border-right: none;
  }

  .chat {
    display: none;
    width: 100%;
  }

  /* Mobile conversation open: hide threads, show chat */
  .app-shell.mobile-chat .threads {
    display: none;
  }

  .app-shell.mobile-chat .chat {
    display: flex;
    width: 100%;
    height: calc(100vh - var(--nav-h, 56px));
    height: calc(100dvh - var(--nav-h, 56px));
  }

  /* Back button */
  #backBtn {
    display: inline-flex !important;
    flex-shrink: 0;
  }

  /* Chat composer: don't overflow */
  .chatComposer .d-flex {
    flex-wrap: nowrap;
  }

  /* Bubbles: cap to viewport */
  .bubble {
    max-width: 90%;
    word-break: break-word;
  }

  .attachmentThumb {
    max-width: 100%;
  }
}
