.chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    sans-serif;
}

.chat-wrapper {
  z-index: 9998;
}

.chat-window {
  display: none;
  flex-direction: column;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 500px;
  max-height: calc(100vh - 100px);
  background: var(--color-cream);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  margin-bottom: 16px;
}

.chat-window.open {
  display: flex;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(
    135deg,
    var(--color-primary) 0%,
    var(--color-primary-dark) 100%
  );
  color: white;
}

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

.chat-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-avatar svg {
  width: 24px;
  height: 24px;
  color: white;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
}

.chat-close-btn {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-close-btn svg {
  width: 20px;
  height: 20px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--color-cream);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-welcome {
  text-align: center;
  padding: 20px;
  color: var(--color-dark);
  font-size: 14px;
}

.chat-message-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
}

.chat-message-wrapper.visitor {
  justify-content: flex-end;
}

.chat-message-wrapper.operator {
  justify-content: flex-start;
}

.chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  align-self: flex-start;
}

.chat-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-sender-name {
  font-size: 11px;
  color: var(--color-dark);
  opacity: 0.7;
  font-weight: 500;
  margin-left: 4px;
}

.chat-message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease-out;
}

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

.chat-message.visitor {
  align-self: flex-end;
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.operator {
  align-self: flex-start;
  background: white;
  color: var(--color-dark);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px var(--color-dark-10);
}

.chat-message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  display: block;
}

.chat-input-container {
  padding: 16px;
  background: white;
  border-top: 1px solid var(--color-cream);
}

.chat-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.chat-typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.chat-typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.chat-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

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

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
  font-family: inherit;
}

.chat-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(85, 14, 5, 0.1);
}

.chat-input::placeholder {
  color: #999;
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  background: var(--color-primary);
  border: none;
  border-radius: 50%;
  color: var(--color-cream);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s,
    transform 0.2s;
  flex-shrink: 0;
  padding: 0;
  box-shadow: none;
  text-transform: none;
  letter-spacing: normal;
}

.chat-send-btn:hover {
  background: var(--color-primary-dark);
  transform: scale(1.05);
  box-shadow: none;
}

.chat-send-btn:disabled {
  background: var(--color-dark);
  cursor: not-allowed;
  transform: none;
}

.chat-send-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Both toggles: smaller icons, border, only icon on load, text on hover */
.messengers-wrapper .messengers-toggle .video-holder {
  width: 64px;
  height: 64px;
  border: 2px solid white;
  box-sizing: border-box;
}

.messengers-wrapper .messengers-toggle .video-holder img {
  width: 64px;
  height: 64px;
}

.messengers-wrapper .messengers-toggle:not(.opened) > .text-block {
  transform: scale(0);
}

.messengers-wrapper .messengers-toggle:not(.opened):hover > .text-block {
  transform: scale(1);
}

/* Peek: show text for 5s on scroll/timer */
.messengers-wrapper .messengers-toggle:not(.opened).peek > .text-block {
  transform: scale(1);
}

/* Chat wrapper - right-side mirror of messengers-wrapper */
.messengers-wrapper.chat-wrapper {
  left: auto;
  right: var(--blockLeftIndent);
}

.chat-wrapper .messengers-toggle {
  align-items: flex-end;
}

.chat-wrapper .messengers-toggle .video-holder {
  margin-left: 0;
  margin-right: 25px;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.chat-wrapper .messengers-toggle .video-holder img {
  width: 32px;
  height: 32px;
  border-radius: 0;
  filter: brightness(0) invert(1);
}

.chat-wrapper .messengers-toggle > .text-block {
  transform-origin: right bottom;
}

/* Arrow pointing left */
.chat-wrapper .messengers-toggle .text-block .icon-arrow-right::before {
  left: auto;
  right: 50px;
  transform: rotate(-45deg);
}

.chat-wrapper .messengers-toggle .text-block .icon-arrow-right::after {
  left: auto;
  right: 25px;
}

.chat-wrapper .messengers-toggle.opened .video-holder {
  margin-right: 0;
}

.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: #e53935;
  color: white;
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  z-index: 2;
}

@media (max-width: 480px) {
  .chat-widget {
    bottom: 0;
    right: 0;
  }

  .chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    margin-bottom: 0;
  }

  .chat-messages {
    padding: 12px;
  }

  .chat-input-container {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .chat-input {
    font-size: 16px;
  }
}
