/* =========================================================
   Nutra Assistant — floating premium chat widget
   Available on every page; gracefully reverts to a launcher
   button when closed.
   ========================================================= */

.assistant {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 90;
}

/* ---------- Launcher (collapsed state) ---------- */
.assistant-launcher {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-direction: row-reverse;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.assistant.is-open .assistant-launcher {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
.assistant-launcher__btn {
  position: relative;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff;
  display: grid; place-items: center;
  box-shadow:
    0 14px 32px -8px rgba(26, 86, 219, 0.55),
    0 4px 12px rgba(11, 23, 51, 0.18);
  cursor: pointer;
  transition: transform var(--t-base) var(--ease);
}
.assistant-launcher__btn:hover { transform: scale(1.05); }
.assistant-launcher__btn::after {
  content: "";
  position: absolute; inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(43, 107, 255, 0.4);
  animation: assistant-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes assistant-pulse {
  0%   { transform: scale(1);   opacity: 0.85; }
  70%  { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}
.assistant-launcher__btn svg { width: 26px; height: 26px; }

.assistant-launcher__bubble {
  background: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-900);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
  position: relative;
  white-space: nowrap;
  animation: assistant-bubble-pop 600ms var(--ease-out) 1.5s both;
}
.assistant-launcher__bubble::after {
  content: "";
  position: absolute;
  right: -6px; top: 50%; transform: translateY(-50%) rotate(45deg);
  width: 12px; height: 12px;
  background: #fff;
  border-right: 1px solid var(--line);
  border-top: 1px solid var(--line);
}
.assistant-launcher__bubble strong { color: var(--brand-700); }
@keyframes assistant-bubble-pop {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Panel (expanded state) ---------- */
.assistant-panel {
  position: absolute;
  bottom: 0; right: 0;
  width: min(94vw, 400px);
  height: min(80vh, 640px);
  background: #fff;
  border-radius: var(--r-xl);
  box-shadow:
    0 30px 80px -10px rgba(11, 23, 51, 0.35),
    0 0 0 1px var(--line);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out);
}
.assistant.is-open .assistant-panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.assistant-header {
  background: linear-gradient(140deg, var(--ink-900), var(--brand-900));
  color: #fff;
  padding: 18px 22px;
  display: flex; align-items: center; gap: 12px;
  position: relative;
}
.assistant-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 1px; background: linear-gradient(90deg, transparent, rgba(43,107,255,0.5), transparent);
}
.assistant-header__avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-700));
  border: 2px solid rgba(255,255,255,0.18);
  display: grid; place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  position: relative;
  flex-shrink: 0;
}
.assistant-header__avatar::after {
  content: "";
  position: absolute; bottom: -2px; right: -2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid var(--ink-900);
}
.assistant-header__name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.015em;
}
.assistant-header__status {
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-top: 2px;
  display: flex; align-items: center; gap: 6px;
}
.assistant-header__status::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}
.assistant-header__close {
  margin-left: auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: rgba(255,255,255,0.7);
  display: grid; place-items: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.assistant-header__close:hover { background: rgba(255,255,255,0.1); color: #fff; }
.assistant-header__close svg { width: 20px; height: 20px; }

/* ---------- Body / message thread ---------- */
.assistant-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  background:
    radial-gradient(40% 40% at 0% 0%, rgba(43,107,255,0.03), transparent 60%),
    var(--canvas);
}
.assistant-body::-webkit-scrollbar { width: 6px; }
.assistant-body::-webkit-scrollbar-thumb { background: var(--slate-200); border-radius: 999px; }

.msg {
  display: flex; gap: 10px;
  align-items: flex-end;
  max-width: 88%;
  animation: msg-in 280ms var(--ease-out);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.msg--user { align-self: flex-end; flex-direction: row-reverse; }
.msg__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-700));
  display: grid; place-items: center;
  color: #fff;
  font-size: 11px; font-weight: 800;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
.msg--user .msg__avatar { background: var(--ink-900); }
.msg__bubble {
  padding: 12px 16px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-900);
  border-bottom-left-radius: 4px;
}
.msg--user .msg__bubble {
  background: var(--brand-600);
  color: #fff;
  border: 0;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 16px;
}
.msg__bubble strong { color: inherit; font-weight: 700; }
.msg__bubble p + p { margin-top: 8px; }

.msg__bubble.is-typing {
  display: flex; gap: 5px;
  padding: 14px 18px;
  align-items: center;
}
.msg__bubble.is-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--slate-400);
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.msg__bubble.is-typing span:nth-child(2) { animation-delay: 0.15s; }
.msg__bubble.is-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Product card mini (in chat) ---------- */
.msg-products {
  margin-left: 38px;
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 4px;
}
.msg-product {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px;
  align-items: center;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color var(--t-fast), transform var(--t-fast);
}
.msg-product:hover { border-color: var(--brand-200); transform: translateY(-1px); }
.msg-product__art {
  width: 44px; height: 54px;
  border-radius: 8px;
  background: linear-gradient(160deg, var(--c1, var(--brand-700)), var(--c2, var(--brand-900)));
  position: relative;
  box-shadow: inset -3px -2px 8px rgba(0,0,0,0.3);
}
.msg-product__art::before {
  content: ""; position: absolute;
  top: -3px; left: 50%; transform: translateX(-50%);
  width: 40%; height: 14%;
  background: var(--ink-900); border-radius: 3px 3px 1px 1px;
}
.msg-product__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-900);
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.msg-product__meta {
  font-size: 11px;
  color: var(--slate-500);
  margin-top: 2px;
}
.msg-product__price {
  font-size: 14px;
  font-weight: 800;
  color: var(--brand-700);
  letter-spacing: -0.01em;
}

/* ---------- Quick replies ---------- */
.msg-quick {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 4px 0 0 38px;
}
.msg-quick button {
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1.5px solid var(--brand-200);
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-700);
  transition: all var(--t-fast);
  cursor: pointer;
  letter-spacing: -0.005em;
}
.msg-quick button:hover {
  background: var(--brand-600);
  color: #fff;
  border-color: var(--brand-600);
  transform: translateY(-1px);
}

/* ---------- Composer ---------- */
.assistant-composer {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 14px 16px;
  display: flex; gap: 8px; align-items: flex-end;
}
.assistant-composer textarea {
  flex: 1;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 14px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
  background: var(--canvas);
  color: var(--ink-900);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.assistant-composer textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  background: #fff;
  box-shadow: var(--shadow-glow);
}
.assistant-composer__send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: background var(--t-fast), transform var(--t-fast);
}
.assistant-composer__send:hover { background: var(--brand-700); transform: translateY(-1px); }
.assistant-composer__send:disabled { background: var(--slate-300); cursor: not-allowed; transform: none; }
.assistant-composer__send svg { width: 18px; height: 18px; }

.assistant-hint {
  padding: 0 16px 12px;
  font-size: 11px;
  color: var(--slate-500);
  text-align: center;
  background: #fff;
  letter-spacing: 0.02em;
}
.assistant-hint span { color: var(--brand-600); font-weight: 600; }

/* Mobile: full width */
@media (max-width: 540px) {
  .assistant { bottom: 16px; right: 16px; }
  .assistant-launcher__bubble { display: none; }
  .assistant-panel {
    width: calc(100vw - 32px);
    height: calc(100dvh - 32px);
    max-height: calc(100dvh - 32px);
  }
}
