/* ============================================
   Betki AI Chat Widget
   ============================================ */

/* Container */
.betki-chat {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 9999;
  font-family: var(--font-family);
}

/* Toggle Button */
.betki-chat__toggle {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: var(--color-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 113, 227, 0.4);
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.betki-chat__toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 113, 227, 0.5);
}

.betki-chat__toggle svg {
  width: 26px;
  height: 26px;
}

.betki-chat__icon-close {
  display: none;
}

.betki-chat--open .betki-chat__icon-open {
  display: none;
}

.betki-chat--open .betki-chat__icon-close {
  display: block;
}

/* Info label next to toggle */
.betki-chat__label {
  position: absolute;
  right: 66px;
  bottom: 10px;
  background: var(--color-white);
  color: var(--color-heading);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(0, 0, 0, 0.06);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  opacity: 1;
  transform: translateX(0);
  transition: opacity var(--transition-base), transform var(--transition-base);
  pointer-events: none;
}

.betki-chat__label::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: var(--color-white);
  border-right: 0;
}

.betki-chat--open .betki-chat__label {
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
}

/* Pulse animation on load */
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(0, 113, 227, 0.4); }
  50% { box-shadow: 0 4px 20px rgba(0, 113, 227, 0.6), 0 0 0 8px rgba(0, 113, 227, 0.1); }
}

.betki-chat__toggle {
  animation: chat-pulse 3s ease-in-out 4s 3;
}

/* Chat Panel */
.betki-chat__panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: min(520px, 50vw);
  max-height: min(680px, 75vh);
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.95);
  transition: opacity var(--transition-base), transform var(--transition-spring);
  pointer-events: none;
}

.betki-chat--open .betki-chat__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.betki-chat__panel[hidden] {
  display: none;
}

/* Header */
.betki-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--color-accent);
  color: var(--color-white);
  flex-shrink: 0;
}

.betki-chat__header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.betki-chat__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.betki-chat__title {
  font-weight: 600;
  font-size: 15px;
}

.betki-chat__status {
  font-size: 12px;
  opacity: 0.8;
}

.betki-chat__close {
  background: none;
  border: none;
  color: var(--color-white);
  cursor: pointer;
  padding: 4px;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}

.betki-chat__close:hover {
  opacity: 1;
}

.betki-chat__close svg {
  width: 20px;
  height: 20px;
}

/* Messages Area */
.betki-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 360px;
  max-height: 500px;
  background: var(--color-bg-alt);
}

/* Message Bubbles */
.betki-chat__msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: var(--text-sm);
  line-height: 1.5;
  word-wrap: break-word;
  animation: msg-appear 250ms ease;
}

@keyframes msg-appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.betki-chat__msg--user {
  align-self: flex-end;
  background: var(--color-accent);
  color: var(--color-white);
  border-bottom-right-radius: 4px;
}

.betki-chat__msg--assistant {
  align-self: flex-start;
  background: var(--color-white);
  color: var(--color-heading);
  border: 1px solid var(--color-border-light);
  border-bottom-left-radius: 4px;
}

.betki-chat__msg--system {
  align-self: center;
  background: var(--color-bg-alt);
  color: var(--color-muted);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  border: 1px solid var(--color-border-light);
}

/* Product Cards in Messages */
.betki-chat__product {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-top: 8px;
  font-size: var(--text-xs);
}

.betki-chat__product-name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-heading);
  margin-bottom: 4px;
}

.betki-chat__product-brand {
  color: var(--color-accent);
  font-weight: 500;
  font-size: var(--text-xs);
}

.betki-chat__product-specs {
  color: var(--color-body);
  margin-top: 4px;
  line-height: 1.4;
}

.betki-chat__product-price {
  font-weight: 600;
  color: var(--color-heading);
  margin-top: 4px;
}

/* Typing Indicator */
.betki-chat__typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.betki-chat__typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-muted);
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.betki-chat__typing-dot:nth-child(1) { animation-delay: 0ms; }
.betki-chat__typing-dot:nth-child(2) { animation-delay: 160ms; }
.betki-chat__typing-dot:nth-child(3) { animation-delay: 320ms; }

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

/* Input Area */
.betki-chat__input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-white);
  flex-shrink: 0;
}

.betki-chat__input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.betki-chat__input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--transition-fast);
  background: var(--color-bg-alt);
}

.betki-chat__input:focus {
  border-color: var(--color-accent);
}

.betki-chat__send {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: var(--color-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.betki-chat__send:hover {
  background: var(--color-accent-hover);
}

.betki-chat__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.betki-chat__send svg {
  width: 18px;
  height: 18px;
}

.betki-chat__powered {
  text-align: center;
  font-size: 10px;
  color: var(--color-muted);
  margin-top: 6px;
}

/* Position at bottom-right */
.betki-chat {
  bottom: var(--space-xl);
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .betki-chat {
    bottom: var(--space-md);
    right: var(--space-md);
  }

  .betki-chat__toggle {
    width: 48px;
    height: 48px;
  }

  .betki-chat__toggle svg {
    width: 22px;
    height: 22px;
  }

  .betki-chat__panel {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
  }

  .betki-chat__messages {
    min-height: 40vh;
    max-height: 60vh;
  }
}

/* Print: hide chat widget */
@media print {
  .betki-chat {
    display: none !important;
  }
}
