/* Coupon Bot PWA — chat-thread UI (Sprint 6). Mobile-first: one
   conversation thread, a slim app bar, and a sticky composer. */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: #1c2420;
  background: #e9ede6;
}
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  background: #f6f7f4;
}

/* ---- slim app bar ---- */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #14532d;
  color: #fff;
  padding: 8px 12px;
  flex: 0 0 auto;
}
.appbar-main { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.appbar-title { font-weight: 700; font-size: 18px; white-space: nowrap; }
.appbar-household {
  opacity: 0.85;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-wrap { position: relative; flex: 0 0 auto; }
.menu-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 16px;
  cursor: pointer;
}
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  color: #1c2420;
  border: 1px solid #d8ddd4;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
  min-width: 210px;
  padding: 6px;
  z-index: 30;
}
.menu-acct { margin: 6px 10px 8px; font-weight: 600; color: #374151; font-size: 15px; }
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px;
  background: none;
  border: 0;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
}
.menu button:hover { background: #f0f2ee; }

.banner {
  background: #fde68a;
  color: #713f12;
  border-bottom: 2px solid #d97706;
  padding: 10px 16px;
  font-weight: 700;
  flex: 0 0 auto;
}

/* ---- the thread ---- */
.thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }
.bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #d8ddd4;
  overflow-wrap: break-word;
}
.bubble.text { white-space: pre-wrap; }
.msg-row.user .bubble {
  background: #14532d;
  border-color: #14532d;
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.msg-row.bot .bubble { border-bottom-left-radius: 4px; }
.bubble.has-card { width: 88%; }

/* ---- rich cards inside bot bubbles ---- */
.card h3 { font-size: 18px; margin: 2px 0 8px; }
.card h4 { font-size: 16px; margin: 14px 0 6px; }
.card p { margin: 6px 0; }
.card label { display: block; margin: 10px 0 4px; font-weight: 600; }
.card input, .card select {
  width: 100%;
  padding: 10px;
  font-size: 17px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  background: #fff;
}
button.primary {
  margin-top: 14px;
  width: 100%;
  padding: 12px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: #14532d;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button.card-btn {
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid #14532d;
  border-radius: 8px;
  background: #fff;
  color: #14532d;
  cursor: pointer;
}
.cards { list-style: none; padding: 0; margin: 8px 0; }
.cards li {
  background: #fbfdfb;
  border: 1px solid #d8ddd4;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.clip { list-style: none; padding: 0; margin: 4px 0; }
.clip li { padding: 8px 0; border-bottom: 1px solid #e5e7eb; }
.clip input { width: auto; margin-right: 8px; }
.notes { color: #374151; font-size: 15px; padding-left: 20px; }
.totals {
  background: #ecfdf5;
  border: 1px solid #14532d;
  border-radius: 8px;
  padding: 12px;
  margin-top: 16px;
}
.totals .register { font-size: 20px; }
.rebates {
  background: #fffbeb;
  border: 1px solid #d97706;
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
}
.msg { font-weight: 600; min-height: 1.2em; }
.hint { color: #374151; }
/* Subtle mark on replies the server gave in deterministic basic mode
   (Grok brain unavailable) — small, muted, inside the bot bubble. */
.mode-note {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: #9ca3af;
}

/* Receipt-photo review card (Stage 4 flow, in-thread since Sprint 6). */
.review-row {
  border: 1px solid #d8ddd4;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #fbfdfb;
}
.review-row.low-conf {
  background: #fffbeb;
  border-color: #d97706;
}
.low-conf-note { margin: 0 0 6px; font-weight: 700; color: #92400e; }
.review-row .rv-remove {
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 15px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

/* ---- chips + composer ---- */
.composer-wrap {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid #d8ddd4;
  padding-bottom: env(safe-area-inset-bottom);
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px 0;
}
.chip {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #14532d;
  background: #fff;
  color: #14532d;
  font-size: 15px;
  cursor: pointer;
}
.chip:disabled { opacity: 0.45; cursor: default; }
.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
}
.attach-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #9ca3af;
  background: #fff;
  font-size: 19px;
  cursor: pointer;
}
.attach-btn:disabled { opacity: 0.45; cursor: default; }
#composer-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  padding: 11px 14px;
  font: inherit;
  border: 1px solid #9ca3af;
  border-radius: 20px;
  background: #fff;
}
#composer-input:disabled { background: #f0f2ee; }
.send-btn {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: #14532d;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.45; cursor: default; }

/* ---- Sprint 7: memories card + watcher messages ---- */
.memory-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.memory-fact { flex: 1 1 auto; }
.memory-forget { flex: 0 0 auto; font-size: 14px; padding: 4px 10px; }
.proactive-tag {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #14532d;
  margin-bottom: 4px;
}
.msg-row.proactive .bubble { border-color: #b9cdb4; }
