/* Agent Moustachir — interface de conversation plein écran.
   Remplace le cadre « téléphone » de 440 px qui laissait ~78 % d'un écran de
   bureau vide. La colonne de texte reste limitée pour la lisibilité, mais le
   conteneur occupe la page. */

:root {
  --brand: #1f4e86;
  --brand-dark: #152e4f;
  --brand-soft: #dae7f7;

  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --ink: #12233a;
  --muted: #5c6b80;
  --line: #d9e0ea;

  --agent-bubble: #ffffff;
  --user-bubble: #1f4e86;
  --user-ink: #ffffff;

  --ok: #2f9e6b;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5b00;
  --err-bg: #fdE3E1;
  --err-ink: #9b2c25;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 34, 58, .06), 0 4px 16px rgba(16, 34, 58, .06);
  --measure: 68ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1520;
    --surface: #16202e;
    --surface-2: #1b2635;
    --ink: #e6edf6;
    --muted: #9aabc0;
    --line: #26344a;
    --agent-bubble: #1b2635;
    --user-bubble: #2d6fbe;
    --brand-soft: #23405f;
    --warn-bg: #3b3218;
    --warn-ink: #f0d493;
    --err-bg: #40211f;
    --err-ink: #f5b3ad;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6; --surface: #fff; --surface-2: #f6f8fb; --ink: #12233a;
  --muted: #5c6b80; --line: #d9e0ea; --agent-bubble: #fff;
  --user-bubble: #1f4e86; --brand-soft: #dae7f7;
  --warn-bg: #fff4d6; --warn-ink: #7a5b00; --err-bg: #fde3e1; --err-ink: #9b2c25;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1520; --surface: #16202e; --surface-2: #1b2635; --ink: #e6edf6;
  --muted: #9aabc0; --line: #26344a; --agent-bubble: #1b2635;
  --user-bubble: #2d6fbe; --brand-soft: #23405f;
  --warn-bg: #3b3218; --warn-ink: #f0d493; --err-bg: #40211f; --err-ink: #f5b3ad;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------------------------------------------------------------- structure */

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto auto;
  max-width: 1100px;
  margin-inline: auto;
  background: var(--surface);
  border-inline: 1px solid var(--line);
}

@media (max-width: 720px) {
  .app { border-inline: 0; }
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px clamp(12px, 3vw, 28px);
  background: var(--brand-dark);
  color: #fff;
}

.brand { height: 30px; width: auto; display: block; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: #b9cde8; flex: 1;
}
.dot-status {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 3px rgba(47, 158, 107, .2);
}
.status[data-state="thinking"] .dot-status { background: #f0b429; box-shadow: 0 0 0 3px rgba(240,180,41,.2); }
.status[data-state="offline"] .dot-status { background: #d64545; box-shadow: 0 0 0 3px rgba(214,69,69,.2); }

.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  background: transparent; border: 0; color: #fff; opacity: .85;
  font-size: 18px; line-height: 1; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px;
  display: inline-grid; place-items: center;   /* centre les SVG */
  padding: 0; text-decoration: none;
}
.icon-btn svg { display: block; }
.icon-btn:hover { opacity: 1; background: rgba(255,255,255,.12); }
.icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ------------------------------------------------------------------ banner */

.banner {
  padding: 10px clamp(12px, 3vw, 28px);
  font-size: 14px;
  background: var(--warn-bg); color: var(--warn-ink);
  border-bottom: 1px solid var(--line);
}
.banner[data-kind="error"] { background: var(--err-bg); color: var(--err-ink); }
.banner button {
  margin-inline-start: 10px; border: 0; border-radius: 6px; cursor: pointer;
  background: currentColor; padding: 4px 10px; font-size: 13px; font-weight: 600;
}
.banner button span { color: var(--surface); }

/* ------------------------------------------------------------ conversation */

.conversation {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 3vw, 32px) clamp(12px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  .conversation { scroll-behavior: auto; }
}

.msg { display: flex; max-width: 100%; }
.msg.user { justify-content: flex-end; }

.bubble {
  max-width: min(var(--measure), 82%);
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}

.msg.agent .bubble {
  background: var(--agent-bubble);
  border-start-start-radius: 4px;
  border: 1px solid var(--line);
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-ink);
  border-start-end-radius: 4px;
}

/* Arabe / darija : direction et police adaptées. */
.bubble.rtl {
  direction: rtl;
  text-align: right;
  font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.85;
}

.meta {
  display: block; margin-top: 5px;
  font-size: 11px; opacity: .65;
  font-variant-numeric: tabular-nums;
}

/* Encart comparatif : met en avant l'argument chiffré au lieu de le noyer. */
.compare {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  margin: 10px 0 4px; border-radius: 10px; overflow: hidden;
  background: var(--line);
}
.compare div { background: var(--surface-2); padding: 10px 12px; text-align: center; }
.compare .k { display: block; font-size: 11px; text-transform: uppercase;
               letter-spacing: .05em; color: var(--muted); }
.compare .v { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.compare .bad .v { color: #c2410c; }
.compare .good .v { color: var(--ok); }

/* Indicateur de frappe */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 14px 16px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: bounce 1.3s infinite; display: block;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes bounce {
  0%, 62%, 100% { transform: translateY(0); opacity: .45; }
  32% { transform: translateY(-5px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; } }

/* Curseur de streaming */
.cursor::after {
  content: "▍"; margin-inline-start: 1px; opacity: .55;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } }

/* -------------------------------------------------------------- suggestions */

.suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: flex-start;      /* sinon les puces s'étirent sur la hauteur */
  padding: 0 clamp(12px, 3vw, 28px) 12px;
}
.chip {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 999px; padding: 9px 15px; font-size: 14px; cursor: pointer;
  font-family: inherit;
  flex: 0 0 auto;               /* largeur au contenu, pas d'étirement */
  white-space: nowrap;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* Suggestions en arabe / darija */
.chip.rtl { direction: rtl; font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, system-ui, sans-serif; }

/* Les suggestions générées peuvent être plus longues que les puces d'amorçage :
   sur petit écran on autorise le retour à la ligne et on empile proprement.
   `align-self: flex-start` évite que la puce s'étire sur la hauteur de la ligne. */
@media (max-width: 560px) {
  .suggestions { flex-direction: column; align-items: stretch; }
  .chip {
    white-space: normal; max-width: 100%; text-align: start;
    align-self: flex-start; border-radius: 14px;
  }
}

/* ---------------------------------------------------------------- composer */

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px clamp(12px, 3vw, 28px);
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.composer textarea {
  flex: 1; resize: none; font: inherit; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; max-height: 160px; overflow-y: auto;
}
.composer textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 78, 134, .16);
}

.send {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--brand); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.send:hover:not(:disabled) { background: var(--brand-dark); }
.send:disabled { opacity: .45; cursor: not-allowed; }
.send:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ------------------------------------------------------------------- legal */

.legal {
  padding: 0 clamp(12px, 3vw, 28px) 12px;
  font-size: 12px; color: var(--muted); text-align: center;
}
.legal a { color: var(--brand); }
@media (prefers-color-scheme: dark) { .legal a { color: #7fb0ea; } }
