/* ==========================================================================
   StayHope assistant, floating chat widget
   ========================================================================== */

.chat-launcher {
  position: fixed; right: 18px; z-index: 70;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  display: inline-flex; align-items: center; gap: .6rem;
  padding: .85rem 1.2rem;
  font-family: var(--font-head); font-weight: 700; font-size: .93rem;
  color: #fff; background: var(--brand); border: 0; border-radius: var(--r-pill);
  box-shadow: 0 10px 28px rgba(0, 26, 82, .32);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.chat-launcher:hover { transform: translateY(-3px); background: var(--brand-600); box-shadow: 0 14px 34px rgba(0,26,82,.4); }
.chat-launcher svg { width: 21px; height: 21px; flex: none; }
.chat-launcher__dot {
  position: absolute; top: -4px; right: -4px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
@media (max-width: 520px) { .chat-launcher__label { display: none; } .chat-launcher { padding: .95rem; } }
.chat-launcher[aria-expanded="true"] { opacity: 0; pointer-events: none; }

.chat-panel {
  position: fixed; right: 18px; bottom: 18px; z-index: 71;
  width: min(392px, calc(100vw - 32px));
  height: min(640px, calc(100dvh - 36px));
  max-width: 100vw; max-height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 26px 60px rgba(0, 26, 82, .28);
  animation: chat-in .22s ease;
}
@keyframes chat-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@media (max-width: 620px) {
  .chat-panel {
    inset: 0;                 /* pinned to every edge, cannot overflow */
    width: auto; height: auto;
    max-width: 100%; max-height: 100%;
    border-radius: 0; border: 0;
  }
  .chat-head { padding-top: calc(.9rem + env(safe-area-inset-top, 0px)); }
  .chat-foot { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .chat-msg { max-width: 90%; }
}

.chat-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1rem; background: var(--navy); color: #fff; flex: none;
}
.chat-head__avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: #fff; display: grid; place-items: center; overflow: hidden;
}
.chat-head__avatar img { width: 30px; height: auto; }
.chat-head__title { font-family: var(--font-head); font-weight: 700; font-size: .96rem; line-height: 1.2; }
.chat-head__status { font-size: .76rem; color: #a9c4ec; display: flex; align-items: center; gap: .35rem; }
.chat-head__status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #35d07f; }
.chat-head__actions { margin-left: auto; display: flex; gap: .25rem; }
.chat-head button {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: rgba(255,255,255,.12); border: 0; border-radius: 9px; color: #fff; cursor: pointer;
}
.chat-head button:hover { background: rgba(255,255,255,.24); }
.chat-head button svg { width: 16px; height: 16px; }

.chat-log {
  flex: 1; overflow-y: auto; padding: 1.1rem 1rem .6rem;
  display: flex; flex-direction: column; gap: .7rem;
  background: var(--surface);
  overscroll-behavior: contain;
}
.chat-msg { max-width: 86%; display: flex; flex-direction: column; gap: .25rem; }
.chat-msg__bubble {
  padding: .72rem .9rem; border-radius: 16px; font-size: .93rem; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-msg--bot { align-self: flex-start; }
.chat-msg--bot .chat-msg__bubble {
  background: var(--card); color: var(--ink-2);
  border: 1px solid var(--line); border-bottom-left-radius: 5px;
}
.chat-msg--user { align-self: flex-end; align-items: flex-end; }
.chat-msg--user .chat-msg__bubble {
  background: var(--brand); color: #fff; border-bottom-right-radius: 5px;
}
/* A real person is answering. Visibly different from the scripted assistant. */
.chat-msg--staff { align-self: flex-start; }
.chat-msg--staff .chat-msg__bubble {
  background: var(--accent-50); color: var(--ink);
  border: 1px solid var(--accent); border-bottom-left-radius: 5px;
}
.chat-msg--staff .chat-msg__bubble::before {
  content: "StayHope team";
  display: block; margin-bottom: .25rem;
  font-family: var(--font-head); font-weight: 700; font-size: .7rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--accent-600);
}
.chat-msg--staff .chat-msg__bubble a { color: var(--brand); font-weight: 600; }

.chat-msg__bubble a { color: inherit; text-decoration: underline; }
.chat-msg--bot .chat-msg__bubble a { color: var(--brand); font-weight: 600; }
.chat-msg__time { font-size: .68rem; color: var(--muted); padding-inline: .3rem; }

.chat-typing { align-self: flex-start; display: flex; gap: 4px; padding: .8rem .95rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; border-bottom-left-radius: 5px; }
.chat-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: chat-bob 1.1s infinite; }
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-bob { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.chat-quick { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 1rem .7rem; background: var(--surface); flex: none; }
.chat-quick:empty { padding: 0; }
.chat-quick button {
  font-family: var(--font-head); font-weight: 600; font-size: .84rem;
  padding: .5rem .85rem; cursor: pointer;
  color: var(--brand); background: var(--brand-50);
  border: 1.5px solid var(--brand-100); border-radius: var(--r-pill);
  transition: background-color .15s, color .15s, transform .15s;
}
.chat-quick button:hover { background: var(--brand); color: #fff; transform: translateY(-1px); }
.chat-quick button.is-accent { color: var(--accent-600); background: var(--accent-50); border-color: var(--accent); }
.chat-quick button.is-accent:hover { background: var(--accent); color: #fff; }

.chat-progress { height: 3px; background: var(--surface-2); flex: none; }
.chat-progress__bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

.chat-foot { flex: none; border-top: 1px solid var(--line); background: var(--card); }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; padding: .7rem .8rem; }
.chat-form textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 110px;
  padding: .6rem .8rem; font-size: .93rem;
  color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 14px;
}
.chat-form textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.chat-form button[type="submit"] {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  background: var(--brand); color: #fff; border: 0; border-radius: 50%; cursor: pointer;
}
.chat-form button[type="submit"]:hover { background: var(--brand-600); }
.chat-form button[type="submit"]:disabled { opacity: .45; cursor: not-allowed; }
.chat-form button svg { width: 18px; height: 18px; }
.chat-file { padding: 0 .8rem .7rem; }
.chat-file input[type="file"] { width: 100%; font-size: .85rem; padding: .45rem; border: 1.5px dashed var(--line); border-radius: 10px; background: var(--surface); }
.chat-note { padding: 0 1rem .7rem; font-size: .72rem; color: var(--muted); text-align: center; }
