/*
 * Feuille de style autonome et préfixée `ag-`.
 *
 * Les valeurs viennent des variables de la maquette Figma (Les greffiers,
 * nœud 2282-32729) : couleurs de marque, rayons, ombres et graisses y sont
 * nommés, et les noms d'origine sont rappelés en commentaire.
 *
 * Aucune classe utilitaire : le widget vit dans une application qui a son
 * propre Tailwind, et aucun sélecteur ne déborde de `.ag-root`.
 */
.ag-root {
  /* Colors/Brand/Primary/500 → Colors/Task/Indigo/400 */
  --ag-gradient-from: #1d7fce;
  --ag-gradient-to: #6d33ff;
  /* Colors/Task/Indigo/700, Indigo/900 */
  --ag-title: #2d009e;
  --ag-bubble-text: #1a005c;
  /* Content/Neutral/default, /secondary */
  --ag-text: #1c1d1f;
  --ag-text-muted: #666d74;
  --ag-white: #ffffff;
  /* ChatBar/default/border */
  --ag-border: #ced1d3;
  --ag-divider: #e2e8f0;
  --ag-danger: #b42318;

  /* Shadow violet, Elevations/md, Shadow stylised */
  --ag-shadow-violet: 0 3px 5px rgba(90, 110, 240, 0.35);
  --ag-shadow-bubble: 0 2px 1.5px rgba(0, 25, 189, 0.25);
  --ag-shadow-white-bubble: 0 4px 3px rgba(0, 0, 0, 0.12);
  --ag-shadow-chip: 0 8px 12px rgba(30, 50, 90, 0.08);
  --ag-shadow-panel: 0 8px 24px rgba(30, 50, 90, 0.08);

  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  padding: 16px 14px;
  gap: 10px;
  background: rgba(255, 255, 255, 0.48);
  border-radius: 18px;
  box-shadow: var(--ag-shadow-panel);
  color: var(--ag-text);
  /* Body/Default */
  font-family: 'Urbanist', ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 16px;
  overflow: hidden;
}

.ag-root *,
.ag-root *::before,
.ag-root *::after {
  box-sizing: inherit;
}

/* Inséré dans un panneau de l'hôte : celui-ci porte déjà le cadre, le fond et
   l'en-tête. Le widget ne rend alors que le fil et le composeur. */
.ag-root-bare {
  padding: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}

.ag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
}

.ag-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ag-logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--ag-gradient-from) 0%, var(--ag-gradient-to) 100%);
  color: var(--ag-white);
  filter: drop-shadow(var(--ag-shadow-violet));
}

.ag-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 16px;
  color: var(--ag-title);
  white-space: nowrap;
}

.ag-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ag-icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ag-title);
  cursor: pointer;
}

.ag-icon-button:hover:not(:disabled) {
  background: rgba(45, 0, 158, 0.06);
}

.ag-icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ag-history {
  display: flex;
  flex: none;
  max-height: 40%;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 12px;
  background: var(--ag-white);
  box-shadow: var(--ag-shadow-chip);
}

.ag-history-empty {
  margin: 0;
  padding: 6px 8px;
  color: var(--ag-text-muted);
}

.ag-history-item {
  /* Sans cela les entrées se compriment sous la hauteur de leur texte quand la
     liste dépasse `max-height`, et se chevauchent. */
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ag-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* Un titre est la première ligne du message : il peut être long, et c'est lui
   qui cède la place, jamais la date. */
.ag-history-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ag-history-date {
  flex: none;
  color: var(--ag-text-muted);
  font-size: 12px;
  font-weight: 400;
}

.ag-history-item:hover {
  background: rgba(45, 0, 158, 0.06);
}

.ag-history-current {
  color: var(--ag-title);
  font-weight: 700;
}

.ag-stop {
  color: var(--ag-title);
}

.ag-thread {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}

.ag-empty {
  margin: auto 0;
  color: var(--ag-text-muted);
  text-align: center;
}

.ag-row {
  display: flex;
  flex-direction: column;
}

.ag-row-user {
  align-items: flex-end;
}

.ag-row-assistant {
  align-items: stretch;
}

.ag-bubble {
  overflow-wrap: anywhere;
}

/* Le message de l'utilisateur n'est pas du Markdown : ses retours à la ligne
   sont les siens. */
.ag-bubble-user {
  white-space: pre-wrap;
}

.ag-bubble p {
  margin: 0 0 8px;
}

.ag-bubble p:last-child {
  margin-bottom: 0;
}

.ag-bubble .ag-heading {
  font-weight: 700;
}

.ag-bubble ul,
.ag-bubble ol {
  margin: 0 0 8px;
  padding-left: 20px;
}

.ag-bubble li {
  margin-bottom: 4px;
}

.ag-bubble .ag-rule {
  margin: 10px 0;
  border: none;
  border-top: 1px solid rgba(45, 0, 158, 0.15);
}

.ag-bubble code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(45, 0, 158, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}

.ag-bubble a {
  color: var(--ag-title);
  text-decoration: underline;
}

/* Un tableau large ne doit pas élargir le panneau : il défile pour son compte. */
.ag-table-scroll {
  overflow-x: auto;
  margin-bottom: 8px;
}

.ag-table {
  border-collapse: collapse;
  font-size: 13px;
}

.ag-table th,
.ag-table td {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(45, 0, 158, 0.12);
  text-align: left;
  white-space: nowrap;
}

.ag-table th {
  font-weight: 700;
}

.ag-bubble-assistant {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  /* Deux couches, comme dans la maquette : la teinte de marque à 15 % posée
     sur un aplat blanc, sans quoi le texte perdrait son contraste. */
  background:
    linear-gradient(171.69deg, rgba(29, 127, 206, 0.15) 0%, rgba(109, 51, 255, 0.15) 100%),
    linear-gradient(90deg, #ffffff 0%, #ffffff 100%);
  box-shadow: var(--ag-shadow-bubble);
  color: var(--ag-bubble-text);
}

.ag-bubble-user {
  max-width: 88%;
  padding: 5px 14px;
  border-radius: 14px;
  background: var(--ag-white);
  box-shadow: var(--ag-shadow-white-bubble);
  color: var(--ag-text);
}

.ag-bubble-error {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fef3f2;
  color: var(--ag-danger);
}

.ag-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ag-action {
  padding: 8px 12px;
  border: 1px solid var(--ag-gradient-to);
  border-radius: 9999px;
  background: var(--ag-white);
  color: var(--ag-title);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--ag-shadow-chip);
}

.ag-action:hover {
  background: rgba(109, 51, 255, 0.08);
}

.ag-status {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  color: var(--ag-text-muted);
}

.ag-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ag-gradient-to);
  animation: ag-pulse 1.2s ease-in-out infinite;
}

@keyframes ag-pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .ag-dot { animation: none; opacity: 0.7; }
}

.ag-footer {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--ag-divider);
}

.ag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ag-suggestion {
  padding: 8px 12px;
  border: none;
  border-radius: 9999px;
  background: var(--ag-white);
  color: var(--ag-text);
  font: inherit;
  font-weight: 700;
  line-height: 16px;
  cursor: pointer;
  box-shadow: var(--ag-shadow-chip);
}

.ag-suggestion:hover:not(:disabled) {
  color: var(--ag-title);
}

.ag-suggestion:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Le rembourrage de 8 px est celui de la maquette : c'est lui qui donne sa
   hauteur au composeur. Il formerait un anneau mort au clic, d'où le
   gestionnaire qui fait du cadre l'étiquette du champ (voir ChatWidget). */
.ag-composer {
  display: flex;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--ag-border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.5);
  cursor: text;
}

.ag-composer:focus-within {
  border-color: var(--ag-gradient-to);
}

.ag-input {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 8px 10px 8px 12px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ag-text);
  font: inherit;
}

.ag-input::placeholder {
  color: var(--ag-text-muted);
}

.ag-send {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  padding: 8px;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: var(--ag-text-muted);
  cursor: pointer;
}

.ag-send:not(:disabled) {
  color: var(--ag-title);
}

.ag-send:hover:not(:disabled) {
  background: rgba(45, 0, 158, 0.06);
}

.ag-send:disabled {
  cursor: not-allowed;
}

.ag-connection {
  color: var(--ag-text-muted);
  font-size: 12px;
}
