/* Popup чата по лиду — premium CRM chat panel (Intercom / Linear / Telegram Desktop feel) */
/* z-index > callback call overlay (9999): chat opened from call must stack on top */
.chat-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 10040;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.chat-popup-overlay.is-open {
  display: flex;
}
.chat-popup {
  width: 90%;
  max-width: 440px;
  height: 88vh;
  max-height: 88vh;
  min-height: 420px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 1px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- 1. HEADER: premium chat-bar ---------- */
.chat-popup-header {
  flex-shrink: 0;
  height: 64px;
  min-height: 64px;
  padding: 0 48px 0 20px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}
.chat-popup-title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.chat-popup-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: #6b7280;
  margin: 4px 0 0 0;
  line-height: 1.3;
  display: inline-block;
  padding: 2px 8px;
  background: #f3f4f6;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: none;
}
.chat-popup-close {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.chat-popup-close:hover {
  background: #f3f4f6;
  color: #111827;
}
.chat-tab-btn {
  padding: 1px 8px;
  border-radius: 10px;
  border: 1px solid #2AABEE;
  background: #e8f6ff;
  color: #2AABEE;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
}
.chat-tab-btn.active {
  background: #2AABEE;
  color: #fff;
  border-color: #2AABEE;
}
.chat-tab-btn[data-channel="max"].active {
  background: #0088cc;
  border-color: #0088cc;
}

.msg-channel-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.3px;
}

.msg-channel-badge--max {
  background: #0088cc;
  color: #fff;
}

.msg-channel-badge--tg {
  background: #2AABEE;
  color: #fff;
}

#chat-channel-hint {
  text-align: center;
  font-size: 11px;
  color: #999;
  padding: 6px 0 12px;
  margin-top: -4px;
  display: none;
}

/* ---------- 2. CHAT BACKGROUND: soft canvas ---------- */
.chat-popup-messages {
  flex: 1;
  min-height: 260px;
  overflow-y: auto;
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  background-image: linear-gradient(180deg, #fafbfc 0%, #f8fafc 100%);
}
.chat-popup-messages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-day-divider {
  align-self: center;
  font-size: 11px;
  font-weight: 500;
  color: #64748b;
  margin: 10px 0 6px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  letter-spacing: 0.02em;
}
.chat-popup-loading,
.chat-popup-empty,
.chat-popup-no-chat,
.chat-popup-error {
  text-align: center;
  color: #64748b;
  font-size: 14px;
  padding: 24px 16px;
}
.chat-popup-error {
  color: #dc2626;
}

/* ---------- 3. MESSAGE BUBBLES ---------- */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.chat-msg.inbound {
  align-self: flex-start;
}
.chat-msg.outbound {
  align-self: flex-end;
}
.chat-msg-bubble {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 6px 10px;
  padding: 12px 14px 10px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  transition: box-shadow 0.15s ease;
}
.chat-msg-body {
  flex: 1 1 100%;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.chat-msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: 1 1 100%;
  margin-top: 2px;
}
.chat-msg-bubble .chat-msg-time {
  font-size: 11px;
  opacity: 0.9;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
}
.chat-msg-delivery {
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.95;
  letter-spacing: -0.06em;
}
.chat-msg.outbound .chat-msg-delivery--sent {
  color: rgba(255, 255, 255, 0.75);
}
.chat-msg.outbound .chat-msg-delivery--delivered {
  color: rgba(255, 255, 255, 0.95);
}
.chat-msg.outbound .chat-msg-delivery--queued {
  color: rgba(255, 255, 255, 0.65);
  font-size: 11px;
}
.chat-msg.outbound .chat-msg-delivery--failed {
  color: #fecaca;
  font-weight: 700;
}
/* Неуспешная отправка: не как обычный outbound */
.chat-msg.outbound .chat-msg-bubble--failed {
  background: #fef2f2;
  color: #7f1d1d;
  border: 1px solid #fecaca;
  box-shadow: 0 1px 3px rgba(127, 29, 29, 0.08);
}
.chat-msg.outbound .chat-msg-bubble--failed .chat-msg-time {
  color: #991b1b;
  opacity: 0.9;
}
.chat-msg.outbound .chat-msg-bubble--failed .chat-msg-delivery--failed {
  color: #b91c1c;
}
.chat-msg-error-detail {
  flex: 1 1 100%;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(185, 28, 28, 0.25);
  font-size: 12px;
  line-height: 1.4;
  font-weight: 500;
  color: #b91c1c;
}
.chat-msg.inbound .chat-msg-bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.chat-msg.inbound .chat-msg-bubble .chat-msg-time {
  color: #6b7280;
}
.chat-msg.outbound .chat-msg-bubble {
  background: #0ea5e9;
  color: #fff;
  border: none;
  border-bottom-right-radius: 6px;
  box-shadow: 0 1px 3px rgba(14, 165, 233, 0.25);
}
.chat-msg.outbound .chat-msg-bubble .chat-msg-time {
  color: rgba(255, 255, 255, 0.88);
}

/* ---------- 4. TIME / GROUPING — already in bubbles and divider above ---------- */

/* ---------- 5. INPUT BAR: composer ---------- */
.chat-popup-input-wrap {
  flex-shrink: 0;
  padding: 12px 14px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-popup-input {
  flex: 1;
  min-height: 42px;
  max-height: 60px;
  padding: 10px 16px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  font-family: inherit;
  resize: none;
  overflow-y: auto;
  background: #f8fafc;
  color: #111827;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.chat-popup-input::placeholder {
  color: #9ca3af;
}
.chat-popup-input:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
  background: #fff;
}
.chat-popup-input:disabled {
  background: #f1f5f9;
  cursor: not-allowed;
  color: #94a3b8;
}
.chat-popup-send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0ea5e9;
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(14, 165, 233, 0.2);
  transition: background 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
}
.chat-popup-send .chat-popup-send-ico {
  display: block;
}
.chat-popup-send:hover:not(:disabled) {
  background: #0284c7;
  box-shadow: 0 2px 6px rgba(14, 165, 233, 0.3);
}
.chat-popup-send:active:not(:disabled) {
  transform: scale(0.97);
}
.chat-popup-send:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

/* ---------- 6. POLISH: scroll, spacing ---------- */
.chat-popup-messages {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
}
.chat-popup-messages::-webkit-scrollbar {
  width: 8px;
}
.chat-popup-messages::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}
.chat-popup-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.chat-popup-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

@media (max-width: 768px) {
  .chat-popup {
    height: 92vh;
    max-height: 92vh;
    width: 100%;
    border-radius: 16px 16px 0 0;
    min-height: 380px;
  }
  .chat-popup-messages {
    min-height: 220px;
  }
}
