/* Reset & tokens */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== THÈMES ===== */
:root, :root[data-theme="dark"] {
  --body-bg:       radial-gradient(ellipse at 50% 30%, #0e1f38 0%, #06121f 55%, #02060d 100%);
  --bg-surface:    rgba(0, 0, 0, 0.52);
  --bg-elevated:   rgba(255, 255, 255, 0.06);
  --bg-input:      rgba(255, 255, 255, 0.04);
  --menu-bg:       #152238;  /* fond OPAQUE de la liste d'options du select (popup natif) */
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  --accent:        #b58dff;
  --accent-hover:  #c9a6ff;
  --accent-glow:   rgba(181, 141, 255, 0.2);
  --accent-soft:   rgba(181, 141, 255, 0.18);
  --accent-faint:  rgba(181, 141, 255, 0.07);

  --bubble-user:        #7a52d4;
  --bubble-ai:          #1e1540;
  --bubble-ai-border:   rgba(255, 255, 255, 0.08);
  --bubble-user-text:   #ffffff;

  --text:          #e8ecf5;
  --text-muted:    rgba(232, 236, 245, 0.62);
  --text-faint:    rgba(232, 236, 245, 0.45);

  --success:       #8ee3c0;
  --error:         #ff9a8a;
  --warning:       #f0c060;

  --radius-xl:     20px;
  --radius-lg:     16px;
  --radius-md:     12px;
  --radius-sm:     8px;
  --radius-xs:     6px;
  --shadow:        0 16px 48px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .3);
  --shadow-sm:     0 4px 16px rgba(0, 0, 0, .3);

  --modal-scrim:   rgba(6, 12, 30, 0.62);

  /* Aligne les contrôles natifs (liste d'options du select, scrollbars) sur le thème sombre. */
  color-scheme: dark;
}

:root[data-theme="light"] {
  --body-bg:       linear-gradient(135deg, #cdd9ff 0%, #e3d4f8 30%, #f4d4ec 60%, #d4ecf2 100%);
  --bg-surface:    rgba(255, 255, 255, 0.55);
  --bg-elevated:   rgba(255, 255, 255, 0.70);
  --bg-input:      rgba(255, 255, 255, 0.65);
  --menu-bg:       #ffffff;
  --border:        rgba(255, 255, 255, 0.55);
  --border-strong: rgba(255, 255, 255, 0.80);

  --accent:        #7a52d4;
  --accent-hover:  #6a42c4;
  --accent-glow:   rgba(122, 82, 212, 0.15);
  --accent-soft:   rgba(122, 82, 212, 0.18);
  --accent-faint:  rgba(122, 82, 212, 0.06);

  --bubble-user:        #7a52d4;
  --bubble-ai:          rgba(255, 255, 255, 0.85);
  --bubble-ai-border:   rgba(255, 255, 255, 0.7);
  --bubble-user-text:   #ffffff;

  --text:          #2a1d4a;
  --text-muted:    rgba(42, 29, 74, 0.66);
  --text-faint:    rgba(42, 29, 74, 0.52);

  --success:       #2fa775;
  --error:         #d35a45;
  --warning:       #c07a10;

  --modal-scrim:   rgba(122, 82, 212, 0.22);

  color-scheme: light;
}

/* ===== BASE ===== */
html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: rgba(181, 141, 255, .35); }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--body-bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  line-height: 1.5;
  letter-spacing: -0.01em;
}


/* ===== HEADER ===== */
.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-strong);
  gap: 12px;
  box-shadow: 0 1px 0 0 rgba(181, 141, 255, 0.15);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: none;
  flex-shrink: 0;
  overflow: hidden;
}

.header-brand h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ===== BOUTON ICÔNE ===== */
/* Cible tactile 44px : usage tablette au doigt (Galaxy Tab A9+) */
.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover { background: var(--bg-elevated); color: var(--text); }
.btn-icon:active { transform: scale(0.93); }

html.embed #themeBtn { display: none; }

.btn-reco {
  height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-soft);
  background: var(--accent-faint);
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-reco:hover { background: var(--accent-soft); color: var(--accent); }
.btn-reco:active { transform: scale(0.93); }

html.embed .header {
  background: transparent;
  border-bottom: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
html.embed .header-brand { display: none; }

/* ===== ICÔNE ROBOT (thème clair/sombre) ===== */
/* position: relative obligatoire pour que les img absolute se calent dans le container */
.robot-icon-wrap {
  position: relative;
}

.robot-icon-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Sombre (défaut) : on masque la variante claire */
.robot-icon-wrap > .robot-light { display: none; }

/* Clair : on inverse */
:root[data-theme="light"] .robot-icon-wrap > .robot-dark  { display: none; }
:root[data-theme="light"] .robot-icon-wrap > .robot-light { display: block; }

/* ===== ZONE CHAT ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 16px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

.chat-area::-webkit-scrollbar { width: 3px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* ===== ÉCRAN D'ACCUEIL ===== */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 32px 16px;
  animation: fadeIn 0.4s ease;
}

.welcome-visual {
  position: relative;
  margin-bottom: 8px;
}

.welcome-avatar {
  width: 72px;
  height: 72px;
  background: none;
  position: relative;
  z-index: 1;
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(122, 82, 212, 0.35)); }
  50%       { filter: drop-shadow(0 0 10px rgba(122, 82, 212, 0.65)); }
}

.welcome h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.welcome p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.7;
}

.welcome strong { color: var(--text); font-weight: 500; }

/* ===== CHIPS ===== */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.chip {
  min-height: 44px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.chip:active { transform: scale(0.96); }

/* ===== MESSAGES ===== */
.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.message {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: msg-slide-in 0.2s ease-out both;
}

.message.streaming-row {
  animation: none;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes msg-slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

/* ===== AVATAR ===== */
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  align-self: flex-end;
}

.message.user .msg-avatar {
  background: var(--bubble-user);
  color: white;
}

.message.assistant .msg-avatar,
.typing .msg-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--accent);
}

/* ===== GROUPE + BULLE ===== */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: min(74%, 520px);
}

.message.user .msg-group  { align-items: flex-end; }
.message.assistant .msg-group { align-items: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 5px;
}

.message.assistant .bubble {
  background: var(--bubble-ai);
  color: var(--text);
  border: 1px solid var(--bubble-ai-border);
  border-bottom-left-radius: 5px;
}

.bubble code {
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 13px;
  background: rgba(181, 141, 255, 0.12);
  padding: 1px 5px;
  border-radius: 4px;
}

:root[data-theme="light"] .bubble code {
  background: rgba(122, 82, 212, 0.10);
}

/* ===== ERREUR ===== */
.message.error .bubble {
  background: rgba(255, 154, 138, 0.1);
  border: 1px solid rgba(255, 154, 138, 0.25);
  color: var(--error);
  border-radius: var(--radius-lg);
}

.message.error .msg-avatar {
  background: rgba(255, 154, 138, 0.15);
  border: 1px solid rgba(255, 154, 138, 0.2);
  color: var(--error);
}

/* ===== SOURCES ===== */
.sources {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sources-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 2px 0;
  transition: color 0.15s;
}

.sources-btn:hover { color: var(--accent); }

.sources-btn svg {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}
.sources-btn.open svg { transform: rotate(90deg); }

.sources-list {
  display: none;
  flex-wrap: wrap;
  gap: 5px;
  border-left: 2px solid var(--accent);
  padding-left: 8px;
  margin-top: 2px;
}

.sources-list.visible { display: flex; }

.source-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.15s ease, border-color 0.15s;
}

.source-tag:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

/* ===== FEEDBACK ===== */
.feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

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

.feedback-btn {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.feedback-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ===== INDICATEUR DE FRAPPE ===== */
.typing {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: slideUp 0.22s ease;
}

.typing-bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--bubble-ai-border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 5px;
  padding: 14px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.3s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.18s; }
.dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ===== STREAMING ===== */
@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.bubble.streaming::after {
  content: '\25ae';
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: blink-cursor 0.9s step-end infinite;
  vertical-align: baseline;
  font-size: 0.9em;
  line-height: 1;
}

@keyframes stream-bar {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.bubble.streaming {
  position: relative;
  padding-bottom: 18px;
}

.bubble.streaming::before {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 12px;
  right: 12px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: stream-bar 1.4s linear infinite;
  opacity: 0.7;
}

/* ===== ZONE DE SAISIE ===== */
.input-area {
  flex-shrink: 0;
  padding: 10px 16px 14px;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-strong);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.input-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 6px 8px 6px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.55;
  max-height: 130px;
  overflow-y: auto;
}

textarea::placeholder { color: var(--text-faint); }

textarea::-webkit-scrollbar { width: 3px; }
textarea::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:active:not(:disabled) { transform: scale(0.9); }
.btn-send:disabled { opacity: 0.35; cursor: not-allowed; }

.input-hint {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  margin-top: 6px;
}

/* ===== MODAL ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--modal-scrim);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: min(440px, 100%);
  box-shadow: var(--shadow);
  transform: scale(0.94) translateY(8px);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.modal-backdrop.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.field input {
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  min-height: 44px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-hint {
  font-size: 12px;
  color: var(--text-faint);
}

.password-field {
  position: relative;
}

.password-field input { padding-right: 52px; }

.btn-eye {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-xs);
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.btn-eye:hover { color: var(--text); }

.modal-footer {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-ghost {
  min-height: 44px;
  padding: 9px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-ghost:hover { background: var(--bg-elevated); color: var(--text); }

.btn-primary {
  min-height: 44px;
  padding: 9px 22px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.96); }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 9px 18px;
  font-size: 13px;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== MODALE PDC (centrée — réutilise .modal-backdrop / .modal) ===== */
.modal-pdc {
  width: min(480px, 100%);
}

:root[data-theme="light"] .modal-pdc {
  background: #ffffff;
}

.modal-pdc .modal-header .btn-icon {
  border: none;
}

.pdc-body {
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Bandeau : teinte bleutée reprise du gradient body (haut = #cdd9ff clair / #0e1f38 sombre) */
.modal-pdc .modal-header {
  background: rgba(14, 31, 56, 0.55);
}
:root[data-theme="light"] .modal-pdc .modal-header {
  background: rgba(205, 217, 255, 0.55);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.form-row input {
  background-color: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 8px;
  min-height: 44px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, background-color .15s;
}

.form-row input:focus {
  border-color: var(--accent);
  background-color: rgba(255, 255, 255, 0.28);
}

/* Select de cascade : calque l'input + chevron inline (CSP-safe, pas d'asset externe) */
.form-row select {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 8px;
  min-height: 44px;
  padding: 8px 32px 8px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, background .15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a9aec2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}

/* Chevron violet muté en thème clair (le gris clair par défaut est pour le sombre) */
:root[data-theme="light"] .form-row select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b7fa8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* Thème clair : typo noire dans la modale PDC (contraste sur fond glass clair) */
:root[data-theme="light"] .modal-pdc,
:root[data-theme="light"] .modal-pdc .modal-header h3,
:root[data-theme="light"] .modal-pdc .form-row label,
:root[data-theme="light"] .modal-pdc .form-row input,
:root[data-theme="light"] .modal-pdc .form-row select,
:root[data-theme="light"] .modal-pdc .form-optional-group > summary,
:root[data-theme="light"] .modal-pdc .form-optional {
  color: #0a0a12;
}

:root[data-theme="light"] .modal-pdc .modal-header .btn-icon {
  color: #0a0a12;
}

:root[data-theme="light"] .modal-pdc .form-row input::placeholder {
  color: rgba(10, 10, 18, 0.45);
}

/* ===== COMBOBOX (input filtrable + liste portalisée) ===== */
.aq-combo { position: relative; }
.aq-combo-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
  clip: rect(0 0 0 0);
}
.aq-combo .aq-combo-input {
  width: 100%;
  background-color: rgba(255, 255, 255, 0.18);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a9aec2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 8px;
  min-height: 44px;
  padding: 8px 32px 8px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, background-color .15s;
}
.aq-combo .aq-combo-input:focus {
  border-color: var(--accent);
  background-color: rgba(255, 255, 255, 0.28);
}
:root[data-theme="light"] .aq-combo .aq-combo-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b7fa8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  color: #0a0a12;
}
:root[data-theme="light"] .aq-combo .aq-combo-input::placeholder {
  color: rgba(10, 10, 18, 0.45);
}

.aq-combo-list {
  position: fixed;
  z-index: 200;
  list-style: none;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--menu-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.aq-combo-list[hidden] { display: none; }
.aq-combo-list::-webkit-scrollbar { width: 6px; }
.aq-combo-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.aq-combo-item {
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.aq-combo-item:hover,
.aq-combo-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.aq-combo-empty {
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  cursor: default;
}

.form-row select:focus {
  border-color: var(--accent);
}

/* Liste d'options native : fond opaque + texte contrasté (corrige le popup blanc en thème sombre) */
.form-row select option {
  background-color: var(--menu-bg);
  color: var(--text);
}

/* Champ texte libre révélé par l'option « Autre… » d'un select d'affinage */
.form-row .fc-autre {
  margin-top: 6px;
}
.form-row .fc-autre.hidden {
  display: none;
}

/* Champ obligatoire : astérisque accent */
.form-row.required label::after {
  content: " *";
  color: var(--accent);
}

/* Groupe « Affiner (optionnel) » repliable */
.form-optional-group {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.form-optional-group[open] {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-optional-group > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 2px 0;
}

.form-optional-group > summary::-webkit-details-marker { display: none; }
.form-optional-group > summary::before { content: "▸ "; }
.form-optional-group[open] > summary::before { content: "▾ "; }

.form-optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}


/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .msg-group { max-width: 86%; }
  .input-hint { display: none; }
  .brand-sub { display: none; }
  .chip { font-size: 12px; padding: 8px 14px; }
}

@media (hover: none) {
  .chip:hover, .btn-icon:hover { background: inherit; color: inherit; border-color: inherit; }
}

/* ===== ACCESSIBILITÉ ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-icon:focus-visible,
.btn-send:focus-visible,
.btn-ghost:focus-visible,
.btn-primary:focus-visible,
.btn-eye:focus-visible,
.sources-btn:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea:focus-visible {
  outline: none;
}

/* ===== PREFERS-REDUCED-MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .bubble.streaming::after {
    animation: none;
    opacity: 1;
  }

  .bubble.streaming::before {
    animation: none;
    opacity: 0.4;
  }

  .message,
  .message.streaming-row {
    animation: none;
  }
}
