/* AI chat widget and WhatsApp button, carried over from the live site
   (assets/chat.js, src/css/47-chat.css, 21-whatsapp-float.css) and
   recoloured to the concept palette. The widget talks to the same
   /api/chat edge function. */
/* --dock-bottom carries the iPhone home-bar inset, so every rung of the dock rises with it.
   Only the WhatsApp button used to add it; on an iPhone it rose 34px into the chat launcher. */
:root{--dock-right:2rem;--dock-bottom:calc(2rem + env(safe-area-inset-bottom,0px));--dock-size:54px;--dock-gap:18px;--dock-step:calc(var(--dock-size) + var(--dock-gap))}
@media (max-width:480px){:root{--dock-right:1rem;--dock-bottom:calc(1rem + env(safe-area-inset-bottom,0px))}}
.wa-float{position:fixed;bottom:var(--dock-bottom);right:var(--dock-right);z-index:800;width:54px;height:54px;background:#25D366;border-radius:50%;display:flex;align-items:center;justify-content:center;box-shadow:0 4px 22px rgba(37,211,102,.42);transition:transform .22s,box-shadow .22s}
.wa-float:hover{transform:scale(1.08);box-shadow:0 8px 32px rgba(37,211,102,.58)}
.wa-float svg{width:28px;height:28px;fill:#fff}
.menu-open .wa-float,.menu-open .chat-toggle,.menu-open .chat-panel{display:none!important}
/* ── AI Chat Widget ─────────────────────────────────────────────────── */

/* Toggle button — rung 1 of the dock, directly above WhatsApp.
   Stated as a rung rather than a measurement, so it keeps its place when
   the sticky mobile bar lifts the dock. See 02-tokens.css. */
.chat-toggle {
  position: fixed;
  bottom: calc(var(--dock-bottom) + var(--dock-step));
  right: var(--dock-right);
  z-index: 810;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0b0b0c, #16171b);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 22px rgba(31,94,255,.35);
  transition: transform .22s, box-shadow .22s;
}
.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 32px rgba(31,94,255,.5);
}
.chat-toggle svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  transition: opacity .15s;
}
.chat-toggle .chat-ico-close { display: none; }
.chat-panel-open .chat-toggle .chat-ico-chat  { display: none; }
.chat-panel-open .chat-toggle .chat-ico-close { display: block; }

/* Unread dot */
.chat-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #1f5eff;
  border: 2px solid #fff;
  display: none;
}
.chat-badge.on { display: block; }

/* Panel — clears the two rungs of the dock and then some.
   Stated against the dock anchor for the same reason the launcher is: at a
   fixed 12rem it stayed put while the sticky bar lifted the stack, and the
   launcher rose into it. Two steps plus a rem is exactly the 12rem it was
   written with, so a desktop is unchanged; the max-height is the same 14rem
   of clearance re-expressed, so the panel cannot grow past the top of the
   window once the dock has been lifted. */
.chat-panel {
  position: fixed;
  bottom: calc(var(--dock-bottom) + var(--dock-step) * 2 + 1rem);
  right: var(--dock-right);
  z-index: 809;
  width: 380px;
  max-height: calc(100vh - var(--dock-bottom) - 12rem);
  min-height: 360px;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 0 12px 48px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
  transform: scale(.92) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s;
}
.chat-panel-open .chat-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.chat-hd {
  padding: 1rem 1.1rem .85rem;
  background: linear-gradient(135deg, #0b0b0c 0%, #16171b 100%);
  display: flex;
  align-items: center;
  gap: .7rem;
  flex-shrink: 0;
}
.chat-hd-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(31,94,255,.22);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-hd-avatar svg { width: 20px; height: 20px; fill: #1f5eff; }
.chat-hd-info { flex: 1; min-width: 0; }
.chat-hd-name { font-size: .85rem; font-weight: 700; color: #fff; line-height: 1.2; }
.chat-hd-sub  { font-size: .72rem; color: rgba(255,255,255,.55); }
.chat-hd-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: .25rem;
  color: rgba(255,255,255,.5);
  line-height: 0;
  transition: color .15s;
}
.chat-hd-close:hover { color: #fff; }
.chat-hd-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* Messages area */
.chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  scroll-behavior: smooth;
}
.chat-msgs::-webkit-scrollbar { width: 4px; }
.chat-msgs::-webkit-scrollbar-thumb { background: #e0e4ea; border-radius: 4px; }

.chat-msg {
  max-width: 85%;
  padding: .55rem .8rem;
  border-radius: 12px;
  font-size: .82rem;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.bot {
  background: #f2f4f8;
  color: #0b0b0c;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  background: #0b0b0c;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.error {
  background: #fff3cd;
  color: #7a5800;
  align-self: flex-start;
  border: 1px solid #ffe08a;
  border-bottom-left-radius: 4px;
}

/* Markdown rendered inside bot messages */
.chat-msg.bot p          { margin: 0 0 .35em; }
.chat-msg.bot p:last-child { margin-bottom: 0; }
.chat-msg.bot ul         { margin: .25em 0 .35em 1.1em; padding: 0; }
.chat-msg.bot li         { margin-bottom: .2em; }
.chat-msg.bot strong     { font-weight: 700; }

/* Typing dots while streaming */
.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: .55rem .8rem;
  background: #f2f4f8;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9aa3b2;
  animation: chat-bounce .9s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* Quick-question chips */
.chat-chips {
  padding: 0 1rem .75rem;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  flex-shrink: 0;
}
.chat-chip {
  font-size: .73rem;
  padding: .3rem .65rem;
  border-radius: 20px;
  border: 1px solid #d0d6e2;
  background: #fff;
  color: #0b0b0c;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.chat-chip:hover {
  background: #0b0b0c;
  border-color: #0b0b0c;
  color: #fff;
}

/* Input row */
.chat-input-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem .8rem;
  border-top: 1px solid #edf0f5;
  flex-shrink: 0;
  background: #fff;
}
.chat-input {
  flex: 1;
  border: 1px solid #d0d6e2;
  border-radius: 20px;
  padding: .45rem .85rem;
  font-size: .82rem;
  font-family: inherit;
  outline: none;
  resize: none;
  color: #0b0b0c;
  background: #f8f9fb;
  transition: border-color .15s;
  max-height: 90px;
  overflow-y: auto;
  line-height: 1.4;
}
.chat-input:focus { border-color: #1f5eff; background: #fff; }
.chat-input:disabled { opacity: .5; cursor: not-allowed; }
.chat-input::placeholder { color: #9aa3b2; }
.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #0b0b0c;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.chat-send:hover:not(:disabled)  { background: #1f5eff; }
.chat-send:active:not(:disabled) { transform: scale(.92); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }
.chat-send svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Hide WhatsApp button whenever chat panel is open (avoids overlap at all sizes) */
.chat-panel-open .wa-float { display: none !important; }

/* Mobile: panel takes almost the full screen */
@media (max-width: 480px) {
  .chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }
  .chat-panel-open .chat-panel {
    transform: translateY(0);
  }
  /* The launcher used to be repositioned here to bottom:5.5rem/right:1rem,
     which put it within 2px of the WhatsApp button's height and 16px inside
     its right edge. It now takes its place from the dock like everything
     else, and the narrow-screen inset applies to the whole stack. */
}

/* concept: the launcher must stand out on black and white pages alike */
.chat-toggle{background:var(--electric,#1f5eff)!important;box-shadow:0 8px 26px rgba(31,94,255,.45)!important}
.chat-toggle:hover{background:#3b72ff!important}
/* phones: the panel has its own close button, so the launcher steps aside */
@media (max-width:480px){.chat-panel-open .chat-toggle{display:none}}
