/*
 * Get-AI public chat (task 6.1, R2.1, R7.2): /chat, the widget's frame (/chat?embed=1) and the chat block of the home
 * page. Mobile first, from 320 px without sideways scrolling; colours from the Kit's tokens (light / dark follow the
 * theme switch), the brand colour for the visitor's bubbles and the send button.
 */
.gai-chat-page { padding-block: var(--space-6) var(--space-10); }

.gai-chat {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 820px;
  margin-inline: auto;
  min-width: 0;
}
.gai-chat * { min-width: 0; }

.gai-chat-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-2) var(--space-4); }
.gai-chat-title { flex: 1 1 16rem; }
.gai-chat-title h1, .gai-chat-title h2 {
  display: flex; align-items: center; gap: var(--space-2);
  margin: 0; font-size: var(--text-2xl); line-height: var(--leading-tight);
}
.gai-chat-logo { width: 1.5em; height: 1.5em; color: var(--brand-text); flex: none; }
.gai-chat-intro { margin: var(--space-2) 0 0; color: var(--text-muted); font-size: var(--text-sm); line-height: var(--leading-normal); }
.gai-chat-tools { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.gai-chat-tools [hidden] { display: none; }

.gai-chat-log {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 14rem;
  max-height: min(60vh, 36rem);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: var(--space-4) var(--space-3);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  scroll-behavior: smooth;
}
.gai-chat-log:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }
.gai-chat-empty, .gai-chat-note { margin: auto 0; text-align: center; color: var(--text-muted); font-size: var(--text-sm); }
.gai-chat-note { margin: 0; }

.gai-msg { display: flex; flex-direction: column; max-width: 100%; }
.gai-msg-visitor { align-items: flex-end; }
.gai-msg-bot { align-items: flex-start; }
.gai-bubble {
  max-width: min(100%, 38rem);
  padding: var(--space-2) var(--space-3);
  border-radius: 16px;
  line-height: var(--leading-normal);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.gai-bubble p { margin: 0; }
.gai-bubble p + p { margin-top: var(--space-2); }
.gai-msg-visitor .gai-bubble { background: var(--brand); color: var(--brand-fg); border-bottom-right-radius: 4px; }
.gai-msg-bot .gai-bubble { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.gai-sources { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); margin: var(--space-2) 0 0; padding: 0; list-style: none; }
.gai-sources li { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); max-width: 100%; }
.gai-source {
  display: inline-block; max-width: 100%; padding: 2px var(--space-2);
  border: 1px solid var(--brand-border); border-radius: 999px; background: var(--brand-soft); color: var(--brand-text);
  font-size: var(--text-xs); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gai-source:hover { text-decoration: underline; }
.gai-licence { font-size: var(--text-xs); color: var(--text-muted); }

.gai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin-top: var(--space-1); }
.gai-votes { display: inline-flex; gap: var(--space-1); }
.gai-action {
  display: inline-flex; align-items: center; justify-content: center; min-height: 32px; min-width: 32px; padding: 2px var(--space-2);
  border: 1px solid transparent; border-radius: var(--radius-lg); background: transparent; color: var(--text-muted);
  font: inherit; font-size: var(--text-xs); cursor: pointer;
}
.gai-action:hover { background: var(--bg-muted); color: var(--text); }
.gai-action:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 1px; }
.gai-vote { font-size: var(--text-base); }
.gai-vote[aria-pressed="true"] { border-color: var(--brand-border); background: var(--brand-soft); }
.gai-vote-note { font-size: var(--text-xs); color: var(--text-muted); }

.gai-typing .gai-bubble { padding-block: var(--space-3); }
.gai-dots { display: inline-flex; gap: 4px; }
.gai-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-subtle); animation: gai-dot 1.2s infinite ease-in-out; }
.gai-dots i:nth-child(2) { animation-delay: .15s; }
.gai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes gai-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) {
  .gai-dots i { animation: none; opacity: .7; }
  .gai-chat-log { scroll-behavior: auto; }
}

.gai-suggest[hidden] { display: none; }
.gai-suggest-title { margin: 0 0 var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }
.gai-suggest ul { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.gai-suggest li { max-width: 100%; }
.gai-chip {
  max-width: 100%; padding: var(--space-1) var(--space-3); min-height: 36px;
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--text-sm); text-align: start; cursor: pointer; overflow-wrap: anywhere;
}
.gai-chip:hover { border-color: var(--brand-border); background: var(--brand-soft); color: var(--brand-text); }
.gai-chip:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }

.gai-chat-error { display: flex; gap: var(--space-2); align-items: center; margin: 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-lg); background: var(--danger-soft); color: var(--danger); font-size: var(--text-sm); }
.gai-chat-error[hidden] { display: none; }

.gai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface);
}
.gai-chat-form:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.gai-input {
  width: 100%; min-height: 44px; max-height: 160px; padding: var(--space-2) var(--space-2); resize: none;
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: var(--text-base); line-height: var(--leading-snug);
}
.gai-input:focus { outline: none; }
.gai-send { min-width: 44px; min-height: 44px; padding-inline: var(--space-3); border-radius: var(--radius-lg); }
.gai-send:disabled { opacity: .6; }
.gai-hint { grid-column: 1 / -1; margin: 0; padding-inline: var(--space-2); font-size: var(--text-xs); color: var(--text-subtle); }
.gai-privacy { margin: 0; font-size: var(--text-xs); color: var(--text-subtle); line-height: var(--leading-normal); }

.gai-history { padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); }
.gai-history[hidden] { display: none; }
.gai-history h3 { margin: 0 0 var(--space-2); font-size: var(--text-base); }
.gai-history ul { display: flex; flex-direction: column; gap: var(--space-1); margin: 0; padding: 0; list-style: none; max-height: 14rem; overflow-y: auto; }
.gai-history-item {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); width: 100%; padding: var(--space-2);
  border: 0; border-radius: var(--radius-lg); background: transparent; color: var(--text); font: inherit; text-align: start; cursor: pointer;
}
.gai-history-item:hover { background: var(--bg-muted); }
.gai-history-item small { color: var(--text-muted); }

/* The home page's chat block (until the home page of phase 10). */
.gai-home-chat { padding-block: var(--space-6) var(--space-10); }

/* The widget's frame: the whole window is the chat. */
.gai-embed-body { margin: 0; background: var(--bg); }
.gai-embed { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding: var(--space-3); box-sizing: border-box; }
.gai-embed-lang { display: flex; justify-content: flex-end; font-size: var(--text-xs); }
.gai-chat-embed { flex: 1; max-width: none; width: 100%; }
.gai-chat-embed .gai-chat-title h1 { font-size: var(--text-lg); }
.gai-chat-embed .gai-chat-log { flex: 1; max-height: none; min-height: 6rem; }
.gai-chat-embed .gai-privacy { font-size: 11px; }

@media (min-width: 768px) {
  .gai-chat-log { padding: var(--space-5) var(--space-4); }
  .gai-chat-title h1, .gai-chat-title h2 { font-size: var(--text-3xl); }
}
