/* ── Chat Support Widget ── */

/* Root container — containment boundary on mobile */
.chat-widget-root--open {
  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow: hidden;
}

/* Bubble */
.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, oklch(0.65 0.25 260), oklch(0.55 0.2 280));
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px oklch(0.3 0.15 260 / 0.5);
  z-index: 10001;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px oklch(0.3 0.15 260 / 0.7);
}
.chat-bubble--unread::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: oklch(0.7 0.25 25);
  border-radius: 50%;
  border: 2px solid oklch(0.15 0.01 260);
  animation: chat-pulse 2s ease-in-out infinite;
}

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

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 520px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  touch-action: none;
  box-sizing: border-box;
  z-index: 10000;
  background: oklch(0.15 0.01 260 / 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid oklch(0.3 0.02 260 / 0.4);
  box-shadow: 0 8px 40px oklch(0.05 0 0 / 0.6);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: oklch(0.18 0.02 260 / 0.9);
  border-bottom: 1px solid oklch(0.25 0.02 260 / 0.4);
  flex-shrink: 0;
}
.chat-header__title {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: oklch(0.9 0.01 260);
}
.chat-header__actions {
  display: flex;
  gap: 4px;
}
.chat-header__btn {
  background: none;
  border: none;
  color: oklch(0.6 0.02 260);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-header__btn:hover {
  color: oklch(0.9 0.01 260);
  background: oklch(0.25 0.02 260 / 0.5);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: oklch(0.3 0.02 260) transparent;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

/* Message bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  min-width: 0;
}
.chat-msg--user {
  align-self: flex-end;
}
.chat-msg--assistant {
  align-self: flex-start;
}
.chat-msg__bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  font-family: 'Inter', system-ui, sans-serif;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  box-sizing: border-box;
}
.chat-msg--user .chat-msg__bubble {
  background: linear-gradient(135deg, oklch(0.55 0.2 260), oklch(0.45 0.18 280));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg--assistant .chat-msg__bubble {
  background: oklch(0.2 0.015 260 / 0.8);
  color: oklch(0.85 0.01 260);
  border: 1px solid oklch(0.28 0.02 260 / 0.4);
  border-bottom-left-radius: 4px;
}

/* Links in messages */
.chat-link {
  color: oklch(0.72 0.20 260);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.chat-link:hover {
  color: oklch(0.82 0.22 260);
}

/* Ratings */
.chat-rating {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding-left: 4px;
}
.chat-rating__btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  opacity: 0.35;
  transition: opacity 0.15s, transform 0.15s;
  padding: 2px 4px;
  border-radius: 4px;
}
.chat-rating__btn:hover {
  opacity: 0.8;
  transform: scale(1.2);
}
.chat-rating--active-up {
  opacity: 1 !important;
}
.chat-rating--active-down {
  opacity: 1 !important;
}

/* Streaming cursor */
.chat-cursor {
  animation: chat-blink 0.8s step-end infinite;
  color: oklch(0.65 0.25 260);
}
@keyframes chat-blink {
  50% { opacity: 0; }
}

/* Product selector chips */
.chat-products {
  padding: 8px 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}
.chat-product-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid oklch(0.4 0.1 260 / 0.5);
  background: oklch(0.2 0.02 260 / 0.6);
  color: oklch(0.8 0.05 260);
  font-size: 12px;
  font-family: 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.chat-product-chip:hover {
  background: oklch(0.3 0.08 260 / 0.7);
  border-color: oklch(0.5 0.15 260);
  transform: translateY(-1px);
}

/* Input bar */
.chat-input {
  display: flex;
  align-items: flex-end;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  gap: 8px;
  border-top: 1px solid oklch(0.25 0.02 260 / 0.4);
  background: oklch(0.13 0.01 260 / 0.9);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}
.chat-input--disabled {
  opacity: 0.5;
  pointer-events: none;
}
.chat-input__field {
  flex: 1;
  min-width: 0;
  background: oklch(0.18 0.01 260 / 0.8);
  border: 1px solid oklch(0.3 0.02 260 / 0.4);
  border-radius: 10px;
  padding: 8px 12px;
  color: oklch(0.9 0.01 260);
  font-size: 16px;
  font-family: 'Inter', system-ui, sans-serif;
  resize: none;
  outline: none;
  max-height: 80px;
  overflow-y: auto;
  box-sizing: border-box;
  -webkit-appearance: none;
}
.chat-input__field::placeholder {
  color: oklch(0.45 0.02 260);
}
.chat-input__field:focus {
  border-color: oklch(0.5 0.15 260);
}
.chat-input__send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, oklch(0.6 0.22 260), oklch(0.5 0.18 280));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}
.chat-input__send:hover:not(:disabled) {
  transform: scale(1.08);
}
.chat-input__send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Lock body scroll when chat open on mobile */
body.chat-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .chat-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    border-radius: 0;
    overflow: hidden;
  }
  .chat-panel * {
    max-width: 100%;
    box-sizing: border-box;
  }
  .chat-bubble {
    bottom: 16px;
    right: 16px;
  }
  .chat-bubble--hidden {
    display: none !important;
  }
}
