/* ============================================================
   Assistant de conversation — préfixe ac-
   ============================================================ */

/* 1. Design tokens */
:root {
  --ac-bg:        #f3f6fb;
  --ac-surface:   #ffffff;
  --ac-text:      #17233a;
  --ac-muted:     #55617a;
  --ac-border:    #ccd5e6;
  --ac-accent:    #1f5fd1;
  --ac-accent-h:  #194eab;
  --ac-on-accent: #ffffff;
  --ac-me:        #dfeafd;
  --ac-other:     #eef0f4;
  --ac-danger:    #b42318;
  --ac-radius:    12px;
  --ac-shadow:    0 2px 12px rgba(0,0,0,.10);
  --ac-transition: 0.2s ease;
}

/* 2. Thème sombre (préférence système, sauf thème clair forcé) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ac-bg:       #0f1626;
    --ac-surface:  #19233a;
    --ac-text:     #eaf0fb;
    --ac-muted:    #a3b0c9;
    --ac-border:   #2c3a58;
    --ac-accent:   #6ea0ff;
    --ac-accent-h: #8db4ff;
    --ac-on-accent:#0b1424;
    --ac-me:       #223a66;
    --ac-other:    #25304a;
    --ac-danger:   #ff8a80;
  }
}
[data-theme="dark"] {
  --ac-bg: #0f1626; --ac-surface: #19233a; --ac-text: #eaf0fb; --ac-muted: #a3b0c9;
  --ac-border: #2c3a58; --ac-accent: #6ea0ff; --ac-accent-h: #8db4ff; --ac-on-accent: #0b1424;
  --ac-me: #223a66; --ac-other: #25304a; --ac-danger: #ff8a80;
}

/* 3. Layout */
.ac-app {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 0 48px;
  color: var(--ac-text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.ac-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.ac-title { font-size: clamp(1.3rem, 4vw, 1.9rem); font-family: inherit; }
.ac-top__tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ac-switch { font-size: .9rem; color: var(--ac-muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.ac-section {
  background: var(--ac-surface);
  border: 1px solid var(--ac-border);
  border-radius: var(--ac-radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--ac-shadow);
}
.ac-h { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ac-muted); margin-bottom: 10px; font-family: inherit; font-weight: 600; }

/* 4. Contextes (chips) */
.ac-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.ac-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; min-height: 40px;
  border: 1px solid var(--ac-border); border-radius: 999px;
  background: var(--ac-bg); color: var(--ac-text);
  font: inherit; font-size: .95rem; cursor: pointer;
  transition: background var(--ac-transition), border-color var(--ac-transition);
}
.ac-chip[aria-pressed="true"] { background: var(--ac-accent); color: var(--ac-on-accent); border-color: var(--ac-accent); }
.ac-chip__x { font-weight: 700; opacity: .8; }

/* 5. Historique */
.ac-history { list-style: none; display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; padding: 2px; }
.ac-history:empty::before { content: "Aucun échange pour l'instant."; color: var(--ac-muted); font-size: .9rem; }
.ac-msg { cursor: pointer; max-width: 85%; padding: 8px 12px; border-radius: var(--ac-radius); font-size: 1rem; line-height: 1.4; }
.ac-msg--moi { align-self: flex-end; background: var(--ac-me); }
.ac-msg--interlocuteur { align-self: flex-start; background: var(--ac-other); }
.ac-msg:focus-visible { outline: 2px solid var(--ac-accent); }
.ac-msg--interim { opacity: .7; font-style: italic; }
.ac-status { min-height: 1.4em; margin-top: 8px; font-size: .9rem; color: var(--ac-muted); }
.ac-status--error { color: var(--ac-danger); font-weight: 600; }

/* 6. Zone de choix (orientations / phrases) */
.ac-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.ac-choice {
  position: relative; text-align: left;
  min-height: 64px; padding: 12px 14px 12px 40px;
  border: 2px solid var(--ac-border); border-radius: var(--ac-radius);
  background: var(--ac-bg); color: var(--ac-text);
  font: inherit; font-size: clamp(1rem, 2.6vw, 1.15rem); line-height: 1.3; cursor: pointer;
  transition: border-color var(--ac-transition), background var(--ac-transition);
}
.ac-choice:hover { border-color: var(--ac-accent); }
.ac-choice__n {
  position: absolute; left: 12px; top: 12px;
  font-size: .8rem; font-weight: 700; color: var(--ac-muted);
}
.ac-choice--phrase { grid-column: 1 / -1; }
.ac-choice--other { border-style: dashed; }
.ac-choice[disabled], .ac-choice.loading { opacity: .6; cursor: progress; }
.ac-placeholder { color: var(--ac-muted); padding: 10px 0; }

.ac-free { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ac-free input { flex: 1 1 240px; }
.ac-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ac-actions:empty { display: none; }

/* 7. Composants */
.ac-inline { display: flex; gap: 8px; margin-top: 10px; }
.ac-inline input, .ac-free input {
  flex: 1; min-width: 0; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--ac-border); border-radius: 8px;
  background: var(--ac-bg); color: var(--ac-text); font: inherit;
}
.ac-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px;
  border: 1px solid var(--ac-border); border-radius: 8px;
  background: var(--ac-surface); color: var(--ac-text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background var(--ac-transition);
}
.ac-btn:hover { background: var(--ac-other); }
.ac-btn--primary { background: var(--ac-accent); border-color: var(--ac-accent); color: var(--ac-on-accent); }
.ac-btn--primary:hover { background: var(--ac-accent-h); }
.ac-btn--small { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.ac-btn--listen { width: 100%; font-size: 1.05rem; }
.ac-hint { color: var(--ac-muted); font-size: .85rem; margin-top: 10px; }
.ac-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ac-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 12, 24, .7); }
.ac-overlay[hidden] { display: none; }
.ac-dialog { max-width: 480px; background: var(--ac-surface); color: var(--ac-text); border-radius: var(--ac-radius); padding: 22px; box-shadow: var(--ac-shadow); }
.ac-dialog h2 { margin-bottom: 10px; font-family: inherit; }
.ac-dialog p { margin-bottom: 10px; font-size: .95rem; line-height: 1.5; }
.ac-dialog__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.ac-mic { margin-top: 10px; padding: 12px 14px; border: 2px solid var(--ac-danger); border-radius: var(--ac-radius); background: var(--ac-bg); }
.ac-mic p { margin-bottom: 10px; font-size: .95rem; line-height: 1.45; }

@keyframes ac-pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ac-accent) 35%, transparent); } }
.ac-btn--attn { border-color: var(--ac-accent); animation: ac-pulse 1.2s ease-in-out infinite; }

/* Paramètres */
.ac-gear { font-size: 1.25rem; line-height: 1; padding: 6px 12px; }
.ac-fieldset { border: 1px solid var(--ac-border); border-radius: var(--ac-radius); padding: 10px 14px 12px; margin-bottom: 12px; display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.ac-fieldset legend { padding: 0 6px; font-weight: 700; font-size: .9rem; }
.ac-field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--ac-muted); }
.ac-field select { min-height: 44px; padding: 8px; border: 1px solid var(--ac-border); border-radius: 8px; background: var(--ac-bg); color: var(--ac-text); font: inherit; }
.ac-choice__gloss { display: block; margin-top: 4px; font-size: .85rem; color: var(--ac-muted); font-style: italic; }

/* 8. États selon la phase */
.ac-app[data-phase="SPEAKING"] .ac-stage,
.ac-app[data-phase="LISTENING"] .ac-stage { border-color: var(--ac-accent); }
.ac-app[data-phase="LISTENING"] #ac-listen { background: var(--ac-danger); color: #fff; border-color: var(--ac-danger); }
.ac-app[data-phase="GENERATING_ORIENTATIONS"] .ac-placeholder::after { content: " …"; }

:focus-visible { outline: 3px solid var(--ac-accent); outline-offset: 2px; }

/* 9. Responsive */
@media (max-width: 600px) {
  .ac-fieldset { grid-template-columns: 1fr; }
  .ac-section { padding: 12px; }
  .ac-choices { grid-template-columns: 1fr; }
  .ac-msg { max-width: 95%; }
  .ac-inline { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* L'attribut hidden doit l'emporter sur les display: flex des composants */
.ac-app [hidden] { display: none !important; }
