/* =====================================================================
   Chat widget
   ===================================================================== */
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 200; font-family: var(--font-body); }

/* Floating button */
.chat__fab {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 18px 12px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.15);
  background: var(--gradient); color: #0a0a0f; font: 600 .92rem var(--font-body);
  cursor: pointer; box-shadow: 0 16px 40px -14px rgba(124,92,255,.9);
  transition: transform .35s var(--ease), box-shadow .3s;
}
.chat__fab:hover { transform: translateY(-2px); box-shadow: 0 22px 48px -14px rgba(56,232,255,.8); }
.chat__fab-icon { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: rgba(10,10,15,.18); }
.chat__fab-icon svg { width: 16px; height: 16px; fill: none; stroke: #0a0a0f; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat.is-open .chat__fab { display: none; }

/* Panel */
.chat__panel {
  width: min(380px, calc(100vw - 32px)); height: min(600px, calc(100vh - 40px));
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 18px; overflow: hidden;
  background: rgba(14,14,20,.96); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 40px 80px -30px rgba(0,0,0,.8), 0 0 0 1px rgba(255,255,255,.03) inset;
  animation: chatIn .35s var(--ease);
}
@keyframes chatIn { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.chat__head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.03); }
.chat__head strong { display: block; font-family: var(--font-display); font-size: .95rem; }
.chat__status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .75rem; }
.chat__status i { width: 7px; height: 7px; border-radius: 50%; background: #28c840; box-shadow: 0 0 0 0 rgba(40,200,64,.6); animation: pulse 2s infinite; }
.chat__close { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.1rem; cursor: pointer; }
.chat__close:hover { background: rgba(255,255,255,.1); }

/* Log */
.chat__log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; }
.chat__msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: .9rem; line-height: 1.5; animation: msgIn .3s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.chat__msg--assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat__msg--user { align-self: flex-end; background: var(--gradient); color: #0a0a0f; border-bottom-right-radius: 4px; font-weight: 500; }
.chat__msg--system { align-self: center; background: none; color: var(--muted); font-size: .78rem; padding: 4px 8px; }
.chat__msg--note { color: var(--accent-2); }
.chat__msg a { color: var(--accent-2); text-decoration: underline; }
.chat__msg--user a { color: #0a0a0f; }
.chat__li { display: block; padding-left: 14px; position: relative; }
.chat__li::before { content: "•"; position: absolute; left: 2px; color: var(--accent-2); }
.chat__typing { display: flex; gap: 4px; padding: 12px 14px; }
.chat__typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: dot 1.2s infinite; }
.chat__typing i:nth-child(2) { animation-delay: .2s; } .chat__typing i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.chat__offer { align-self: flex-start; margin-top: 2px; padding: 8px 12px; border-radius: 999px; border: 1px solid rgba(56,232,255,.4); background: rgba(56,232,255,.08); color: var(--text); font: 600 .82rem var(--font-body); cursor: pointer; }
.chat__offer:hover { background: rgba(56,232,255,.16); }

/* Quick chips */
.chat__chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chat__chips button { padding: 6px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: 500 .78rem var(--font-body); cursor: pointer; transition: color .2s, border-color .2s; }
.chat__chips button:hover { color: var(--text); border-color: rgba(124,92,255,.6); }

/* Composer */
.chat__form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat__form textarea { flex: 1; resize: none; font: inherit; font-size: .9rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; max-height: 120px; line-height: 1.4; }
.chat__form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.15); }
.chat__send { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--gradient); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.chat__send svg { width: 18px; height: 18px; fill: none; stroke: #0a0a0f; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Handoff form */
.chat__handoff { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--border); background: linear-gradient(160deg, rgba(124,92,255,.08), rgba(56,232,255,.05)); }
.chat__handoff-title { margin: 0; font-family: var(--font-display); font-weight: 700; }
.chat__handoff-sub { margin: 0 0 4px; color: var(--muted); font-size: .82rem; }
.chat__handoff input, .chat__handoff textarea { font: inherit; font-size: .9rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; resize: vertical; }
.chat__handoff input:focus, .chat__handoff textarea:focus { outline: none; border-color: var(--accent); }
.chat__hp { position: absolute; left: -9999px; }
.chat__handoff-actions { display: flex; gap: 8px; justify-content: flex-end; }
.chat__primary { padding: 9px 16px; border-radius: 999px; border: 0; background: var(--gradient); color: #0a0a0f; font: 600 .85rem var(--font-body); cursor: pointer; }
.chat__ghost { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text); font: 600 .85rem var(--font-body); cursor: pointer; }
.chat__foot { margin: 0; padding: 8px 16px 10px; color: var(--muted); font-size: .7rem; text-align: center; }
.chat__foot-link { background: none; border: 0; padding: 0; margin-right: 8px; color: var(--accent-2); font: 600 .7rem var(--font-body); cursor: pointer; border-bottom: 1px solid rgba(56,232,255,.4); }
.chat__foot-link::after { content: " ·"; color: var(--muted); border: 0; }

.chat__panel--form { height: auto; max-height: calc(100vh - 40px); }
.chat__panel--form .chat__chips { padding: 0 0 6px; }
.chat__done { display: flex; flex-direction: column; gap: 8px; padding: 18px 16px; }

@media (max-width: 600px) {
  .chat { right: 12px; bottom: 12px; }
  .chat.is-open { inset: 0; }
  .chat__panel { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
  .chat__fab-label { display: none; }
  .chat__fab { padding: 12px; }
}
@media print { .chat { display: none; } }
