/* ---------------------------------------------------------------
   Site AI chat
   --------------------------------------------------------------- */
.site-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 96;
}

.site-chat-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 50px;
  padding: 0 17px;
  border: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-lg);
  transition: background-color 0.16s, transform 0.16s, box-shadow 0.16s;
}

.site-chat-toggle:hover {
  background: var(--accent-2);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--accent-soft);
}

.site-chat-toggle .icon {
  width: 18px;
  height: 18px;
}

.site-chat-toggle-text {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.site-chat-panel {
  position: absolute;
  right: 0;
  bottom: 62px;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 110px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.985);
  transform-origin: bottom right;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), visibility 0.2s;
}

.site-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.site-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.site-chat-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.site-chat-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}

.site-chat-mark .icon {
  width: 16px;
  height: 16px;
}

.site-chat-title {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.site-chat-title strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
}

.site-chat-title small {
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
}

.site-chat-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.site-chat-reset,
.site-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 7px;
  border-radius: var(--radius-xs);
  color: var(--muted);
  font-size: 10.5px;
  transition: background-color 0.16s, color 0.16s;
}

.site-chat-reset:hover,
.site-chat-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.site-chat-close .icon {
  width: 15px;
  height: 15px;
}

.site-chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 190px;
  max-height: 360px;
  padding: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.site-chat-message {
  max-width: 88%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.site-chat-message.is-assistant {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: var(--surface-2);
  color: var(--text-soft);
}

.site-chat-message.is-user {
  align-self: flex-end;
  border-color: var(--accent);
  border-bottom-right-radius: 4px;
  background: var(--accent);
  color: var(--on-accent);
}

.site-chat-message.is-error {
  border-color: var(--line-strong);
  background: var(--surface-3);
  color: var(--text-soft);
}

.site-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 14px 10px;
}

.site-chat-suggestions[hidden] {
  display: none;
}

.site-chat-suggestions button {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  transition: border-color 0.16s, color 0.16s, background-color 0.16s;
}

.site-chat-suggestions button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.site-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.site-chat-form textarea {
  flex: 1;
  min-height: 34px;
  max-height: 96px;
  padding: 8px 10px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.55;
}

.site-chat-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.site-chat-send {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: var(--accent);
  color: var(--on-accent);
  transition: background-color 0.16s, opacity 0.16s;
}

.site-chat-send:hover {
  background: var(--accent-2);
}

.site-chat-send:disabled {
  opacity: 0.45;
  cursor: wait;
}

.site-chat-send svg {
  width: 16px;
  height: 16px;
}

.site-chat-foot {
  margin: 0;
  padding: 0 14px 10px;
  color: var(--muted-2);
  font-size: 9.5px;
  line-height: 1.5;
  text-align: center;
}

.site-chat-message.is-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}

.site-chat-message.is-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted-2);
  animation: site-chat-blink 1.1s infinite ease-in-out;
}

.site-chat-message.is-typing i:nth-child(2) { animation-delay: 0.15s; }
.site-chat-message.is-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes site-chat-blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

body.has-site-chat .back-to-top { bottom: 84px; }
body.has-site-chat .toc-fab { bottom: 138px; }

@media (max-width: 640px) {
  .site-chat {
    right: 14px;
    bottom: 14px;
  }

  .site-chat-toggle {
    height: 46px;
    padding: 0 14px;
  }

  .site-chat-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 74px;
    width: auto;
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
  }

  .site-chat-messages {
    min-height: 150px;
    max-height: 48vh;
    max-height: 48dvh;
  }

  body.has-site-chat .back-to-top { bottom: 74px; }
  body.has-site-chat .toc-fab { bottom: 126px; }
}

@media (prefers-reduced-motion: reduce) {
  .site-chat-panel { transition: none; }
  .site-chat-toggle { transition: none; }
  .site-chat-message.is-typing i { animation: none; opacity: 0.7; }
}

@media print {
  .site-chat { display: none !important; }
}
