/* =========================
   Thèmes (clair par défaut)
   ========================= */
:root {
  --bg: #89c2d9;          /* blanc très bleuté, net et distinctif */
  --text: #0D1117;
  --input-bg: #A9D6E5;    /* champ / bulles user */
  --assistant-bg: #BAE6EA;/* bulles IA, plus marquées */
  --border: #468FAF;      /* gris bleuté plus présent */
  --accent: #d65108;      /* tu gardes ton accent actuel */

  /* Liens (thème clair) */
  --link: #89C2D9;
  --link-hover: #A9D6E5;
  --link-visited: #89C2D9;
  --focus-ring: #ffb74d;

  --header-h: 56px;
}

body[data-theme='dark']{
  --bg:#01497C;           /* bleu nuit lisible, signature forte */
  --text:#F2F5F9;
  --input-bg:#013A63;     /* zones d’entrée/bulles user */
  --assistant-bg:#10304A; /* bulles IA, bien distinctes */
  --border:#2C7DA0;       /* bordure plus affirmée */
  --accent:#fdc500;

  /* Liens (thème sombre) */
  --link: #89C2D9;
  --link-hover: #A9D6E5;
  --link-visited: #89C2D9;
  --focus-ring: #ffb74d;
}


*{ box-sizing:border-box }
html,body{ height:100% }

body{
  margin:0;
  font-family:system-ui, sans-serif;
  background:var(--bg);
  color:var(--text);
  display:flex; flex-direction:column;
  overflow:hidden;
}

/* Liens: lisibilité claire/sombre + accessibilité */
a:not(.btn){
  color: var(--link);
  text-decoration: none;
  text-decoration-thickness: .08em;
  text-underline-offset: .18em;
  text-decoration-skip-ink: auto;
}
a:not(.btn):hover{ color: var(--link-hover); }
a:not(.btn):visited{ color: var(--link-visited); }
/* focus visible sans déplacer la mise en page */
a:not(.btn):focus-visible{
  outline: 3px solid color-mix(in oklab, var(--focus-ring) 85%, transparent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Liens dans bulles assistant/utilisateur (héritent des mêmes règles) */
.message a{ color: var(--link); }
.message a:hover{ color: var(--link-hover); }
.message a:visited{ color: var(--link-visited); }

.powerIA {
  display:inline-block;
  font-size:.75em;
  transform:translate(0px,-.20em);
}

/* Utilitaires */
.hidden{ display:none !important }

/* =========================
   Layout principal
   ========================= */
#wrapper{
  max-width:1200px; width:100%;
  margin:0 auto;
  display:flex; flex-direction:column;
  height:100%; flex:1;
  /* réserve l’espace sous l’entête fixe */
  padding: var(--header-h) 1em 0;
  overflow:hidden;
}

/* Quand l’historique est ouvert, on libère la place à gauche */
body.with-history-open{
  padding-left:340px;
  transition: padding .25s ease;
}
@media (max-width:700px){
  body.with-history-open{ padding-left:70vw; }
}

/* =========================
   Barre de titre (haut)
   ========================= */
#header-bar{
  position:fixed; top:0; left:0; right:0;
  height:var(--header-h);
  display:grid;
  grid-template-columns:auto 1fr auto;
  align-items:center; gap:8px;
  padding:0 10px; z-index:1002;

  /* fallback sans mix, puis version adoucie */
  background: var(--bg);                                        /* Fallback */
  border-bottom:1px solid var(--border);                        /* Fallback */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  border-bottom:1px solid color-mix(in oklab, var(--border) 65%, transparent);
}

#header-bar .header-left,
#header-bar .header-right{
  display:flex; align-items:center; gap:8px;
}

/* Centre = titre + bouton info */
#header-bar .header-center{
  display:flex; align-items:center; gap:8px; min-width:0;
}

/* Titre : centré verticalement dans la barre (16–20px) */
.app-title{
  margin:0;
  font-weight:400;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  font-size: clamp(16px, 1vw + .5rem, 20px);

  /* alignement vertical parfait */
  height: var(--header-h);
  display: flex;
  align-items: center;
  line-height: 1;
}
/* Desktop : version longue par défaut */
.app-title .title-full{ display:inline; }
.app-title .title-short{ display:none; }

/* Mobile : on bascule sur “GO IA” seulement */
@media (max-width:720px){
  .app-title{ font-size: clamp(16px, 2vw + .5rem, 20px); }
  .app-title .title-full{ display:none; }
  .app-title .title-short{ display:inline; }
}

/* Boutons du header + icônes */
#header-bar button{
  border:none; background:transparent; color:var(--text);
  cursor:pointer; display:inline-flex; align-items:center; justify-content:center;
  width:40px; height:40px; border-radius:999px;
  transition: background-color .15s ease, opacity .15s ease;
  opacity:.9;
}
#header-bar button:hover,
#header-bar button:focus-visible{
  background: color-mix(in oklab, var(--input-bg) 85%, transparent);
  outline:none;
}
#header-bar button[aria-pressed="true"]{
  background: color-mix(in oklab, var(--input-bg) 100%, transparent);
}
/* évite le décalage baseline des pictos */
#header-bar .material-icons{
  font-size:1.5em; line-height:1; display:inline-flex; align-items:center; justify-content:center;
}

/* ====== Bouton info & popover ====== */
.info-btn{
  width:36px; height:36px; border-radius:999px;
  display:inline-flex; align-items:center; justify-content:center;
  opacity:.9;
}
.info-btn:focus-visible{
  outline:2px solid color-mix(in oklab, var(--accent) 60%, transparent);
  outline-offset:2px;
}

.info-popover{
  position:absolute;                 /* popover positionnée */
  /* borne la hauteur + active le scroll interne du contenu */
  max-height: calc(100vh - var(--header-h) - 24px - env(safe-area-inset-bottom, 0px));
  overflow: auto;
  overscroll-behavior: contain;

  top: calc(var(--header-h) + 8px);
  left: 16px;
  max-width:min(98vw, 800px);
  z-index: 1100;
  background: var(--bg);
  color: var(--text);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0px 0px 0px 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  padding: 12px 14px;
  opacity:0; transform: translateY(-6px);
  pointer-events:none;
  transition: opacity .15s ease, transform .15s ease;
}
.info-popover.open{
  opacity:1; transform: translateY(0);
  pointer-events:auto;
}

/* Tête: défile normalement (pas sticky) mais on réserve la place pour la croix */
.info-popover-head{
  display:flex; align-items:center; gap:12px;
  margin:2px 0 8px;
  padding-right: 40px;   /* espace pour la croix qui flotte */
}

/* La croix: flottante au coin de la popover, indépendante du scroll interne */
.info-close{
  position:fixed;
  top: 8px;
  right: 8px;
  z-index: 2;
  display:inline-flex; align-items:center; justify-content:center;
  width:32px; height:32px; border-radius:999px; border:none; background:transparent; color:inherit; cursor:pointer;
}
.info-close:hover, .info-close:focus-visible{
  background: color-mix(in oklab, var(--input-bg) 85%, transparent);
  outline:none;
}

.info-popover-body{ line-height:1.5; font-size: .95rem; }

/* =========================
   Chat principal
   ========================= */
main{ display:flex; flex-direction:column; height:100%; width:100%; flex:1 }

#chat{
  flex:1; overflow-y:auto;
  padding:.5em 1em;
  display:flex; flex-direction:column; gap:1em;
}

.message{
  max-width:80%; padding:.4em .8em;
  border-radius:.75em; line-height:1.4;
}
.message.user{
  align-self:flex-end; background:var(--input-bg); color:var(--text);
}
.message.assistant{
  align-self:flex-start; background:var(--assistant-bg); color:var(--text);
}

.message pre{
  background:#00000022; padding:.5em; overflow-x:auto;
  border-radius:6px; margin-top:.5em; font-size:.95em;
}
.copy-button{
  float:right; background:var(--accent); border:none; color:#fff;
  padding:.3em .6em; margin-top:.3em; border-radius:5px; cursor:pointer;
}

/* =========================
   Formulaire / actions
   ========================= */
form{
  display:flex; flex-direction:column; gap:.5em;
  padding:.5em 0 1em; background:var(--bg); width:100%;
  border-top:none;
}
textarea{
  width:100%; padding:1.5em; border-radius:1em;
  background:var(--input-bg); color:var(--text);
  resize:none; border:0; outline:0;
  font-size:1.2em; min-height:2em; max-height:8em;
}
.actions{
  display:flex; justify-content:space-between; width:100%;
  margin-top:.2em; padding:0 .5em;
}
.left-actions,.right-actions{
  display:flex; gap:.4em; align-items:center;
}
button,label{
  border:none; background:none; color:var(--text); cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center; padding:.4em;
  min-width:44px;
}
/* Bouton envoyer + flash 150ms */
#send-button{
  background:var(--accent); color:#fff; border-radius:2em; padding:.4em 1em;
  transition: background-color .15s ease, color .15s ease;
}
#send-button.flash{ background:#fff !important; color:#111 !important }

/* =========================
   Pièces jointes
   ========================= */
#attachments-list{
  display:flex; flex-wrap:wrap; gap:8px; margin-bottom:.5em;
}
.attachment-item{
  width:60px; display:flex; flex-direction:column; align-items:center;
  position:relative; justify-content:center; font-size:12px;
}
.attachment-item img.attachment-preview{
  width:60px; height:60px; object-fit:contain; background:#888;
  border-radius:4px; padding:2px;
}
.attachment-item .material-icons.attachment-icon{
  font-size:36px; color:var(--accent-color, #555); line-height:60px; height:60px;
  background:var(--input-bg); border-radius:6px; padding:4px;
}
.attachment-item .attachment-name{
  max-width:100%; font-size:11px; text-align:center; overflow:hidden;
  white-space:nowrap; text-overflow:ellipsis; margin-top:4px; color:var(--text);
}
.attachment-item .attachment-remove{
  position:absolute; top:2px; right:2px;
  background:rgba(0,0,0,.5); border-radius:50%;
  font-size:16px; cursor:pointer; padding:2px; color:#fff;
}
.attachment-item .attachment-remove:hover{ background:rgba(0,0,0,.8); color:red }

/* =========================
   Drag & drop mask
   ========================= */
#drop-mask{
  position:fixed; inset:0; -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
  background:rgba(0,0,0,.2); z-index:9999;
  display:none; align-items:center; justify-content:center; color:#fff;
  font-size:20px; text-align:center;
}
#drop-mask.visible{ display:flex }
.drop-content span{ font-size:64px; margin-bottom:12px }

/* =========================
   Overlay chargement global
   ========================= */
#loading-overlay{
  position:fixed; inset:0; background:rgba(0,0,0,.2);
  display:flex; align-items:center; justify-content:center; z-index:9998;
}
#loading-overlay.hidden{ display:none }
.spinner{
  width:40px; height:40px; border:5px solid #ddd; border-top-color:var(--accent);
  border-radius:50%; animation:spin 1s linear infinite;
}
@keyframes spin{ to{ transform:rotate(360deg) } }

/* =========================
   Panneau Historique (gauche)
   ========================= */
#history-panel{
  position:fixed; top:var(--header-h); left:0; bottom:0;
  width:340px; max-width:85vw;
  transform:translateX(-100%); transition:transform .25s ease;
  background:var(--bg); color:var(--text);
  border-right:1px solid var(--border); z-index:1001;
  display:flex; flex-direction:column;
  box-shadow:2px 0 12px rgba(0,0,0,.18);
}
#history-panel.open{ transform:translateX(0) }

.hist-header{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px; border-bottom:1px solid var(--border);
}
.hist-list{
  list-style:none; margin:0; padding:8px; overflow-y:auto; flex:1;
  display:flex; flex-direction:column; gap:6px;
}

/* éléments sans liseret, fond doux */
.hist-item{
  position:relative; background:var(--input-bg);
  border-radius:10px; padding:8px;
  display:grid; grid-template-columns:1fr auto; grid-template-rows:auto auto;
  gap:4px 6px; cursor:pointer;
}
.hist-item .title{
  font-weight:600; grid-column:1; grid-row:1;
}
.hist-item .title[contenteditable="true"]{
  cursor:text; outline:2px dashed var(--border); border-radius:6px; padding:2px 4px;
}
.hist-item .meta{
  grid-column:1 / -1; grid-row:2; font-size:12px; opacity:.8; margin:0;
}

/* Sélection visuelle de l’item actif */
.hist-item.active{
  outline:2px solid var(--accent);
  box-shadow:0 0 0 2px color-mix(in oklab, var(--accent) 30%, transparent);
}

/* Corbeille : masquée, visible seulement si actif ≠ NEW */
.hist-delete{
  display:none !important; position:absolute; right:8px; bottom:8px;
  width:28px; height:28px; align-items:center; justify-content:center;
  background:transparent; border:none; cursor:pointer;
}
.hist-item.active:not([data-id="NEW"]) .hist-delete{ display:inline-flex !important }

/* =========================
   Footer de l’historique (tiroir)
   ========================= */
.hist-footer{
  border-top:1px solid var(--border); padding:10px; font-size:12px; position:relative;
}
.hist-note{ opacity:.8; margin-bottom:4px }

/* Tiroir : tête + chevron */
.hist-footer-head{
  cursor:pointer; display:flex; flex-direction:column; gap:4px;
  position:relative; padding-right:28px;
}
.hist-footer-head .chev{
  position:absolute; right:6px; top:50%; transform:translateY(-50%) rotate(0);
  transition:transform .2s ease, opacity .2s ease; font-size:18px; opacity:.7; user-select:none;
}
.hist-footer.open .hist-footer-head .chev{ transform:translateY(-50%) rotate(180deg) }

/* Contenu tiroir */
.hist-footer-extra{
  max-height:0; overflow:hidden; opacity:0; padding:0 10px;
  transition:max-height .25s ease, padding .25s ease, opacity .2s ease;
}
#history-panel.open .hist-footer.open .hist-footer-extra{
  max-height:220px; padding:8px 10px 12px; opacity:1;
}
#history-panel.open .hist-footer.open .storage-legend {
  display: block;
  font-size: 12px;
  opacity: .85;
  margin-top: 6px;
  line-height: 1.3;
}
/* Actions */
.hist-footer-actions{ display:flex; gap:8px; flex-wrap:wrap; align-items:center }
.hist-footer .btn{
  border:1px solid var(--border); background:var(--input-bg); color:var(--text);
  border-radius:8px; padding:6px 10px; font-size:12px; cursor:pointer;
}
.hist-footer .btn.accent{ background:var(--accent); color:#fff; border-color:transparent }
.hist-footer .btn.icon{
  width:34px; height:34px; padding:0; display:inline-flex; align-items:center; justify-content:center; border-radius:8px;
}
.hist-footer .btn.icon .material-icons{ font-size:18px }
.hist-footer .btn.icon.push-right{ margin-left:auto }

/* Modale de confirmation */
.modal-overlay{
  position:fixed; inset:0; background:rgba(0,0,0,.45);
	z-index: 10050;
  display:flex; align-items:center; justify-content:center;
}
.modal-card{
  background:var(--bg); color:var(--text); border:1px solid var(--border);
  border-radius:12px; padding:16px; width:min(92vw, 360px);
  box-shadow:0 10px 30px rgba(0,0,0,.3);
}
.modal-card h3{ margin:0 0 8px; font-size:16px }
.modal-card p{ margin:0 0 12px; font-size:13px; opacity:.85 }
.modal-actions{ display:flex; justify-content:flex-end; gap:8px }
.btn.danger{ background:#d64545; color:#fff; border-color:transparent }

/* Barre d’état stockage */
.hist-storage{ margin-top:4px }
.storage-bar{
  position:relative; height:10px;
  background: var(--input-bg);                                 /* Fallback */
  border:1px solid var(--border); border-radius:999px; overflow:hidden;
  xxbackground: color-mix(in oklab, var(--input-bg) 70%, transparent);
	background: var(--border);
}
.storage-fill{
  height:100%; width:0%; background:var(--input-bg);
  transition: width .3s ease, background-color .2s ease;
}
.storage-legend{ display:none }

/* Bloc "MS-DOS" qui clignote (fond transparent, hérite de la couleur du texte) */
.typing-dos {
  display: inline-block;
  width: 0.7em;           /* largeur du rectangle */
  height: 1.05em;         /* hauteur ~ ligne de texte */
  background: currentColor;
  border-radius: 2px;
  vertical-align: -0.15em;
  opacity: .9;
  animation: blink-rect 1s steps(1) infinite;
}

/* Caret qui clignote à la fin du texte pendant le stream */
.caret {
  display: inline-block;
  width: 0.56em;
  height: 1.05em;
  background: currentColor;
  border-radius: 2px;
  vertical-align: -0.15em;
  margin-left: .08em;
  animation: blink-rect 1s steps(1) infinite;
}

/* Clignotement on/off sans flou (points bien nets) */
@keyframes blink-rect { 50% { opacity: 0; } }

/* ───── Scrollbars minimalistes (barre fine, fond transparent) ───── */
:root { --sb-thumb: rgba(0,0,0,.35); }
body[data-theme='dark']{ --sb-thumb: rgba(255,255,255,.28); }

/* Firefox */
* { scrollbar-width: thin; scrollbar-color: var(--sb-thumb) transparent; }

/* WebKit (Chrome/Edge/Safari) */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--sb-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: rgba(0,0,0,.52); }
body[data-theme='dark'] *::-webkit-scrollbar-thumb:hover { background-color: rgba(255,255,255,.45); }

/* Bouton "envoyer" → devient STOP rouge pendant le stream */
#send-button.streaming{
  background: rgb(211,42,79) !important;   /* rouge demandé */
  color:#fff;
  animation: goia-pulse-red 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(211,42,79,.55);
}
#send-button.streaming:hover{ filter: brightness(1.02); }
@keyframes goia-pulse-red{
  0%{box-shadow:0 0 0 0 rgba(211,42,79,.55)}
  70%{box-shadow:0 0 0 10px rgba(211,42,79,0)}
  100%{box-shadow:0 0 0 0 rgba(211,42,79,0)}
}

/* Bouton "aller en bas" */
.scroll-to-bottom{
  position: fixed;
  right: 16px;
  bottom: 88px; /* au-dessus de la barre d'entrée */
  width: 42px; height: 42px;
  border: none;
  border-radius: 999px;
  display: none;
  align-items: center; justify-content: center;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  cursor: pointer;
  z-index: 1003;
}
.scroll-to-bottom.show{ display: inline-flex; }
.scroll-to-bottom .material-icons{ font-size: 22px; }

• Badge file d’attente */
.queue-pill{
  display: none;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: color-mix(in oklab, var(--accent) 25%, transparent);
  border: 1px solid var(--accent);
  color: var(--text);
}
.queue-pill.show{ display: inline-block; }

/* Statut dans la ligne IA */
.assistant-line .net-status{
  margin-left: 8px;
  font-size: .85em;
  opacity: .8;
}

/* Réduction des animations si l’utilisateur préfère moins de mouvement */
@media (prefers-reduced-motion: reduce){
  .typing-dos, .caret, #send-button.streaming, .spinner { animation: none !important; }
  * { scroll-behavior: auto !important; }
}
/* =========================
   Menu du bouton +
   ========================= */
.left-actions { position: relative; }

#plus-button{
  border:none; background:transparent; color:var(--text);
  cursor:pointer; display:inline-flex; align-items:center; justify-content:center;
  width:40px; height:40px; border-radius:999px;
  transition: background-color .15s ease, opacity .15s ease; opacity:.9;
}
#plus-button:hover, #plus-button:focus-visible{
  background: color-mix(in oklab, var(--input-bg) 85%, transparent);
  outline:none;
}

.plus-menu{
  position:absolute; bottom:46px; left:0;

  min-width: 400px; z-index:1100;
  background: var(--bg); color: var(--text);
  border:1px solid var(--border); border-radius:12px;
  box-shadow:0 10px 30px rgba(0,0,0,.35);
  padding:6px; opacity:0; transform: translateY(6px);
  pointer-events:none; transition: opacity .15s ease, transform .15s ease;
}
.plus-menu.open{ opacity:1; transform: translateY(0); pointer-events:auto; }

.plus-menu .mi{ display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:8px; }
.plus-menu .mi.item{ cursor:pointer; text-align:left; vertical-align:top;width:100%; }
.plus-menu .mi.item:hover, .plus-menu .mi.item:focus-visible{
  background: color-mix(in oklab, var(--input-bg) 85%, transparent); outline:none;
}
.plus-menu .mi.group{
  font-size:.8rem; opacity:.75; cursor:default; padding:8px 10px 6px; margin-top:2px;
}
.plus-menu .mi .material-icons{ font-size:28px; line-height:1; }
.plus-menu .mi.item .check{ margin-left:auto; opacity:0; font-size:18px; }
.plus-menu .mi.item[aria-checked="true"] .check{ opacity:1; }

.plus-menu .mi.item.clicked{
  filter: invert(100%); transition: filter .12s linear;
}

/* Item import désactivé */
.plus-menu .mi.item.is-disabled{
  opacity:.45;
  cursor:not-allowed;
  filter:grayscale(.2);
}
.plus-menu .mi.item.is-disabled:hover{ background:transparent; }
.plus-menu .mi.item.is-disabled:active{ transform:none; }
