/* Épure — iPad d'abord. Cibles tactiles ≥ 44 px. Thème clair/sombre par jetons. */
:root {
  --fond: #f4f1ea; --surface: #fffdf8; --surface-2: #ece7dd; --trait: #d8d1c4;
  --texte: #2d2d2d; --texte-2: #6b665d; --accent: #c8882a; --accent-texte: #fff; --accent-doux: #f3e3c8;
  --danger: #b4483c; --ok: #4f7a4a; --scene: #e9e5dc; --bulle-moi: #2d2d2d; --bulle-moi-texte: #f4f1ea;
  --ombre: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --rayon: 12px; --cible: 44px;
  --police: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #1e1f21; --surface: #26282b; --surface-2: #303236; --trait: #3c3f44;
    --texte: #ece8e0; --texte-2: #a19c92; --accent: #d79a3e; --accent-texte: #1e1f21; --accent-doux: #4a3a22;
    --danger: #e0715f; --ok: #8bbf83; --scene: #1a1b1d; --bulle-moi: #3a3c40; --bulle-moi-texte: #ece8e0;
    --ombre: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #1e1f21; --surface: #26282b; --surface-2: #303236; --trait: #3c3f44;
  --texte: #ece8e0; --texte-2: #a19c92; --accent: #d79a3e; --accent-texte: #1e1f21; --accent-doux: #4a3a22;
  --danger: #e0715f; --ok: #8bbf83; --scene: #1a1b1d; --bulle-moi: #3a3c40; --bulle-moi-texte: #ece8e0;
  --ombre: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fond); color: var(--texte); font: 17px/1.45 var(--police);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.discret { color: var(--texte-2); font-size: 14px; }

/* ---- boutons */
.bouton {
  min-height: var(--cible); padding: 0 16px; border-radius: 10px; border: 1px solid var(--trait);
  background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; text-decoration: none; white-space: nowrap;
}
.bouton.plein { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 600; }
.bouton.fantome { background: transparent; }
.bouton.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.bouton.petit { min-height: 40px; padding: 0 12px; font-size: 15px; }
.bouton.grand { min-height: 52px; padding: 0 24px; font-size: 18px; }
.bouton:disabled { opacity: .45; cursor: default; }
.icone {
  width: var(--cible); height: var(--cible); border-radius: 10px; border: 1px solid var(--trait);
  background: var(--surface); cursor: pointer; font-size: 20px; line-height: 1; display: inline-grid; place-items: center;
}
.icone.actif { background: var(--accent-doux); border-color: var(--accent); }
.icone:disabled { opacity: .4; }
@media (hover: hover) { .bouton:not(:disabled):hover, .icone:not(:disabled):hover { filter: brightness(.96); } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- connexion */
.connexion { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 50; background: var(--fond); }
.connexion .carte { text-align: center; max-width: 360px; display: grid; gap: 14px; justify-items: center; }
.connexion .logo { width: 72px; height: 72px; color: var(--accent); }
.connexion h1 { font-size: 34px; }
.connexion p { margin: 0 0 8px; color: var(--texte-2); }

/* ---- disposition générale */
.appli {
  height: 100dvh; display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "barre barre" "chat modele";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.barre { grid-area: barre; }
.chat { grid-area: chat; }
.modele { grid-area: modele; }
.feuilles { grid-area: modele; }
.projets {
  position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
  background: var(--surface); border-right: 1px solid var(--trait); box-shadow: var(--ombre);
  transform: translateX(-102%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
}
.appli.projets-ouverts .projets { transform: none; }
.voile { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.25); }
@media (prefers-reduced-motion: reduce) { .projets { transition: none; } }

/* très large : la liste des projets reste affichée */
@media (min-width: 1500px) {
  .appli { grid-template-columns: 280px 400px minmax(0, 1fr); grid-template-areas: "projets barre barre" "projets chat modele"; }
  .projets { position: static; transform: none; box-shadow: none; width: auto; grid-area: projets; padding: 12px; }
  #ouvrir-projets, .seul-etroit, .voile { display: none !important; }
}
/* étroit (iPad portrait, téléphone) : une zone à la fois */
@media (max-width: 1099px) {
  .appli { grid-template-columns: minmax(0, 1fr); grid-template-areas: "barre" "zone"; }
  .chat, .modele, .feuilles { grid-area: zone; }
  .appli[data-zone="chat"] .modele, .appli[data-zone="modele"] .chat,
  .appli[data-zone="feuilles"] .chat, .appli[data-zone="feuilles"] .modele { display: none; }
  .appli[data-zone="feuilles"] .feuilles { display: block !important; }
}
@media (min-width: 1100px) { .onglets-zone { display: none !important; } }

/* ---- projets */
.projets-tete { display: flex; align-items: center; gap: 10px; min-height: var(--cible); }
.projets-tete h1 { font-size: 22px; flex: 1; }
.logo-mini { width: 28px; height: 28px; color: var(--accent); }
.liste-projets { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: grid; align-content: start; gap: 4px; }
.liste-projets a {
  display: flex; flex-direction: column; justify-content: center; min-height: 56px; padding: 6px 12px;
  border-radius: 10px; color: inherit; text-decoration: none;
}
.liste-projets a.courant { background: var(--accent-doux); }
.liste-projets .nom { font-weight: 600; }
.liste-projets .date { font-size: 13px; color: var(--texte-2); }
.liste-projets .occupe::after { content: " · Claude travaille"; color: var(--accent); }
.projets-pied { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- barre */
.barre {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 60px;
  border-bottom: 1px solid var(--trait); background: var(--fond);
}
.titre-projet { font-size: 19px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version { font: 13px var(--mono); color: var(--texte-2); }
.onglets-zone { display: flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.onglets-zone button {
  min-height: 40px; min-width: 76px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
}
.onglets-zone button[aria-selected="true"] { background: var(--surface); box-shadow: var(--ombre); font-weight: 600; }
.onglets-zone button:disabled { opacity: .4; }

/* ---- chat */
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--trait); background: var(--fond); }
.chat-outils { display: flex; gap: 6px; padding: 8px 10px 0; flex-wrap: wrap; }
.prompt { margin: 8px 10px 0; display: grid; gap: 8px; }
.prompt textarea {
  width: 100%; min-height: 180px; max-height: 45dvh; resize: vertical; padding: 10px; border-radius: 10px;
  border: 1px solid var(--trait); background: var(--surface); font: 14px/1.45 var(--mono);
}
.prompt-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.prompt-actions .discret { flex: 1; }
.messages { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.vide-chat { margin: auto; text-align: center; color: var(--texte-2); max-width: 300px; }
.msg { max-width: 94%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.lounes { align-self: flex-end; background: var(--bulle-moi); color: var(--bulle-moi-texte); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.claude { align-self: flex-start; background: var(--surface); border: 1px solid var(--trait); border-bottom-left-radius: 6px; }
.msg.systeme { align-self: center; font-size: 14px; color: var(--texte-2); padding: 2px 8px; }
.msg.claude p { margin: 0 0 .6em; } .msg.claude p:last-child { margin-bottom: 0; }
.msg.claude ul, .msg.claude ol { margin: 0 0 .6em; padding-left: 1.3em; }
.msg.claude code { font: 14px var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.msg.claude pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 0 0 .6em; }
.msg.claude pre code { background: none; padding: 0; font-size: 13px; }
.msg.claude h4 { margin: .4em 0 .3em; font-size: 16px; }
.outils { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.outil { font: 12px var(--mono); padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--texte-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outil.erreur { color: var(--danger); }
.msg .pied { font-size: 12px; color: var(--texte-2); margin-top: 6px; }
.msg .err { color: var(--danger); font-size: 14px; margin-top: 6px; }
.attente::after { content: "▍"; animation: clignote 1s steps(2) infinite; color: var(--accent); }
@keyframes clignote { 50% { opacity: 0; } }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--trait); align-items: flex-end; }
.composer textarea {
  flex: 1; min-height: var(--cible); max-height: 30dvh; resize: none; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--trait); background: var(--surface); font-size: 17px; line-height: 1.35;
  overflow-y: auto; scrollbar-width: none;
}
.composer textarea::-webkit-scrollbar { display: none; }

/* ---- modèle */
.modele { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }
@media (max-width: 759px) { .modele { grid-template-columns: minmax(0, 1fr); grid-template-rows: 48dvh minmax(0, 1fr); } }
.scene { position: relative; background: var(--scene); min-height: 0; overflow: hidden; }
#vue { display: block; width: 100%; height: 100%; touch-action: none; }
.scene-outils { position: absolute; top: 10px; right: 10px; display: grid; gap: 8px; }
.calcul { position: absolute; top: 12px; left: 12px; font-size: 13px; color: var(--texte-2); background: var(--surface); padding: 3px 10px; border-radius: 99px; }
.erreur {
  position: absolute; left: 10px; right: 64px; bottom: 10px; max-height: 40%; overflow: auto; white-space: pre-wrap;
  background: var(--surface); border: 1px solid var(--danger); color: var(--danger); border-radius: 10px; padding: 10px 12px;
  font: 13px/1.4 var(--mono);
}
.cotes { position: absolute; left: 12px; bottom: 10px; font: 13px var(--mono); color: var(--texte-2); pointer-events: none; }
.panneau { overflow-y: auto; overflow-x: hidden; padding: 10px 12px 24px; border-left: 1px solid var(--trait); background: var(--fond); -webkit-overflow-scrolling: touch; }
@media (max-width: 759px) { .panneau { border-left: 0; border-top: 1px solid var(--trait); } }
.pieces-tete { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
.pieces-tete h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--texte-2); }
.pieces { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.piece { display: flex; align-items: center; gap: 8px; min-height: var(--cible); }
.piece label { flex: 1; display: flex; align-items: center; gap: 8px; min-height: var(--cible); cursor: pointer; min-width: 0; }
.piece input { width: 22px; height: 22px; accent-color: var(--accent); }
.piece .pastille { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.piece .infos { display: flex; flex-direction: column; min-width: 0; flex: 1; overflow: hidden; }
.piece .infos small { color: var(--texte-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.piece .ko { color: var(--danger); }
.params details { border-top: 1px solid var(--trait); }
.params summary { min-height: var(--cible); display: flex; align-items: center; font-weight: 600; cursor: pointer; list-style: none; }
.params summary::before { content: "▸"; margin-right: 8px; color: var(--texte-2); transition: transform .15s; }
.params details[open] summary::before { transform: rotate(90deg); }
.param { padding: 4px 0 10px; }
.param-tete { display: flex; align-items: center; gap: 8px; }
.param-libelle { flex: 1; min-height: 36px; display: flex; align-items: center; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; font-size: 15px; }
.param-libelle .unite { color: var(--texte-2); margin-left: 4px; }
.param.a-cabler .param-libelle::after { content: "à câbler"; margin-left: 8px; font-size: 12px; padding: 1px 7px; border-radius: 99px; background: var(--accent-doux); color: var(--texte); }
.param input[type="number"] {
  width: 92px; min-height: 40px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--trait);
  background: var(--surface); text-align: right; font: 16px var(--mono);
}
.param input[type="range"] { width: 100%; height: var(--cible); accent-color: var(--accent); margin: 0; }
.param .case { display: flex; align-items: center; gap: 10px; min-height: var(--cible); }
.param .case input { width: 24px; height: 24px; accent-color: var(--accent); }
.param select { min-height: var(--cible); width: 100%; border-radius: 8px; border: 1px solid var(--trait); background: var(--surface); padding: 0 8px; }
.feuilles { padding: 24px; color: var(--texte-2); }

/* ---- dialogue */
.dialogue { border: 1px solid var(--trait); border-radius: 16px; background: var(--surface); color: var(--texte); padding: 18px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--ombre); }
.dialogue::backdrop { background: rgba(0,0,0,.3); }
.dialogue h3 { margin-bottom: 12px; }
.dialogue label { display: grid; gap: 4px; margin-bottom: 10px; font-size: 15px; color: var(--texte-2); }
.dialogue input { min-height: var(--cible); padding: 0 10px; border-radius: 8px; border: 1px solid var(--trait); background: var(--fond); font-size: 17px; color: var(--texte); }
.dialogue .rangee { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dialogue-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.dialogue .note { font-size: 14px; color: var(--texte-2); margin: 0 0 10px; }
