*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  display: flex;
  justify-content: center;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  height: 100vh;
  height: 100dvh;
  background: #fff;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
  overflow: hidden;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

header {
  flex-shrink: 0;
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid #eee;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-titles {
  flex: 1;
  min-width: 0;
}

.header-logo {
  height: 65px;
  width: auto;
  flex-shrink: 0;
  object-fit: contain;
}

header h1 { font-size: 1.3rem; font-weight: 600; color: #1a1a1a; line-height: 1.25; }
header .subtitle { font-size: 0.85rem; color: #666; margin-top: 2px; line-height: 1.4; }

#chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  overflow-anchor: none;
}

#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  min-height: min-content;
  overflow-anchor: none;
}

.bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: #0071e3;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: #f0f0f0;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  max-width: 100%;
}

.bubble.assistant.error {
  background: #fff0f0;
  color: #b00020;
}

.bubble.assistant p { margin: 0 0 0.5rem; }
.bubble.assistant p:last-child { margin-bottom: 0; }
.bubble.assistant h2, .bubble.assistant h3 { margin: 0.75rem 0 0.25rem; font-size: 1rem; }
.bubble.assistant ul, .bubble.assistant ol { padding-left: 1.25rem; margin: 0.25rem 0; }
.bubble.assistant li { margin-bottom: 0.25rem; }

.bubble-prose { margin-bottom: 0.5rem; }

.question-form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #ddd;
}

.question-form.submitted { opacity: 0.65; pointer-events: none; }

.question-meta {
  font-size: 0.8rem;
  font-weight: 600;
  color: #0071e3;
  margin-bottom: 0.75rem;
}

.question-field {
  border: none;
  margin: 0 0 1rem;
  padding: 0;
}

.question-field legend {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  padding: 0;
}

.option-buttons,
.option-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border: 1px solid #ccc;
  border-radius: 20px;
  background: #fff;
  color: #1a1a1a;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.option-btn:focus {
  outline: 2px solid #0071e3;
  outline-offset: 2px;
}

.option-btn:focus:not(:focus-visible) {
  outline: none;
}

.option-btn.selected {
  background: #0071e3;
  border-color: #0071e3;
  color: #fff;
}

.option-checkboxes .option-btn {
  border-radius: 8px;
}

.option-checkboxes .option-btn.selected::before {
  content: '✓ ';
  font-weight: 700;
}

.question-actions {
  margin-top: 0.25rem;
}

.question-submit {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: #0071e3;
  color: #fff;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.question-submit:hover:not(:disabled) { background: #005bb5; }

.question-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.affiliate-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.affiliate-btn {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  color: #fff;
}

.affiliate-btn.iherb { background: #5a9e2f; }
.affiliate-btn.thorne { background: #1a3a5c; }
.affiliate-btn.onnit { background: #2c2c2c; }

.controls {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid #eee;
  background: #fafafa;
}

.controls.hidden { display: none; }

.btn-primary,
.btn-secondary {
  flex: 1;
  min-height: 48px;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary {
  background: #0071e3;
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: #005bb5; }

.btn-secondary {
  background: #fff;
  color: #b00020;
  border: 1px solid #e8b4b4;
}

.btn-secondary:hover:not(:disabled) { background: #fff5f5; }

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hidden { display: none !important; }

.intro-panel {
  max-width: 100%;
  padding: 0.25rem 0;
  line-height: 1.65;
  font-size: 0.95rem;
  color: #333;
}

.intro-panel h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #1a1a1a;
}

.intro-panel p { margin-bottom: 0.75rem; }

.intro-panel ul {
  margin: 0 0 0.75rem 1.25rem;
}

.intro-panel li { margin-bottom: 0.35rem; }

.intro-note {
  font-size: 0.85rem;
  color: #666;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}

#typing {
  flex-shrink: 0;
  padding: 0 1.5rem 0.5rem;
  display: flex;
  gap: 4px;
  align-items: center;
}

#typing.hidden { display: none; }

#typing span {
  width: 8px;
  height: 8px;
  background: #bbb;
  border-radius: 50%;
  animation: pulse 1.2s infinite;
}

#typing span:nth-child(2) { animation-delay: 0.2s; }
#typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; }
}

footer {
  flex-shrink: 0;
  padding: 0.75rem 1.5rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
  border-top: 1px solid #eee;
  font-size: 0.75rem;
  color: #999;
  text-align: center;
  line-height: 1.5;
}

/* ——— Mobile & small tablets ——— */
@media (max-width: 640px) {
  body {
    background: #fff;
  }

  #app {
    max-width: none;
    box-shadow: none;
  }

  header {
    padding: 0.65rem 1rem 0.6rem;
    padding-top: calc(0.65rem + env(safe-area-inset-top, 0));
  }

  .header-brand {
    gap: 0.65rem;
  }

  .header-logo {
    height: 44px;
  }

  header h1 {
    font-size: 1.05rem;
  }

  header .subtitle {
    font-size: 0.78rem;
    margin-top: 0.15rem;
  }

  #chat-messages {
    padding: 0.85rem 1rem 1rem;
  }

  .bubble {
    max-width: 92%;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
  }

  .bubble.assistant {
    max-width: 100%;
  }

  .bubble.assistant h2,
  .bubble.assistant h3 {
    font-size: 0.95rem;
  }

  .question-field legend {
    font-size: 0.88rem;
    line-height: 1.4;
  }

  .option-buttons,
  .option-checkboxes {
    flex-direction: column;
    gap: 6px;
  }

  .option-btn {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    border-radius: 12px;
    font-size: 0.92rem;
    padding: 0.65rem 1rem;
  }

  .option-checkboxes .option-btn {
    border-radius: 12px;
  }

  .affiliate-links {
    flex-direction: column;
    align-items: stretch;
  }

  .affiliate-btn {
    text-align: center;
    padding: 0.5rem 12px;
    font-size: 0.85rem;
  }

  .controls {
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding: 0.65rem 1rem;
    padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }

  #typing {
    padding: 0.35rem 1rem;
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom, 0));
  }

  footer {
    padding: 0.5rem 1rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0));
    font-size: 0.7rem;
  }

  .intro-panel {
    font-size: 0.9rem;
  }

  .intro-panel h2 {
    font-size: 1rem;
  }
}

@media (max-width: 380px) {
  .header-logo {
    height: 38px;
  }

  header h1 {
    font-size: 0.95rem;
  }

  header .subtitle {
    font-size: 0.72rem;
  }
}
