html, body {
  height: 100%;
  overflow: hidden;
}

:root {
  --header-bg: #2d7a4f;
  --header-text: #fff;
  --bot-bubble: #e8f5e9;
  --user-bubble: #2d7a4f;
  --user-text: #fff;
  --input-bg: #f5f5f5;
  --button-bg: #2d7a4f;
  --button-hover: #236b42;
  --choice-bg: #fff;
  --choice-border: #c8e6c9;
  --shadow: rgba(0,0,0,0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #fafafa;
  color: #333;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.5);
}

.header-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.header-avatar-wrap .header-avatar.hidden {
  display: none;
}

.header-avatar-wrap .header-avatar-placeholder.hidden {
  display: none;
}

.header-avatar-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.header-text {
  min-width: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.header .subtitle {
  font-size: 0.8rem;
  opacity: 0.9;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
  padding: 0 12px 12px;
  min-width: 0;
  overflow-x: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 16px 0 80px;
  min-height: 0;
  min-width: 0;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge legacy */
}

.chat-messages::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.msg {
  display: flex;
  margin-bottom: 12px;
  opacity: 0;
  animation: msgEnter 0.45s ease forwards;
}

.msg.msg-bot-first {
  animation: msgEnterFirst 0.5s ease forwards;
}

@keyframes msgEnter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes msgEnterFirst {
  from {
    opacity: 0;
    transform: translateX(-20px) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(0) translateY(0);
  }
}

.msg.bot {
  justify-content: flex-start;
}

.msg.user {
  justify-content: flex-end;
  animation-name: msgEnterUser;
}

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

.msg-bubble {
  max-width: 85%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  box-shadow: 0 1px 4px var(--shadow);
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-line;
}

.msg.bot .msg-bubble {
  background: var(--bot-bubble);
  color: #1b5e20;
  border-bottom-left-radius: 4px;
}

.msg.user .msg-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 0.7rem;
  color: #888;
  margin-top: 4px;
}

.msg.user .msg-time {
  text-align: right;
}

.choices-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0 12px;
  border-top: 1px solid #eee;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: visible;
  position: sticky;
  bottom: 0;
  z-index: 6;
  background: #fafafa;
  max-height: none;
  scrollbar-width: none;
}

.choices-wrap.choices-two-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-btn {
  background: var(--choice-bg);
  border: 2px solid var(--choice-border);
  color: #1b5e20;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  width: 100%;
  text-align: center;
  min-height: 44px;
}

.choice-btn:hover, .choice-btn:focus {
  background: #e8f5e9;
  border-color: var(--header-bg);
  outline: none;
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  position: sticky;
  bottom: 0;
  background: #fafafa;
}

.chat-input-wrap input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 24px;
  font-size: 1rem;
  background: var(--input-bg);
}

.chat-input-wrap input:focus {
  outline: none;
  border-color: var(--header-bg);
}

.chat-input-wrap input.input-error {
  border-color: #c62828;
  background: #ffebee;
}

.chat-input-wrap button {
  background: var(--button-bg);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}

.chat-input-wrap button:hover {
  background: var(--button-hover);
}

.chat-input-wrap button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 420px) {
  .chat-input-wrap {
    gap: 6px;
  }

  .chat-input-wrap input {
    padding: 10px 12px;
    font-size: 0.95rem;
  }

  .chat-input-wrap button {
    padding: 10px 14px;
    font-size: 0.9rem;
  }
}

.offer-cta-bar {
  padding: 4px 0;
  display: flex;
  justify-content: center;
}

.offer-cta-btn {
  padding: 10px 14px;
  border-radius: 20px;
  border: none;
  background: var(--button-bg);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  max-width: 100%;
}

.offer-cta-btn:hover {
  background: var(--button-hover);
}

.msg.offer-cta-wrap {
  justify-content: center;
}

.offer-cta-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 85%;
}

.msg.offer-cta-wrap .offer-inline-btn {
  width: auto;
  min-width: 200px;
}

.offer-inline-img {
  display: block;
  max-width: 100%;
  border-radius: 16px;
  margin: 8px 0;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.offer-caption {
  white-space: pre-wrap;
}

.image-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.image-preview-img {
  max-width: min(96vw, 980px);
  max-height: 92vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

.open-question-prompt {
  margin-top: 8px;
  font-size: 0.9rem;
  color: #666;
}

.date-sep {
  text-align: center;
  font-size: 0.75rem;
  color: #999;
  margin: 12px 0;
  opacity: 0;
  animation: msgEnter 0.4s ease 0.15s forwards;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px 16px;
  background: var(--bot-bubble);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  max-width: 85%;
  min-width: 0;
  color: #1b5e20;
  font-size: 0.9rem;
  opacity: 0;
  animation: msgEnter 0.3s ease forwards;
  overflow: hidden;
}

.typing-indicator .typing-label {
  flex-shrink: 0;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: typingBounce 0.6s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.1s; }
.typing-dots span:nth-child(3) { animation-delay: 0.2s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.rating-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: overlayFadeIn 0.25s ease;
}

.rating-overlay.hidden {
  display: none !important;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.rating-popup {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  animation: popupSlideIn 0.3s ease;
  position: relative;
}

@keyframes popupSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.rating-finish-line {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: #555;
  text-align: center;
}

.rating-title {
  margin: 0 0 20px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  text-align: center;
}

.rating-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.rating-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 10px 6px;
  border: 2px solid var(--choice-border);
  border-radius: 12px;
  background: #fff;
  color: #1b5e20;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.rating-btn .rating-emoji {
  font-size: 1.6rem;
  line-height: 1;
}

.rating-btn .rating-num {
  font-size: 0.9rem;
}

.rating-btn:hover {
  background: #e8f5e9;
  border-color: var(--header-bg);
  transform: scale(1.05);
}

.hidden {
  display: none !important;
}

@media (min-width: 480px) {
  .chat-container {
    max-width: 480px;
    box-shadow: 0 0 0 1px #eee;
    min-height: 90vh;
  }
}
