/* Assist Buddy — floating AI help. Animations use transform/opacity only. */
.buddy { --bd-ease: cubic-bezier(.22, 1, .36, 1); --bd-glow: #2af0c4; position: fixed; right: 22px; bottom: 22px; z-index: 900; }
html.intro-on .buddy { visibility: hidden; }

/* ---------------------------------------------------------------- launcher */
.bd-launch { position: relative; width: 64px; height: 64px; border: 0; padding: 0; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 35%, #0f4a45, #06201e 70%); box-shadow: 0 14px 34px -10px rgba(10, 160, 140, .65), 0 4px 12px rgba(0, 0, 0, .25);
  transition: transform .35s var(--bd-ease), box-shadow .3s ease; -webkit-tap-highlight-color: transparent; }
.bd-launch:hover { transform: translateY(-2px) scale(1.06); box-shadow: 0 18px 40px -10px rgba(10, 160, 140, .8), 0 4px 12px rgba(0, 0, 0, .25); }
.bd-launch:active { transform: scale(.96); }
.bd-launch:focus-visible { outline: 3px solid var(--bd-glow); outline-offset: 3px; }
.bd-ring { position: absolute; inset: -3px; border-radius: 50%; background: conic-gradient(from 0deg, #2af0c4, #0f9f8f, #3987e5, #8b5cf6, #2af0c4);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px)); mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  animation: bdSpin 6s linear infinite; will-change: transform; }
@keyframes bdSpin { to { transform: rotate(360deg); } }
.bd-facebox { position: absolute; inset: 3px; border-radius: 50%; overflow: hidden; transition: transform .45s var(--bd-ease), opacity .3s ease; }
.bd-face { width: 100%; height: 100%; object-fit: cover; transform: scale(1.12) translateY(4%); animation: bdBob 3.2s ease-in-out infinite; will-change: transform; }
@keyframes bdBob { 0%, 100% { transform: scale(1.12) translateY(4%); } 50% { transform: scale(1.12) translateY(-2%); } }
.bd-close { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; opacity: 0; transform: rotate(-90deg) scale(.6); transition: transform .45s var(--bd-ease), opacity .3s ease; }
.bd-close svg { width: 24px; height: 24px; }
.bd-launch.on .bd-facebox { opacity: 0; transform: rotate(90deg) scale(.5); }
.bd-launch.on .bd-close { opacity: 1; transform: none; }
.bd-ai { position: absolute; top: -4px; right: -6px; padding: 2px 6px; border-radius: 10px; font: 800 9.5px/1.3 Inter, system-ui, sans-serif; letter-spacing: .06em; color: #04201f;
  background: linear-gradient(135deg, #7ff7e4, #2af0c4); box-shadow: 0 2px 8px rgba(42, 240, 196, .55); transition: opacity .25s; }
.bd-launch.on .bd-ai { opacity: 0; }

/* greeting bubble */
.bd-greet { position: absolute; right: 0; bottom: 78px; width: 260px; padding: 12px 34px 12px 14px; border-radius: 16px 16px 4px 16px; cursor: pointer; font-size: 13px; line-height: 1.45; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.bd-greet b { display: block; margin-bottom: 2px; }
.bd-greet-x { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.bd-greet-x:hover { background: var(--surface-3); color: var(--text); }
.bd-pop-enter-active { transition: opacity .4s ease, transform .5s var(--bd-ease); }
.bd-pop-leave-active { transition: opacity .25s ease, transform .25s ease; }
.bd-pop-enter-from, .bd-pop-leave-to { opacity: 0; transform: translateY(10px) scale(.92); transform-origin: 100% 100%; }

/* ---------------------------------------------------------------- panel */
.bd-panel { position: fixed; right: 22px; bottom: 100px; width: 400px; height: min(640px, calc(100vh - 128px)); display: flex; flex-direction: column; overflow: hidden;
  border-radius: 22px; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 30px 80px -20px rgba(2, 20, 19, .45), 0 8px 24px rgba(2, 20, 19, .18);
  transform-origin: calc(100% - 32px) calc(100% + 46px); transition: width .45s var(--bd-ease), height .45s var(--bd-ease); }
.buddy.wide .bd-panel { width: min(760px, calc(100vw - 44px)); height: min(780px, calc(100vh - 128px)); }
.bd-panel-enter-active { transition: opacity .3s ease, transform .5s var(--bd-ease); }
.bd-panel-leave-active { transition: opacity .2s ease, transform .25s ease; }
.bd-panel-enter-from, .bd-panel-leave-to { opacity: 0; transform: translateY(18px) scale(.9); }

.bd-head { display: flex; align-items: center; gap: 10px; padding: 12px 10px 12px 14px; color: #fff; flex: none;
  background: radial-gradient(280px 120px at 0% 0%, rgba(42, 240, 196, .28), transparent 70%), linear-gradient(135deg, #0b3b37, #06201e); }
.bd-avatar { position: relative; width: 40px; height: 40px; flex: none; border-radius: 50%; background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14); }
.bd-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; transform: scale(1.12) translateY(3%); }
.bd-dot { position: absolute; right: -1px; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; background: #3cdc8c; box-shadow: 0 0 0 2px #0a2f2c; }
.bd-dot.off { background: #f0b23c; }
.bd-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.bd-title b { font-size: 15px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bd-title small { font-size: 11.5px; color: rgba(214, 255, 247, .72); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bd-hbtn { width: 34px; height: 34px; flex: none; border: 0; border-radius: 10px; background: transparent; color: inherit; opacity: .82; cursor: pointer; display: grid; place-items: center; transition: background .2s, opacity .2s; }
.bd-hbtn:hover, .bd-hbtn.on { background: rgba(255, 255, 255, .12); opacity: 1; }
.bd-hbtn.sm { width: 28px; height: 28px; color: var(--muted); }
.bd-hbtn.sm:hover { background: var(--surface-3); color: var(--bad); }

.bd-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth;
  background: radial-gradient(420px 260px at 100% 0%, color-mix(in srgb, var(--brand) 6%, transparent), transparent 70%), var(--surface); }

/* welcome */
.bd-welcome { margin: auto 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 4px 6px 10px; animation: bdIn .5s var(--bd-ease) both; }
.bd-hero { position: relative; width: 150px; height: 168px; margin-bottom: 4px; }
.bd-hero img { position: relative; width: 100%; height: 100%; object-fit: contain; animation: bdFloat 4s ease-in-out infinite; will-change: transform; filter: drop-shadow(0 16px 22px rgba(4, 40, 37, .28)); }
.bd-hero-glow { position: absolute; left: 50%; bottom: -4px; width: 120px; height: 22px; margin-left: -60px; border-radius: 50%; background: radial-gradient(closest-side, rgba(15, 159, 143, .35), transparent); animation: bdShadow 4s ease-in-out infinite; }
@keyframes bdFloat { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-8px) rotate(1deg); } }
@keyframes bdShadow { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.82); opacity: .7; } }
@keyframes bdIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.bd-welcome h3 { font-size: 17px; margin: 2px 0 0; }
.bd-welcome p { margin: 0 0 6px; font-size: 13px; color: var(--text-2); line-height: 1.55; max-width: 330px; }
.bd-suggest { width: 100%; display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.bd-suggest button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 12px; cursor: pointer; font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); transition: background .2s, border-color .2s, transform .2s var(--bd-ease); }
.bd-suggest button svg { color: var(--brand); flex: none; }
.bd-suggest button:hover { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); transform: translateX(2px); }

/* messages */
.bd-msg { display: flex; gap: 8px; animation: bdIn .35s var(--bd-ease) both; }
.bd-msg.me { justify-content: flex-end; }
.bd-msg.me .bd-bubble { max-width: 82%; padding: 9px 13px; border-radius: 16px 16px 4px 16px; color: #fff; white-space: pre-wrap; word-break: break-word;
  background: linear-gradient(135deg, #12b3a0, #0b7c70); box-shadow: 0 6px 16px -8px rgba(11, 124, 112, .8); font-size: 13.5px; line-height: 1.5; }
.bd-mini { width: 28px; height: 28px; flex: none; border-radius: 50%; object-fit: cover; background: #0b2e2b; margin-top: 2px; }
.bd-col { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.bd-msg.bot .bd-bubble { max-width: 100%; padding: 10px 13px; border-radius: 4px 16px 16px 16px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13.5px; line-height: 1.6; color: var(--text); word-break: break-word; }
.bd-bubble.err { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--bad-soft) !important; border-color: color-mix(in srgb, var(--bad) 30%, transparent) !important; }
.md p { margin: 0 0 8px; } .md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 20px; } .md li { margin: 3px 0; } .md li::marker { color: var(--brand); }
.md h4 { margin: 10px 0 4px; font-size: 13.5px; }
.md b { font-weight: 700; color: var(--text); }
.md code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 1px 5px; border-radius: 5px; background: var(--surface-3); }
.md pre { margin: 6px 0; padding: 10px; border-radius: 10px; background: #061d1c; color: #d6fff6; overflow-x: auto; }
.md pre code { background: none; padding: 0; color: inherit; }
.md a { color: var(--brand-strong); font-weight: 600; }
.md a.bd-link { display: inline-flex; align-items: center; gap: 5px; margin: 2px 2px 2px 0; padding: 3px 10px; border-radius: 20px; text-decoration: none; font-size: 12.5px;
  background: var(--brand-soft); color: var(--brand-strong); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); transition: background .2s, transform .2s var(--bd-ease); }
.md a.bd-link:hover { background: color-mix(in srgb, var(--brand) 18%, var(--surface)); transform: translateY(-1px); }
.md a.bd-link span { transition: transform .2s var(--bd-ease); } .md a.bd-link:hover span { transform: translateX(2px); }
.bd-table { overflow-x: auto; margin: 6px 0; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.md th, .md td { padding: 6px 9px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.md th { background: var(--surface-3); font-weight: 650; } .md tr:last-child td { border-bottom: 0; }
.bd-bubble.typing > div > :last-child::after { content: ''; display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px; border-radius: 2px; background: var(--brand); animation: bdBlink .9s steps(2) infinite; }
@keyframes bdBlink { 50% { opacity: 0; } }
.bd-dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.bd-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); opacity: .4; animation: bdDot 1.1s ease-in-out infinite; }
.bd-dots i:nth-child(2) { animation-delay: .15s; } .bd-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bdDot { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-5px); opacity: 1; } }
.bd-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.bd-tool { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 12px; color: var(--text-2); background: var(--surface-2); border: 1px dashed var(--border-strong); animation: bdIn .3s var(--bd-ease) both; }
.bd-tool.done { border-style: solid; color: var(--brand-strong); }
.bd-spin { width: 11px; height: 11px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--brand) 30%, transparent); border-top-color: var(--brand); animation: bdSpin .8s linear infinite; }
.bd-actions { display: flex; gap: 2px; opacity: .75; transition: opacity .2s; }
.bd-msg:hover .bd-actions { opacity: 1; }
.bd-actions button { width: 28px; height: 26px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.bd-actions button:hover { background: var(--surface-3); color: var(--text); }
.bd-actions button.on { color: var(--brand-strong); background: var(--brand-soft); }

/* history */
.bd-history { display: flex; flex-direction: column; gap: 4px; animation: bdIn .3s var(--bd-ease) both; }
.bd-hist-h { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 6px; }
.bd-thread { display: flex; align-items: center; gap: 10px; padding: 9px 8px 9px 10px; border-radius: 12px; cursor: pointer; color: var(--text-2); transition: background .2s; }
.bd-thread:hover { background: var(--surface-2); }
.bd-thread .grow { flex: 1; min-width: 0; font-size: 13px; color: var(--text); }
.bd-thread small { color: var(--muted); font-size: 11px; }

/* composer */
.bd-foot { flex: none; padding: 10px 12px 10px; border-top: 1px solid var(--border); background: var(--surface); }
.bd-input { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--border); transition: border-color .2s, box-shadow .2s; }
.bd-input:focus-within { border-color: color-mix(in srgb, var(--brand) 55%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent); }
.bd-input.disabled { opacity: .6; }
.bd-input textarea { flex: 1; min-height: 22px; max-height: 140px; padding: 6px 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); font: inherit; font-size: 14px; line-height: 1.45; }
.bd-send { width: 36px; height: 36px; flex: none; border: 0; border-radius: 12px; cursor: pointer; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #14c2ad, #0b7c70); box-shadow: 0 6px 14px -6px rgba(11, 124, 112, .9); transition: transform .2s var(--bd-ease), opacity .2s; }
.bd-send:hover:not(:disabled) { transform: translateY(-1px) scale(1.05); }
.bd-send:disabled { opacity: .35; cursor: default; box-shadow: none; }
.bd-send.stop { background: linear-gradient(135deg, #4b5563, #1f2937); }
.bd-fine { margin-top: 6px; text-align: center; font-size: 10.5px; color: var(--muted); }

/* small screens: full-screen sheet */
@media (max-width: 600px) {
  .buddy { right: 16px; bottom: 16px; }
  .bd-launch { width: 56px; height: 56px; }
  .buddy.open .bd-launch { opacity: 0; pointer-events: none; }
  .bd-panel, .buddy.wide .bd-panel { inset: 0; right: 0; bottom: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; border: 0; transform-origin: 100% 100%; }
  .bd-greet { bottom: 70px; }
  .bd-hbtn.hide-sm { display: none; }
}
/* reduced motion */
html.motion-reduced .bd-ring, html.motion-reduced .bd-face, html.motion-reduced .bd-hero img, html.motion-reduced .bd-hero-glow { animation: none; }
@media (prefers-reduced-motion: reduce) { .bd-ring, .bd-face, .bd-hero img, .bd-hero-glow { animation: none; } }
