/* System note inline in the conversation — e.g. "visitor set their name".
   Plain centered text, smaller and more muted than a real message, no
   bubble background. */
.chat-system-note {
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.75;
  line-height: 1.4;
  padding: 0 8px;
}

/* Floating Chat Button */
.chat-toggle-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(21, 37, 55, 0.35);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transition: var(--transition-smooth);
  animation: pulse-glow 2s infinite;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.chat-toggle-btn:hover {
  transform: translateY(-3px) scale(1.05);
  background: rgba(21, 37, 55, 0.55);
  border-color: rgba(255, 255, 255, 0.15);
}

.chat-toggle-btn:active {
  transform: translateY(-1px) scale(0.98);
}

.chat-toggle-btn.active {
  animation: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* Unread-message counter on the floating toggle button — same red-pill
   treatment as admin's chat-tab badge, shown only while the widget is
   closed. Positioned via fixed coordinates (not nested inside the button)
   since the button clips overflow for its logo/close icon crossfade. */
.chat-toggle-badge {
  position: fixed;
  bottom: 74px;
  right: 27px;
  /* Same stacking as the toggle button itself (999) — below the lead-form
     modal overlay (1000), so it doesn't float on top of it. */
  z-index: 999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
  transition: var(--transition-fast);
}

.chat-toggle-badge.visible {
  opacity: 1;
  transform: scale(1);
}

@keyframes pulse-glow {
  0% {
    box-shadow: 0 0 0 0 rgba(97, 117, 162, 0.5);
  }
  70% {
    box-shadow: 0 0 0 15px rgba(97, 117, 162, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(97, 117, 162, 0);
  }
}

.chat-toggle-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  transition: var(--transition-smooth);
}

.chat-toggle-close {
  position: absolute;
  color: var(--text-white);
  transform: scale(0);
  opacity: 0;
  transition: var(--transition-smooth);
}

.chat-toggle-btn.active .chat-toggle-logo {
  transform: scale(0);
  opacity: 0;
}

.chat-toggle-btn.active .chat-toggle-close {
  transform: scale(1);
  opacity: 1;
}

/* Chat Widget Window */
.chat-widget {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 360px;
  height: 480px;
  max-height: calc(100vh - 140px);
  border-radius: 8px;
  background: rgba(21, 37, 55, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  z-index: 998;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: var(--transition-smooth);
  overflow: hidden;
}

.chat-widget.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Chat Header */
.chat-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #152537 0%, #1A2C42 100%);
  border-bottom: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 50%;
  padding: 2px;
}

.chat-header-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-white);
  line-height: 1.2;
}

.chat-status-container {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
  0% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.5;
  }
}

.chat-status-text {
  font-size: 0.75rem;
  color: var(--accent-cyan);
}

.chat-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: var(--transition-fast);
}

.chat-close-btn:hover {
  color: var(--text-white);
}

/* Chat Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar for Chat */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Message Bubbles */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.agent {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-white);
  border-top-left-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.chat-msg.agent a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition-fast);
}

.chat-msg.agent a:hover {
  text-decoration: underline;
  color: var(--accent-blue);
}

/* Engagement-injected message: slight accent highlight */
.chat-msg.agent.eng-injected {
  border-left: 3px solid var(--accent-cyan);
  padding-left: 13px;
}

.chat-msg.agent.eng-injected strong {
  color: var(--accent-cyan);
  font-size: 0.8rem;
  display: block;
  margin-bottom: 4px;
}

/* Which operator replied — the client only ever sees their position (e.g.
   "Менеджер"), never their name; same treatment as the engagement-message
   label above. */
.chat-msg-operator-position {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 4px;
  opacity: 0.85;
}


.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: var(--text-dark);
  font-weight: 500;
  border-top-right-radius: 2px;
}

.chat-msg-img {
  display: block;
  max-width: 220px;
  max-height: 180px;
  min-width: 120px;
  min-height: 90px;
  margin-top: 6px;
  border-radius: 6px;
  cursor: zoom-in;
  background: rgba(255, 255, 255, 0.06);
}

/* Image-only message: no text, so the padded "bubble" look isn't needed —
   the image fills the whole rounded shape edge to edge. */
.chat-msg.img-only {
  /* No overflow:hidden here: on a flex column item, it broke this
     container's height to 0 (a flex intrinsic-sizing quirk), letting later
     messages overlap it. Corner-rounding is done on the <img> itself
     instead (border-radius:inherit below), which doesn't need clipping. */
  padding: 0;
  line-height: 0;
  border: none;
  /* A small guaranteed gap before the input row's divider — the container's
     own bottom padding can end up looking flush when this is the last
     message, so give the image itself a bit of breathing room too. */
  margin-bottom: 6px;
}
.chat-msg.img-only .chat-msg-img {
  width: 260px;
  height: 200px;
  max-width: 100%;
  max-height: none;
  margin-top: 0;
  border-radius: inherit;
  object-fit: cover;
}

.chat-msg-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.85rem;
}

/* Chat Typing Indicator */
.chat-msg.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border-top-left-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.chat-msg.typing .dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.chat-msg.typing .dot:nth-child(1) {
  animation-delay: -0.32s;
}

.chat-msg.typing .dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* Chat Input Area */
.chat-input-container {
  padding: 14px 16px;
  background: rgba(8, 33, 66, 0.2);
  border-top: 1px solid var(--border-card);
  display: flex;
  gap: 8px;
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  color: var(--text-white);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-fast);
}

.chat-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(97, 117, 162, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-dark);
  transition: var(--transition-fast);
}

.chat-send-btn:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

.chat-send-btn:active {
  transform: scale(0.95);
}

/* Input field wrapper — holds emoji + attach icon buttons and the text
   input together inside one bordered pill, mirroring admin's chat input. */
.chat-input-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  position: relative;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0 4px;
  transition: var(--transition-fast);
}

.chat-input-field:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(97, 117, 162, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

.chat-input-field .chat-input {
  background: none;
  border: none;
  padding: 10px 6px;
}

.chat-input-field .chat-input:focus {
  border: none;
  box-shadow: none;
  background: none;
}

.chat-input-icon-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
}

.chat-input-icon-btn:hover {
  color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.06);
}

/* Emoji picker dropdown */
/* Bigger, tabbed picker — same categories/behavior as admin's chat emoji
   picker, just themed for the public site. */
.chat-emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 320px;
  padding: 8px;
  background: rgba(21, 37, 55, 0.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 5;
}

.chat-emoji-picker.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.chat-emoji-tabs-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-card);
  padding-bottom: 6px;
  margin-bottom: 6px;
}

.chat-emoji-tab-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 4px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.chat-emoji-tab-btn.active {
  color: var(--accent-cyan);
}

.chat-emoji-tabs-line {
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -1px;
  height: 2px;
  background: var(--accent-gradient);
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1), right 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.chat-emoji-tabs-line.no-transition {
  transition: none !important;
}

.chat-emoji-scroll-container {
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
}

.chat-emoji-category-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}

.chat-emoji-option {
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.chat-emoji-option:hover {
  transform: scale(1.2);
  background: rgba(255, 255, 255, 0.08);
}

/* Pending attachment preview strip — sits above the input row */
.chat-attach-preview {
  display: none;
  padding: 0 16px;
  gap: 8px;
}

.chat-attach-preview.visible {
  display: flex;
}

.chat-attach-item {
  position: relative;
  margin-top: 10px;
  margin-bottom: 10px;
}

.chat-attach-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-card);
  display: block;
}

.chat-attach-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(21, 37, 55, 0.95);
  border: 1px solid var(--border-card);
  color: var(--text-white);
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.chat-attach-remove:hover {
  color: var(--accent-cyan);
}

/* New-message badge — shown when the visitor has scrolled up and a new
   agent message arrives at the bottom; click (or scrolling to bottom
   themselves) dismisses it. */
.chat-new-msg-badge {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%) translateY(6px);
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-gradient);
  color: var(--text-dark);
  border: none;
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-fast);
  z-index: 6;
}

.chat-new-msg-badge.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: all;
}

.chat-new-msg-badge:hover {
  transform: translateX(-50%) translateY(-2px);
}

.chat-new-msg-badge-count {
  min-width: 14px;
  text-align: center;
}

/* Pre-chat name form — overlays the input area */
.chat-prechat {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 14px;
  background: rgba(21, 37, 55, 0.97);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255,255,255,0.1);
  z-index: 10;
  animation: slideUpFade 0.2s ease;
}
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-prechat-label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  margin-bottom: 8px;
}
.chat-prechat-form {
  display: flex;
  gap: 8px;
}
.chat-prechat-input {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.chat-prechat-input:focus { border-color: rgba(255,255,255,0.45); }
.chat-prechat-input::placeholder { color: rgba(255,255,255,0.3); }
.chat-prechat-btn {
  background: rgba(97,117,162,0.85);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.chat-prechat-btn:hover { background: rgba(97,117,162,1); }

/* Outside-hours callback area — takes over the exact same slot as
   .chat-input-container (same padding/border-top) instead of stacking
   another block above the messages, since it's meant to fully stand in for
   the text input + send/emoji/attach buttons while nobody's there to
   answer them. One state (CTA button / name+phone form / thanks note) at a
   time — see renderOfflineCta/renderOfflineForm/submitOfflineForm in
   chat.js, which replace this container's content wholesale rather than
   toggling several always-mounted pieces, so there's never more than one
   message shown here at once. */
.chat-offline-area {
  padding: 14px 16px;
  background: rgba(8, 33, 66, 0.2);
  border-top: 1px solid var(--border-card);
  animation: slideUpFade 0.2s ease;
}
.chat-offline-cta-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(97, 117, 162, 0.85);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 11px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-offline-cta-btn:hover { background: rgba(97,117,162,1); }
.chat-offline-form-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-offline-form-input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  color: #fff;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.chat-offline-form-input:focus { border-color: rgba(255,255,255,0.45); }
.chat-offline-form-input::placeholder { color: rgba(255,255,255,0.3); }
.chat-offline-form-submit {
  background: rgba(97,117,162,0.85);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-offline-form-submit:hover { background: rgba(97,117,162,1); }
.chat-offline-thanks {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.85);
  text-align: center;
  margin: 0;
  line-height: 1.4;
}

/* Mobile adjustments */
@media (max-width: 576px) {
  .chat-toggle-btn {
    bottom: 20px;
    right: 20px;
    width: 54px;
    height: 54px;
  }
  
  .chat-toggle-logo {
    width: 28px;
    height: 28px;
  }

  .chat-widget {
    bottom: 85px;
    right: 16px;
    left: 16px;
    width: auto;
    height: 400px;
    max-height: calc(100vh - 120px);
  }
}
