/* ============================================================
   AI gift-finder chat — floating launcher + panel, and the same
   markup mounted inline (e.g. on the gift-finder page).
   ============================================================ */

/* ---------- Launcher ---------- */
.hv-launcher {
  position: fixed;
  right: max(var(--sp-4), env(safe-area-inset-right));
  bottom: max(var(--sp-4), env(safe-area-inset-bottom));
  z-index: 120;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: .7rem .85rem;
  border: none;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-300);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur) var(--ease-out), background-color var(--dur) var(--ease);
}
.hv-launcher:hover { transform: translateY(-2px); background: var(--coral); }
.hv-launcher svg { width: 20px; height: 20px; flex: none; }
.hv-launcher__text { display: none; padding-right: var(--sp-2); }
@media (min-width: 480px) { .hv-launcher__text { display: inline; } }
.hv-launcher.is-hidden { opacity: 0; visibility: hidden; transform: scale(.9); }

/* Attention pip — shown until the visitor opens the chat once. */
.hv-launcher__pip {
  position: absolute;
  top: 6px; right: 6px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 2px var(--ink);
}
.hv-launcher:hover .hv-launcher__pip { background: #fff; }
.hv-launcher.is-seen .hv-launcher__pip { display: none; }

/* ---------- Panel ---------- */
.hv-panel {
  position: fixed;
  z-index: 130;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease-out), visibility var(--dur);
}
.hv-panel.is-open { opacity: 1; visibility: visible; transform: none; }

@media (min-width: 640px) {
  .hv-panel {
    inset: auto;
    right: max(var(--sp-4), env(safe-area-inset-right));
    bottom: max(var(--sp-4), env(safe-area-inset-bottom));
    width: min(420px, calc(100vw - var(--sp-6)));
    height: min(660px, calc(100vh - var(--sp-8)));
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
  }
}

/* Inline mount (a page section rather than a floating panel). */
.hv-chat--inline {
  position: static;
  inset: auto;
  width: 100%;
  height: min(680px, 78vh);
  opacity: 1;
  visibility: visible;
  transform: none;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  background: var(--surface);
}
.hv-chat--inline .hv-close { display: none; }

/* ---------- Head ---------- */
.hv-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  padding-top: max(var(--sp-3), env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.hv-head__avatar {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  flex: none;
}
.hv-head__avatar svg { width: 20px; height: 20px; }
.hv-head__who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.hv-head__who strong { font-family: var(--font-display); font-size: 1.0625rem; font-weight: 500; }
.hv-head__who span { font-size: var(--fs-200); color: var(--ink-3); }

.hv-close {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  flex: none;
}
.hv-close:hover { background: var(--paper-2); }
.hv-close svg { width: 16px; height: 16px; }

/* Demo-mode ribbon — visible only while running without an OpenAI key. */
.hv-demo {
  padding: var(--sp-2) var(--sp-4);
  background: #FBF9DE;
  color: var(--yellow-deep);
  font-size: var(--fs-200);
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid var(--line);
  flex: none;
}

/* ---------- Log ---------- */
.hv-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  background: var(--paper);
  scroll-behavior: smooth;
}

.hv-msg {
  max-width: 88%;
  padding: .7rem .95rem;
  border-radius: var(--r-md);
  font-size: var(--fs-300);
  line-height: 1.55;
  white-space: normal;
  word-wrap: break-word;
  animation: hv-in .3s var(--ease-out) both;
}
@keyframes hv-in { from { opacity: 0; transform: translateY(8px); } }

.hv-msg--bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.hv-msg--user {
  align-self: flex-end;
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.hv-msg p:last-child { margin-bottom: 0; }
.hv-msg a { color: var(--coral-deep); font-weight: 600; }
.hv-msg--user a { color: #fff; }
.hv-msg ul, .hv-msg ol { margin: var(--sp-2) 0 0; padding-left: 1.1em; }
.hv-msg li { margin-bottom: .25em; }
.hv-msg strong { font-weight: 600; }

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

/* ---------- Recommendation cards inside the log ---------- */
.hv-recos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
  animation: hv-in .3s var(--ease-out) both;
}
.hv-reco {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.hv-reco:hover { border-color: var(--ink); transform: translateY(-2px); }
.hv-reco img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--paper-3); }
.hv-reco__info { padding: var(--sp-2) var(--sp-3) var(--sp-3); display: grid; gap: 2px; }
.hv-reco__info strong {
  font-family: var(--font-display);
  font-size: var(--fs-300);
  font-weight: 500;
  line-height: 1.25;
}
.hv-reco__info span { font-size: var(--fs-200); color: var(--ink-3); }

/* ---------- One-tap options & starter chips ---------- */
.hv-options, .hv-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.hv-options { animation: hv-in .3s var(--ease-out) both; }
.hv-chips {
  padding: 0 var(--sp-4) var(--sp-3);
  background: var(--paper);
  flex: none;
}
.hv-opt, .hv-chip {
  padding: .45em .9em;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: var(--fs-200);
  font-weight: 500;
  cursor: pointer;
  color: var(--ink-2);
  transition: all var(--dur-fast) var(--ease);
}
.hv-opt:hover, .hv-chip:hover { border-color: var(--coral); color: var(--coral-deep); }

/* ---------- Composer ---------- */
.hv-form {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: none;
}
.hv-form textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: .6rem .9rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--paper);
  font-size: var(--fs-400);   /* 16px — stops iOS Safari zooming on focus */
  line-height: 1.45;
  resize: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.hv-form textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-tint);
}
.hv-send {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  cursor: pointer;
  flex: none;
  transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.hv-send:hover:not(:disabled) { background: var(--coral-deep); transform: scale(1.05); }
.hv-send:disabled { opacity: .4; cursor: not-allowed; }
.hv-send svg { width: 18px; height: 18px; }

.hv-foot {
  padding: 0 var(--sp-4) var(--sp-3);
  background: var(--surface);
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
  flex: none;
}
.hv-foot a { color: var(--ink-2); }

/* Scrim behind the panel on tablet+ so the page recedes. */
.hv-scrim {
  position: fixed;
  inset: 0;
  z-index: 125;
  background: rgba(34,31,31,.32);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur);
}
.hv-scrim.is-open { opacity: 1; visibility: visible; }
@media (max-width: 639px) { .hv-scrim { display: none; } }
