
/* ==========================================================================
   Galaxy Star AI - the chat widget
   ========================================================================== */

/*
 * The panel is pinned with both edges, so nothing inside it - a long unbroken
 * word in a reply, a wide product card, the composer's input - can widen the
 * box past the edge of the screen. min-width:0 lets the flex children shrink
 * below the size their content asks for, which is what actually keeps a chat log
 * inside its panel.
 */
.ai-launcher, .ai-panel { max-width: 100%; }
.ai-panel > *, .ai-panel__log > * { min-width: 0; }
.ai-bubble, .ai-card b, .ai-card span { overflow-wrap: anywhere; }

.ai-launcher {
  position: fixed; inset-inline-end: 24px; bottom: 84px; z-index: 120;
  display: flex; align-items: center; gap: 9px;
  padding: 11px 20px 11px 13px; border: 0; border-radius: 999px;
  background: linear-gradient(135deg, var(--pink), var(--pink-accent));
  color: #fff; font-weight: 700; font-size: 14.5px;
  box-shadow: 0 8px 24px rgba(214, 36, 110, .38);
  transition: transform .18s, box-shadow .18s;
}
[dir="rtl"] .ai-launcher { padding: 11px 13px 11px 20px; }
.ai-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(214, 36, 110, .46); }
.ai-launcher__icon { font-size: 19px; }
.ai-launcher.is-hidden { display: none; }

.ai-panel {
  position: fixed; inset-inline-end: 20px; bottom: 190px; z-index: 130;
  width: min(384px, calc(100vw - 32px));
  /* dvh is the viewport height that changes when the phone's address bar slides
     away; vh is not, so a panel sized in vh ends up taller than the screen it
     is measured against once the bar is showing. */
  height: min(560px, calc(100dvh - 220px));
  background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--line);
  transform-origin: bottom right;
  animation: aiPop .18s ease;
}
[dir="rtl"] .ai-panel { transform-origin: bottom left; }
@keyframes aiPop { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.ai-panel[hidden] { display: none; }

.ai-panel__head {
  display: flex; align-items: center; gap: 11px; padding: 13px 15px;
  background: linear-gradient(135deg, var(--pink), var(--pink-accent)); color: #fff;
}
.ai-panel__avatar {
  width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.22);
  display: grid; place-items: center; font-size: 19px; flex: 0 0 auto;
}
.ai-panel__status { font-size: 12px; opacity: .95; display: flex; align-items: center; gap: 5px; }
.ai-dot { width: 7px; height: 7px; border-radius: 50%; background: #7dffb0; }
.ai-panel__close {
  background: rgba(255,255,255,.18); border: 0; color: #fff; width: 30px; height: 30px;
  border-radius: 50%; font-size: 21px; line-height: 1; flex: 0 0 auto;
}
.ai-panel__close:hover { background: rgba(255,255,255,.32); }

.ai-panel__log {
  flex: 1; overflow-y: auto; padding: 15px; background: var(--pink-soft);
  /*
   * Without this the log refuses to shrink below the height of its messages. A
   * flex item's minimum height is its content by default, so a long answer
   * pushed the input box and the footer straight off the bottom of the panel
   * instead of scrolling inside it.
   */
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.ai-msg { margin-bottom: 11px; display: flex; }
.ai-msg--user { justify-content: flex-end; }
.ai-bubble {
  max-width: 84%; padding: 10px 14px; border-radius: 15px; font-size: 14px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.ai-msg--bot .ai-bubble { background: #fff; border: 1px solid var(--line); border-start-start-radius: 4px; }
.ai-msg--user .ai-bubble { background: var(--pink); color: #fff; border-start-end-radius: 4px; }
.ai-msg--err .ai-bubble { background: #fdecec; color: #a01f24; border: 1px solid #f5c9c9; }

.ai-typing { display: flex; gap: 4px; padding: 4px 2px; }
.ai-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--pink-accent);
  animation: aiBounce 1.1s infinite;
}
.ai-typing i:nth-child(2) { animation-delay: .18s; }
.ai-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes aiBounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }

.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ai-chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--pink-dark); font-size: 12.5px; font-weight: 600;
}
.ai-chip:hover { background: var(--pink-light); border-color: var(--pink-accent); }

.ai-cards { display: grid; gap: 8px; margin-top: 8px; }
.ai-card {
  display: flex; gap: 10px; align-items: center; padding: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 11px;
  color: var(--ink); font-size: 13px;
}
.ai-card:hover { border-color: var(--pink); }
.ai-card img { width: 46px; height: 46px; object-fit: cover; border-radius: 7px; flex: 0 0 auto; }
.ai-card b { display: block; font-size: 13.5px; }
.ai-card .ai-card__price { color: var(--pink); font-weight: 700; }
.ai-card .ai-card__was { text-decoration: line-through; color: var(--ink-faint); font-size: 11.5px; margin-inline-start: 5px; }

.ai-panel__form {
  display: flex; gap: 8px; padding: 11px; border-top: 1px solid var(--line); background: #fff;
}
.ai-panel__form input {
  flex: 1; padding: 10px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--pink-soft); font-size: 14px; min-width: 0;
}
.ai-panel__form input:focus { outline: 0; border-color: var(--pink); background: #fff; }
.ai-panel__form button {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: 0 0 auto;
  background: var(--pink); color: #fff; font-size: 16px;
}
.ai-panel__form button:hover { background: var(--pink-dark); }
.ai-panel__form button[disabled] { opacity: .5; }
.ai-panel__foot { padding: 0 11px 9px; font-size: 11px; color: var(--ink-faint); text-align: center; background: #fff; }

/*
 * Phones.
 *
 * The panel is pinned with both edges rather than a width, so it fills the
 * screen exactly and cannot be pushed past it by a long word or a wide bubble.
 * The height comes off the top as well as the bottom, and the input stays above
 * the phone's home bar via the safe-area inset - otherwise the send button ends
 * up underneath the bar and looks untappable.
 */
@media (max-width: 720px) {
  .ai-launcher {
    bottom: calc(130px + env(safe-area-inset-bottom)); inset-inline-end: 16px;
    padding: 12px; gap: 0;
  }
  .ai-launcher__text { display: none; }

  .ai-panel {
    inset-inline: 10px;
    /* Clears the mobile nav bar at the bottom, the phone's home bar, and
       whatever the software keyboard is covering right now. --ai-kb is set by
       ai.js from the visual viewport and is 0 when no keyboard is up. */
    top: max(10px, env(safe-area-inset-top));
    bottom: calc(66px + env(safe-area-inset-bottom) + var(--ai-kb, 0px));
    width: auto;
    max-width: none;
    max-height: none;
    height: auto;
    border-radius: 16px;
  }

  .ai-bubble { max-width: 88%; }

  /* The composer is the part that must stay reachable, so it never scrolls away
     and never shrinks below a comfortable tap target. */
  .ai-panel__form { padding: 9px 10px; }
  .ai-panel__form input { font-size: 16px; padding: 11px 14px; }
  .ai-panel__form button { width: 44px; height: 44px; }
}

/*
 * Short screens - a phone held sideways, or a small window on a laptop. The
 * panel is tall enough that the header and the composer were the first things to
 * disappear, so the height is capped against the space that is actually there.
 */
@media (max-height: 520px) {
  .ai-panel { height: auto; }
  .ai-panel__foot { display: none; }
  .ai-panel__head { padding: 9px 12px; }
  .ai-launcher { bottom: 90px; }
}
