/* Support chat: launcher button and the panel. */

.chat-launch {
  position: fixed;
  right: clamp(0.9rem, 2.5vw, 1.6rem);
  bottom: clamp(0.9rem, 2.5vw, 1.6rem);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 52px;
  padding: 0.8rem 1.2rem 0.8rem 1rem;
  border: 0;
  border-radius: 14px;
  background: var(--ink);
  color: var(--sheet);
  font-family: var(--f-display);
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 14px 30px -12px rgb(var(--ink-rgb) / 0.6);
  transition: transform var(--fast) ease, background-color var(--fast) ease;
}
.chat-launch:hover { background: var(--ink-soft); transform: translateY(-2px); }
.chat-launch[aria-expanded="true"] { display: none; }

.chat-launch__dot {
  position: relative;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
}
.chat-launch__dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: live 2.4s ease-out infinite;
}
@keyframes live {
  0% { opacity: 0.7; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.6); }
}

.chat {
  position: fixed;
  right: clamp(0.75rem, 2vw, 1.4rem);
  bottom: clamp(0.75rem, 2vw, 1.4rem);
  z-index: 45;
  display: flex;
  flex-direction: column;
  width: min(410px, 100vw - 1.5rem);
  height: min(640px, 100dvh - 6rem);
  overflow: hidden;
  background: var(--sheet);
  border-radius: 18px;
  box-shadow: 0 30px 70px -20px rgb(var(--ink-rgb) / 0.55), 0 0 0 1px rgb(var(--ink-rgb) / 0.06);
  animation: chat-in 360ms var(--ease-out) both;
}
.chat[hidden] { display: none; }
@keyframes chat-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.chat__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 0.9rem 0.95rem 1.15rem;
  background: var(--ink);
  color: var(--paper);
}
.chat__title { font-size: 1.08rem; font-weight: 700; letter-spacing: -0.015em; }
.chat__sub {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.3rem;
  color: var(--on-ink);
  font-family: var(--f-mono);
  font-size: 0.72rem;
  line-height: 1.4;
}
.chat__sub::before {
  content: "";
  flex: none;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
}

.chat__tools { display: flex; align-items: center; gap: 0.25rem; }
.chat__tool {
  min-height: 36px;
  padding: 0.3rem 0.55rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--on-ink);
  font-family: var(--f-display);
  font-size: 0.8rem;
  white-space: nowrap;
}
.chat__tool:hover { color: var(--paper); background: rgb(var(--paper-rgb) / 0.08); }
.chat__close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--paper);
}
.chat__close:hover { background: rgb(var(--paper-rgb) / 0.1); }
.chat__close svg, .chat__send svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat__head :focus-visible { outline-color: var(--accent); }

.chat__log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0;
  padding: 1.1rem 1rem 0.6rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  background: var(--paper);
}

.msg {
  max-width: 86%;
  padding: 0.65rem 0.9rem;
  border-radius: 16px;
  font-family: var(--f-display);
  font-size: 0.96rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg--bot { align-self: flex-start; background: var(--sheet); border-bottom-left-radius: 5px; box-shadow: 0 1px 0 rgb(var(--ink-rgb) / 0.06); }
.msg--me { align-self: flex-end; background: var(--action); color: var(--sheet); border-bottom-right-radius: 5px; }
.msg--error { align-self: stretch; max-width: none; background: var(--danger-tint); color: var(--danger); font-size: 0.9rem; }
.msg--note {
  align-self: center;
  max-width: 100%;
  padding: 0.3rem 0.6rem;
  background: none;
  color: var(--mute);
  font-family: var(--f-mono);
  font-size: 0.72rem;
  text-align: center;
}

.msg--typing { display: inline-flex; gap: 0.3rem; padding: 0.85rem 1rem; }
.msg--typing i {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--line-strong);
  animation: typing 1.2s ease-in-out infinite;
}
.msg--typing i:nth-child(2) { animation-delay: 0.15s; }
.msg--typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat__asks {
  display: flex;
  gap: 0.4rem;
  padding: 0.2rem 1rem 0.7rem;
  overflow-x: auto;
  background: var(--paper);
  scrollbar-width: none;
}
.chat__asks:empty { display: none; }
.chat__ask {
  flex: none;
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--sheet);
  color: var(--ink);
  font-family: var(--f-display);
  font-size: 0.85rem;
  white-space: nowrap;
}
.chat__ask:hover { border-color: var(--ink); }

.chat__form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem 0.75rem 1rem;
  border-top: 1px solid var(--haze);
  background: var(--sheet);
}
.chat__form textarea {
  flex: 1;
  max-height: 140px;
  min-height: 44px;
  padding: 0.65rem 0.2rem;
  border: 0;
  background: transparent;
  font-family: var(--f-display);
  font-size: 1rem;
  line-height: 1.4;
  resize: none;
}
.chat__form textarea:focus { outline: none; }
.chat__form:focus-within { border-top-color: var(--action); }

.chat__send {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--action);
  color: var(--sheet);
  transition: background-color var(--fast) ease;
}
.chat__send:hover { background: var(--action-deep); }
.chat__send:disabled { background: var(--line-strong); cursor: progress; }

@media (max-width: 560px) {
  .chat { inset: 0; width: 100%; height: 100dvh; border-radius: 0; }
  .chat-launch { min-height: 48px; padding: 0.7rem 1rem 0.7rem 0.85rem; font-size: 0.92rem; }
}
