/* Site assistant: floating button, chat panel, agent bar and the pixel helper. Uses the shared design tokens (light/dark follow the theme).
   Every animation is switched off under prefers-reduced-motion at the bottom. */
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 55; }

/* ---- Button */
.chat-fab { position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; border: 0; border-radius: var(--r-pill); cursor: pointer; font: inherit; font-weight: 600; color: var(--brand-fg);
  background: linear-gradient(135deg, var(--brand), #6a3df0); box-shadow: 0 10px 28px color-mix(in srgb, var(--brand) 40%, transparent); transition: transform .2s var(--ease), box-shadow .2s; animation: chat-fab-in .5s var(--ease) both; }
.chat-fab::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 45%, transparent); animation: chat-ring 3.2s ease-out 1.2s 3; }
.chat-fab:hover { transform: translateY(-2px) scale(1.03); }
.chat-fab:active { transform: scale(.97); }
.chat-fab[hidden] { display: none; }
.chat-fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@keyframes chat-fab-in { from { opacity: 0; transform: translateY(14px) scale(.9); } }
@keyframes chat-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 45%, transparent); } 70%, 100% { box-shadow: 0 0 0 16px transparent; } }

/* ---- Panel */
.chat-panel { display: flex; flex-direction: column; width: min(392px, calc(100vw - 24px)); height: min(600px, calc(100vh - 40px)); background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-3); overflow: hidden; transform-origin: 100% 100%;
  opacity: 0; transform: translateY(14px) scale(.96); transition: opacity .18s ease, transform .22s var(--ease); }
.chat-panel.is-open { opacity: 1; transform: none; }
.chat-panel[hidden] { display: none; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 12px 12px 14px; background: var(--band-royal, var(--brand)); color: #fff; }
.chat-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-title strong { display: block; font-size: 1rem; line-height: 1.2; }
.chat-sub { display: flex; align-items: center; gap: 6px; font-size: .75rem; opacity: .85; }
.chat-online { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgb(74 222 128 / 25%); }
.chat-avatar { flex: none; width: 36px; height: 36px; border-radius: 12px; background: #fff url("/icon.svg") center / 26px no-repeat; box-shadow: 0 2px 8px rgb(0 0 0 / 25%); }
.chat-head-actions { display: flex; gap: 2px; }
.chat-head .icon-btn { color: #fff; min-width: 36px; height: 36px; }
.chat-head .icon-btn:hover { background: rgb(255 255 255 / 16%); color: #fff; }
.chat-body { position: relative; flex: 1; min-height: 0; display: flex; }
.chat-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); scroll-behavior: smooth; }
.chat-down { position: absolute; right: 12px; bottom: 10px; width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2); cursor: pointer; animation: chat-pop .2s var(--ease); }
.chat-down[hidden] { display: none; }
.chat-down svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Messages */
.chat-msg { max-width: 86%; padding: 9px 13px; border-radius: 16px; font-size: .9375rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; animation: chat-pop .26s var(--ease) both; }
.chat-msg.no-anim { animation: none; }
.chat-bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chat-user { align-self: flex-end; background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 70%, #6a3df0)); color: var(--brand-fg); border-bottom-right-radius: 5px; }
.chat-saved { align-self: center; max-width: 100%; padding: 6px 12px; border-radius: var(--r-pill); background: var(--ok-bg); text-align: center; font-size: .8125rem; color: var(--ok); }
.chat-msg.is-error { border-color: var(--danger); color: var(--danger); }
@keyframes chat-pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
.chat-typing { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-3); }
.chat-typing-text { font-size: .8125rem; animation: chat-fade 2.2s ease-in-out infinite; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); opacity: .35; animation: chat-dot 1.1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-5px); opacity: 1; } }
@keyframes chat-fade { 50% { opacity: .55; } }

/* ---- Chips and composer */
.chat-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; background: var(--surface-2); }
.chat-chips:empty { display: none; }
.chat-chip { padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-pill); background: var(--surface); color: var(--link); font: inherit; font-size: .8125rem; cursor: pointer; text-align: left;
  transition: background .15s, border-color .15s, transform .15s var(--ease); animation: chat-pop .3s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
.chat-chip:hover { background: var(--brand-subtle); border-color: var(--brand); transform: translateY(-1px); }
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; background: var(--surface-2); }
.chat-form .field { flex: 1; min-width: 0; min-height: 44px; max-height: 120px; resize: none; line-height: 1.4; padding: 10px 14px; border-radius: 22px; }
.chat-send { flex: none; width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
.chat-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-send:disabled { opacity: .5; transform: none; box-shadow: none; }
.chat-note { margin: 0; padding: 0 14px 10px; background: var(--surface-2); font-size: .6875rem; line-height: 1.35; color: var(--ink-3); }
.chat-note a { text-decoration: underline; }

/* ---- Agent bar: replaces the panel while the helper is on the page; the visitor can keep giving it commands */
.chat-agentbar { display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px)); padding: 10px; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3); animation: chat-pop .25s var(--ease); }
.chat-agentbar[hidden] { display: none; }
.chat-agent-reply { max-height: 180px; overflow-y: auto; padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); font-size: .875rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-agent-row { display: flex; align-items: center; gap: 8px; }
.chat-agent-mini { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--accent, #ffd400); animation: chat-pulse 1.2s ease-in-out infinite; }
.chat-agent-text { flex: 1; min-width: 0; font-size: .875rem; font-weight: 600; }
.chat-agent-form { display: flex; gap: 8px; }
.chat-agent-form .field { flex: 1; min-width: 0; border-radius: var(--r-pill); }
.chat-agent-form .chat-send { width: 44px; }
@keyframes chat-pulse { 50% { transform: scale(1.5); opacity: .55; } }
.chat-wake-owl { width: 22px; height: 22px; background: url("/icon.svg") center / contain no-repeat; }

/* ---- Pixel helper (original 16x16 owl), moved by script with transform */
.chat-pet { position: fixed; left: 0; top: 0; z-index: 70; width: 48px; height: 48px; pointer-events: none; transition: transform .7s cubic-bezier(.45, .05, .25, 1); will-change: transform; }
.chat-pet[hidden] { display: none; }
.chat-pet-sprite svg { display: block; filter: drop-shadow(0 6px 6px rgb(0 0 0 / 30%)); image-rendering: pixelated; }
.chat-pet-bubble { position: absolute; right: -6px; bottom: calc(100% + 8px); width: max-content; max-width: min(220px, calc(100vw - 24px)); padding: 5px 10px; border: 2px solid #0b1030; border-radius: 8px; background: #fff; color: #0b1030;
  font-size: .75rem; font-weight: 700; line-height: 1.25; text-align: left; box-shadow: 3px 3px 0 #0b1030; }
.chat-pet-bubble:empty { display: none; }
.chat-pet-bubble::after { content: ""; position: absolute; right: 24px; top: 100%; width: 8px; height: 8px; margin: -5px 0 0 0; background: #fff; border-right: 2px solid #0b1030; border-bottom: 2px solid #0b1030; transform: rotate(45deg); }
.pet-blink { animation: pet-blink 4s steps(1) infinite; opacity: 0; }
.pet-wing { transform-origin: 8px 10px; }
[data-mood="walk"] .pet-body { animation: pet-hop .35s steps(2) infinite; }
[data-mood="walk"] .pet-wing-l { animation: pet-flap-l .25s steps(2) infinite; }
[data-mood="walk"] .pet-wing-r { animation: pet-flap-r .25s steps(2) infinite; }
[data-mood="type"] .pet-body { animation: pet-peck .3s steps(2) infinite; }
[data-mood="type"] .pet-wing-l, [data-mood="type"] .pet-wing-r { animation: pet-flap-l .18s steps(2) infinite; }
[data-mood="click"] .pet-body { animation: pet-press .5s steps(3) 1; }
[data-mood="think"] .pet-body { animation: pet-think 1.2s steps(2) infinite; transform-origin: 8px 12px; }
[data-mood="happy"] .pet-body { animation: pet-jump .5s steps(4) 3; }
[data-mood="sad"] .pet-body { transform: translateY(1px); filter: saturate(.5); }
@keyframes pet-blink { 0%, 92%, 100% { opacity: 0; } 94%, 98% { opacity: 1; } }
@keyframes pet-think { 50% { transform: rotate(-6deg) translateY(-1px); } }
@keyframes pet-hop { 50% { transform: translateY(-1.5px); } }
@keyframes pet-peck { 50% { transform: translateY(1.5px) rotate(4deg); transform-origin: 8px 12px; } }
@keyframes pet-press { 50% { transform: scale(.9, 1.1); transform-origin: 8px 16px; } }
@keyframes pet-jump { 50% { transform: translateY(-3px); } }
@keyframes pet-flap-l { 50% { transform: rotate(-18deg); } }
@keyframes pet-flap-r { 50% { transform: rotate(18deg); } }

@media (max-width: 640px) {
  .chat { right: 12px; bottom: 12px; }
  .chat-panel { position: fixed; inset: 0; width: 100vw; height: 100dvh; border-radius: 0; border: 0; transform-origin: 50% 100%; }
  .chat-fab span { display: none; }
  .chat-fab { padding: 14px; }
}
/* ---- Guided tour: a spotlight over the current element and a card. The page stays usable underneath. */
.tour-layer[hidden] { display: none; }
.tour-ring { position: fixed; left: 0; top: 0; z-index: 68; pointer-events: none; border-radius: var(--r-lg); outline: 3px solid var(--accent, #ffd400); outline-offset: 0;
  box-shadow: 0 0 0 100vmax rgb(5 9 38 / 55%); transition: transform .35s var(--ease), width .35s var(--ease), height .35s var(--ease); }
.tour-ring[hidden] { display: none; }
.tour-card { position: fixed; left: 20px; bottom: 20px; z-index: 71; display: flex; flex-direction: column; gap: 10px; width: min(392px, calc(100vw - 24px)); max-height: 60vh; overflow-y: auto; padding: 16px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-3); animation: chat-fab-in .3s var(--ease); }
.tour-head { display: flex; align-items: center; gap: 12px; }
.tour-owl { flex: none; width: 40px; height: 40px; }
.tour-owl svg { display: block; image-rendering: pixelated; }
.tour-progress { font-size: .75rem; font-weight: 600; color: var(--ink-3, var(--ink-2)); }
.tour-title { font-size: 1.0625rem; font-weight: 700; line-height: 1.3; }
.tour-text { font-size: .9375rem; line-height: 1.55; color: var(--ink-2); }
.tour-extras { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; }
.tour-dots { display: flex; flex-wrap: wrap; }
.tour-dot { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; background: none; cursor: pointer; }
.tour-dot::before { content: ""; width: 9px; height: 9px; border-radius: var(--r-pill); background: var(--line-strong); transition: width .2s var(--ease), background .2s; }
.tour-dot.is-done::before { background: color-mix(in srgb, var(--brand) 55%, transparent); }
.tour-dot[aria-current="step"]::before { width: 18px; background: var(--brand); }
.tour-ask { min-height: 24px; padding: 2px 0; border: 0; background: none; color: var(--link, var(--brand)); font: inherit; font-size: .8125rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.tour-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.tour-actions .tour-end { margin-right: auto; }
.tour-actions .btn[hidden] { display: none; }
.tour-actions .btn:disabled { opacity: .5; cursor: default; }
.chat-chip-tour { border-color: var(--brand); font-weight: 700; }
.chat-invite { position: absolute; right: 0; bottom: calc(100% + 12px); width: min(280px, calc(100vw - 24px)); padding: 12px 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3); font-size: .875rem; animation: chat-fab-in .4s var(--ease); }
.chat-invite[hidden] { display: none; }
.chat-invite-actions { display: flex; gap: 8px; margin-top: 10px; }
@media (max-width: 640px) { .tour-card { left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 46vh; } }

@media print { .chat { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .chat *, .chat *::before, .chat *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .chat-panel { opacity: 1; transform: none; }
}
@media (max-width: 640px) { .chat-pet-bubble { display: none; } }
