:root {
  --color-primary-500: #2196f3;
  --color-primary-200: #90caf9;
  --color-primary-50: #e3f2fd;
  --color-white: #ffffff;
  --color-black: #000000;
  --color-grey-50: #f6f6f4;
  --color-grey-100: #d9e0e3;
  --color-grey-300: #90a4ae;
  --color-grey-500: #607d8b;
  --color-grey-600: #546e7a;
  --color-grey-700: #455a64;
  --background-base: #ffffff;

  --font-heading: "Poppins", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-base: "Poppins", -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-sm: 4px;
  --radius-lg: 12px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f5f5f7;
  font-family: var(--font-base);
  color: var(--color-black);
  display: flex;
  align-items: center;
  justify-content: center;
}

.flow-nav {
  position: fixed;
  top: 18px;
  left: 20px;
  z-index: 10;
}

.flow-nav a {
  color: var(--color-grey-600);
  text-decoration: none;
  font-size: 0.75rem;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.flow-nav a:hover {
  opacity: 1;
}

/* Mirrors .flow-nav's subtlety, mirrored to the opposite corner — a
   passive label naming which track/prototype you're currently in. */
.flow-context {
  position: fixed;
  top: 18px;
  right: 20px;
  z-index: 10;
  color: var(--color-grey-600);
  font-size: 0.75rem;
  opacity: 0.55;
}

/* Frame — same phone-like base as TR1 Classic */
.screen {
  max-width: 390px;
  width: 100%;
  height: calc(100vh - 80px);
  max-height: 844px;
  background: var(--background-base);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  border-radius: 32px;
}

/* Chat header */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: 85px;
  padding: 24px 16px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-grey-100);
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.chat-contact {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.chat-name {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 18px;
  color: var(--color-black);
}

.chat-status {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-base);
  font-weight: 400;
  font-style: italic;
  font-size: 12px;
  color: var(--color-grey-600);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34c759;
  flex-shrink: 0;
}

/* Message thread */
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 24px 8px;
  background: var(--color-white);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 12px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-grey-300);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

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

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

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

.message-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.message-group--user {
  align-items: flex-end;
}

.message-group--bot {
  align-items: flex-start;
}

/* Extra space only when the conversation switches sides — consecutive
   messages from the same side keep the tight default gap. */
.message-group--bot + .message-group--user,
.message-group--user + .message-group--bot {
  margin-top: 16px;
}

.message-bubble {
  margin: 0;
  max-width: 300px;
  padding: 8px 12px;
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-black);
}

.message-bubble--bot {
  border-radius: var(--radius-sm);
}

.message-bubble--user {
  background: var(--color-primary-50);
  border-radius: var(--radius-lg);
}

.message-caption {
  max-width: 300px;
  white-space: pre-line;
  padding: 0 12px;
  font-family: var(--font-base);
  font-size: 12px;
  line-height: 16px;
  color: var(--color-grey-500);
}

/* Info card bubble */
.message-card-row {
  display: flex;
  gap: var(--space-3);
  width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.message-card {
  flex-shrink: 0;
  width: 280px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-white);
  border: 1px solid var(--color-grey-100);
  border-radius: var(--radius-lg);
}

.message-card-title {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 20px;
  line-height: 28px;
}

.message-card-body {
  margin: 0;
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
}

.message-card a {
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-black);
  text-decoration: underline;
}

.text-link {
  color: var(--color-primary-500);
  text-decoration: underline;
  font-weight: 500;
}

.text-link:hover {
  color: #1c86e0;
}

/* Inline rating picker */
.rating-picker {
  display: flex;
  gap: var(--space-1);
  width: 100%;
}

.rating-option {
  flex: 1 0 0;
  height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--color-white);
  border: 1px solid var(--color-grey-100);
  border-radius: 8px;
  font-family: var(--font-base);
  cursor: pointer;
}

.rating-option:hover {
  border-color: var(--color-primary-500);
}

.rating-option .emoji {
  font-size: 16px;
  line-height: 24px;
}

.rating-option .value {
  font-weight: 600;
  font-size: 14px;
  line-height: 14px;
}

/* Inline category picker */
.category-picker {
  display: grid;
  /* minmax(0, 1fr): a long word must wrap, not stretch its column past the frame */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  width: 100%;
}

.category-card {
  min-width: 0;
  min-height: 116px;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--color-white);
  border: 1px solid var(--color-grey-100);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.category-card:hover {
  border-color: var(--color-primary-500);
}

.category-card img {
  width: 20px;
  height: 20px;
}

.category-card span {
  max-width: 100%;
  font-family: var(--font-base);
  font-weight: 600;
  font-size: 14px;
  line-height: 18px;
  color: var(--color-black);
  text-align: center;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Suggestion bar — quick-reply chips pinned directly above the input
   bar, outside the scrolling message thread, so they read as a prefill
   shortcut for the field below rather than a chat message. Collapses to
   zero height when empty so it never reserves space between turns. */
.suggestion-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) 16px 0;
}

.suggestion-bar:empty {
  padding: 0;
}

.suggestion-chip {
  padding: 10px 16px;
  background: var(--color-white);
  border: 1px solid var(--color-primary-200);
  border-radius: 20px;
  font-family: var(--font-base);
  font-size: 14px;
  line-height: 20px;
  color: var(--color-primary-500);
  cursor: pointer;
}

.suggestion-chip:hover {
  background: var(--color-primary-50);
}

/* Bottom input bar */
.chat-input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--color-white);
}

.chat-input {
  flex: 1 0 0;
  height: 48px;
  line-height: 46px;
  padding: 0 16px;
  background: var(--color-white);
  border: 1px solid var(--color-grey-100);
  border-radius: var(--radius-lg);
  font-family: var(--font-base);
  font-size: 16px;
  color: var(--color-grey-600);
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  cursor: text;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-input:focus {
  outline: none;
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 4px rgba(33, 150, 243, 0.15);
}

.chat-input-bar[data-disabled="true"] .chat-input {
  background: var(--color-grey-50);
  cursor: default;
  pointer-events: none;
}

.chat-send {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 24px;
  background: var(--color-primary-500);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat-send:hover {
  background: #1c86e0;
}

.chat-send:disabled {
  background: var(--color-grey-300);
  cursor: default;
}

.chat-send img {
  width: 24px;
  height: 24px;
}

/* Speech answer panel — replaces the input bar for the open question */
.chat-input-bar[hidden],
.answer-panel[hidden],
.chat-speech-alt[hidden] {
  display: none;
}

.answer-panel {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: 16px;
  background: var(--color-white);
  border-top: 1px solid var(--color-grey-100);
}

.answer-primary {
  width: 100%;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--color-primary-500);
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-base);
  font-weight: 600;
  font-size: 16px;
  line-height: 20px;
  color: var(--color-white);
  cursor: pointer;
}

.answer-primary:hover {
  background: #1c86e0;
}

.answer-primary:disabled {
  background: var(--color-grey-300);
  cursor: default;
}

.answer-primary img {
  width: 20px;
  height: 20px;
}

.answer-secondary {
  width: 100%;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--color-white);
  border: 1px solid var(--color-grey-100);
  border-radius: var(--radius-lg);
  font-family: var(--font-base);
  font-weight: 600;
  font-size: 16px;
  line-height: 20px;
  color: var(--color-primary-500);
  cursor: pointer;
}

.answer-secondary:hover {
  border-color: var(--color-primary-500);
}

.answer-secondary img {
  width: 20px;
  height: 20px;
}

.answer-hint {
  margin: 0;
  font-family: var(--font-base);
  font-size: 12px;
  line-height: 16px;
  color: var(--color-grey-600);
  text-align: center;
}

.answer-type {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 12px;
  background: var(--color-white);
  border: 1px solid var(--color-grey-100);
  border-radius: 12px;
  font-family: var(--font-base);
  font-size: 12px;
  line-height: 16px;
  color: var(--color-grey-600);
  cursor: pointer;
}

.answer-type:hover {
  border-color: var(--color-primary-500);
}

.answer-type img {
  width: 14px;
  height: 14px;
}

/* Status row: "Listening..." / "Microphone unavailable" */
.answer-status {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-black);
}

.answer-status img {
  width: 20px;
  height: 20px;
}

.answer-status--listening {
  gap: 10px;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d32f2f;
  animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.listening-timer {
  margin-left: auto;
  font-size: 14px;
  color: var(--color-grey-600);
  font-variant-numeric: tabular-nums;
}

.answer-body {
  margin: 0;
  width: 100%;
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-grey-600);
}

/* Live transcript while listening */
.listening-transcript {
  margin: 0;
  width: 100%;
  min-height: 72px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: var(--radius-lg);
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-black);
}

/* Review: edit before sending */
.answer-edit-hint {
  margin: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-base);
  font-size: 12px;
  line-height: 16px;
  color: var(--color-grey-600);
}

.answer-edit-hint img {
  width: 14px;
  height: 14px;
}

.review-textarea {
  width: 100%;
  min-height: 72px;
  padding: 16px;
  border: 1px solid var(--color-grey-100);
  border-radius: var(--radius-lg);
  outline: none;
  resize: none;
  overflow: hidden;
  background: var(--color-white);
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-black);
}

.review-textarea:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 4px rgba(33, 150, 243, 0.15);
}

/* Text alternative: mic button next to the input field */
.chat-speech-alt {
  flex-shrink: 0;
  width: 40px;
  height: 48px;
  margin: 0 -4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
}

.chat-speech-alt img {
  width: 20px;
  height: 20px;
}
