/* ==========================================================================
   MODERN ENTERPRISE WORK CHAT DOCK & PANEL (RESIZABLE & MULTI-CHANNEL)
   ========================================================================== */

.chat-dock {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 900;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Floating Modern Toggle Button */
.chat-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px; /* Modern squircle pill */
  background: linear-gradient(135deg, #1769ff 0%, #0d52d6 100%);
  color: #ffffff;
  box-shadow: 0 10px 25px -4px rgba(23, 105, 255, 0.45), 0 4px 10px -2px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.22s ease, background 0.2s ease;
  user-select: none;
}

.chat-toggle:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 14px 32px -4px rgba(23, 105, 255, 0.55), 0 6px 14px -2px rgba(15, 23, 42, 0.16);
  background: linear-gradient(135deg, #1f72ff 0%, #105aee 100%);
}

.chat-toggle:active {
  transform: translateY(0) scale(0.96);
  box-shadow: 0 6px 16px -2px rgba(23, 105, 255, 0.4);
}

.chat-toggle-icon {
  width: 25px;
  height: 25px;
  display: block;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.18s ease;
}

.chat-toggle .chat-icon-close {
  display: none;
  width: 22px;
  height: 22px;
}

.chat-toggle[aria-expanded="true"] {
  background: #0f172a;
  box-shadow: 0 10px 25px -4px rgba(15, 23, 42, 0.4);
}

.chat-toggle[aria-expanded="true"] .chat-icon-bubble {
  display: none;
}

.chat-toggle[aria-expanded="true"] .chat-icon-close {
  display: block;
}

/* Pulsing Status Dot */
.chat-status-pulse {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 12px;
  height: 12px;
  background: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: chat-pulse 2.2s infinite;
}

.chat-toggle[aria-expanded="true"] .chat-status-pulse {
  display: none;
}

@keyframes chat-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* Chat Panel Resizable Container */
.chat-panel {
  position: absolute;
  right: 0;
  bottom: 70px;
  display: flex;
  flex-direction: column;
  width: var(--chat-w, 580px);
  height: var(--chat-h, 560px);
  min-width: 360px;
  min-height: 460px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 84px);
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.25), 0 0 1px rgba(0, 0, 0, 0.12);
  transform-origin: bottom right;
  animation: chat-panel-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
  transition: width 0.2s cubic-bezier(0.16, 1, 0.3, 1), height 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-panel.is-maximized {
  width: min(1360px, calc(100vw - 32px)) !important;
  height: calc(100vh - 90px) !important;
}

.chat-panel.is-fullscreen {
  position: fixed !important;
  top: 12px !important;
  left: 12px !important;
  right: 12px !important;
  bottom: 12px !important;
  width: calc(100vw - 24px) !important;
  height: calc(100vh - 24px) !important;
  max-width: none !important;
  max-height: none !important;
  z-index: 99999 !important;
  border-radius: 16px !important;
  box-shadow: 0 25px 60px -12px rgba(15, 23, 42, 0.45) !important;
}

@keyframes chat-panel-pop {
  0% {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.chat-panel[hidden] {
  display: none;
}

/* Multi-Direction Resize Handles */
.chat-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 22px;
  height: 22px;
  cursor: nwse-resize;
  z-index: 102;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.chat-resize-handle::before {
  content: '';
  width: 9px;
  height: 9px;
  border-top: 2.5px solid #94a3b8;
  border-left: 2.5px solid #94a3b8;
  border-top-left-radius: 4px;
}
.chat-resize-handle:hover::before {
  border-color: #2563eb;
}

/* Resize Top Edge (Height Up / Down) */
.chat-resize-top {
  position: absolute;
  top: 0;
  left: 22px;
  right: 0;
  height: 10px;
  cursor: ns-resize;
  z-index: 101;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  user-select: none;
}
.chat-resize-top-grip {
  width: 44px;
  height: 4px;
  margin-top: 2px;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.45);
  transition: all 0.15s ease;
}
.chat-resize-top:hover .chat-resize-top-grip {
  background: #2563eb;
  height: 5px;
  width: 58px;
}

/* Resize Left Edge (Width Left / Right) */
.chat-resize-left {
  position: absolute;
  top: 22px;
  left: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
  z-index: 101;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  user-select: none;
}
.chat-resize-left-grip {
  width: 4px;
  height: 44px;
  margin-left: 2px;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.45);
  transition: all 0.15s ease;
}
.chat-resize-left:hover .chat-resize-left-grip {
  background: #2563eb;
  width: 5px;
  height: 58px;
}

/* Chat Header */
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
  border-bottom: 1px solid #e2e8f0;
  user-select: none;
  flex-shrink: 0;
}

.chat-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.chat-head strong {
  color: #0f172a;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.chat-head-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
  padding: 0;
}
.chat-head-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #cbd5e1;
}

.chat-head-back {
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #eff6ff;
  color: #2563eb;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
  user-select: none;
  flex-shrink: 0;
}
.chat-head-back:hover {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.chat-head-back.is-collapsed {
  background: #f8fafc;
  color: #475569;
  border-color: #cbd5e1;
}
.chat-head-back.is-collapsed:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #94a3b8;
}

/* Sidebar collapsed state */
.chat-panel.sidebar-collapsed .chat-channels-sidebar {
  display: none !important;
}
.chat-panel.sidebar-collapsed .chat-content-area {
  width: 100% !important;
  flex: 1 !important;
}

/* 2-Column Body Layout */
.chat-body-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left Sidebar (Channels & DMs) */
.chat-channels-sidebar {
  width: 195px;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 10px 8px;
  user-select: none;
}

.chat-category-title {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px 3px;
  margin-top: 4px;
}

.chat-chan-btn {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.chat-chan-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.chat-chan-btn.active {
  background: #eff6ff;
  color: #2563eb;
  font-weight: 700;
}
.chat-chan-btn.is-locked {
  color: #7c3aed;
}
.chat-chan-btn.is-locked.active {
  background: #f5f3ff;
  color: #6d28d9;
}

.chat-new-dm-btn {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  background: #eff6ff;
  color: #2563eb;
  border: 1px dashed #bfdbfe;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  margin-top: 6px;
}
.chat-new-dm-btn:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

/* User footer in channels sidebar */
.chat-user-footer {
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-user-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #2563eb;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-user-name {
  font-size: 11px;
  font-weight: 700;
  color: #0f172a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-user-role {
  font-size: 9.5px;
  font-weight: 700;
  color: #7c3aed;
}

/* Right Content Area */
.chat-content-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: #ffffff;
}

/* Sub-header inside channel */
.chat-subhead {
  padding: 8px 14px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 11px;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
}

/* In-Chat Search Bar */
.chat-search-bar {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--chat-subhead-bg, #f8fafc);
  border-bottom: 1px solid var(--chat-border, #e2e8f0);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
}
.chat-search-bar.is-active,
.chat-search-bar:not([hidden]) {
  display: flex !important;
}
.chat-search-bar[hidden]:not(.is-active) {
  display: none !important;
}
.chat-search-bar-icon {
  font-size: 13px;
  opacity: 0.6;
  flex-shrink: 0;
}
.chat-search-bar input {
  min-width: 0;
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  background: #ffffff;
  color: #0f172a;
  outline: none;
  transition: border-color 0.15s ease;
}
.chat-search-bar input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.chat-search-bar button {
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
  padding: 4px 6px;
  border-radius: 4px;
}
.chat-search-bar button:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.chat-line.is-hidden-by-search {
  display: none !important;
}
.chat-line.is-search-match {
  box-shadow: 0 0 0 2px #3b82f6 !important;
}

/* Messages Scroll Area */
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 14px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-log::-webkit-scrollbar {
  width: 5px;
}
.chat-log::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

/* Speech Bubbles */
.chat-line {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  background: #f1f5f9;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  align-self: flex-start;
}

.chat-line.mine {
  align-self: flex-end;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1);
}

.chat-line.mine .chat-line-meta {
  color: #cbd5e1;
}

.chat-line.mine small {
  color: #94a3b8;
}

.chat-line-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 10.5px;
  font-weight: 600;
  opacity: 0.85;
}

.chat-line p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-line small {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.72;
}

/* People Picker (DM Start) */
.chat-people {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}
.chat-people button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 6px;
  padding: 10px 12px;
  border: 1px solid #f1f5f9;
  border-radius: 12px;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-people button:hover {
  background: #eff6ff;
  border-color: #dbeafe;
  color: #2563eb;
}

/* Compose bar */
.chat-compose:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid #f1f5f9;
  background: #ffffff;
}

.chat-compose input {
  flex: 1;
  min-width: 0;
  padding: 9px 13px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: all 0.15s ease;
}

.chat-compose input:focus {
  background: #ffffff;
  border-color: #1769ff;
  box-shadow: 0 0 0 3px rgba(23, 105, 255, 0.12);
}

.chat-compose button {
  padding: 9px 15px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #1769ff 0%, #0d52d6 100%);
  color: #ffffff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(23, 105, 255, 0.25);
  transition: all 0.15s ease;
}

.chat-compose button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.chat-compose button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-note {
  margin: 8px 14px;
  color: #64748b;
  font-size: 12px;
  text-align: center;
}

/* Mobile responsive WhatsApp experience (< 900px) */
@media (max-width: 900px) {
  .chat-dock .chat-toggle {
    display: none !important;
  }
  .chat-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    right: 0 !important;
    bottom: 0 !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 99999 !important;
    margin: 0 !important;
  }
  .chat-resize-top,
  .chat-resize-left,
  .chat-resize-handle {
    display: none !important;
  }
  .chat-body-layout.in-channel .chat-channels-sidebar {
    display: none !important;
  }
  .chat-body-layout:not(.in-channel) .chat-content-area {
    display: none !important;
  }
  #chatMaxBtn {
    display: none !important;
  }
  .chat-head {
    padding-top: max(env(safe-area-inset-top, 0px), 18px) !important;
    padding-left: max(env(safe-area-inset-left, 0px), 16px) !important;
    padding-right: max(env(safe-area-inset-right, 0px), 16px) !important;
    padding-bottom: 12px !important;
    min-height: calc(58px + env(safe-area-inset-top, 0px)) !important;
    background: #ffffff !important;
    border-bottom: 1px solid #e2e8f0 !important;
    box-sizing: border-box !important;
  }
  .chat-head-left {
    gap: 12px !important;
    align-items: center !important;
  }
  .chat-head-back {
    padding: 8px 14px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    min-height: 40px !important;
    border-radius: 10px !important;
    background: #eff6ff !important;
    color: #2563eb !important;
    border: 1px solid #bfdbfe !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    cursor: pointer !important;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.12) !important;
    flex-shrink: 0 !important;
  }
  .chat-head-back:active {
    background: #dbeafe !important;
    transform: scale(0.96) !important;
  }
  .chat-head-btn, #chatCloseBtn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    font-size: 18px !important;
    border-radius: 10px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
  }
  .chat-body-layout:not(.in-channel) .chat-channels-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 !important;
  }
  .chat-compose {
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 12px) !important;
    padding-left: max(env(safe-area-inset-left, 0px), 12px) !important;
    padding-right: max(env(safe-area-inset-right, 0px), 12px) !important;
  }
}

/* Dark Mode Overrides */
html[data-theme="dark"] .chat-panel {
  background: #111827;
  border-color: #1f2937;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.6);
}
html[data-theme="dark"] .chat-head {
  background: #111827;
  border-bottom-color: #1f2937;
}
html[data-theme="dark"] .chat-head strong {
  color: #f3f4f6;
}
html[data-theme="dark"] .chat-head-btn {
  background: #1f2937;
  border-color: #374151;
  color: #9ca3af;
}
html[data-theme="dark"] .chat-head-back {
  background: #1e3a8a30;
  color: #60a5fa;
  border-color: #1e40af;
}
html[data-theme="dark"] .chat-head-back:hover {
  background: #1e40af50;
  color: #93c5fd;
}
html[data-theme="dark"] .chat-head-back.is-collapsed {
  background: #1f2937;
  color: #94a3b8;
  border-color: #374151;
}
html[data-theme="dark"] .chat-head-back.is-collapsed:hover {
  background: #374151;
  color: #f1f5f9;
}
html[data-theme="dark"] .chat-resize-top-grip,
html[data-theme="dark"] .chat-resize-left-grip {
  background: rgba(148, 163, 184, 0.25);
}
html[data-theme="dark"] .chat-resize-top:hover .chat-resize-top-grip,
html[data-theme="dark"] .chat-resize-left:hover .chat-resize-left-grip {
  background: #3b82f6;
}
html[data-theme="dark"] .chat-channels-sidebar {
  background: #0f172a;
  border-right-color: #1f2937;
}
html[data-theme="dark"] .chat-chan-btn {
  color: #94a3b8;
}
html[data-theme="dark"] .chat-chan-btn:hover {
  background: #1e293b;
  color: #f1f5f9;
}
html[data-theme="dark"] .chat-chan-btn.active {
  background: #1e3a8a30;
  color: #60a5fa;
}
html[data-theme="dark"] .chat-content-area {
  background: #111827;
}
html[data-theme="dark"] .chat-subhead {
  background: #0f172a;
  border-bottom-color: #1f2937;
  color: #94a3b8;
}
html[data-theme="dark"] .chat-line {
  background: #1f2937;
  color: #f3f4f6;
}
html[data-theme="dark"] .chat-line.mine {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
html[data-theme="dark"] .chat-compose {
  background: #111827;
  border-top-color: #1f2937;
}
html[data-theme="dark"] .chat-compose input {
  background: #1f2937;
  border-color: #374151;
  color: #f3f4f6;
}
html[data-theme="dark"] .chat-people button {
  background: #1f2937;
  border-color: #374151;
  color: #f3f4f6;
}
html[data-theme="dark"] .chat-settings-popover,
html[data-theme="dark"] .chat-attach-menu,
html[data-theme="dark"] .chat-share-modal {
  background: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
  box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.5);
}
html[data-theme="dark"] .chat-attach-item {
  color: #cbd5e1;
}
html[data-theme="dark"] .chat-attach-item:hover {
  background: #334155;
  color: #ffffff;
}
html[data-theme="dark"] .chat-attach-btn {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}
html[data-theme="dark"] .chat-attach-btn:hover {
  background: #334155;
  color: #60a5fa;
}
html[data-theme="dark"] .chat-erp-card {
  background: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}
html[data-theme="dark"] .chat-erp-title {
  color: #f8fafc;
}
html[data-theme="dark"] .chat-erp-meta {
  color: #94a3b8;
}
html[data-theme="dark"] .chat-erp-action-btn {
  background: #1e3a8a40;
  border-color: #3b82f6;
  color: #93c5fd;
}
html[data-theme="dark"] .chat-erp-action-btn:hover {
  background: #1e3a8a80;
  color: #bfdbfe;
}
html[data-theme="dark"] .chat-file-pill {
  background: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}
html[data-theme="dark"] .chat-search-bar-wrap {
  background: #0f172a;
  border-bottom-color: #334155;
}
html[data-theme="dark"] .chat-search-input-box {
  background: #1e293b;
  border-color: #334155;
}
html[data-theme="dark"] .chat-search-input-box input {
  color: #f1f5f9;
}
html[data-theme="dark"] .chat-search-item {
  background: #1e293b;
  border-color: #334155;
}
html[data-theme="dark"] .chat-search-item:hover {
  background: #334155;
}
html[data-theme="dark"] .chat-search-item-title {
  color: #f8fafc;
}
html[data-theme="dark"] .chat-search-item-sub {
  color: #94a3b8;
}
html[data-theme="dark"] .chat-search-go-btn {
  background: #1e293b;
  border-color: #334155;
  color: #cbd5e1;
}
html[data-theme="dark"] .chat-search-go-btn:hover {
  background: #334155;
  color: #ffffff;
}

/* ==========================================================================
   IN-CHAT SETTINGS POPOVER & ATTACHMENT MENU & ERP SMART CARDS
   ========================================================================== */

.chat-head-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
  color: #64748b;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-head-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #cbd5e1;
}

/* Settings Popover */
.chat-settings-popover[hidden] {
  display: none !important;
}
.chat-settings-popover:not([hidden]) {
  position: absolute;
  top: 50px;
  right: 12px;
  width: 300px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 16px 36px -6px rgba(15, 23, 42, 0.22);
  z-index: 200;
  padding: 14px;
  box-sizing: border-box;
  animation: chat-popover-in 0.16s ease-out;
}
@keyframes chat-popover-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e2e8f0;
}
.chat-popover-header strong {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
}
.chat-popover-close {
  background: transparent;
  border: 0;
  color: #94a3b8;
  font-size: 15px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.chat-popover-close:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.chat-room-badge-sec {
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.45;
  color: #475569;
  margin-bottom: 12px;
}
.chat-room-badge-sec strong {
  display: block;
  font-size: 12px;
  color: #0f172a;
  margin-bottom: 2px;
}

.chat-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  border-bottom: 1px solid #f1f5f9;
}

.chat-settings-btn-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #0f172a;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-settings-btn-link:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #2563eb;
}

.chat-clear-history-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #dc2626;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-clear-history-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

/* Attachment Button & Menu */
.chat-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  color: #64748b;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.chat-attach-btn:hover {
  background: #eff6ff;
  color: #2563eb;
  border-color: #bfdbfe;
}

.chat-attach-menu[hidden] {
  display: none !important;
}
.chat-attach-menu:not([hidden]) {
  position: absolute;
  bottom: 58px;
  left: 14px;
  width: 360px;
  max-width: calc(100% - 28px);
  max-height: 440px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 20px 40px -8px rgba(15, 23, 42, 0.28);
  z-index: 200;
  padding: 0;
  box-sizing: border-box;
  animation: chat-popover-in 0.16s ease-out;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Omni Search in Chat Attachment Menu */
.chat-search-bar-wrap {
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-search-input-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 6px 10px;
  transition: all 0.15s ease;
}
.chat-search-input-box:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.chat-search-icon {
  font-size: 13px;
  color: #94a3b8;
  flex-shrink: 0;
}
.chat-search-input-box input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: #0f172a;
  font: inherit;
  font-size: 12.5px;
  min-width: 0;
}
.chat-search-input-box input::placeholder {
  color: #94a3b8;
}
.chat-search-clear-btn {
  background: transparent;
  border: 0;
  color: #94a3b8;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.chat-search-clear-btn:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.chat-search-results-list {
  flex: 1;
  overflow-y: auto;
  max-height: 350px;
  padding: 8px 10px;
}
.chat-search-results-list::-webkit-scrollbar {
  width: 5px;
}
.chat-search-results-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.chat-search-category {
  margin-bottom: 10px;
}
.chat-search-category-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  margin-bottom: 4px;
  padding-left: 4px;
}
.chat-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  margin-bottom: 4px;
  transition: all 0.12s ease;
}
.chat-search-item:hover {
  background: #f1f5f9;
  border-color: #e2e8f0;
}
.chat-search-item-info {
  min-width: 0;
  flex: 1;
}
.chat-search-item-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-search-item-sub {
  font-size: 10.5px;
  color: #64748b;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-search-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.chat-search-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  background: #eff6ff;
  color: #2563eb;
  font: inherit;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
}
.chat-search-share-btn:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}
.chat-search-go-btn {
  display: inline-flex;
  align-items: center;
  padding: 4px 6px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  color: #475569;
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.12s ease;
}
.chat-search-go-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #cbd5e1;
}
.chat-search-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
}

.chat-default-options-wrap {
  padding: 6px;
  overflow-y: auto;
  max-height: 350px;
}

.chat-attach-menu-title {
  padding: 6px 10px 4px;
  font-size: 10.5px;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.chat-attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #1e293b;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}
.chat-attach-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.chat-attach-item .chat-attach-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* ERP Smart Card inside message */
.chat-erp-card {
  display: block;
  margin-top: 6px;
  margin-bottom: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #2563eb;
  color: #0f172a;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.chat-line.mine .chat-erp-card {
  background: #ffffff;
  border-color: rgba(255, 255, 255, 0.7);
  border-left: 4px solid #f59e0b;
  color: #0f172a;
}
.chat-erp-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}
.chat-erp-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 3px;
}
.chat-erp-meta {
  font-size: 11px;
  color: #475569;
  margin-bottom: 8px;
  line-height: 1.4;
}
.chat-erp-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #2563eb;
  background: #eff6ff;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #bfdbfe;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s;
}
.chat-erp-action-btn:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

/* File Previews */
.chat-file-img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  margin-top: 6px;
  cursor: pointer;
  object-fit: cover;
  border: 1px solid rgba(0,0,0,0.1);
  display: block;
}
.chat-file-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
}
.chat-line.mine .chat-file-pill {
  color: #0f172a;
}

/* Mini Share Selector Modal Inside Chat */
.chat-share-modal-backdrop[hidden] {
  display: none !important;
}
.chat-share-modal-backdrop:not([hidden]) {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  animation: chat-popover-in 0.16s ease-out;
}
.chat-share-modal {
  width: 100%;
  max-width: 380px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.35);
  border: 1px solid #e2e8f0;
  padding: 16px;
  box-sizing: border-box;
}
.chat-share-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.chat-share-modal-head strong {
  font-size: 13.5px;
  font-weight: 700;
  color: #0f172a;
}
.chat-share-list {
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.chat-share-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid #f1f5f9;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.chat-share-list button:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #2563eb;
}

/* ==========================================
   ADVANCED CHAT: EDIT, DELETE, ATTACHMENT & VOICE
   ========================================== */
.chat-line {
  position: relative;
}
.chat-line-actions {
  position: absolute;
  top: -12px;
  right: 8px;
  display: none;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  padding: 2px 4px;
  gap: 3px;
  z-index: 20;
}
.chat-line:hover .chat-line-actions {
  display: flex;
}
.chat-msg-action-btn {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 3px 6px;
  font-size: 11.5px;
  border-radius: 5px;
  color: #475569;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
}
.chat-msg-action-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.chat-msg-action-btn.del-btn:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* Editing Banner */
.chat-editing-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  background: #eff6ff;
  border-top: 1px solid #bfdbfe;
  font-size: 11.5px;
  color: #1e40af;
  flex-shrink: 0;
}
.chat-editing-banner[hidden] {
  display: none !important;
}
.chat-editing-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.chat-editing-text small {
  display: block;
  font-weight: 700;
  color: #2563eb;
  font-size: 10px;
}
.chat-editing-orig {
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #334155;
  font-style: italic;
}
.chat-editing-cancel-btn {
  border: 0;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.chat-editing-cancel-btn:hover {
  background: #bfdbfe;
}

/* Pending Attachment Preview */
.chat-pending-attach-wrap {
  padding: 8px 14px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.chat-pending-attach-wrap[hidden] {
  display: none !important;
}
.chat-pending-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.chat-pending-preview {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  overflow: hidden;
  flex-shrink: 0;
}
.chat-pending-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.chat-pending-meta {
  flex: 1;
  min-width: 0;
}
.chat-pending-meta strong {
  display: block;
  font-size: 12px;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-pending-meta span {
  display: block;
  font-size: 10.5px;
  color: #64748b;
}
.chat-pending-cancel {
  border: 0;
  background: #f1f5f9;
  color: #64748b;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 12px;
}
.chat-pending-cancel:hover {
  background: #fef2f2;
  color: #dc2626;
}

/* Voice Message Recording Bar */
.chat-voice-recording-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #fef2f2;
  border-top: 1px solid #fee2e2;
  flex-shrink: 0;
}
.chat-voice-recording-wrap[hidden] {
  display: none !important;
}
.chat-voice-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: voicePulse 1s infinite alternate;
}
@keyframes voicePulse {
  0% { transform: scale(0.85); opacity: 0.5; }
  100% { transform: scale(1.25); opacity: 1; }
}
.chat-voice-cancel-btn {
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 11px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.chat-voice-cancel-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}
.chat-voice-send-btn {
  border: 0;
  background: #ef4444;
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 8px;
}
.chat-voice-send-btn:hover {
  background: #dc2626;
}

/* Voice Message Card inside Chat */
.chat-voice-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  margin: 4px 0;
  min-width: 160px;
}
.chat-line:not(.mine) .chat-voice-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
}
.chat-voice-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: #2563eb;
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}
.chat-voice-play-btn:hover {
  transform: scale(1.08);
}
.chat-line.mine .chat-voice-play-btn {
  background: #ffffff;
  color: #1769ff;
}
.chat-voice-waveform {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 20px;
  flex: 1;
}
.chat-voice-bar {
  width: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.6;
}
.chat-voice-duration {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

/* Add Participant Modal */
.chat-participant-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.chat-participant-modal-backdrop[hidden] {
  display: none !important;
}
.chat-participant-modal {
  width: 100%;
  max-width: 340px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 15px 30px rgba(0,0,0,0.18);
}
.chat-participant-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.chat-participant-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-participant-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.chat-participant-item:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
}
.chat-participant-info {
  display: flex;
  flex-direction: column;
}
.chat-participant-name {
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
}
.chat-participant-role {
  font-size: 10px;
  color: #64748b;
}
.chat-participant-add-btn {
  border: 0;
  background: #2563eb;
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
}
.chat-participant-add-btn:hover {
  background: #1d4ed8;
}

.chat-voice-trigger-btn {
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: all 0.12s ease;
  flex-shrink: 0;
}
.chat-voice-trigger-btn:hover {
  background: #f1f5f9;
  color: #ef4444;
}

/* ==========================================================================
   CENTERED CONFIRMATION & ALERT MODAL (IN-APP DIALOGS)
   ========================================================================== */
.chat-confirm-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999999;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: chatBackdropFade 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.15s ease;
}

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

.chat-confirm-box {
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 24px;
  padding: 28px 24px 22px;
  box-shadow: 0 25px 60px -15px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.04);
  text-align: center;
  position: relative;
  animation: chatModalPop 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
  box-sizing: border-box;
}

@keyframes chatModalPop {
  0% { transform: scale(0.85) translateY(12px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.chat-confirm-icon-wrap {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.chat-confirm-icon-wrap.danger {
  background: #fef2f2;
  color: #dc2626;
  border: 2px solid #fee2e2;
  box-shadow: 0 8px 20px rgba(239, 68, 68, 0.15);
}

.chat-confirm-icon-wrap.warning {
  background: #fffbeb;
  color: #d97706;
  border: 2px solid #fef3c7;
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.15);
}

.chat-confirm-title {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 8px;
  letter-spacing: -0.3px;
}

.chat-confirm-desc {
  font-size: 13.5px;
  color: #64748b;
  line-height: 1.5;
  margin: 0 0 16px;
}

.chat-confirm-snippet {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 12.5px;
  color: #475569;
  font-style: italic;
  margin: 0 0 20px;
  max-height: 80px;
  overflow-y: auto;
  text-align: left;
  line-height: 1.45;
  word-break: break-word;
}

.chat-confirm-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-confirm-btn {
  flex: 1;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.16s ease;
  font-family: inherit;
}

.chat-confirm-btn.cancel {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}
.chat-confirm-btn.cancel:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.chat-confirm-btn.confirm.danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}
.chat-confirm-btn.confirm.danger:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.45);
  transform: translateY(-1px);
}

.chat-confirm-btn.confirm.primary {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.chat-confirm-btn.confirm.primary:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  transform: translateY(-1px);
}

/* ==========================================================================
   TRASH CAN / PAPER CRUMBLE VORTEX ANIMATION FOR DELETED MESSAGES
   ========================================================================== */
@keyframes trashVortexSuck {
  0% {
    transform: scale(1) translateY(0) rotate(0deg);
    opacity: 1;
    filter: brightness(1);
  }
  18% {
    transform: scale(1.03) translateY(-6px) rotate(-1.5deg);
    background: #fee2e2 !important;
    border-color: #fca5a5 !important;
    color: #991b1b !important;
    box-shadow: 0 10px 25px -4px rgba(239, 68, 68, 0.35);
  }
  40% {
    transform: scale(0.9) translateY(10px) rotate(4deg);
    opacity: 0.92;
    background: #fecaca !important;
  }
  65% {
    transform: scale(0.5) translateY(32px) rotate(-12deg);
    opacity: 0.55;
    filter: blur(0.5px);
  }
  88% {
    transform: scale(0.18) translateY(55px) rotate(22deg);
    opacity: 0.2;
    filter: blur(1.5px);
  }
  100% {
    transform: scale(0) translateY(75px) rotate(35deg);
    opacity: 0;
    max-height: 0;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    border: 0 !important;
  }
}

.chat-line.is-deleting {
  animation: trashVortexSuck 0.52s cubic-bezier(0.22, 1, 0.36, 1) forwards !important;
  pointer-events: none !important;
  overflow: hidden !important;
}

.chat-trash-vortex-icon {
  position: absolute;
  bottom: -18px;
  right: 18px;
  font-size: 26px;
  z-index: 60;
  pointer-events: none;
  animation: trashCanPop 0.52s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes trashCanPop {
  0% { transform: scale(0) translateY(15px); opacity: 0; }
  25% { transform: scale(1.35) translateY(-2px); opacity: 1; }
  65% { transform: scale(1.1) translateY(4px); opacity: 1; }
  90% { transform: scale(0.7) translateY(12px); opacity: 0.4; }
  100% { transform: scale(0) translateY(20px); opacity: 0; }
}

/* ==========================================================================
   SLEEK TOAST NOTIFICATION SYSTEM
   ========================================================================== */
.chat-toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  align-items: center;
}

.chat-toast {
  pointer-events: auto;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 25px -4px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.08);
  animation: chatToastIn 0.26s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.22s ease;
  cursor: pointer;
  max-width: 90vw;
  box-sizing: border-box;
}

.chat-toast.out {
  opacity: 0;
  transform: translateY(-8px) scale(0.94);
}

.chat-toast.success {
  border-left: 3.5px solid #22c55e;
}
.chat-toast.warning {
  border-left: 3.5px solid #f59e0b;
}
.chat-toast.error {
  border-left: 3.5px solid #ef4444;
}
.chat-toast.info {
  border-left: 3.5px solid #3b82f6;
}

.chat-toast-icon {
  font-size: 15px;
  flex-shrink: 0;
}
.chat-toast-text {
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes chatToastIn {
  0% { transform: translateY(-16px) scale(0.92); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@media print {
  .chat-dock {
    display: none !important;
  }
}

/* ==============================================================================
   SMART RECEIPT & ORDER CARDS, VIDEO & WEBRTC VOICE CALL OVERLAYS
   ============================================================================== */
.chat-file-video {
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  margin-top: 6px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  display: block;
}

.chat-receipt-chip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #cbd5e1;
  border-left: 4px solid #0284c7;
  border-radius: 10px;
  text-decoration: none;
  color: #0f172a;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
  transition: all 0.16s ease;
  cursor: pointer;
}
.chat-receipt-chip:hover {
  transform: translateY(-1px);
  border-color: #0284c7;
  box-shadow: 0 6px 16px rgba(2, 132, 199, 0.12);
}
.chat-receipt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-receipt-no {
  font-weight: 700;
  font-size: 13px;
  color: #0369a1;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-receipt-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}
.chat-receipt-badge.approved, .chat-receipt-badge.completed, .chat-receipt-badge.delivered {
  background: #dcfce7;
  color: #15803d;
}
.chat-receipt-badge.pending, .chat-receipt-badge.in_transit, .chat-receipt-badge.draft {
  background: #fef3c7;
  color: #b45309;
}
.chat-receipt-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: #475569;
}
.chat-receipt-amount {
  font-weight: 700;
  font-size: 13px;
  color: #0f172a;
}

/* Voice Call Overlay Modal */
.chat-call-overlay[hidden] {
  display: none !important;
}
.chat-call-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  animation: chat-popover-in 0.2s ease-out;
  color: #ffffff;
}
.chat-call-avatar-wrap {
  position: relative;
  width: 90px;
  height: 90px;
  margin-bottom: 16px;
}
.chat-call-avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.4);
}
.chat-call-pulse {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(59, 130, 246, 0.6);
  animation: chatCallPulse 1.8s infinite;
}
@keyframes chatCallPulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}
.chat-call-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.chat-call-status {
  font-size: 12.5px;
  color: #94a3b8;
  margin-top: 4px;
}
.chat-call-timer {
  font-size: 14px;
  font-family: monospace;
  font-weight: 600;
  color: #38bdf8;
  margin-top: 10px;
}
.chat-call-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 28px;
}
.chat-call-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-call-btn.end {
  background: #ef4444;
  color: #ffffff;
}
.chat-call-btn.end:hover {
  background: #dc2626;
  transform: scale(1.05);
}
.chat-call-btn.mute {
  background: #334155;
  color: #ffffff;
}
.chat-call-btn.mute:hover {
  background: #475569;
}
.chat-call-btn.mute.is-muted {
  background: #f59e0b;
}
.chat-call-btn.answer {
  background: #16a34a;
  color: #ffffff;
  font-size: 22px;
  font-weight: 700;
}
.chat-call-btn.answer:hover {
  background: #15803d;
  transform: scale(1.05);
}
