:root {
  /* ProductChimp brand palette (matched to the marketing site) */
  --bg: #f4f7ec;          /* soft cream */
  --bg-grad: #dcebcf; /* (overridden below via gradient) */
  --panel: #ffffff;
  --accent: #2f4a2a;      /* deep forest green — primary buttons */
  --accent-hover: #3b5c34;
  --accent-ink: #ffffff;
  --accent-light: #8fcf6e; /* bright leaf green — highlights */
  --ink: #1b2417;          /* near-black text */
  --muted: #6e7a63;
  --border: #e1e8d6;
  --bot-bubble: #eef3e5;   /* pale green */
  --link: #2f6b2e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  background: linear-gradient(135deg, #f6f8f0 0%, #f1f6e8 45%, #dcebd0 100%);
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
}

.chat-wrap {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0; /* never let the header get squeezed out of view */
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title-row .logo { height: 32px; width: auto; display: block; flex-shrink: 0; }
.chat-header h1 { margin: 0; font-size: 1.2rem; color: var(--accent); overflow-wrap: anywhere; }
.chat-header p { margin: 8px 0 0; color: var(--muted); font-size: 0.85rem; }

.lang-switch { display: flex; gap: 6px; flex-shrink: 0; }
.lang-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.lang-btn:hover { border-color: var(--accent-light); }
.lang-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain; /* don't chain scroll past the top/bottom */
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }

/* Column holding a message's bubble + (bot) source card + feedback, stacked. */
.msg .content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 80%;
  min-width: 0;
}
.msg.user .content { align-items: flex-end; }
.msg.bot .content { align-items: flex-start; }

.bubble {
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.95rem;
}
.msg.bot .bubble { background: var(--bot-bubble); border-bottom-left-radius: 4px; }
.msg.user .bubble {
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 4px;
}
.bubble a { color: var(--link); text-decoration: underline; }
.bubble code { background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 4px;
  font-size: 0.88em; }
.bubble strong { font-weight: 700; }
.msg.user .bubble a { color: #dbe9d0; }

/* Animated "thinking" dots */
.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  animation: pcblink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pcblink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Tappable suggestion chips (onboarding starters + follow-ups) */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.chip {
  border: 1px solid var(--accent-light);
  background: #fff;
  color: var(--accent);
  border-radius: 999px;
  padding: 9px 14px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.chip:hover { background: var(--accent); color: var(--accent-ink); }
.chip:active { transform: scale(0.97); }
/* CTA chip: filled/prominent */
.chip-cta { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip-cta:hover { background: var(--accent-hover); }

/* Article source card (rendered from the bot's 📄 line) */
.source-card {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}
.source-card:hover { border-color: var(--accent-light); background: var(--bot-bubble); }
.source-card .sc-icon { font-size: 1.1rem; }
.source-card .sc-body { display: flex; flex-direction: column; min-width: 0; }
.source-card .sc-title { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.source-card .sc-open { font-size: 0.78rem; color: var(--accent); margin-top: 1px; }

/* Answer feedback (thumbs) */
.feedback { display: flex; gap: 6px; margin-top: 4px; align-items: center; flex-wrap: wrap; }
.fb-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 42px;
  min-height: 38px;
  font-size: 1.15rem;
  cursor: pointer;
  line-height: 1;
  touch-action: manipulation; /* reliable taps on mobile (no double-tap-zoom delay) */
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
  transition: background 0.15s, border-color 0.15s;
}
.fb-btn:hover { background: var(--bot-bubble); border-color: var(--accent-light); }
.fb-thanks { font-size: 0.78rem; color: var(--muted); }

/* Header actions row (lang switch + reset) */
.header-actions { display: flex; align-items: center; gap: 8px; }
.reset-chat {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  width: 30px;
  height: 30px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.reset-chat:hover { background: var(--bot-bubble); color: var(--ink); }

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 16px 6px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0; /* keep the input+Send row fully visible */
}
.disclaimer {
  flex-shrink: 0;
  margin: 0;
  padding: 0 16px 8px;
  text-align: center;
  font-size: 0.66rem;
  line-height: 1.3;
  color: var(--muted);
  opacity: 0.65;
  background: var(--panel);
}
#input {
  flex: 1;
  min-width: 0; /* allow the textarea to shrink instead of forcing body overflow */
  width: 100%;
  resize: none;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  max-height: 140px;
  touch-action: manipulation; /* no double-tap-zoom delay swallowing the first tap */
  -webkit-user-select: text;
  user-select: text;
}
#send { flex-shrink: 0; }
#input:focus { outline: 2px solid var(--accent-light); border-color: transparent; }
#send {
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#send:hover:not(:disabled) { background: var(--accent-hover); }
#send:disabled { opacity: 0.5; cursor: default; }
