/* ==========================================================================
   Crew Assistant — AI chatbot widget
   ========================================================================== */
.chat { position: fixed; right: 22px; bottom: 22px; z-index: 120; font-family: var(--f-body); }
.chat__launcher {
  position: relative; width: 62px; height: 62px; border-radius: 50%; background: #fff; color: var(--ink);
  display: grid; place-items: center; box-shadow: 0 18px 40px -12px rgba(5, 34, 55,.6), 0 0 0 3px rgba(62, 168, 226,.25);
  transition: transform .4s var(--ease), box-shadow .3s;
}
.chat__launcher:hover { transform: scale(1.06) rotate(-6deg); box-shadow: 0 22px 44px -12px rgba(5, 34, 55,.7), 0 0 0 5px rgba(62, 168, 226,.35); }
.chat__launcher-icon { grid-area: 1 / 1; display: grid; place-items: center; transition: transform .4s var(--ease), opacity .25s; }
.chat__launcher-icon--close { opacity: 0; transform: rotate(-90deg) scale(.6); font-size: 1.4rem; color: var(--brand); }
.chat__launcher-icon img { width: 34px; height: 34px; }
.chat[data-state="open"] .chat__launcher-icon--open { opacity: 0; transform: rotate(90deg) scale(.6); }
.chat[data-state="open"] .chat__launcher-icon--close { opacity: 1; transform: none; }
.chat__ping { position: absolute; top: 2px; right: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; }
.chat__ping::after { content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--accent); animation: ping 1.8s var(--ease) infinite; }
.chat[data-state="open"] .chat__ping, .chat.is-seen .chat__ping { display: none; }
@keyframes ping { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(2.4); opacity: 0; } }

.chat__nudge {
  position: absolute; right: 0; bottom: 76px; width: 250px; padding: 14px 32px 14px 16px; border-radius: 16px 16px 4px 16px;
  background: #fff; color: var(--ink); font-size: .9rem; line-height: 1.45; box-shadow: var(--shadow-lift); border: 1px solid var(--line);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .4s, transform .5s var(--ease);
}
.chat__nudge.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.chat__nudge-close { position: absolute; top: 6px; right: 8px; width: 22px; height: 22px; border-radius: 50%; color: var(--slate); font-size: 1.1rem; line-height: 1; }
.chat__nudge-close:hover { background: var(--porcelain); }

.chat__panel {
  position: absolute; right: 0; bottom: 78px; width: min(400px, calc(100vw - 24px)); height: min(620px, calc(100vh - 130px));
  display: flex; flex-direction: column; border-radius: 24px; overflow: hidden; background: #fff; color: var(--ink);
  box-shadow: 0 40px 90px -30px rgba(5, 34, 55,.55), 0 0 0 1px rgba(5, 34, 55,.06);
  transform-origin: bottom right; animation: chat-in .45s var(--ease);
}
.chat__panel[hidden] { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }

.chat__head { display: flex; align-items: center; gap: 12px; padding: 16px 14px 16px 18px; background: linear-gradient(120deg, var(--brand), var(--navy)); color: #fff; }
.chat__avatar { position: relative; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: #fff; flex-shrink: 0; }
.chat__avatar img { width: 26px; height: 26px; }
.chat__online { position: absolute; right: 0; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; background: #3DD68C; border: 2px solid var(--ink); }
.chat__name { margin: 0; font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; }
.chat__status { margin: 0; font-size: .78rem; color: var(--on-dark-muted); }
.chat__icon-btn { width: 36px; height: 36px; border-radius: 10px; color: var(--on-dark-muted); display: grid; place-items: center; transition: background-color .2s, color .2s; }
.chat__icon-btn:first-of-type { margin-left: auto; }
.chat__icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.chat__body { flex: 1; overflow-y: auto; padding: 18px 16px 8px; background: var(--porcelain); display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: .93rem; line-height: 1.5; animation: msg-in .35s var(--ease); word-wrap: break-word; }
.msg p { margin: 0 0 .5em; } .msg p:last-child { margin: 0; }
.msg ul { margin: .3em 0 .5em 1.1em; padding: 0; } .msg li { margin: .15em 0; }
.msg a { color: var(--blue-deep); font-weight: 600; }
.msg--bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg--user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 4px; }
.msg--user a { color: var(--accent); }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.msg__actions a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--ink); color: #fff; font-size: .82rem; font-weight: 600; text-decoration: none; }
.msg__actions a.alt { background: var(--porcelain); color: var(--ink); border: 1px solid var(--line); }
.typing { align-self: flex-start; display: flex; gap: 4px; padding: 14px 16px; border-radius: 16px; border-bottom-left-radius: 4px; background: #fff; border: 1px solid var(--line); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--slate); animation: typing 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

.lead-card { align-self: stretch; padding: 16px; border-radius: 16px; background: #fff; border: 1px solid var(--line); animation: msg-in .35s var(--ease); }
.lead-card p { margin: 0 0 10px; font-weight: 600; font-size: .92rem; }
.lead-card input { width: 100%; padding: 10px 12px; margin-bottom: 8px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--porcelain); font-size: .9rem; }
.lead-card input:focus { outline: none; border-color: var(--blue); background: #fff; }
.lead-card button { width: 100%; padding: 11px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 700; font-size: .9rem; }
.lead-card small { display: block; margin-top: 8px; color: var(--slate); font-size: .76rem; }

.chat__chips { display: flex; gap: 6px; padding: 10px 14px 4px; overflow-x: auto; background: var(--porcelain); scrollbar-width: none; }
.chat__chips::-webkit-scrollbar { display: none; }
.chat__chips button { flex-shrink: 0; padding: 7px 13px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: .82rem; font-weight: 600; transition: background-color .2s, color .2s, border-color .2s; }
.chat__chips button:hover { background: var(--ink); color: #fff; border-color: var(--ink); }

.chat__form { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); background: #fff; }
.chat__form textarea { flex: 1; resize: none; max-height: 110px; padding: 11px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--porcelain); font-size: .93rem; line-height: 1.4; }
.chat__form textarea:focus { outline: none; border-color: var(--blue); background: #fff; }
.chat__send { width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; flex-shrink: 0; transition: transform .2s; }
.chat__send:hover { transform: scale(1.06); }
.chat__send:disabled { opacity: .5; }
.chat__foot { margin: 0; padding: 0 14px 10px; background: #fff; font-size: .72rem; color: var(--slate); text-align: center; }
.chat__foot a { color: var(--blue-deep); font-weight: 600; }

@media (max-width: 720px) {
  .chat { right: 14px; bottom: 14px; }
  .chat__launcher { width: 56px; height: 56px; }
  .chat__panel { position: fixed; inset: 0; width: 100%; height: 100%; border-radius: 0; bottom: 0; right: 0; }
  .chat[data-state="open"] .chat__launcher { display: none; }
  .chat__nudge { bottom: 70px; width: 220px; }
}
