/* Chat button, panel, messages, and quick-reply controls. */

/* Panel is fixed bottom-right and hidden by default.
   Visibility (not display:none) is used so it can fade + slide open smoothly —
   `display` can't transition. `visibility` is toggled alongside so the
   hidden panel also isn't focusable/clickable while closed. */
.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 90px;
  width: 340px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 81;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(.97);
  transform-origin: bottom right;   /* scale out from the bottom-right corner toward the FAB */
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
}

/* Open state: fade in, slide up, and scale to full size. */
.chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Full-width panel on phones, anchored a touch higher. */
@media (max-width:480px) {
  .chat-panel {
    right: 16px;
    bottom: 82px;
    width: calc(100vw - 32px);
  }
}

/* Maroon header bar with the assistant name and close/new-chat buttons. */
.chat-header {
  background: linear-gradient(120deg, var(--maroon-900), var(--maroon-800));
  color: var(--cream);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Round avatar. The logo mark is drawn purely in CSS:
   a gold gradient circle with a maroon "A"-like triangle clipped inside. */
.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex: none;
  position: relative;
  background: linear-gradient(155deg, var(--gold-light), var(--gold));
}

/* The inner maroon shape — clip-path cuts an "A" / triangle out of a full-bleed square. */
.chat-avatar::after {
  content: "";
  position: absolute;
  inset: 10px;
  background: var(--maroon-950);
  clip-path: polygon(50% 0%, 100% 100%, 68% 100%, 50% 45%, 32% 100%, 0% 100%);
}

.chat-header-info strong {
  display: block;
  font-size: 14.5px;
  font-weight: 700;
}

/* "Online" status line with a small green dot injected via ::before. */
.chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: rgba(249, 241, 228, .75);
}

.chat-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3FAE5C;
}

.chat-close {
  background: none;
  border: none;
  color: var(--cream);
  font-size: 20px;
  line-height: 1;
  opacity: .8;
}

.chat-close:hover {
  opacity: 1;
}

/* Scrollable message area. min/max-height keeps the panel a sensible size
   whether there's one message or many. */
.chat-body {
  flex: 1;
  max-height: 320px;
  min-height: 140px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper-bg);
}

.chat-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
}

.chat-msg p {
  margin: 0;
}

/* Links inside messages inherit the bubble colour + get underlined. */
.chat-msg a {
  color: inherit;
  text-decoration: underline;
}

/* Bot bubble: left-aligned, light surface, with a "tail" corner at bottom-left. */
.chat-msg-bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

/* User bubble: right-aligned, maroon, with a "tail" corner at bottom-right. */
.chat-msg-user {
  align-self: flex-end;
  background: var(--maroon-800);
  color: var(--cream);
  border-bottom-right-radius: 4px;
}

/* Wrapper for clickable paper-result buttons inside a bot message. */
.chat-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.chat-result-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--paper-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--maroon-800);
  font-family: inherit;
}

.chat-result-btn:hover {
  border-color: var(--maroon-700);
  background: var(--surface);
}

/* Second line inside a result button (e.g. author names) — lighter weight. */
.chat-result-btn span {
  display: block;
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 11.5px;
  margin-top: 2px;
}

/* Three-dot "typing…" indicator. */
.chat-typing {
  display: flex;
  gap: 4px;
  align-self: flex-start;
  padding: 12px 14px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-soft);
  opacity: .5;
  animation: chatTyping 1s infinite ease-in-out;
}

/* Stagger the dots so they bounce in a wave. */
.chat-typing span:nth-child(2) {
  animation-delay: .15s;
}

.chat-typing span:nth-child(3) {
  animation-delay: .3s;
}

/* Small upward hop in the first 30% of each cycle, then rest. */
@keyframes chatTyping {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: .4;
  }

  30% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

/* Row of suggested quick-reply chips just above the input. */
.chat-quick-replies {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px 0;
  background: var(--paper-bg);
}

/* Pill-shaped quick-reply chip. */
.chip {
  border: 1.5px solid var(--maroon-700);
  color: var(--maroon-800);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  transition: background .15s, color .15s;
}

.chip:hover {
  background: var(--maroon-800);
  color: var(--cream);
}

/* Bottom input row: rounded text box + circular send button. */
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 14px 16px;
  background: var(--paper-bg);
  border-top: 1px solid var(--line);
}

.chat-input-row input {
  flex: 1;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 10px 15px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
}

.chat-input-row input:focus {
  border-color: var(--maroon-700);
}

.chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--maroon-800);
  border: none;
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: background .15s;
}

.chat-send:hover {
  background: var(--maroon-900);
}

/* Disabled while a message is being sent or when the input is empty. */
.chat-send:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* Header buttons (new chat + close) and follow-up chips shown inside the conversation. */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Follow-up chips embedded inside a bot message (distinct from the standalone row above). */
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 10px;
}