/* Car Valuation Chat — Spatial Design System */

:root {
  /* ===== SPACING SCALE (4pt) ===== */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Fluid spacing for responsive breathing room */
  --space-fluid: clamp(16px, 4vw, 32px);

  /* ===== COLORS ===== */
  /* Dark theme with warm undertones */
  --color-bg: #0D1117;
  --color-bg-elevated: #161B22;
  --color-bg-input: #21262D;

  --color-text: #c8c8c8;
  --color-text-muted: #8B949E;
  --color-text-inverse: #161B22;

  /* Accent — warm green, not electric */
  --color-accent: #38e58b;
  --color-accent-hover: #2bd47a;

  /* Message backgrounds */
  --color-user-bg: #38e58b;
  --color-bot-bg: #21262D;

  /* Borders */
  --color-border: #30363D;

  /* ===== TYPOGRAPHY ===== */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 24px;

  /* Line height for readability */
  --line-height-base: 1.5;
  --line-height-relaxed: 1.6;

  /* ===== COMPONENT TOKENS ===== */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --message-max-width: 70ch;
  --message-padding: 14px 18px;

  --chat-button-size: 44px;
  --chat-button-size-sm: 36px;

  /* Shadows — subtle, semantic */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);

  /* Z-index scale */
  --z-input: 10;
  --z-sticky: 20;
}

/* ===== BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1 {
  text-align: center;
}

/* ===== LAYOUT ===== */
#chat-container-wrapper {
  --section-max-width: none;
  --text-padding: 0;
  --margin-center: 0;
  padding-bottom: 0;

  & .text__basic-wrapper {
    text-align: initial;
  }
}

.chat-container {
  padding-top: 6rem;
}

/* Title — left-aligned, bold presence */
#chat-title {
  margin: 0;
  padding: var(--space-5) var(--space-fluid);
  font-size: var(--font-size-xl);
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

/* Chat history — scrollable, flexible */
#chat-history {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-fluid) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
  max-width: var(--message-max-width);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: var(--space-8);
}

/* Scrollbar styling for Webkit */
#chat-history::-webkit-scrollbar {
  width: 8px;
}

#chat-history::-webkit-scrollbar-track {
  background: transparent;
}

#chat-history::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

#chat-history::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

#chat-history>*:first-child {
  margin-top: auto;
}

#chat-history>*:last-child {
  margin-bottom: auto;
}

/* ===== MESSAGES ===== */
.message {
  padding: var(--message-padding);
  border-radius: var(--radius-lg);
  max-width: var(--message-max-width);
  line-height: var(--line-height-relaxed);
  font-size: var(--font-size-base);
  animation: message-in 0.2s ease-out;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User message — right-aligned, accent color */
.user-message {
  align-self: flex-end;
  background: var(--color-user-bg);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-sm);
}

/* Bot message — left-aligned, dark elevated */
.bot-message {
  align-self: flex-start;
  background: var(--color-bot-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

/* Message content with HTML (for valuations, etc.) */
.message br {
  margin-bottom: var(--space-2);
}

.message b,
.message strong {
  font-weight: 600;
}

/* ===== INPUT WRAPPER ===== */
#input-wrapper {
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  background: var(--color-bg-elevated);
  border-top: 1px solid var(--color-border);
  position: sticky;
  bottom: 0;
  z-index: var(--z-input);
}

/* Textarea — seamless, dark theme */
#user-input {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  font-family: inherit;
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background: var(--color-bg-input);
  resize: none;
  outline: none;
  min-height: 48px;
  max-height: 120px;
  max-width: var(--message-max-width);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: var(--space-3);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#user-input::placeholder {
  color: var(--color-text-muted);
}

#user-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(56, 229, 139, 0.15);
}

/* Toolbar — right-aligned action */
#input-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  max-width: var(--message-max-width);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

#toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Send button — prominent, circular */
#send-btn {
  width: var(--chat-button-size);
  height: var(--chat-button-size);
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-accent);
  color: var(--color-text-inverse);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.15s ease, transform 0.1s ease;
}

#send-btn:hover {
  background: var(--color-accent-hover);
}

#send-btn:active {
  transform: scale(0.96);
}

#send-btn:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* Restart button — secondary action */
#restart-btn {
  width: var(--chat-button-size);
  height: var(--chat-button-size);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-bg-input);
  color: var(--color-text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.15s ease;
}

#restart-btn:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

#restart-btn:active {
  transform: scale(0.96);
}

#restart-btn:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* ===== CTA BUTTONS (inside messages) ===== */
.cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--color-text);
  color: var(--color-bg);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.cta-btn:hover {
  background: var(--color-accent);
}

.cta-btn:active {
  transform: scale(0.98);
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
  .message {
    animation: none;
  }

  #chat-history {
    scroll-behavior: auto;
  }

  #user-input,
  #send-btn,
  .cta-btn {
    transition: none;
  }
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

/* =========================================================================
 * QUICK REPLY BUTTONS
 * Inline clickable buttons inside the chat flow
 * ========================================================================= */
#quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  animation: message-in 0.2s ease-out;
}

.quick-reply-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: var(--chat-button-size-sm);
}

.quick-reply-btn:hover {
  background: var(--color-accent);
  color: var(--color-text-inverse);
  border-color: var(--color-accent);
}

.quick-reply-btn:active {
  transform: scale(0.96);
}

.quick-reply-btn:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* Selected state for multi-select extras */
.quick-reply-btn.selected {
  background: var(--color-accent);
  color: var(--color-text-inverse);
  border-color: var(--color-accent);
}

/* Primary action button (e.g., "Klar" in extras) */
.quick-reply-btn.primary {
  background: var(--color-accent);
  color: var(--color-text-inverse);
  border-color: var(--color-accent);
  font-weight: 600;
  padding: var(--space-2) var(--space-5);
}

.quick-reply-btn.primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

/* =========================================================================
 * LOADING INDICATOR
 * Visual feedback when chat is processing - efficient, subtle, friendly
 * ========================================================================= */
.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  animation: fade-in 0.2s ease-out;
  background: none;
  border: 0;
}

.loading-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.loading-dots::before,
.loading-dots::after,
.loading-dots span {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  animation: loading-pulse 1.4s ease-in-out infinite;
}

.loading-dots::before {
  animation-delay: 0s;
}

.loading-dots::after {
  animation-delay: 0.2s;
}

.loading-dots span {
  animation-delay: 0.4s;
}

@keyframes loading-pulse {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive adjustments for quick replies */
@media (max-width: 600px) {
  #quick-replies {
    gap: var(--space-1);
  }

  .quick-reply-btn {
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
    min-height: 40px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #quick-replies {
    animation: none;
  }

  .quick-reply-btn {
    transition: none;
  }
}


/**
 * Card
 */
.val-card {
  background: var(--color-bg);
  border-color: var(--color-bg-elevated);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
}

.car-header {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--color-text);
}

.car-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--color-bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.car-icon svg {
  width: 22px;
  height: 22px;
  fill: var(--color-text-muted);
}

.car-title {
  font-size: 17px;
  font-weight: 500;
  /* color: #1a1a18; */
  margin-bottom: 0;
  line-height: 1;
}

.car-subtitle {
  font-size: 13px;
  /* color: #5f5e5a; */
  margin-top: 0;
  margin-bottom: 0;
}

.car-mileage-badge {
  margin-left: auto;
  background: var(--color-bg-input);
  border: 0.5px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  /* color: #5f5e5a; */
  white-space: nowrap;
}

.divider {
  border: none;
  border-top: 0.5px solid rgba(255, 255, 255, 0.1);
  margin: 0.5rem 0 1.5rem;
}

.price-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 1.25rem;
  color: var(--color-text);

  @media screen and (min-width: 640px) {
    grid-template-columns: 1fr 1fr;
  }
}

.price-block {
  background: var(--color-bg-input);
  border-radius: 8px;
  padding: 1rem;
}

.price-block.featured {
  background: var(--color-accent);
  color: var(--color-text-inverse);
  border: 0.5px solid var(--color-text-muted);
}

.price-label {
  font-size: 12px;
  /* color: #888780; */
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.price-amount {
  font-size: 24px;
  font-weight: 500;
  margin: 0;
  margin-top: 0.5rem;
  line-height: 1.1;
}

.price-range {
  font-size: 11px;
  margin: 0;
  min-height: 1em;
}

.price-block.featured .price-range {
  opacity: 0.75;
}

.price-desc {
  font-size: 12px;
  margin-top: 6px;
  margin-bottom: 6px;
}

.diff-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-bg-input);
  border-radius: 8px;
  padding: 12px 14px;
}

.diff-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-bg-elevated);
  border: 0.5px solid rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.diff-text {
  font-size: 13px;
  color: var(--color-text-muted);
  flex: 1;
}

.diff-text strong {
  color: var(--color-text);
  font-weight: 500;
}

/**
 * Chat table
 */
.chat-table {
  & thead th {
    text-align: left;
    text-transform: uppercase;
  }

  & td,
  & th {
    padding: 0.25rem 0.5rem;

  }
}

/**
 * Form
 */
#form-valuation-lead select,
#form-valuation-lead input {
  width: 100%;
  margin-bottom: 1rem;
  background: var(--color-bg-elevated);
  padding: 0.5rem;
  border-radius: 0.5rem;
}

#form-valuation-lead button[type="submit"] {
  width: 100%;
}
