/* Jarvis — thème sombre, mobile d'abord. */
:root {
  --fond: #0b1020;
  --fond-2: #111831;
  --surface: #161f3d;
  --surface-2: #1d2850;
  --bord: #26325e;
  --texte: #e8ecf8;
  --discret: #8c97bd;
  --accent: #5b8cff;
  --accent-2: #8a5bff;
  --ok: #2fbf71;
  --alerte: #f2a93b;
  --danger: #ef4f5f;
  --rayon: 14px;
  --nav: 64px;
  --sur-haut: env(safe-area-inset-top, 0px);
  --sur-bas: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: #8fb0ff; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.discret { color: var(--discret); font-size: 13px; }
.deux-lignes { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Boutons ---------- */
.bouton {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600;
  min-height: 44px; transition: filter .15s, transform .05s;
}
.bouton:active { transform: scale(.98); }
.bouton:disabled { opacity: .55; cursor: default; }
.bouton.principal { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.bouton.secondaire { background: var(--surface-2); color: var(--texte); border: 1px solid var(--bord); }
.bouton.danger { background: var(--danger); color: #fff; }
.bouton.plein { width: 100%; }
.bouton:hover:not(:disabled) { filter: brightness(1.08); }
.icone {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--texte);
}
.icone:hover { background: var(--surface-2); }
.icone.actif { color: var(--accent); background: rgba(91, 140, 255, .14); }
.lien { background: none; border: 0; color: #8fb0ff; padding: 0 4px; text-decoration: underline; }
.puce {
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; min-height: 38px; white-space: nowrap; flex: none;
}
.puce.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Connexion ---------- */
.connexion {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 30% 10%, #1b2a66 0, transparent 55%), var(--fond);
}
.carte-connexion {
  width: min(380px, 100%); background: var(--fond-2); border: 1px solid var(--bord);
  border-radius: 20px; padding: 28px 24px; display: grid; gap: 14px; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.carte-connexion .logo { margin: 0 auto; border-radius: 18px; }
.carte-connexion h1 { margin: 0; font-size: 26px; }
.sous-titre { margin: -8px 0 6px; color: var(--discret); }
.carte-connexion label { display: grid; gap: 6px; text-align: left; font-size: 14px; color: var(--discret); }
input, textarea {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 12px;
  padding: 11px 13px; outline: none; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, .2); }
.erreur { margin: 0; color: #ff9aa4; font-size: 14px; }

/* ---------- Structure ---------- */
.app { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.entete {
  display: flex; align-items: center; gap: 6px;
  padding: calc(6px + var(--sur-haut)) 8px 6px; background: var(--fond-2);
  border-bottom: 1px solid var(--bord);
}
.titre-entete { flex: 1; min-width: 0; display: grid; text-align: center; }
.titre-entete strong { font-size: 17px; }
.titre-entete span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main { min-height: 0; position: relative; }
.vue { height: 100%; }
.page { overflow-y: auto; padding: 14px 14px 24px; }

.barre-nav {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--fond-2); border-top: 1px solid var(--bord); padding-bottom: var(--sur-bas);
}
.onglet {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 8px 0 7px;
  background: none; border: 0; color: var(--discret); font-size: 12px; min-height: var(--nav);
}
.onglet.actif { color: var(--accent); }
.badge {
  position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; padding: 0 5px;
}

/* ---------- Tiroir ---------- */
.voile { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 20; }
.tiroir {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(330px, 86vw); z-index: 21;
  background: var(--fond-2); border-right: 1px solid var(--bord);
  display: flex; flex-direction: column; gap: 10px;
  padding: calc(10px + var(--sur-haut)) 12px calc(12px + var(--sur-bas));
  transform: translateX(-105%); transition: transform .22s ease;
}
.tiroir.ouvert { transform: none; }
.tiroir-entete { display: flex; align-items: center; justify-content: space-between; padding-left: 6px; }
.tiroir .liste { flex: 1; overflow-y: auto; }
.tiroir-pied { display: grid; gap: 8px; }

.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; align-content: start; }
.element {
  width: 100%; text-align: left; background: none; border: 0; border-radius: 12px;
  padding: 10px 12px; display: grid; gap: 2px;
}
.element:hover, .element.actif { background: var(--surface); }
.element-titre { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vide { color: var(--discret); text-align: center; padding: 28px 8px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; }
.messages {
  flex: 1; overflow-y: auto; padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth;
}
.accueil { margin: auto; text-align: center; display: grid; gap: 12px; justify-items: center; padding: 20px 8px; }
.accueil img { border-radius: 16px; }
.accueil h2 { margin: 0; font-size: 20px; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.bulle {
  max-width: min(760px, 92%); border-radius: 18px; padding: 10px 14px;
  overflow-wrap: anywhere; animation: apparition .18s ease;
}
@keyframes apparition { from { opacity: 0; transform: translateY(4px); } }
.bulle.moi { align-self: flex-end; background: linear-gradient(135deg, #3c6cf0, #6a46e8); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.bulle.jarvis { align-self: flex-start; background: var(--surface); border: 1px solid var(--bord); border-bottom-left-radius: 6px; }
.bulle.erreur { border-color: rgba(239, 79, 95, .6); }
.bulle .meta { font-size: 11px; color: rgba(232, 236, 248, .6); margin-top: 4px; text-align: right; }
.bulle.jarvis .meta { text-align: left; color: var(--discret); }

.contenu > :first-child { margin-top: 0; }
.contenu > :last-child { margin-bottom: 0; }
.contenu p { margin: 0 0 8px; }
.contenu h3, .contenu h4, .contenu h5, .contenu h6 { margin: 12px 0 6px; line-height: 1.3; }
.contenu ul, .contenu ol { margin: 4px 0 8px; padding-left: 22px; }
.contenu li { margin: 2px 0; }
.contenu li.case { list-style: none; margin-left: -18px; }
.contenu code { background: rgba(255, 255, 255, .08); padding: 1px 5px; border-radius: 6px; font-size: .92em; }
.contenu pre {
  position: relative; background: #0a0f1e; border: 1px solid var(--bord); border-radius: 10px;
  padding: 34px 12px 12px; overflow-x: auto; margin: 8px 0;
}
.contenu pre code { background: none; padding: 0; font-size: 13px; white-space: pre; }
.copier {
  position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 3px 8px; border-radius: 8px;
  border: 1px solid var(--bord); background: var(--surface-2); color: var(--discret);
}
.contenu blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--accent); color: var(--discret); }
.contenu hr { border: 0; border-top: 1px solid var(--bord); margin: 10px 0; }
.tableau { overflow-x: auto; margin: 8px 0; }
.contenu table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.contenu th, .contenu td { border: 1px solid var(--bord); padding: 6px 9px; text-align: left; vertical-align: top; }
.contenu th { background: var(--surface-2); }

.statut-direct { display: flex; align-items: center; gap: 8px; color: var(--discret); font-size: 13px; }
.statut-texte { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chrono { font-variant-numeric: tabular-nums; }
.points { display: inline-flex; gap: 3px; }
.points i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: rebond 1s infinite; }
.points i:nth-child(2) { animation-delay: .15s; }
.points i:nth-child(3) { animation-delay: .3s; }
@keyframes rebond { 0%, 80%, 100% { opacity: .3; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
.actions-direct {
  list-style: none; margin: 6px 0 0; padding: 0 0 0 10px; border-left: 2px solid var(--bord);
  font-size: 12.5px; color: var(--discret); display: grid; gap: 2px; max-height: 140px; overflow-y: auto;
}
.en-cours .contenu:not(:empty) { margin-top: 8px; }
.journal { margin-bottom: 6px; font-size: 13px; color: var(--discret); }
.journal summary { cursor: pointer; }
.journal .actions-direct { max-height: 220px; }

.composeur {
  padding: 8px 10px 10px; background: var(--fond-2); border-top: 1px solid var(--bord);
}
.ligne-saisie { display: flex; align-items: flex-end; gap: 6px; max-width: 900px; margin: 0 auto; }
.ligne-saisie textarea { resize: none; min-height: 44px; max-height: 180px; line-height: 1.4; }
.envoyer { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.envoyer:disabled { opacity: .5; }
.agent-choisi {
  max-width: 900px; margin: 0 auto 6px; font-size: 13px; color: var(--discret);
  display: flex; gap: 6px; align-items: center;
}
.agent-choisi strong { color: var(--accent); }

/* ---------- Cartes (tâches, agents, dépôt) ---------- */
.cartes { gap: 10px; }
.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 14px; display: grid; gap: 8px; margin-bottom: 12px;
}
.cartes .carte { margin: 0; }
.carte h3 { margin: 4px 0 0; font-size: 15px; }
.carte p { margin: 0; }
.carte.attention { border-color: rgba(242, 169, 59, .6); }
.element-carte { width: 100%; text-align: left; color: inherit; font: inherit; }
.element-carte:hover { border-color: var(--accent); }
.carte-entete { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.carte-entete strong { flex: 1; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; flex: none;
}
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.pastille { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px; background: var(--surface-2); }
.pastille.en_cours, .pastille.en_attente { background: rgba(91, 140, 255, .18); color: #9db8ff; }
.pastille.terminee { background: rgba(47, 191, 113, .16); color: #6fe0a2; }
.pastille.erreur { background: rgba(239, 79, 95, .16); color: #ff9aa4; }
.pastille.interrompue { background: rgba(242, 169, 59, .16); color: #f7c77a; }
.filtres { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; }
.recherche { margin-bottom: 12px; }
.bloc {
  margin: 0; background: #0a0f1e; border: 1px solid var(--bord); border-radius: 10px; padding: 10px;
  font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow-y: auto;
}

/* ---------- Feuille (choix d'agent) ---------- */
.feuille {
  border: 1px solid var(--bord); background: var(--fond-2); color: var(--texte);
  border-radius: 18px; padding: 12px; width: min(460px, 94vw); max-height: 80vh;
}
.feuille::backdrop { background: rgba(0, 0, 0, .55); }
.feuille .liste { max-height: 62vh; overflow-y: auto; margin-top: 6px; }
@media (max-width: 640px) {
  .feuille { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; padding-bottom: calc(12px + var(--sur-bas)); }
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + 20px + var(--sur-bas)); transform: translateX(-50%);
  background: #22305f; border: 1px solid var(--bord); color: var(--texte); padding: 10px 16px;
  border-radius: 12px; z-index: 50; max-width: 90vw; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}

/* ---------- Grand écran ---------- */
@media (min-width: 900px) {
  .page { max-width: 860px; margin: 0 auto; width: 100%; }
  .messages { padding: 24px max(16px, calc(50% - 440px)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
