/* ============================================================
   AI chat — embedded/inline (mounted into [data-chat] containers).
   Used on the dedicated chat page and inline on the catalog page.
   ============================================================ */

.tg-chat-embed {
  display: flex; flex-direction: column; height: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}

/* header */
.tg-chat__head {
  display: flex; align-items: center; gap: .7rem;
  padding: var(--sp-4); color: #fff; background: var(--ink-dark);
  border-bottom: 1px solid rgba(255,255,255,.08); flex: none;
}
.tg-chat__head .avatar { width: 38px; height: 38px; border-radius: 11px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.tg-chat__head .avatar svg { width: 20px; height: 20px; }
.tg-chat__head .who strong { font-family: var(--font-display); font-size: var(--fs-400); display: block; line-height: 1.2; }
.tg-chat__head .who span { font-size: var(--fs-300); color: #b4c2cb; display: inline-flex; align-items: center; gap: .35rem; }
.tg-chat__head .who span::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* messages */
/* NOTE: no `scroll-behavior: smooth` here. The reply streams in word-by-word and
   each delta re-targets scrollTop; smooth restarts the animation every time, so a
   long answer never catches up and appears not to auto-scroll. Instant wins. */
.tg-chat__log { flex: 1; overflow-y: auto; padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); background: var(--paper); overscroll-behavior: contain; }
.tg-msg { max-width: 88%; padding: .7rem .9rem; border-radius: 16px; font-size: var(--fs-400); line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; animation: tg-in .25s var(--ease-out); }
@keyframes tg-in { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }
.tg-msg--bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; color: var(--ink); }
.tg-msg--user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 5px; }
.tg-msg a { color: var(--accent-deep); text-decoration: underline; }
.tg-msg--user a { color: #cfeefb; }
.tg-msg strong { font-weight: 600; }
.tg-msg .tg-list { margin: .45rem 0 .3rem; padding-left: 1.35rem; white-space: normal; }
.tg-msg ul.tg-list { list-style: disc; }
.tg-msg ol.tg-list { list-style: decimal; }
.tg-msg .tg-list li { margin: .22rem 0; padding-left: .1rem; }
.tg-msg .tg-list li::marker { color: var(--accent-deep); }

/* product recommendation cards */
.tg-recos { display: flex; flex-direction: column; gap: var(--sp-2); align-self: stretch; }
.tg-reco { display: flex; gap: .7rem; align-items: center; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: .55rem; transition: border-color var(--dur), transform var(--dur), box-shadow var(--dur); }
.tg-reco:hover { border-color: var(--accent-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.tg-reco img { width: 52px; height: 52px; border-radius: 9px; object-fit: cover; background: var(--paper-2); flex: none; }
.tg-reco .info { min-width: 0; }
.tg-reco .info strong { display: block; font-family: var(--font-display); font-size: var(--fs-400); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-reco .info span { font-size: var(--fs-300); color: var(--ink-3); }
.tg-reco--quote { display: block; border-color: var(--accent-strong); background: var(--accent-tint); }
.tg-reco__qt { font-family: var(--font-display); font-weight: 600; color: var(--ink); margin-bottom: .3rem; }
.tg-reco__qd { font-size: var(--fs-300); color: var(--ink-2); margin-bottom: .6rem; }

/* typing indicator */
.tg-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; border-bottom-left-radius: 5px; }
.tg-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: tg-bounce 1.2s infinite; }
.tg-typing i:nth-child(2) { animation-delay: .15s; }
.tg-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes tg-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5;} 30% { transform: translateY(-5px); opacity: 1; } }

/* quick chips */
.tg-chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 var(--sp-4) var(--sp-3); background: var(--paper); flex: none; }
.tg-chip { font-size: var(--fs-300); padding: .45rem .7rem; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; transition: all var(--dur); }
.tg-chip:hover { border-color: var(--accent-strong); background: var(--accent-tint); color: var(--accent-deep); }
/* one-tap style choices under a "which one?" question */
.tg-options { display: flex; flex-wrap: wrap; gap: .45rem; align-self: flex-start; max-width: 88%; margin: .1rem 0 .2rem; }
.tg-opt { font-size: var(--fs-300); font-weight: 600; padding: .5rem .85rem; border-radius: var(--r-pill);
  border: 1.5px solid var(--accent-strong); background: var(--accent-tint); color: var(--accent-deep);
  cursor: pointer; transition: background var(--dur), color var(--dur); animation: tg-in .25s var(--ease-out); }
.tg-opt:hover { background: var(--accent-strong); color: #fff; }

/* composer */
.tg-chat__form { display: flex; gap: .5rem; align-items: flex-end; padding: var(--sp-3); border-top: 1px solid var(--line); background: var(--surface); flex: none; }
.tg-chat__form textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 14px; padding: .7rem .85rem; max-height: 140px; min-height: 46px; background: var(--paper); font-size: var(--fs-400); line-height: 1.4; transition: border-color var(--dur), box-shadow var(--dur); }
.tg-chat__form textarea:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 3px var(--accent-tint); background: var(--surface); }
.tg-send { flex: none; width: 46px; height: 46px; border-radius: 13px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; transition: transform var(--dur), background var(--dur); }
.tg-send:hover:not(:disabled) { transform: translateY(-2px); background: var(--accent-strong); }
.tg-send:disabled { opacity: .45; cursor: not-allowed; }
.tg-send svg { width: 20px; height: 20px; }

.tg-chat__foot { font-size: 11px; color: var(--ink-3); text-align: center; padding: 0 0 .6rem; background: var(--surface); flex: none; }
.tg-chat__foot .stub { color: var(--accent-deep); font-weight: 600; }

/* page/embed sizing wrappers */
.chat-full { height: min(72vh, 680px); }
.chat-embed { height: 520px; }
@media (max-width: 720px) { .chat-embed { height: 460px; } }

/* ---- design image upload (print-method analysis) ---- */
.tg-chat__form .tg-attach {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-3); display: grid; place-items: center; cursor: pointer;
  transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.tg-chat__form .tg-attach:hover { color: var(--accent-deep); border-color: var(--accent-strong); background: var(--accent-tint); }
.tg-chat__form .tg-attach svg { width: 18px; height: 18px; }
.tg-attach-preview { display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem; margin: 0 0 .4rem; border: 1px dashed var(--accent-strong); border-radius: 10px; background: var(--accent-tint); }
.tg-attach-preview img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.tg-attach-preview .name { font-size: var(--fs-300); color: var(--ink-2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-attach-x { border: none; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 1rem; padding: 0 .25rem; }
.tg-attach-x:hover { color: #e5484d; }
.tg-msg__img { max-width: 200px; max-height: 200px; border-radius: 10px; display: block; margin-bottom: .35rem; }

/* "New chat" — resets the conversation. Sits at the top-right of the header
   (margin-left:auto pushes it past the avatar/title), quiet until hovered so it
   never competes with the assistant's name. */
.tg-reset {
  margin-left: auto; flex: none;
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .55rem; border-radius: var(--r-pill);
  border: 1px solid rgba(255,255,255,.22); background: transparent;
  color: #dbe6ec; font: inherit; font-size: var(--fs-300); font-weight: 600;
  line-height: 1; cursor: pointer;
  transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.tg-reset:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.4); color: #fff; }
.tg-reset svg { width: 14px; height: 14px; flex: none; }
/* Narrow embeds: keep the icon, drop the label so the header never wraps. */
@media (max-width: 420px) {
  .tg-reset span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tg-reset { padding: .35rem; }
}

/* WhatsApp hand-off — the next step, so it gets button weight rather than
   sitting inline in the paragraph. WhatsApp's own green signals where the tap
   goes; the assistant's other links stay plain text links. */
.tg-msg--bot a.tg-wa-btn {
  display: inline-flex; align-items: center; gap: .45rem;
  margin-top: .6rem; padding: .55rem .95rem;
  background: #25d366; color: #05301a;
  font-weight: 600; font-size: .9375rem; line-height: 1.2;
  border-radius: 999px; text-decoration: none;
  transition: background .15s ease, transform .15s ease;
}
.tg-msg--bot a.tg-wa-btn::before {
  content: ""; width: 16px; height: 16px; flex: none;
  background: currentColor;
  -webkit-mask: var(--tg-wa-icon) center/contain no-repeat;
  mask: var(--tg-wa-icon) center/contain no-repeat;
}
.tg-msg--bot a.tg-wa-btn:hover { background: #1fbb57; }

/* Sits under the WhatsApp button. WhatsApp cannot send on the customer's behalf,
   so they still have to press send — this explains why there is a code in the
   message they are about to send, and reassures them the conversation itself is
   already with us. Without it the code reads as junk to be deleted. */
.tg-msg--bot .tg-ref-note {
  display: block;
  margin-top: .45rem;
  font-size: .78rem;
  line-height: 1.45;
  color: var(--ink-3, #77746A);
}
.tg-msg--bot a.tg-wa-btn:active { transform: translateY(1px); }
.tg-msg--bot a.tg-wa-btn:focus-visible { outline: 2px solid #05301a; outline-offset: 2px; }
:root {
  --tg-wa-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12.04 2A9.9 9.9 0 0 0 2.15 11.9c0 1.75.46 3.45 1.32 4.95L2 22l5.3-1.39a9.9 9.9 0 0 0 4.74 1.21h.01A9.9 9.9 0 0 0 21.94 11.9 9.9 9.9 0 0 0 12.04 2Zm5.8 14.06c-.24.68-1.4 1.3-1.94 1.34-.5.04-.98.22-3.3-.69-2.78-1.09-4.55-3.93-4.69-4.11-.14-.18-1.12-1.49-1.12-2.84 0-1.35.71-2.02.96-2.29.25-.28.55-.34.73-.34l.52.01c.17 0 .4-.06.62.48.24.57.8 1.97.87 2.11.07.14.12.31.02.49-.09.18-.14.29-.28.45l-.42.49c-.14.14-.28.3-.12.58.16.28.71 1.17 1.53 1.9 1.05.94 1.94 1.23 2.22 1.37.28.14.44.12.6-.07.17-.19.7-.81.88-1.09.19-.28.37-.23.63-.14.25.09 1.65.78 1.93.92.28.14.47.21.54.33.07.11.07.65-.17 1.33Z'/%3E%3C/svg%3E");
}
