/* Agent Score Gr33t — thème Material 3 Gr33t (tokens du projet API Gr33t) */

:root {
  --primary: #0057cd;
  --on-primary: #ffffff;
  --primary-container: #d9e2ff;
  --on-primary-container: #001946;
  --secondary-container: #c1e8ff;
  --on-secondary-container: #001e2b;
  --error: #b41f4f;
  --error-container: #ffd9de;
  --on-error-container: #400015;
  --surface: #fbf8fd;
  --surface-lowest: #ffffff;
  --surface-low: #f5f3f7;
  --surface-container: #efedf1;
  --surface-high: #e9e7ec;
  --on-surface: #1b1b1f;
  --on-surface-variant: #44464f;
  --outline-variant: #c5c6d0;
  --vert-gr33t: #1d6f42;
  --vert-container: #d3f4de;
}

* { box-sizing: border-box; }

/* L'attribut hidden doit gagner sur les display explicites (flex, etc.) */
[hidden] { display: none !important; }

/* Icônes Material Symbols — configuration du design system Gr33t
   (gr33t-theme.css : FILL 0 inactif / 1 actif, wght 400, GRAD 0, opsz 24) */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 18px;
  line-height: 1;
  display: inline-block;
  vertical-align: -3px;
  letter-spacing: normal;
  white-space: nowrap;
  direction: ltr;
  user-select: none;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.material-symbols-outlined.active {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--surface);
  color: var(--on-surface);
  font-size: 15px;
}

body { display: flex; flex-direction: column; }

/* ── Topbar ─────────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface-lowest);
  border-bottom: 1px solid var(--outline-variant);
}
.topbar-titre { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.badge-env {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px;
  background: var(--secondary-container); color: var(--on-secondary-container);
  letter-spacing: 0.5px; text-transform: uppercase;
}
.badge-env.demo { background: var(--error-container); color: var(--on-error-container); }

.chip-score {
  font-size: 13px; font-weight: 700;
  padding: 4px 12px; border-radius: 16px;
  background: var(--vert-container); color: var(--vert-gr33t);
}
.compte-login { font-size: 13px; color: var(--on-surface-variant); }

.chip-profil {
  font-size: 13px; font-weight: 600;
  padding: 4px 12px; border-radius: 16px;
  background: var(--primary-container); color: var(--on-primary-container);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.chip-recent {
  display: inline-block;
  margin: 4px 6px 0 0; padding: 5px 12px;
  font: inherit; font-size: 13px;
  border: 1px solid var(--outline-variant); border-radius: 14px;
  background: var(--surface-low); color: var(--on-surface);
  cursor: pointer;
}
.chip-recent:hover { background: var(--primary-container); }

/* ── Structure ──────────────────────────────────────────── */

.corps { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 240px; flex-shrink: 0;
  border-right: 1px solid var(--outline-variant);
  background: var(--surface-low);
  padding: 12px;
  overflow-y: auto;
}
.sidebar-titre {
  font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
  color: var(--on-surface-variant);
  margin: 16px 4px 8px;
  text-transform: uppercase;
}
.conv {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; cursor: pointer;
  color: var(--on-surface);
}
.conv:hover { background: var(--surface-container); }
.conv.active { background: var(--primary-container); color: var(--on-primary-container); }
.conv-titre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-suppr {
  border: none; background: none; cursor: pointer;
  color: var(--on-surface-variant);
  padding: 0 2px; border-radius: 4px; visibility: hidden;
  display: inline-flex; align-items: center;
}
.conv-suppr .material-symbols-outlined { font-size: 16px; vertical-align: 0; }
.conv:hover .conv-suppr { visibility: visible; }
.conv-suppr:hover { color: var(--error); }

.principal { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Chat ───────────────────────────────────────────────── */

.chat { flex: 1; overflow-y: auto; padding: 20px 8%; }

.message { display: flex; margin-bottom: 14px; }
.message.user { justify-content: flex-end; }

.bulle {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.message.user .bulle { background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 4px; }
.message.assistant .bulle { background: var(--surface-lowest); border: 1px solid var(--outline-variant); border-bottom-left-radius: 4px; }
.message.assistant .bulle p { margin: 0 0 8px; }
.message.assistant .bulle p:last-child { margin-bottom: 0; }
.astuce { color: var(--on-surface-variant); font-size: 13px; }
.accueil .bulle { white-space: normal; }

/* Largeur fixée sur la bulle (une bulle auto-dimensionnée + img en % boucle
   sur elle-même) : affichage à la taille LOGIQUE du SVG — le PNG est rendu en
   2x pour la netteté — pour que les textes du graphique gardent la même taille
   que le texte des réponses de l'agent (~15 px). */
.bulle-image {
  padding: 8px;
  /* 476 = 460 (largeur logique du SVG) + 2x8 de padding : l'image s'affiche
     à 460 px quand la place le permet, sinon s'adapte. */
  width: min(476px, 95%);
  max-width: none;
}
.bulle-image img {
  display: block;
  border-radius: 10px;
  width: 100%;
}

/* Tableaux Markdown rendus dans les bulles (style des tableaux de l'app) */
.bulle .tableau {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 14px;
  white-space: normal;
  width: 100%;
}
.bulle .tableau th {
  background: var(--surface-container);
  color: var(--on-surface);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
}
.bulle .tableau td {
  padding: 7px 12px;
  border-top: 1px solid var(--outline-variant);
}
.bulle .tableau tr:nth-child(even) td { background: var(--surface-low); }
.bulle .tableau th:first-child { border-radius: 8px 0 0 0; }
.bulle .tableau th:last-child { border-radius: 0 8px 0 0; }

.bulle a { color: var(--primary); font-weight: 500; }
.message.user .bulle a { color: var(--on-primary); text-decoration: underline; }

.bulle code {
  background: var(--surface-container);
  padding: 1px 5px; border-radius: 4px;
  font-size: 13px;
}

/* Trace d'appel d'outil */
.outil {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 2px 0 10px;
  padding: 4px 12px;
  border-radius: 14px;
  background: var(--surface-container);
  color: var(--on-surface-variant);
  font-size: 12.5px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.outil::before {
  content: 'construction';
  font-family: 'Material Symbols Outlined';
  font-size: 15px;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.outil.encours::before { content: 'hourglass_top'; }

/* Pied de réponse : coût / tokens */
.pied-tour {
  font-size: 11.5px; color: var(--on-surface-variant);
  margin: -8px 0 14px 4px;
}

/* Compteur CO2 de l'assistant : fragment cliquable du pied de réponse
   (détail dans le volet d'objets) */
.co2-fragment { cursor: pointer; }
.co2-fragment:hover { text-decoration: underline dotted; }

.impact-detail { font-size: 13px; display: grid; gap: 6px; }
.impact-ligne { display: flex; justify-content: space-between; gap: 12px; }
.impact-titre { color: var(--on-surface-variant); }
.impact-valeur { white-space: nowrap; text-align: right; }
.impact-methodo {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--outline-variant);
  color: var(--on-surface-variant); font-size: 12px; line-height: 1.45;
}
.impact-methodo a { color: inherit; }

.erreur-tour {
  background: var(--error-container); color: var(--on-error-container);
  padding: 10px 14px; border-radius: 10px;
  font-size: 13.5px; margin-bottom: 14px;
}

/* ── Saisie ─────────────────────────────────────────────── */

.saisie { padding: 12px 8% 8px; background: var(--surface); }
#form { display: flex; gap: 10px; }
#question {
  flex: 1; resize: none;
  padding: 12px 14px;
  font: inherit;
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  background: var(--surface-lowest);
  outline: none;
  max-height: 160px;
}
#question:focus { border-color: var(--primary); }
#envoyer {
  padding: 0 24px;
  font: inherit; font-weight: 600;
  border: none; border-radius: 12px;
  background: var(--primary); color: var(--on-primary);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
#envoyer:disabled { opacity: 0.5; cursor: not-allowed; }
.mentions {
  text-align: center;
  font-size: 11.5px; color: var(--on-surface-variant);
  padding-top: 6px;
}

/* ── Boutons génériques ─────────────────────────────────── */

.btn-primaire {
  padding: 10px 24px; min-height: 44px;
  font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 8px; border: none; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
  transition: opacity 0.15s;
}
.btn-primaire:hover { opacity: 0.92; }
.btn-primaire:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-clair {
  padding: 6px 14px;
  font: inherit; font-size: 13px; font-weight: 500;
  border-radius: 8px; cursor: pointer;
  border: 1px solid var(--outline-variant);
  background: var(--surface-lowest); color: var(--on-surface);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-clair .material-symbols-outlined { font-size: 16px; vertical-align: 0; }
.btn-clair:hover { background: var(--surface-container); }
.btn-clair:disabled { opacity: 0.5; cursor: wait; }

.btn-nouvelle {
  width: 100%;
  padding: 10px;
  font: inherit; font-size: 13.5px; font-weight: 600;
  border: none; border-radius: 10px; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-nouvelle:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Modale de connexion (style API Gr33t) ──────────────── */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.modal-card {
  background: var(--surface-lowest);
  border-radius: 16px;
  padding: 32px;
  width: 100%; max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}
.modal-title { font-size: 22px; font-weight: 500; margin: 0 0 4px; }
.modal-subtitle { font-size: 14px; color: var(--on-surface-variant); margin: 0 0 24px; }
.modal-field { margin-bottom: 16px; }
.modal-label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--on-surface-variant);
  margin-bottom: 6px; letter-spacing: 0.5px;
}
.modal-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px; font-family: inherit;
  border: 1px solid var(--outline-variant);
  border-radius: 8px;
  background: var(--surface-low);
  color: var(--on-surface);
  outline: none;
  transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--primary); border-width: 2px; padding: 11px 13px; }
select.modal-input { appearance: auto; }
.modal-error {
  background: var(--error-container); color: var(--on-error-container);
  padding: 10px 14px; border-radius: 8px;
  font-size: 13px; margin-bottom: 12px;
}
.modal-actions { display: flex; justify-content: flex-end; margin-top: 24px; }
.lien-demo {
  display: block; width: 100%;
  margin-top: 16px; padding: 8px;
  font: inherit; font-size: 13px;
  border: none; background: none; cursor: pointer;
  color: var(--primary); text-decoration: underline;
}

/* ── Trajectoire CO2 — carte fidèle à l'app Gr33t ─────────────────────────── */
/* Alignée sur la largeur de la conversation (mêmes marges que .chat) */
.carte-trajectoire { padding: 14px 8% 0; }
.traj-carte {
  display: flex; gap: 0; background: #fff; border: 1px solid #dbe5f4;
  border-radius: 12px; overflow: hidden;
}
/* white-space:normal : la bulle hérite de pre-wrap (voulu pour le texte de l'agent),
   mais dans une carte construite en HTML indenté, chaque retour à la ligne du gabarit
   deviendrait un blanc rendu (éléments fantômes en flex) — constaté le 24/07. */
.bulle-trajectoire { max-width: 78%; width: 78%; padding: 0; background: none; border: none; white-space: normal; }
.traj-carte { white-space: normal; }
.bulle-trajectoire .traj-carte { width: 100%; }
.traj-panneau {
  flex: 0 0 240px; display: flex; flex-direction: column; border-right: 1px solid #dbe5f4;
}
.traj-bloc { padding: 16px 18px; }
.traj-bloc + .traj-bloc { border-top: 1px solid #dbe5f4; }
.traj-titre { font-weight: 700; font-size: 15px; color: #1c1b1f; line-height: 1.25; }
.traj-info { color: #2067dc; cursor: help; font-size: 13px; margin-left: 2px; }
.traj-evo { font-size: 30px; font-weight: 800; margin-top: 6px; }
.traj-evo.hausse { color: #c62828; }
.traj-evo.baisse { color: #1D6F42; }
.traj-cumul { font-size: 28px; font-weight: 800; color: #2067dc; margin-top: 6px; }
.traj-cumul sub { font-size: 60%; }
.traj-sous { font-size: 12.5px; color: #5f6368; margin-top: 2px; }
.traj-graph { position: relative; flex: 1; padding: 10px 8px 4px; min-width: 0; }
.traj-graph svg { width: 100%; height: auto; display: block; }
.traj-mois { font: 600 12px 'Source Sans Pro', sans-serif; fill: #8a94a6; }
.traj-objectif { font: 700 14px 'Source Sans Pro', sans-serif; fill: #1D6F42; }
.traj-tooltip {
  position: absolute; background: #1c1b1f; color: #fff; border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.5; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); white-space: nowrap; z-index: 5;
}
.traj-tooltip strong { display: block; margin-bottom: 2px; }
.traj-tooltip .pt-n, .traj-tooltip .pt-n1 { display: block; }
.traj-tooltip .pt-n { color: #9dbff5; }
.traj-tooltip .pt-n1 { color: #c9cdd6; }
@media (max-width: 720px) {
  .traj-carte { flex-direction: column; }
  .traj-panneau { flex-direction: row; border-right: none; border-bottom: 1px solid #dbe5f4; }
  .traj-bloc + .traj-bloc { border-top: none; border-left: 1px solid #dbe5f4; }
}

/* Tout visuel du fil occupe la largeur de la conversation, textes à taille réelle */
.bulle-image { max-width: 78%; width: 78%; }
.bulle-image img { width: 100%; height: auto; display: block; }

/* ── Volet des objets de la conversation (droite, redimensionnable) ───────── */
.volet-objets {
  position: relative; flex: 0 0 auto; width: 420px; min-width: 360px; max-width: 45vw;
  background: #fff; border-left: 1px solid #dbe5f4; display: flex;
}
.volet-poignee {
  position: absolute; left: -3px; top: 0; bottom: 0; width: 7px;
  cursor: col-resize; z-index: 4;
}
.volet-poignee:hover { background: #2067dc22; }
body.volet-en-glisse { cursor: col-resize; user-select: none; }
.volet-interieur { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.volet-entete {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid #dbe5f4;
}
.volet-titre { font-weight: 700; font-size: 14px; color: #1c1b1f; }
.volet-contenu { flex: 1; overflow-y: auto; padding: 12px 14px; }
.volet-objet {
  border: 1px solid #dbe5f4; border-radius: 10px; margin-bottom: 12px; overflow: hidden;
}
.volet-objet-titre {
  font-weight: 700; font-size: 13px; color: #1c1b1f;
  padding: 10px 12px 6px;
}
.volet-objet-corps { padding: 0 8px 6px; }
.volet-objet-corps img { width: 100%; height: auto; display: block; }
.volet-objet-corps .traj-carte { border: none; }
/* Dans un volet étroit, la carte trajectoire s'empile (comme en mobile) */
.volet-objet-corps .traj-carte { flex-direction: column; }
.volet-objet-corps .traj-panneau {
  flex-direction: row; flex-basis: auto; border-right: none; border-bottom: 1px solid #dbe5f4;
}
.volet-objet-corps .traj-bloc + .traj-bloc { border-top: none; border-left: 1px solid #dbe5f4; }
.volet-objet-date { font-size: 11.5px; color: #8a94a6; padding: 0 12px 10px; }
@media (max-width: 900px) {
  .volet-objets { position: fixed; right: 0; top: 52px; bottom: 0; z-index: 20;
    box-shadow: -8px 0 24px rgba(0,0,0,.12); }
}

/* (1) Volet ouvert : l'inline se replie en vignette (le volet devient le lieu de lecture) */
.traj-vignette { display: none; }
body.volet-ouvert .bulle-trajectoire .traj-carte { display: none; }
body.volet-ouvert .bulle-trajectoire .traj-vignette {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 16px; background: #fff; border: 1px solid #dbe5f4; border-radius: 12px;
  font: inherit; font-size: 14px; color: #1c1b1f; cursor: pointer; text-align: left;
}
body.volet-ouvert .bulle-trajectoire .traj-vignette:hover { border-color: #2067dc; }
.traj-vignette .material-symbols-outlined { color: #2067dc; }
.traj-vignette .vignette-ouvrir { margin-left: auto; color: #2067dc; font-size: 12.5px; white-space: nowrap; }

/* (2) États par largeur de CONTENEUR (classes posées par le ResizeObserver) */
.traj-carte.carte-etroite { flex-direction: column; }
.traj-carte.carte-etroite .traj-panneau {
  flex-direction: row; flex-basis: auto; border-right: none; border-bottom: 1px solid #dbe5f4;
}
.traj-carte.carte-etroite .traj-bloc + .traj-bloc { border-top: none; border-left: 1px solid #dbe5f4; }
.traj-carte.carte-etroite .traj-evo, .traj-carte.carte-etroite .traj-cumul { font-size: 22px; }
/* KPIs seuls : uniquement dans le FIL (où le volet offre la vue complète).
   Dans le volet, le graphe doit exister à toute largeur — constaté le 25/07 :
   un volet à ~330 px perdait son graphe, vidant le volet de son objet. */
.bulle-trajectoire .traj-carte.carte-mini .traj-graph { display: none; }

/* (4) Les valeurs ne se coupent jamais */
.traj-evo, .traj-cumul { white-space: nowrap; }
