/* Total Trust Home Loans — website assistant (launcher + panel).
   Brand: navy #113a5c, sky #3f93d1. Tokens come from styles.css, which always
   loads first. Nothing here animates content it could strand: the panel is
   either open or closed, never faded by an observer. */

.chat-launcher {
  position: fixed;
  right: clamp(.9rem, 2.5vw, 1.5rem);
  bottom: calc(clamp(.9rem, 2.5vw, 1.5rem) + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  display: flex; align-items: center; gap: .6rem;
  padding: .8rem 1.15rem .8rem .95rem;
  border: none; border-radius: 999px;
  background: linear-gradient(135deg, var(--navy) 0%, #17507c 100%);
  color: #fff; cursor: pointer;
  font-family: var(--font-head); font-weight: 700; font-size: .95rem;
  box-shadow: 0 10px 28px rgba(17, 58, 92, .32);
  transition: transform .18s ease, box-shadow .18s ease;
}
.chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(17, 58, 92, .4); }
.chat-launcher:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
.chat-launcher svg { width: 22px; height: 22px; fill: #fff; flex: none; }
.chat-launcher[hidden] { display: none; }

/* A quiet dot that says "this answers questions" without shouting. */
.chat-launcher-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #7ee2a8; flex: none;
  box-shadow: 0 0 0 3px rgba(126, 226, 168, .25);
}

.chat-panel {
  position: fixed;
  right: clamp(.9rem, 2.5vw, 1.5rem);
  bottom: calc(clamp(.9rem, 2.5vw, 1.5rem) + env(safe-area-inset-bottom, 0px));
  z-index: 95;
  width: min(390px, calc(100vw - 1.8rem));
  max-height: min(640px, calc(100vh - 2.5rem - env(safe-area-inset-bottom, 0px)));
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(12, 43, 69, .28);
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1rem;
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 60%, #17507c 100%);
  color: #fff;
  border-bottom: 3px solid var(--sky);
}
.chat-head-photo {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  object-position: 50% 18%; flex: none; background: var(--sky-soft);
}
.chat-head-text { flex: 1 1 auto; min-width: 0; }
.chat-head-text strong {
  display: block; font-family: var(--font-head); font-size: .98rem; line-height: 1.2;
}
.chat-head-text span { font-size: .78rem; color: #cfe3f3; }
.chat-close {
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  background: rgba(255, 255, 255, .14); border: none; color: #fff;
  font-size: 1.15rem; line-height: 1; cursor: pointer;
}
.chat-close:hover { background: rgba(255, 255, 255, .26); }
.chat-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.chat-log {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 1rem; background: var(--bg-alt);
  display: flex; flex-direction: column; gap: .7rem;
}

.chat-msg {
  max-width: 88%; padding: .7rem .9rem; border-radius: 14px;
  font-size: .92rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-msg-bot {
  align-self: flex-start; background: #fff; border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.chat-msg-me {
  align-self: flex-end; background: var(--navy); color: #fff;
  border-bottom-right-radius: 5px;
}
.chat-msg-note {
  align-self: stretch; max-width: 100%; background: var(--sky-soft);
  border: 1px solid #c9e0f2; color: #27527a; font-size: .84rem; border-radius: 10px;
}
.chat-msg a { color: var(--sky); font-weight: 600; text-decoration: underline; }
.chat-msg-me a { color: #cfe7fa; }

.chat-src {
  display: block; margin-top: .5rem; font-size: .8rem; font-weight: 700;
  color: var(--navy); text-decoration: underline;
}

/* Suggestion chips — the fastest route to the question they actually have. */
.chat-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chat-chip {
  border: 1px solid #c9ddee; background: #fff; color: var(--navy);
  font-family: var(--font-body); font-size: .82rem; font-weight: 600;
  padding: .42rem .7rem; border-radius: 999px; cursor: pointer; text-align: left;
}
.chat-chip:hover { background: var(--sky-soft); border-color: var(--sky); }
.chat-chip:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

.chat-foot { border-top: 1px solid var(--line); background: #fff; padding: .7rem .8rem .5rem; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; }
.chat-form label { flex: 1 1 auto; min-width: 0; font-size: .78rem; color: var(--muted); font-weight: 600; }
.chat-form input,
.chat-form textarea {
  width: 100%; margin-top: .25rem; padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: 10px;
  font-family: var(--font-body); font-size: .92rem; color: var(--ink); background: #fff;
  resize: none;
}
.chat-form input:focus,
.chat-form textarea:focus {
  outline: none; border-color: var(--sky); box-shadow: 0 0 0 3px rgba(63, 147, 209, .18);
}
.chat-send {
  flex: none; border: none; border-radius: 10px; cursor: pointer;
  background: var(--sky); color: #fff; font-family: var(--font-head); font-weight: 700;
  padding: .62rem .9rem; font-size: .9rem;
}
.chat-send:hover { background: #2f80bd; }
.chat-send:disabled { background: #9dc4e2; cursor: default; }
.chat-send:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }

.chat-skip {
  background: none; border: none; padding: .2rem 0; margin-top: .35rem;
  font-size: .78rem; color: var(--muted); text-decoration: underline; cursor: pointer;
}
.chat-skip:hover { color: var(--navy); }

.chat-fine {
  margin: .5rem 0 0; font-size: .7rem; line-height: 1.45; color: var(--muted);
}
.chat-fine a { color: var(--muted); text-decoration: underline; }

.chat-error { color: #a4262c; font-size: .8rem; margin-top: .4rem; }

/* Typing/working indicator */
.chat-working { display: flex; gap: .25rem; align-items: center; padding: .2rem .3rem; }
.chat-working span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--sky);
  animation: chat-bounce 1s infinite ease-in-out;
}
.chat-working span:nth-child(2) { animation-delay: .15s; }
.chat-working span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* Phone: the panel takes the screen, because a 390px card on a 360px phone
   is a worse experience than a full sheet. */
@media (max-width: 480px) {
  .chat-panel {
    right: 0; bottom: 0; left: 0;
    width: 100%; max-height: 100vh; height: 100dvh;
    border-radius: 0; border: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .chat-launcher span.chat-launcher-label { display: none; }
  .chat-launcher { padding: .85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher { transition: none; }
  .chat-launcher:hover { transform: none; }
  .chat-working span { animation: none; }
}
