/* ═══════════════════════════════════════════════════════════════
   CHAT WIDGET - STYLES (Responsive + multi-tenant theming)
   ═══════════════════════════════════════════════════════════════ */

:root {
  --cw-primary: #3b82f6;
  --cw-primary-dark: #2563eb;
  --cw-accent: #7c3aed;
  --cw-accent-light: #22d3ee;
  --cw-gradient: linear-gradient(135deg, #3b82f6, #7c3aed);
  --cw-gradient-alt: linear-gradient(135deg, #3b82f6, #6366f1, #22d3ee);
  --cw-font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --cw-header-title: #1e293b;
  --cw-header-bg: #ffffff;
  --cw-header-text: var(--cw-header-title);
  --cw-header-status-color: var(--cw-text-muted);
  --cw-header-border: var(--cw-border);
  --cw-header-close-color: #94a3b8;
  --cw-header-close-hover: var(--cw-surface-muted);
  --cw-avatar-bg: var(--cw-primary);
  --cw-text-muted: #64748b;
  --cw-text: #1e293b;
  --cw-secondary: #222222;
  --cw-border: rgba(0, 0, 0, 0.125);
  --cw-radius: 0.625rem;
  --cw-font-size: 14px;
  --cw-line-height: 1.5;
  --cw-surface-muted: #f1f5f9;
  --cw-quick-border: rgba(59, 130, 246, 0.35);
  --cw-quick-hover-bg: #eff6ff;
  --cw-bubble-assistant-bg: color-mix(in srgb, var(--cw-primary) 10%, white);
  --cw-bubble-assistant-border: color-mix(
    in srgb,
    var(--cw-primary) 18%,
    transparent
  );
  --cw-bubble-assistant-text: var(--cw-text);
  --cw-viewport-width: 100vw;
  --cw-viewport-height: 100dvh;
  --cw-panel-max-width: 480px;
  --cw-panel-max-height: 440px;
  --cw-panel-max-height-expanded: 600px;
  --cw-panel-height-ratio: 0.5;
  --cw-panel-height-ratio-expanded: 0.88;
  --cw-panel-inset-x: 24px;
  --cw-panel-inset-y: 24px;
  --cw-panel-min-width: 430px;
  --cw-panel-min-height: 360px;
  --cw-panel-radius: 16px;
  --cw-shadow-bleed: 24px;
  --cw-widget-gap: 12px;
  --cw-widget-pad: 12px;
  --cw-status-online: #34d399;
  --cw-launcher-size: 82px;
  --cw-launcher-icon-size: 24px;
  --cw-closed-pad: 8px;
}

#chat-widget,
#chat-widget *,
#chat-widget *::before,
#chat-widget *::after {
  box-sizing: border-box;
}

/* ─── Reset & Base ─── */
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  background: transparent;
  overflow: hidden;
}

body {
  height: 100%;
  min-height: 0;
}

/* ─── Animations ─── */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

/* ─── Widget Container ─── */
#chat-widget {
  position: fixed;
  bottom: 0;
  right: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 12px;
  z-index: 9999;
  font-family: var(--cw-font-family);
  font-size: var(--cw-font-size);
  line-height: var(--cw-line-height);
  pointer-events: none;
}

#chat-widget > * {
  pointer-events: auto;
}

#chat-widget:not(.is-open) {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: var(--cw-closed-pad, 8px);
  align-items: stretch;
  overflow: visible;
}

#chat-widget.is-open {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 0;
  overflow: visible;
}

#chat-widget.is-open.has-shadow-room {
  padding: var(--cw-shadow-bleed);
  box-sizing: border-box;
}

#chat-widget.is-open .chat-panel {
  flex: 0 0 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  max-width: 100%;
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  margin: 0;
  box-sizing: border-box;
  transition:
    height 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

#chat-widget.is-open.is-panel-entering {
  align-items: flex-end;
  justify-content: flex-end;
}

#chat-widget.is-open.is-panel-entering .chat-panel {
  flex: 0 0 auto;
  width: var(--cw-panel-enter-width, var(--cw-launcher-size));
  height: var(--cw-panel-enter-height, var(--cw-launcher-size));
  max-width: 100%;
  max-height: 100%;
}

/* ─── Chat Panel ─── */
.chat-panel {
  width: max(
    var(--cw-panel-min-width),
    min(
      calc(var(--cw-viewport-width) - var(--cw-panel-inset-x) * 2),
      calc(var(--cw-viewport-width) * var(--cw-panel-width-ratio))
    )
  );
  height: min(
    var(--cw-panel-max-height),
    max(
      var(--cw-panel-min-height),
      calc(
        var(--cw-viewport-height) - var(--cw-panel-inset-y) * 2 -
          env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
      )
    )
  );
  max-width: 100%;
  min-height: 0;
  min-width: 0;
  border-radius: var(--cw-panel-radius);
  overflow: hidden;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  box-shadow: var(--cw-panel-shadow, 0 12px 40px rgba(0, 0, 0, 0.12));
  transition:
    height 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-panel.is-expanded {
  --cw-panel-max-height: var(--cw-panel-max-height-expanded);
}

#chat-widget.is-open.is-panel-entering .chat-panel {
  transition:
    height 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ─── Header ─── */
.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--cw-header-bg);
  border-bottom: 1px solid var(--cw-header-border);
  flex-shrink: 0;
  min-width: 0;
}

.panel-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cw-avatar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

/* .panel-avatar svg {
  width: 18px;
  height: 18px;
  color: white;
} */

.panel-header-info {
  flex: 1;
  min-width: 0; /* Allow text truncation */
  overflow: hidden;
}

.panel-header-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--cw-header-text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--cw-header-status-color);
}

.panel-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cw-status-online);
  flex-shrink: 0;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.panel-expand-btn,
.panel-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
}

.panel-expand-btn:hover,
.panel-close-btn:hover {
  background: var(--cw-header-close-hover);
}

.panel-expand-btn svg {
  width: 18px;
  height: 18px;
  color: var(--cw-header-close-color);
  display: block;
}

.panel-close-btn svg {
  width: 16px;
  height: 16px;
  color: var(--cw-header-close-color);
  display: block;
}

html.is-parent-compact .panel-expand-btn {
  display: none;
}

/* ─── Messages Area ─── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  background: rgba(248, 250, 252, 0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0; /* Allow flex shrinking */
}

/* ─── Message Bubbles ─── */
.msg-row {
  display: flex;
  gap: 8px;
  max-width: 100%; /* Prevent overflow */
}

.msg-row.user {
  justify-content: flex-end;
}
.msg-row.system {
  justify-content: center;
}
.msg-row.assistant {
  align-items: flex-start;
}

.msg-content {
  flex: 1;
  min-width: 0;
  max-width: min(100%, calc(100% - 40px));
}

.msg-content .msg-bubble.user,
.msg-content .msg-bubble.assistant {
  max-width: 100%;
}

.msg-row.user .msg-bubble {
  max-width: min(85%, 100%);
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--cw-avatar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-avatar svg {
  width: 16px;
  height: 16px;
  color: white;
}

.msg-bubble {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word; /* Better word breaking */
}

.msg-bubble.user {
  background: var(--cw-primary);
  color: white;
  border-bottom-right-radius: 6px;
}

.msg-bubble.assistant {
  background: var(--cw-bubble-assistant-bg);
  color: var(--cw-bubble-assistant-text);
  border: 1px solid var(--cw-bubble-assistant-border);
  border-bottom-left-radius: 6px;
}

.msg-bubble.system {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  font-size: 12px;
  max-width: 85%;
}

.msg-bubble.system svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ─── Typing Indicator ─── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--cw-bubble-assistant-bg);
  border: 1px solid var(--cw-bubble-assistant-border);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cw-primary);
  opacity: 0.55;
  animation: bounce 1.4s infinite ease-in-out both;
}

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

/* ─── Car Cards ─── */
.car-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.car-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--cw-car-border, #e8e8e8);
  min-width: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.car-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.car-thumb {
  width: 96px;
  height: 96px;
  border-radius: 10px;
  background: #f3f4f6;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.car-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.car-thumb svg {
  width: 28px;
  height: 28px;
  color: #cbd5e1;
}

.car-head {
  flex: 1;
  min-width: 0;
}

.car-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}

.car-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--cw-primary);
  color: #ffffff;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.car-badge.sold {
  background: #6b7280;
}

.car-price {
  font-size: clamp(13px, 3.5vw, 15px);
  font-weight: 700;
  color: var(--cw-primary);
  white-space: nowrap;
  margin-left: auto;
}

.car-monthly {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--cw-car-monthly, #3d77fd);
}

.car-list,
.car-card,
.car-detail {
  max-width: 100%;
  overflow: hidden;
}

.car-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.car-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: #6b7280;
}

.car-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.car-meta svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--cw-primary);
}

.car-divider {
  height: 1px;
  background: #eeeeee;
  margin: 0;
}

.car-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 14px;
}

.car-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--cw-car-tag-bg, #f3f4f6);
  color: var(--cw-car-tag-text, #4b5563);
  font-size: 11px;
  font-weight: 500;
}

.car-benefits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.car-benefit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
}

.car-benefit svg {
  width: 12px;
  height: 12px;
}

.car-benefit.inspect {
  background: #e8f1ff;
  color: #2563eb;
}

.car-benefit.finance {
  background: #e8f7ee;
  color: #15803d;
}

.car-benefit.warranty {
  background: #fff4e5;
  color: #c2410c;
}

.showroom-locations {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.showroom-location-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--cw-border, rgba(0, 0, 0, 0.08));
  border-radius: var(--cw-radius, 10px);
  font-size: 13px;
  font-weight: 500;
  color: var(--cw-primary, #da3655);
  text-decoration: none;
  width: fit-content;
  max-width: 100%;
}

.showroom-location-item:hover {
  text-decoration: underline;
}

.financing-card {
  margin-top: 8px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--cw-border, rgba(0, 0, 0, 0.08));
  border-radius: var(--cw-radius, 10px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.financing-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.financing-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #111;
  line-height: 1.3;
}

.financing-card-price {
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--cw-primary, #da3655);
}

.financing-card-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.financing-card-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.financing-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #444;
}

.financing-meta-item svg {
  width: 14px;
  height: 14px;
  color: var(--cw-primary, #da3655);
}

.financing-card-monthly {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--cw-car-monthly, #3d77fd);
  white-space: nowrap;
}

.financing-card-divider {
  height: 1px;
  background: var(--cw-border, rgba(0, 0, 0, 0.08));
  margin: 12px 0;
}

.financing-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.financing-card-price-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.financing-cta-primary {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--cw-primary, #da3655);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.financing-cta-secondary {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--cw-primary, #da3655);
  border-radius: 8px;
  background: #fff;
  color: var(--cw-primary, #da3655);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.financing-cta-primary:hover {
  filter: brightness(0.95);
}

.financing-cta-secondary:hover {
  background: var(--cw-quick-hover-bg, #fdf2f4);
}

.car-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 2px;
  padding: 11px 14px;
  border: none;
  border-radius: 999px;
  background: var(--cw-primary);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.2s,
    transform 0.15s;
}

.car-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.car-cta-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-height: 32px;
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: var(--cw-primary);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.car-cta-primary:hover {
  background: var(--cw-primary-dark);
}

.car-cta-primary svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.car-cta-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 32px;
  padding: 5px 12px;
  border: 1.5px solid var(--cw-primary);
  border-radius: 999px;
  background: #ffffff;
  color: var(--cw-primary);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s;
}

.car-cta-secondary:hover {
  background: var(--cw-quick-hover-bg);
}

.car-cta:hover {
  background: var(--cw-primary-dark);
}

.car-cta svg {
  width: 16px;
  height: 16px;
}

.car-cta-link {
  box-sizing: border-box;
}

/* ─── Car Detail (in-chat) ─── */
.car-detail {
  margin-top: 10px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: 14px;
}

.car-detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.car-detail-title {
  margin: 6px 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: #111827;
}

.car-detail-header .car-meta {
  margin-top: 4px;
}

.car-detail .car-divider {
  margin: 10px 0;
}

.car-detail .car-tags,
.car-detail .car-benefits {
  margin-bottom: 8px;
}

.car-detail-price-block {
  text-align: right;
  flex-shrink: 0;
}

.car-detail-monthly {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 500;
  color: #3d77fd;
}

.car-detail-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #eeeeee;
}

.car-detail-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: #111827;
}

.car-detail-heading svg {
  width: 14px;
  height: 14px;
  color: var(--cw-primary);
}

.car-detail-list {
  margin: 0;
  padding-left: 18px;
  color: #4b5563;
  font-size: 11px;
  line-height: 1.5;
}

.car-detail-list li {
  margin-bottom: 2px;
}

.car-detail-empty {
  margin: 0;
  font-size: 12px;
  color: #6b7280;
}

/* ─── Quick Replies ─── */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quick-reply-btn {
  font-size: 13px;
  padding: 8px 15px;
  border-radius: 9999px;
  border: 1px solid var(--cw-primary);
  background: white;
  color: var(--cw-primary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  font-weight: 600;
}

a.quick-reply-btn {
  text-decoration: none;
  display: inline-block;
}

.quick-reply-btn:hover:not(:disabled) {
  background: var(--cw-quick-hover-bg);
  border-color: var(--cw-primary);
}

.quick-reply-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.quick-reply-btn.is-selected,
.welcome-btn.is-selected {
  background: var(--cw-primary);
  border-color: var(--cw-primary);
  color: #ffffff;
  box-shadow: none;
}

.quick-reply-btn:disabled:not(.is-selected),
.welcome-btn:disabled:not(.is-selected) {
  opacity: 0.5;
  cursor: not-allowed;
  background: #ffffff;
  color: var(--cw-text-muted);
}

.quick-reply-btn.is-selected:disabled,
.welcome-btn.is-selected:disabled {
  opacity: 1;
  cursor: default;
}

/* ─── Welcome Card ─── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 16px 8px;
}

.welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--cw-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.welcome-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

.welcome-screen h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--cw-text);
  margin: 0 0 4px;
}

.welcome-screen p {
  font-size: 12px;
  color: var(--cw-text-muted);
  max-width: 260px;
  line-height: 1.6;
  margin: 0 0 20px;
}

.welcome-btn {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border-radius: var(--cw-radius);
  border: 1px solid var(--cw-border);
  background: white;
  color: var(--cw-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 8px;
}

.welcome-btn:hover:not(:disabled) {
  border-color: var(--cw-primary);
  background: var(--cw-quick-hover-bg);
  color: var(--cw-primary-dark);
}

/* ─── Chat Input ─── */
.composer {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid var(--cw-border);
  flex-shrink: 0;
}

.composer-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  border-radius: 9999px;
  padding: 4px 4px 4px 16px;
  border: 1px solid var(--cw-border);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.composer-field.is-active {
  border-color: var(--cw-primary);
}

.composer-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--cw-text);
  min-width: 0;
}

.composer-input::placeholder {
  color: var(--cw-text-muted);
}

.composer-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--cw-composer-send-disabled-bg, #feeeee);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cw-composer-send-disabled-icon, #ffa5c4);
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s,
    opacity 0.2s;
  flex-shrink: 0;
  padding: 0;
}

.composer-send:disabled {
  opacity: 1;
  cursor: not-allowed;
}

.composer-send:not(:disabled) {
  background: var(--cw-primary);
  color: #ffffff;
}

.composer-send:not(:disabled):hover {
  background: var(--cw-primary-dark);
}

.composer-send svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* ─── Trigger Button ─── */
.launcher-btn {
  --cw-launcher-expand-duration: 600ms;
  --cw-launcher-icon-inset: calc(
    (var(--cw-launcher-size) - var(--cw-launcher-icon-size)) / 2
  );
  --cw-launcher-label-gap: 12px;
  --cw-launcher-label-size: 13px;
  --cw-launcher-label-line-height: 20px;
  position: relative;
  width: var(--cw-launcher-size);
  height: var(--cw-launcher-size);
  border-radius: 9999px;
  border: none;
  background: var(--cw-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: var(--cw-launcher-icon-inset);
  padding-block: 0;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 10px 24px -8px rgba(225, 51, 87, 0.45);
  transition:
    width var(--cw-launcher-expand-duration) ease-in-out,
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.launcher-btn.is-open {
  justify-content: center;
  padding: 0;
  width: var(--cw-launcher-size);
}

.launcher-btn.is-expanded {
  justify-content: center;
}

.launcher-btn.is-expanded-static,
.launcher-btn.is-expanded-static .launcher-label {
  transition: none;
}

.launcher-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
}

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

.launcher-icon {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cw-launcher-icon-size);
  height: var(--cw-launcher-icon-size);
}

.launcher-icon svg,
.launcher-btn.is-open > svg {
  width: var(--cw-launcher-icon-size);
  height: var(--cw-launcher-icon-size);
  color: white;
  display: block;
}

.launcher-btn.is-open > svg {
  position: relative;
  z-index: 1;
}

.launcher-label {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  font-size: var(--cw-launcher-label-size);
  font-weight: 600;
  line-height: var(--cw-launcher-label-line-height);
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  clip-path: inset(0 0 0 100%);
  pointer-events: none;
  transition:
    opacity var(--cw-launcher-expand-duration) ease-in-out,
    clip-path var(--cw-launcher-expand-duration) ease-in-out;
}

.launcher-btn.is-expanded .launcher-label {
  position: static;
  width: auto;
  height: auto;
  flex-shrink: 0;
  min-width: max-content;
  margin-left: var(--cw-launcher-label-gap);
  pointer-events: auto;
  opacity: 1;
  clip-path: inset(0 0 0 0);
}

.launcher-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  z-index: 2;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

@media (prefers-reduced-motion: reduce) {
  .launcher-btn,
  .launcher-label,
  .chat-panel,
  #chat-widget.is-open .chat-panel {
    transition: none !important;
    animation: none !important;
  }
}

/* ─── Notification Bubble ─── */
.prompt-bubble {
  --cw-prompt-bubble-width: 306px;
  --cw-notification-font-family: Outfit, "Outfit Fallback", sans-serif;
  position: relative;
  width: 100%;
  max-width: var(--cw-prompt-bubble-width);
  min-width: 0;
  flex: 0 1 auto;
  align-self: stretch;
  box-sizing: border-box;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--cw-primary);
  box-shadow: 0 8.13px 19.39px 0 #e8174d1f;
  animation: notifIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: box-shadow 0.2s;
}

.prompt-bubble:hover {
  box-shadow: 0 10px 22px 0 #e8174d2e;
}

.prompt-bubble-body {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 14px 40px 14px 16px;
  cursor: pointer;
  text-align: left;
}

.prompt-bubble-message {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  font-family: var(--cw-notification-font-family);
  font-size: 16px;
  font-weight: 400;
  line-height: 22px;
  letter-spacing: 0;
  color: var(--cw-text);
  overflow-wrap: break-word;
}

.prompt-bubble-highlight {
  color: var(--cw-primary);
  font-weight: 500;
}

.prompt-bubble-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  padding: 0;
  color: var(--cw-primary);
  cursor: pointer;
  line-height: 1;
  transition: opacity 0.2s;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  z-index: 1;
}

.prompt-bubble-close:hover {
  opacity: 0.75;
}

.prompt-bubble-close svg {
  width: 14px;
  height: 14px;
  display: block;
  stroke: currentColor;
}

/* ─── Closed Widget (notification + launcher) ─── */
.closed-widget {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
  min-width: 0;
  pointer-events: auto;
}

.launcher-notif-stack {
  display: flex;
  flex-direction: row-reverse;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  flex-shrink: 1;
}

/* ─── Bottom Row ─── */
.launcher-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  align-self: flex-end;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  flex-shrink: 0;
  min-width: 0;
}

/* ─── Scrollbar ─── */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE STYLES
   ═══════════════════════════════════════════════════════════════ */

/* Tablets and narrow desktops */
@media (max-width: 768px) {
  :root {
    --cw-widget-pad: 12px;
  }
}

/* Parent viewport compact (set by JS) — not iframe width */
html.is-parent-compact {
  --cw-panel-max-width: 100%;
  --cw-panel-max-height: 100dvh;
  --cw-panel-min-width: 0px;
  --cw-panel-min-height: 0px;
  --cw-panel-radius: 0;
  --cw-shadow-bleed: 0px;
  --cw-widget-pad: 0;
}

html.is-parent-compact #chat-widget.is-open {
  padding: 0;
}

html.is-parent-compact #chat-widget.is-open .chat-panel {
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  border-left: none;
  border-right: none;
  box-shadow: none;
}

html.is-parent-compact #chat-widget.is-open .panel-header {
  padding-top: max(14px, env(safe-area-inset-top));
}

html.is-parent-compact #chat-widget.is-open .composer {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* Small tablets and large phones */
@media (max-width: 640px) {
  #chat-widget:not(.is-open) {
    bottom: max(12px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
    left: auto;
  }

  :root {
    --cw-launcher-size: 76px;
    --cw-launcher-icon-size: 33px;
  }
}

/* Phones in portrait */
@media (max-width: 480px) {
  #chat-widget:not(.is-open) {
    bottom: max(8px, env(safe-area-inset-bottom));
    right: max(8px, env(safe-area-inset-right));
  }

  .panel-header {
    padding: 12px 14px;
  }

  .panel-header-title {
    font-size: 16px;
  }

  .chat-messages {
    padding: 12px;
  }

  .msg-bubble {
    font-size: 14px;
    padding: 8px 12px;
  }

  .msg-row.user .msg-bubble {
    max-width: 88%;
  }

  .msg-content {
    max-width: calc(100% - 36px);
  }

  .car-card {
    padding: 10px;
    gap: 8px;
  }

  .car-thumb {
    width: clamp(72px, 22vw, 88px);
    height: clamp(72px, 22vw, 88px);
  }

  .car-title {
    font-size: 13px;
    word-break: break-word;
  }

  .car-meta {
    gap: 8px;
    font-size: 12px;
  }

  .car-cta-primary,
  .car-cta-secondary {
    font-size: 11px;
    min-height: 30px;
    padding: 5px 10px;
  }

  .car-detail-header {
    flex-direction: column;
    align-items: stretch;
  }

  .car-detail-price-block {
    text-align: left;
  }

  .quick-reply-btn {
    font-size: 13px;
    padding: 7px 14px;
  }

  .composer {
    padding: 10px 12px;
  }

  .composer-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .composer-send {
    width: 36px;
    height: 36px;
  }

  :root {
    --cw-launcher-size: 70px;
    --cw-launcher-icon-size: 30px;
  }

  .welcome-screen h2 {
    font-size: 15px;
  }

  .welcome-screen p {
    font-size: 11px;
    max-width: 100%;
  }

  .welcome-btn {
    font-size: 12px;
    padding: 10px 14px;
  }
}

/* Very small phones */
@media (max-width: 360px) {
  .car-top {
    gap: 8px;
  }

  .car-head-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .car-price {
    margin-left: 0;
    white-space: normal;
  }

  .car-thumb {
    width: 68px;
    height: 68px;
  }

  :root {
    --cw-launcher-size: 64px;
    --cw-launcher-icon-size: 27px;
  }
}

/* Landscape phones / short viewports */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --cw-panel-max-height: 100dvh;
  }

  #chat-widget.is-open .chat-panel {
    height: 100%;
    max-height: 100dvh;
  }

  .welcome-screen {
    padding: 12px 16px 4px;
  }

  .welcome-icon {
    width: 44px;
    height: 44px;
    margin-bottom: 10px;
  }

  .chat-messages {
    padding: 10px 12px;
  }
}

/* Desktop / PC — viewport-based panel size */
@media (min-width: 641px) {
  :root {
    --cw-panel-max-height: calc(
      var(--cw-viewport-height) * var(--cw-panel-height-ratio)
    );
    --cw-panel-max-height-expanded: calc(
      var(--cw-viewport-height) * var(--cw-panel-height-ratio-expanded)
    );
  }
}
