:root {
  --color-primary-500: #2196f3;
  --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;
}

/* Frame — same phone-like base as TR1 Classic */
.screen {
  max-width: 390px;
  width: 100%;
  height: calc(100vh - 80px);
  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: 280px;
  padding: 10px 14px;
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 24px;
  color: var(--color-black);
}

/* Bot bubbles stay white-on-white (invisible fill, tail shape unused visually)
   — matches Figma exactly: bot messages read as plain text, not a filled bubble. */
.message-bubble--bot {
  border-radius: 18px 18px 18px 4px;
}

/* User bubbles get the classic messaging-app "tail" shape */
.message-bubble--user {
  background: var(--color-primary-50);
  border-radius: 18px 18px 4px 18px;
}

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

/* Info card bubble */
.message-card {
  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 .value {
  font-weight: 500;
  font-size: 16px;
  line-height: 16px;
}

/* Inline Yes/No picker — same bordered-box language as the rating picker */
.yesno-picker {
  display: flex;
  gap: var(--space-1);
  width: 100%;
}

/* 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;
}

/* Replaces the input bar once the conversation is finished */
.close-chat-footer {
  flex-shrink: 0;
  display: flex;
  padding: 24px;
  background: var(--color-white);
  border-top: 1px solid var(--color-grey-100);
}

.close-chat-btn {
  width: 100%;
  padding: 16px;
  background: var(--color-primary-500);
  border: none;
  border-radius: 12px;
  font-family: var(--font-base);
  font-weight: 600;
  font-size: 18px;
  line-height: 18px;
  color: var(--color-white);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

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