/* ========================================
   CHAT-WIDGET.CSS — AI Chat Widget Styles
   Soft UI Evolution — Медведь'Ма
   ======================================== */

/* === Chat Bubble Button === */
.chat-widget-bubble {
  display: none; /* Hidden — replaced by FAB container */
}

/* === Chat Window — opens upward from FAB === */
.chat-widget-window {
  position: fixed;
  bottom: calc(
    var(--bottom-nav-height, 60px) + env(safe-area-inset-bottom, 0px) + 80px
  );
  right: 16px;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - var(--bottom-nav-height, 60px) - 100px);
  background: var(--color-bg, #faf7f2);
  border-radius: 20px;
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.15),
    0 4px 12px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: var(--font-body, "Nunito", sans-serif);
}

.chat-widget-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* === Chat Header === */
.chat-widget-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(
    135deg,
    var(--color-primary),
    var(--color-primary-dark)
  );
  color: #fff;
  flex-shrink: 0;
}

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

.chat-widget-close {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
  padding: 0;
}

.chat-widget-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chat-widget-close svg {
  width: 16px;
  height: 16px;
}

.chat-widget-header-info h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-heading, "Cormorant Garamond", serif);
  letter-spacing: 0.3px;
}

.chat-widget-header-info p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.85;
}

.chat-widget-header-status {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

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

.chat-widget-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-widget-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
  background: var(--color-border, #e0d6cc);
  border-radius: 4px;
}

/* Message bubble */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: chatMsgAppear 0.3s ease-out;
}

.chat-msg.bot {
  align-self: flex-start;
  background: var(--color-bg-card, #fff);
  color: var(--color-text, #2c2017);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(
    135deg,
    var(--color-primary),
    var(--color-primary-dark)
  );
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.bot .chat-msg-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 2px;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--color-bg-card, #fff);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted, #9e9186);
  animation: chatTypingDot 1.2s ease-in-out infinite;
}

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

/* Quick replies */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  flex-shrink: 0;
}

.chat-quick-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--color-border, #e0d6cc);
  background: var(--color-bg-card, #fff);
  color: var(--color-primary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body, "Nunito", sans-serif);
  white-space: nowrap;
}

.chat-quick-btn:hover {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* === Chat Input Area === */
.chat-widget-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--color-border-light, #f0ebe5);
  background: var(--color-bg-card, #fff);
  flex-shrink: 0;
}

.chat-widget-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border, #e0d6cc);
  border-radius: 24px;
  font-size: 16px; /* 16px предотвращает авто-зум на iOS/Android */
  font-family: var(--font-body, "Nunito", sans-serif);
  background: var(--color-bg, #faf7f2);
  color: var(--color-text, #2c2017);
  outline: none;
  transition: border-color 0.2s;
  min-height: 42px;
  resize: none;
  line-height: 1.4;
}

.chat-widget-input:focus {
  border-color: var(--color-primary);
}

.chat-widget-input::placeholder {
  color: var(--color-text-muted, #9e9186);
}

.chat-widget-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(
    135deg,
    var(--color-primary),
    var(--color-primary-dark)
  );
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.2s,
    opacity 0.2s;
  flex-shrink: 0;
}

.chat-widget-send:hover {
  transform: scale(1.05);
}

.chat-widget-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-widget-send svg {
  width: 18px;
  height: 18px;
}

/* === Powered by === */
.chat-widget-footer {
  text-align: center;
  padding: 6px;
  font-size: 10px;
  color: var(--color-text-muted, #9e9186);
  background: var(--color-bg-card, #fff);
}

/* === Proactive Greeting Bubble === */
.proactive-greeting {
  position: fixed;
  bottom: calc(
    var(--bottom-nav-height, 0px) + var(--safe-area-bottom, 0px) + 80px
  );
  right: 16px;
  z-index: 899;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 320px;
  padding: 14px 16px;
  padding-right: 32px;
  background: var(--color-bg-card, #fff);
  border-radius: 16px 16px 4px 16px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(123, 94, 70, 0.12);
  cursor: pointer;
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.proactive-greeting.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.proactive-greeting.hiding {
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  transition: all 0.3s ease;
  pointer-events: none;
}
.proactive-greeting-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--color-text-muted, #9e9186);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}
.proactive-greeting-close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text, #3d3229);
}
.proactive-greeting-avatar {
  font-size: 1.8rem;
  flex-shrink: 0;
  line-height: 1;
}
.proactive-greeting-name {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--color-primary, #7b5e46);
  margin-bottom: 2px;
}
.proactive-greeting-text {
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--color-text, #3d3229);
}
.proactive-greeting-body:hover .proactive-greeting-text {
  color: var(--color-primary, #7b5e46);
}

/* Tail / triangle */
.proactive-greeting::after {
  content: "";
  position: absolute;
  bottom: -8px;
  right: 24px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--color-bg-card, #fff);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.06));
}

@media (max-width: 480px) {
  .proactive-greeting {
    right: 10px;
    left: 10px;
    max-width: none;
    bottom: calc(
      var(--bottom-nav-height, 56px) + var(--safe-area-bottom, 0px) + 78px
    );
  }
}

/* === Animations === */
@keyframes chatBubblePulse {
  0%,
  100% {
    box-shadow:
      0 4px 15px rgba(123, 94, 70, 0.35),
      0 2px 6px rgba(0, 0, 0, 0.1);
  }
  50% {
    box-shadow:
      0 4px 25px rgba(123, 94, 70, 0.5),
      0 2px 10px rgba(0, 0, 0, 0.15);
  }
}

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

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

/* === Mobile Fullscreen === */
@media (max-width: 480px) {
  .chat-widget-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    transform-origin: bottom center;
  }

  .chat-widget-window.open {
    display: flex;
    flex-direction: column;
  }

  .chat-widget-header {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top));
    flex-shrink: 0;
  }

  .chat-widget-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

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

  .chat-quick-btn {
    font-size: 12px;
    padding: 5px 12px;
  }
}

@media (min-width: 1025px) {
  .chat-widget-window {
    bottom: 90px;
    max-height: calc(100vh - 120px);
  }
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  .chat-widget-bubble {
    animation: none;
  }

  .chat-widget-window {
    transition-duration: 0.15s;
  }

  .chat-msg {
    animation: none;
  }

  .chat-typing span {
    animation: none;
    opacity: 0.6;
  }
}
