/* ============================================================
   Cars.ie Chat Assistant Widget
   Uses v2 design tokens from design-tokens.css
   ============================================================ */

/* --- Toggle button --- */
.v2-chat-toggle {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-family);
  font-size: var(--text-14);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transition: transform var(--transition-interactive), box-shadow var(--transition-interactive);
}
.v2-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.v2-chat-toggle svg { width: 20px; height: 20px; flex-shrink: 0; }
.v2-chat-toggle[hidden] { display: none; }

/* Active conversation indicator dot */
.v2-chat-toggle__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border: 2px solid var(--color-surface);
  border-radius: 50%;
}

.v2-chat-debug-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  line-height: 1;
}

/* --- Mobile overlay backdrop --- */
.v2-chat-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,.4);
  z-index: 900;
  display: none;
}
.v2-chat-overlay:not([hidden]) { display: block; }

/* --- Panel --- */
.v2-chat-panel {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 901;
  width: 400px;
  height: 520px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  overflow: hidden;
}
.v2-chat-panel[hidden] { display: none; }

/* --- Header --- */
.v2-chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-tertiary);
  background: var(--color-surface-secondary);
  flex-shrink: 0;
}
.v2-chat-header__title {
  flex: 1;
  font-size: var(--text-14);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}
.v2-chat-header__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.v2-chat-header__btn:hover {
  background: var(--color-border-tertiary);
  color: var(--color-text-primary);
}
.v2-chat-header__btn svg { width: 18px; height: 18px; }

/* --- Messages area --- */
.v2-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overscroll-behavior: contain;
}

/* --- Message bubbles --- */
.v2-chat-msg {
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-14);
  line-height: 1.5;
  word-wrap: break-word;
}
.v2-chat-msg--assistant {
  align-self: flex-start;
  background: var(--color-surface-secondary);
  color: var(--color-text-primary);
  border-bottom-left-radius: var(--radius-sm);
}
.v2-chat-msg--user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}
.v2-chat-msg p { margin: 0 0 0.5em; }
.v2-chat-msg p:last-child { margin-bottom: 0; }

/* --- Typing indicator --- */
.v2-chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-secondary);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
}
.v2-chat-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-tertiary);
  animation: v2-chat-bounce 1.2s infinite;
}
.v2-chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.v2-chat-typing__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes v2-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Listing cards in chat --- */
.v2-chat-listings {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.v2-chat-listing {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text-primary);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}
.v2-chat-listing:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  text-decoration: none;
  color: var(--color-text-primary);
}
.v2-chat-listing__img {
  width: 80px;
  height: 60px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-surface-secondary);
  flex-shrink: 0;
}
.v2-chat-listing__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.v2-chat-listing__title {
  font-size: var(--text-13);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.v2-chat-listing__price {
  font-size: var(--text-14);
  font-weight: var(--font-weight-medium);
  color: var(--color-primary);
}
.v2-chat-listing__meta {
  font-size: var(--text-12);
  color: var(--color-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Input area --- */
.v2-chat-input {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border-tertiary);
  background: var(--color-surface);
  flex-shrink: 0;
}
.v2-chat-input__row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}
.v2-chat-input__field {
  flex: 1;
  max-height: 80px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  background: var(--color-surface-secondary);
  color: var(--color-text-primary);
  font-family: var(--font-family);
  font-size: var(--text-14);
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color var(--transition-interactive);
}
.v2-chat-input__field::placeholder { color: var(--color-text-tertiary); }
.v2-chat-input__field:focus { border-color: var(--color-primary); }
.v2-chat-input__field:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.v2-chat-input__send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-interactive);
}
.v2-chat-input__send:disabled { opacity: 0.4; cursor: not-allowed; }
.v2-chat-input__send svg { width: 18px; height: 18px; }

/* Start over link */
.v2-chat-start-over {
  align-self: center;
  background: none;
  border: none;
  color: var(--color-text-tertiary);
  font-family: var(--font-family);
  font-size: var(--text-12);
  cursor: pointer;
  padding: 0;
  transition: color var(--transition-interactive);
}
.v2-chat-start-over:hover { color: var(--color-text-primary); }
.v2-chat-start-over[hidden] { display: none; }

/* --- Desktop: hide overlay --- */
@media (min-width: 769px) {
  .v2-chat-overlay { display: none !important; }
}

/* --- Mobile --- */
@media (max-width: 768px) {
  .v2-chat-toggle {
    bottom: var(--space-4);
    right: var(--space-4);
    padding: 0;
    width: 48px;
    height: 48px;
    justify-content: center;
  }
  .v2-chat-toggle__label { display: none; }

  .v2-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 85vh;
    max-height: 85vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
  }
}
