/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #05364D;  /* marktguru deep navy */
  --brand-accent: #05364D;  /* marktguru primary blue */
  --brand-light:  #A9E5FB;  /* light blue tint */
  --brand-border: #67CCF2;  /* blue border tint */
  --bg:           #FFFFFF;  /* white background */
  --surface:      #FFFFFF;
  --border:       #CCD5DB;
  --text-primary: #202427;
  --text-muted:   #4F5A64;
  --bubble-user:  #05364D;
  --bubble-bot:   #E0F7FF;
  color-scheme:   light;
  --radius-lg:    18px;
  --radius-sm:    6px;
  --shadow-sm:    0 1px 3px rgba(0,58,82,.08);
  --shadow-md:    0 4px 12px rgba(0,58,82,.10);
  --font:         'Source Sans 3', 'Inter', system-ui, -apple-system, sans-serif;
  --font-headline:'Montserrat', 'Inter', sans-serif;
  --header-h:     64px;
  --footer-h:     auto;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}


/* ── App shell ────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* dynamic viewport height — handles mobile browser chrome */
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg);
}

/* ── Header ───────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-menu-icon {
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}
.header-brand {
  font-family: var(--font-headline);
  font-weight: 800;
  font-size: 20px;
  color: var(--brand-accent);
  letter-spacing: -0.3px;
}
.header-zip-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #E0F7FF;
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 10px;
  cursor: pointer;
  user-select: none;
}
.header-zip-badge[hidden] { display: none; }
.header-zip-icon {
  font-size: 14px;
  color: var(--text-muted);
}
.header-zip-badge span:last-child {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.input-btn-group {
  display: flex;
  align-items: center;
  gap: 7px;
}
.clear-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: #3e4850;
  padding: 6px 10px;
  line-height: 0;
  flex-shrink: 0;
  transition: color .15s, opacity .15s;
  display: flex;
  align-items: center;
}
.clear-btn .material-symbols-outlined { font-size: 26px; }
.clear-btn:disabled { opacity: .25; cursor: not-allowed; pointer-events: none; }
.clear-btn:not(:disabled):hover  { color: #ef4444; }
.clear-btn:not(:disabled):active { opacity: .6; }

/* ── Messages area ────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Individual message ───────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: fadeUp .2s ease;
}
.message.user  { align-self: flex-end; align-items: flex-end; }
.message.bot   { align-self: flex-start; align-items: flex-start; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Card image loading placeholder ───────────────────────────────── */
/* Shared shimmer shown while images are fetching. Works for all four
   card image types. object-fit:cover images are fully replaced on load;
   for object-fit:contain (offer-img) the gray persists as a neutral surround. */
.message.bot .bubble .offer-img,
.message.bot .bubble .cashback-img,
.message.bot .bubble .campaign-card .offer-img,
.message.bot .bubble .recipe-img {
  background: linear-gradient(90deg, #e8eaed 25%, #f2f3f5 50%, #e8eaed 75%);
  background-size: 400% 100%;
  animation: imgShimmer 1.4s ease-in-out infinite;
}
@keyframes imgShimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
/* Once the image has loaded (class added by JS), kill the placeholder */
.message.bot .bubble .offer-img.img-loaded,
.message.bot .bubble .cashback-img.img-loaded,
.message.bot .bubble .campaign-card .offer-img.img-loaded,
.message.bot .bubble .recipe-img.img-loaded {
  background: none;
  animation: none;
}

/* ── Streaming width lock ──────────────────────────────────────────── */
/* Hold the bubble at full width while content is streaming so the
   layout doesn't jump left/right as each token arrives. */
.message.bot.streaming {
  width: 88%;
  align-items: stretch;  /* stretch .bubble to fill the full wrapper width */
}

/* ── Streaming cursor ──────────────────────────────────────────────── */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 0.85em;
  background: currentColor;
  margin-left: 2px;
  vertical-align: text-bottom;
  opacity: 0.6;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink {
  0%, 100% { opacity: 0.6; }
  50%       { opacity: 0; }
}

/* ── Grid entrance animation ───────────────────────────────────────── */
.grid-entering {
  animation: gridIn 0.3s ease both;
}
@keyframes gridIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Incremental render containers ────────────────────────────────── */
/* display:contents makes these divs transparent to layout so existing
   margin/spacing rules between bubble children still apply correctly. */
.msg-intro,
.msg-tail { display: contents; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}
.message.user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.bot .bubble {
  background: var(--bubble-bot);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* Markdown-like formatting inside bot bubbles */
.message.bot .bubble strong { font-weight: 600; }
.message.bot .bubble em     { font-style: italic; }
.message.bot .bubble a      { color: var(--brand-accent); text-decoration: underline; }
.message.bot .bubble ul,
.message.bot .bubble ol     { padding-left: 18px; margin: 4px 0; }
.message.bot .bubble li     { margin: 2px 0; }
.message.bot .bubble p      { margin: 4px 0; }
.message.bot .bubble div + p { margin-top: 20px; }
.message.bot .bubble h1,
.message.bot .bubble h2,
.message.bot .bubble h3,
.message.bot .bubble h4,
.message.bot .bubble h5,
.message.bot .bubble h6    { margin-top: 20px; margin-bottom: 4px; }
.message.bot .bubble p:first-child { margin-top: 0; }
.message.bot .bubble p:last-child  { margin-bottom: 0; }
.message.bot .bubble code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  background: #f4f4f5;
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Offer grid ───────────────────────────────────────────────── */
.message.bot .bubble .offers-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 6px 0;
  white-space: normal;
}
.message.bot .bubble .recipes-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 6px 0;
  white-space: normal;
}
.message.bot .bubble .offer-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 0.8em;
  line-height: 1.35;
}
.message.bot .bubble .offer-card p { margin: 2px 0; }
.message.bot .bubble .offer-card strong { font-size: 0.95em; }
.message.bot .bubble .offer-card a {
  color: var(--brand-accent);
  text-decoration: none;
  font-weight: 600;
  margin-top: 4px;
  display: inline-block;
}

/* ── Offer images ─────────────────────────────────────────────── */
.message.bot .bubble .offer-img {
  display: block;
  width: 100px;
  height: 100px;
  border-radius: 6px;
  margin: 0 auto 6px;
  object-fit: contain;
}

/* ── Cashback grid ────────────────────────────────────────────── */
.message.bot .bubble .cashbacks-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 6px 0;
  white-space: normal;
}

/* ── Cashback campaign cards ──────────────────────────────────── */
.message.bot .bubble .cashback-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 0.8em;
  line-height: 1.35;
  overflow: hidden;
}
.message.bot .bubble .cashback-card > * {
  padding: 0 8px;
  width: 100%;
  box-sizing: border-box;
}
.message.bot .bubble .cashback-card > *:first-child { padding-top: 6px; }
.message.bot .bubble .cashback-card > *:last-child  { padding-bottom: 8px; }
.message.bot .bubble .cashback-card > p:has(.cashback-img) {
  padding: 0;
  margin: 0;
}
.message.bot .bubble .cashback-card p { margin: 2px 0; }
.message.bot .bubble .cashback-card strong { font-size: 0.95em; }
.message.bot .bubble .cashback-card a {
  color: var(--brand-accent);
  text-decoration: none;
  font-weight: 600;
  margin-top: 4px;
  display: inline-block;
}

/* ── Cashback campaign images ─────────────────────────────────── */
.message.bot .bubble .cashback-img {
  display: block;
  width: 100%;
  height: 126px;
  border-radius: 12px 12px 0 0;
  margin: 0 0 10px;
  object-fit: cover;
}

/* ── Campaign cards (leaflet-page thumbnails, portrait) ──────── */
.message.bot .bubble .campaigns-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 6px 0;
  white-space: normal;
}
.message.bot .bubble .campaign-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 0.8em;
  line-height: 1.35;
  overflow: hidden;
}
.message.bot .bubble .campaign-card > * {
  padding: 0 6px;
  width: 100%;
  box-sizing: border-box;
}
.message.bot .bubble .campaign-card > p:has(.offer-img) { padding: 0; margin: 0; }
.message.bot .bubble .campaign-card > *:last-child { padding-bottom: 6px; }
.message.bot .bubble .campaign-card p { margin: 2px 0; }
.message.bot .bubble .campaign-card strong { font-size: 0.95em; }
.message.bot .bubble .campaign-card a {
  color: var(--brand-accent);
  text-decoration: none;
  font-weight: 600;
  margin-top: 2px;
  display: inline-block;
}
/* Portrait image overriding the square offer-img defaults */
.message.bot .bubble .campaign-card .offer-img {
  display: block;
  width: 100%;
  height: 150px;
  border-radius: 0;
  margin: 0;
  object-fit: cover;
}

/* ── Recipe cards ─────────────────────────────────────────────── */
.message.bot .bubble .recipe-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 0.8em;
  line-height: 1.35;
  overflow: hidden;
}
.message.bot .bubble .recipe-card > * {
  padding: 0 8px;
  width: 100%;
}
.message.bot .bubble .recipe-card > *:first-child { padding-top: 6px; }
.message.bot .bubble .recipe-card > *:last-child  { padding-bottom: 8px; }
.message.bot .bubble .recipe-card > p:has(.recipe-img) {
  padding: 0;
  margin: 0;
}
.message.bot .bubble .recipe-card p  { margin: 2px 0; }
.message.bot .bubble .recipe-card strong { font-size: 0.95em; }
.message.bot .bubble .recipe-card a {
  color: var(--brand-accent);
  text-decoration: none;
  font-weight: 600;
  margin-top: 4px;
  display: inline-block;
}

/* ── Recipe images ─────────────────────────────────────────────── */
.message.bot .bubble .recipe-img {
  display: block;
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 12px 12px 0 0;
  margin: 0 0 4px;
  padding: 0 !important;
  flex-shrink: 0;
}
.message.bot .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* ── Typing GIF ───────────────────────────────────────────────── */
.message.bot:has(.typing-gif-wrapper) {
  max-width: none;
}
.typing-gif-wrapper {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  gap: 4px;
}
.typing-msg {
  margin: 6px 0 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--brand-accent);
  opacity: 1;
  transition: opacity 0.3s ease;
  text-align: center;
  min-height: 1.4em;
  /* Force GPU compositing layer — prevents iOS WebKit text ghosting
     when content changes during an opacity transition */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: opacity;
}
.typing-msg.fade-out {
  opacity: 0;
}
.typing-gif {
  height: 160px;
  width: auto;
  display: block;
  border-radius: 20px;
}

/* ── Welcome card ─────────────────────────────────────────────── */
.welcome-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-self: stretch;
  padding-bottom: 4px;
}

/* Bot avatar + bubble row */
.welcome-avatar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bot-avatar {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.bot-avatar img {
  width: 44px;
  height: 44px;
  display: block;
}
.bot-avatar img.avatar-dark  { display: none; }
html.dark-mode .bot-avatar img.avatar-light { display: none; }
html.dark-mode .bot-avatar img.avatar-dark  { display: block; }
.welcome-bubble {
  background: var(--bubble-bot);
  border-radius: 18px;
  border-top-left-radius: 4px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-muted);
  max-width: calc(100% - 50px);
  box-shadow: var(--shadow-sm);
}
.welcome-bubble p { margin: 0; }

/* Suggestion tiles carousel */
.tiles-carousel {
  overflow: hidden;
  width: 100%;
  touch-action: pan-y;
}
.tiles-track {
  display: flex;
  gap: 16px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}
.tiles-page {
  flex: 0 0 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tiles-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}
.tiles-dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: var(--text-muted);
  opacity: 0.3;
  transition: width 0.25s ease, opacity 0.25s ease, background 0.25s ease;
  flex-shrink: 0;
}
.tiles-dot.active {
  width: 20px;
  opacity: 1;
  background: var(--brand-accent);
}
.suggestion-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.suggestion-chip:hover {
  border-color: var(--brand-accent);
  box-shadow: 0 2px 8px rgba(5,54,77,.12);
}
.chip-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chip-icon-box .material-symbols-outlined {
  font-size: 20px;
}
.chip-icon-blue  { background: #A9E5FB; color: #05364D; }
.chip-icon-green { background: #d4edbc; color: #486800; }
.chip-icon-gray  { background: #dee3e8; color: #3e4850; }
.chip-icon-olive { background: #bff45e; color: #354e00; }
.chip-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.chip-title {
  font-family: var(--font-headline);
  font-weight: 700;
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tip block inside welcome card */
.welcome-tip-block {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #E0F7FF;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}
.welcome-tip-icon {
  font-size: 16px;
  color: var(--brand-accent);
  flex-shrink: 0;
}
.welcome-tip-content { flex: 1; }
.tip-cursor {
  display: inline;
  margin-left: 1px;
  color: var(--text-muted);
  animation: tip-blink 0.7s step-end infinite;
}
@keyframes tip-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Input area — floating pill ──────────────────────────────── */
.input-area {
  position: relative;   /* anchor for debug popup */
  flex-shrink: 0;
  margin: 0 12px max(16px, env(safe-area-inset-bottom));
  padding: 14px 16px 14px;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: 0 4px 32px rgba(0,58,82,.14), 0 1px 6px rgba(0,58,82,.08);
  overflow: visible;
}
/* Input label (top hint in the card) */
.input-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
/* Text input section */
.input-text-row {
  padding: 0 2px;
}
.input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
.input-field {
  width: 100%;
  font-family: var(--font);
  font-size: 20px;
  line-height: 1.5;
  color: var(--text-primary);
  background: transparent;
  border: none;
  padding: 6px 0;
  resize: none;
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  -webkit-appearance: none;
}
.input-field::placeholder { color: #909090; font-size: 20px; }
.input-field::-webkit-scrollbar { display: none; }
.input-field { scrollbar-width: none; }

.send-btn {
  height: 48px;
  padding: 0 22px;
  border-radius: 100px;
  background: #e0e6ed;
  border: none;
  color: #8f979c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s, opacity .15s;
}
.send-btn .material-symbols-outlined { font-size: 26px; }
.send-btn:disabled { cursor: not-allowed; }
.send-btn:not(:disabled) { background: var(--brand-light); color: var(--brand); }
.send-btn:not(:disabled):hover { background: #8dd9f7; }
.send-btn:not(:disabled):active { transform: scale(.95); }

/* ── Hidden file inputs (display:none blocks pickers in some browsers) ── */
.file-input-hidden {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ── Attach button & popup menu ────────────────────────────────── */
.attach-wrap {
  position: relative;
  flex-shrink: 0;
}
.photo-btn {
  background: transparent;
  border: none;
  color: #3e4850;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 6px 10px;
  transition: color .15s, opacity .15s;
}
.photo-btn .material-symbols-outlined { font-size: 26px; }
.photo-btn:hover  { color: var(--brand-accent); }
.photo-btn:active { opacity: .7; }
.photo-btn:disabled { opacity: 0.4; pointer-events: none; cursor: default; }
.photo-btn.has-image { color: var(--brand-accent); }
.photo-btn[aria-expanded="true"] { color: var(--brand-accent); }

.attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-width: 160px;
  z-index: 20;
}
.attach-menu[hidden] { display: none; }
.attach-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  transition: background .12s;
  user-select: none;
  -webkit-user-select: none;
}
.attach-option:hover { background: var(--brand-light); color: var(--brand-accent); }
.attach-option:not(:last-child) { border-bottom: 1px solid var(--border); }
.attach-option svg { flex-shrink: 0; }

/* ── Mic button ───────────────────────────────────────────────── */
.mic-btn {
  background: transparent;
  border: none;
  color: #3e4850;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  flex-shrink: 0;
  padding: 6px 10px;
  transition: color .15s, opacity .15s;
  position: relative;
}
.mic-btn .material-symbols-outlined { font-size: 26px; }
.mic-btn:hover  { color: var(--brand-accent); }
.mic-btn:active { opacity: .7; }
.mic-btn.has-audio { color: var(--brand-accent); }

@keyframes mic-pulse {
  0%, 100% { color: var(--brand-accent); }
  50%       { color: #e53e3e; }
}
.mic-btn.recording {
  animation: mic-pulse 1.2s ease-in-out infinite;
}
.mic-btn.recording::after {
  content: attr(data-timer);
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 600;
  color: var(--brand-accent);
  white-space: nowrap;
  pointer-events: none;
}

/* ── Image preview strip ──────────────────────────────────────── */
.image-preview-wrap {
  display: none;           /* shown via JS when an image is pending */
  align-items: center;
  gap: 8px;
  padding: 6px 4px 6px;
}
.image-preview-wrap.visible { display: flex; }
.image-preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1.5px solid var(--brand-border);
}
.image-preview-clear {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-muted);
  border: none;
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.image-preview-clear:hover { background: #ef4444; }

/* ── Audio preview strip ──────────────────────────────────────── */
.audio-preview-wrap {
  display: none;           /* shown via JS when audio is pending */
  align-items: center;
  gap: 8px;
  padding: 6px 4px 6px;
}
.audio-preview-wrap.visible { display: flex; }
.audio-preview-label {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-light);
  border: 1.5px solid var(--brand-border);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}
.audio-preview-clear {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-muted);
  border: none;
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.audio-preview-clear:hover { background: #ef4444; }

/* ── User voice message bubble ────────────────────────────────── */
.voice-msg-pill {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

/* ── User image bubble ────────────────────────────────────────── */
.user-upload-img {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
  margin-bottom: 4px;
  object-fit: cover;
}

/* ── Input card inner divider ─────────────────────────────────── */
.input-divider {
  height: 1px;
  background: #e4eaed;
  margin: 10px 0;
}


/* ── Settings button & popup ─────────────────────────────────── */
.settings-wrap {
  position: relative;
}
.settings-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 0;
  flex-shrink: 0;
  transition: color .15s, opacity .15s;
  display: flex;
  align-items: center;
}
.settings-btn:hover  { color: var(--brand-accent); }
.settings-btn:active { opacity: .6; }
.settings-btn[aria-expanded="true"] { color: var(--brand-accent); }

.settings-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 14px 16px;
  min-width: 220px;
  z-index: 30;
}
.settings-menu[hidden] { display: none; }

.settings-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: default;
}
.settings-zip {
  width: 90px;
  font-family: var(--font);
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  outline: none;
  text-align: center;
  transition: border-color .15s;
}
.settings-zip:focus { border-color: var(--brand-accent); }

.lang-toggle {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.lang-opt {
  flex: 1;
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.lang-opt.active {
  background: var(--brand-accent);
  color: #fff;
}
.lang-opt:not(.active):hover { background: var(--brand-light); color: var(--brand-accent); }

.settings-apply {
  width: 100%;
  background: var(--brand-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.settings-apply:hover  { opacity: .88; }
.settings-apply:active { opacity: .7; }

/* ── Clear confirmation popup ──────────────────────────────────── */
.clear-wrap {
  position: relative;
}
.clear-menu {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 14px 16px;
  width: 80vw;
  z-index: 30;
}
.clear-menu[hidden] { display: none; }

.clear-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.4;
}
.clear-actions {
  display: flex;
  gap: 8px;
}
.clear-cancel {
  flex: 1;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-primary);
  transition: background .15s;
}
.clear-cancel:hover  { background: var(--brand-light); }
.clear-cancel:active { opacity: .7; }

.clear-confirm {
  flex: 1;
  background: #e53e3e;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.clear-confirm:hover  { opacity: .88; }
.clear-confirm:active { opacity: .7; }

/* ── Debug info popup (long-press on hint) ────────────────────── */
.debug-popup {
  position: fixed;
  top: 33vh;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 14px 16px;
  width: 72vw;
  z-index: 100;
}
.debug-popup[hidden] { display: none; }

.debug-info {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 14px;
  word-break: break-all;
}
.debug-info strong {
  color: var(--text-primary);
  font-weight: 600;
}
.debug-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.debug-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--brand-accent);
}

/* ── Markdown tables ──────────────────────────────────────────── */
.message.bot .bubble .table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 12px 0;
  font-size: 0.85em;
}
.message.bot .bubble table {
  border-collapse: collapse;
  width: 100%;
}
.message.bot .bubble th,
.message.bot .bubble td {
  border: 1px solid var(--border);
  padding: 7px 14px;
  text-align: left;
  white-space: nowrap;
}
.message.bot .bubble th {
  background: var(--brand-light);
  font-weight: 600;
  color: var(--brand);
}
.message.bot .bubble tr:nth-child(even) td { background: #f9fbfc; }

/* ── Error state ──────────────────────────────────────────────── */
.error-bubble {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #78350f;
}

.retry-btn {
  display: block;
  margin: 10px auto 0;
  padding: 5px 12px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.retry-btn:active {
  background: #1d4ed8;
}

.response-timing {
  display: none; /* hidden by default; shown when html has .show-timings */
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: #aab4c4;
  text-align: right;
  letter-spacing: .2px;
}
.show-timings .response-timing { display: block; }

/* ── Material Symbols base ────────────────────────────────────── */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 24px;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}

/* ── Dark mode ──────────────────────────────────────────────────────────── */
html.dark-mode {
  color-scheme:   dark;
  --bg:           #0C1223;
  --surface:      #122333;
  --border:       #1F3A4A;
  --text-primary: #E8E9EA;
  --text-muted:   #D0D2D6;
  --bubble-user:  #151F32;
  --bubble-bot:   #2A354C;
  --brand-light:  #0C2637;
  --brand-accent: #E8E9EA;
  --brand-border: #1A3848;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.4);
  --shadow-md:    0 4px 16px rgba(0,0,0,.5);
}

/* Card surfaces */
html.dark-mode .message.bot .bubble .offer-card,
html.dark-mode .message.bot .bubble .cashback-card,
html.dark-mode .message.bot .bubble .campaign-card,
html.dark-mode .message.bot .bubble .recipe-card {
  background: #1a3040;
  border: 1px solid var(--border);
}

/* Inline code */
html.dark-mode .message.bot .bubble code { background: #1a2f3c; }

/* Header zip badge */
html.dark-mode .header-zip-badge { background: var(--surface); }

/* Welcome tip block */
html.dark-mode .welcome-tip-block { background: var(--brand-light); }

/* Input divider */
html.dark-mode .input-divider { background: #253d4e; }

/* Input placeholder */
html.dark-mode .input-field::placeholder { color: #4a6575; }

/* Disabled send button */
html.dark-mode .send-btn:disabled { background: #1a2f3c; color: #4a6575; }
html.dark-mode .send-btn:not(:disabled) { background: #A9E5FB; color: #05364D; }
html.dark-mode .send-btn:not(:disabled):hover { background: #8dd9f7; }

/* Photo and mic buttons */
html.dark-mode .photo-btn,
html.dark-mode .mic-btn { color: var(--text-muted); }

/* Suggestion chip icon boxes */
html.dark-mode .chip-icon-blue  { background: #E0F7FF; color: #05364D; }
html.dark-mode .chip-icon-green { background: #0e2b1a; color: #4cba70; }
html.dark-mode .chip-icon-gray  { background: #1a2a30; color: #8caabb; }
html.dark-mode .chip-icon-olive { background: #1c2c00; color: #a2d848; }

/* Chip titles */
html.dark-mode .chip-title { color: var(--text-muted); }

/* Table alternating rows */
html.dark-mode .message.bot .bubble tr:nth-child(even) td { background: #162533; }

/* Table header */
html.dark-mode .message.bot .bubble th {
  background: var(--brand-light);
  color: var(--text-primary);
}

/* Trash/clear button */
html.dark-mode .clear-btn { color: var(--text-muted); }

/* Settings panel */
html.dark-mode .settings-zip {
  background: var(--surface);
  color: var(--text-primary);
}
html.dark-mode .lang-opt.active {
  color: var(--surface);
}
html.dark-mode .settings-apply {
  color: var(--surface);
}

/* Error bubble */
html.dark-mode .error-bubble {
  background: #2a2000;
  border-color: #5a4a00;
  color: #fde68a;
}


/* Response timing */
html.dark-mode .response-timing { color: #4a6575; }

/* Input area shadow */
html.dark-mode .input-area {
  box-shadow: 0 4px 32px rgba(0,0,0,.4), 0 1px 6px rgba(0,0,0,.3);
}
