/* APOK — charte commune du studio et de tous ses modules.
 *
 * Un seul fichier porte la palette, l'échelle typographique, les espacements et
 * les composants. Avant lui, chaque module redéclarait la même charte sous des
 * noms différents (--panel ici, --p là) et dessinait ses propres boutons : cinq
 * hauteurs de bouton, quatre gris de fond, trois façons de faire un bandeau.
 *
 * La source vit dans `ui/apok-ui.css`. `tools/sync_ui.py` en dépose une copie
 * dans chaque module : un module exporté chez un prestataire doit rester
 * affichable sans le hub, donc il emporte sa feuille de style avec lui.
 *
 * Règle : un module n'écrit ici rien qui lui soit propre. Ce qui ne sert qu'à
 * un seul module reste dans son fichier.
 */

:root {
  /* --------------------------------------------------------------- surfaces */
  --bg: #0c1015;
  --panel: #12181f;
  --panel2: #182029;
  --panel3: #1e2833;
  --creux: #0e141a;
  --line: #26303b;
  --line-forte: #35424f;

  /* ------------------------------------------------------------------ texte */
  --text: #e8eef4;
  --muted: #7d8996;
  --faible: #5d6874;

  /* ---------------------------------------------------------------- accents */
  --accent: #f58220;
  --accent-vif: #ff9a43;
  --accent-sourd: #f5822022;
  --steel: #678097;
  --ok: #4bd58c;
  --warn: #efb84d;
  --bad: #ef6464;

  /* --------------------------------------------------------------- mesures */
  --h-controle: 34px;
  --h-barre: 52px;
  --rayon: 8px;
  --rayon-large: 12px;
  --rayon-plein: 999px;
  --ombre: 0 16px 50px #0009;
  --ombre-douce: 0 2px 10px #0006;

  /* Noms courts encore employés par Material Studio et DXF Pro. Ils tiennent la
   * compatibilité le temps que ces modules passent aux noms longs ; ne pas en
   * ajouter de nouveaux. */
  --p: var(--panel);
  --p2: var(--panel2);
  --txt: var(--text);
  --mut: var(--muted);
  --acc: var(--accent);
  --shadow: var(--ombre);
}

/* Thème clair « Sable ».
 *
 * La bascule Sable / Nuit existe déjà dans le catalogue et dans Montage 3D :
 * clé `apok-theme`, valeurs `clair` et `sombre`, posées en `data-theme` sur la
 * racine. La charte reprend cette convention au lieu d'en inventer une —
 * unifier, ce n'est pas tout passer en sombre, c'est que les MÊMES jetons
 * changent de valeur pour qu'un composant écrit une fois marche dans les deux.
 */
:root[data-theme="clair"] {
  --bg: #f6f3ec;
  --panel: #fffdfa;
  --panel2: #f1eee7;
  --panel3: #e9e4da;
  --creux: #fbf9f5;
  --line: #e7ded2;
  --line-forte: #d6c9b7;
  --text: #24211e;
  --muted: #756f67;
  --faible: #918a80;
  --accent: #ef741b;
  --accent-vif: #ff9a45;
  --accent-sourd: #ef741b1f;
  --steel: #7d8ea0;
  --ok: #147c4f;
  --warn: #a2560c;
  --bad: #b03a2e;
  --ombre: 0 1px 2px rgba(75,48,25,.05), 0 16px 42px rgba(75,48,25,.08);
  --touche: #f1eee7;
  --touche-survol: #e9e4da;
  color-scheme: light;
}
:root[data-theme="clair"] .primaire,
:root[data-theme="clair"] .primary,
:root[data-theme="clair"] .apok-bouton--accent { color: #fff; }
:root[data-theme="clair"] .apok-barre,
:root[data-theme="clair"] header.apok { background: var(--panel); }

/* Fixer la palette sombre sur un document, quelle que soit la bascule.
 *
 * Montage 3D suit la bascule Sable / Nuit dans sa BIBLIOTHEQUE, mais son
 * editeur 3D est sombre depuis toujours : le fond de la scene est pose dans le
 * moteur three.js, pas en CSS, et un editeur clair autour d'une scene sombre ne
 * va pas ensemble. `data-palette="sombre"` sur la racine garde donc les jetons
 * sombres pendant que `data-theme` continue de piloter ce qui doit basculer.
 */
:root[data-palette="sombre"] {
  --bg: #0c1015;
  --panel: #12181f;
  --panel2: #182029;
  --panel3: #1e2833;
  --creux: #0e141a;
  --line: #26303b;
  --line-forte: #35424f;
  --text: #e8eef4;
  --muted: #7d8996;
  --faible: #5d6874;
  --accent: #f58220;
  --accent-vif: #ff9a43;
  --accent-sourd: #f5822022;
  --ok: #4bd58c;
  --warn: #efb84d;
  --bad: #ef6464;
  --touche: #252d37;
  --touche-survol: #313b47;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 Inter, "Segoe UI", system-ui, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--steel); outline-offset: 1px; }

/* ==========================================================================
   BOUTONS — une seule hauteur, un seul rayon, jamais de texte sur deux lignes
   ========================================================================== */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--h-controle);
  padding: 0 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--rayon);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  /* Un libellé qui passe à la ligne fait grandir la barre et casse l'alignement
   * de tous ses voisins : c'est ce qui donnait cet aspect empilé. */
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover:not(:disabled) { background: var(--panel3); border-color: var(--line-forte); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }

/* Variantes. `primary`/`soft` restent reconnus : le hub et les modules les
 * emploient déjà partout. */
.primaire, .primary, .apok-bouton--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #16110b;
  font-weight: 800;
}
.primaire:hover:not(:disabled), .primary:hover:not(:disabled),
.apok-bouton--accent:hover:not(:disabled) {
  background: var(--accent-vif);
  border-color: var(--accent-vif);
}

.doux, .soft, .apok-bouton--fantome {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-weight: 600;
}
.doux:hover:not(:disabled), .soft:hover:not(:disabled),
.apok-bouton--fantome:hover:not(:disabled) {
  background: var(--panel2);
  border-color: var(--line);
  color: var(--text);
}

.danger { background: #3a1f1f; border-color: #5c2f2f; color: #ffb4b4; }

/* Bouton d'icône : carré, sans libellé visible, le titre porte le sens. */
.apok-bouton--icone {
  width: var(--h-controle);
  padding: 0;
  font-size: 15px;
}

.apok-groupe { display: flex; align-items: center; gap: 4px; }
.apok-groupe + .apok-groupe { margin-left: 10px; position: relative; }
.apok-groupe + .apok-groupe::before {
  content: "";
  position: absolute;
  left: -6px; top: 50%;
  width: 1px; height: 18px;
  transform: translateY(-50%);
  background: var(--line);
}

/* ==========================================================================
   BARRE DE TITRE — la même pour le hub et pour chaque module
   ========================================================================== */

.apok-barre, header.apok {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--h-barre);
  padding: 0 12px;
  background: linear-gradient(180deg, #141b23, #10161d);
  border-bottom: 1px solid var(--line);
  flex-wrap: nowrap;
  overflow: hidden;
}

.apok-marque {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  letter-spacing: .2px;
  white-space: nowrap;
}
/* Le signe est le gizmo d'orientation : trois anneaux, un par axe, au code
 * couleur du metier — X rouge, Y vert, Z bleu. Les axes s'allument l'un apres
 * l'autre, comme quand on survole le gizmo dans un logiciel 3D. */
.apok-marque__signe {
  width: 28px; height: 28px;
  flex: none;
  display: block;
}
.apok-signe { width: 100%; height: 100%; display: block; overflow: visible; }
.apok-axe { opacity: .26; }

/* La lumiere fait le TOUR de l'anneau avant de passer au suivant.
 *
 * Un simple fondu ne disait pas dans quel sens tourne l'axe. Ici un arc court
 * parcourt l'ellipse : `stroke-dasharray` decoupe un trait de 17 unites dans un
 * perimetre de 71 (rx 15,5 · ry 6, approximation de Ramanujan), et l'animation
 * fait defiler `stroke-dashoffset` d'un tour complet. Le meme trace est dessine
 * en deux fois — avant et apres la sphere — donc la lumiere disparait derriere
 * la boule et ressort devant, ce qui donne la profondeur.
 */
.apok-comete {
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 17 54;
  opacity: 0;
}
.apok-comete--x { animation: apokTour 5.4s linear infinite; }
.apok-comete--y { animation: apokTour 5.4s linear infinite 1.8s; }
.apok-comete--z { animation: apokTour 5.4s linear infinite 3.6s; }

@keyframes apokTour {
  0%   { stroke-dashoffset: 71; opacity: 0; }
  4%   { opacity: 1; }
  29%  { stroke-dashoffset: 0; opacity: 1; }
  33%  { stroke-dashoffset: 0; opacity: 0; }
  100% { stroke-dashoffset: 0; opacity: 0; }
}

/* Au survol, tout s'allume et le mouvement s'arrete : le logo redevient le
 * gizmo complet, celui qu'on lit d'un coup d'oeil. */
.apok-marque:hover .apok-axe { opacity: .85; }
.apok-marque:hover .apok-comete { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .apok-comete { animation: none; opacity: 0; }
  .apok-axe { animation: none; opacity: .7; }
}

/* Un module ouvert DANS le hub ne réaffiche pas sa marque : deux logos APOK
 * l'un sous l'autre, c'était la même application qui se présentait deux fois.
 * L'attribut est posé par apok-ui.js quand la page tourne dans un cadre. */
html[data-embarque] .apok-marque { display: none; }
html[data-embarque] .apok-barre,
html[data-embarque] header.apok { height: 44px; background: #10161d; }

.espace, .apok-espace { flex: 1; min-width: 0; }

/* ==========================================================================
   PASTILLES ET ÉTATS
   ========================================================================== */

.pastille, .apok-puce {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--rayon-plein);
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.pastille.ok, .apok-puce--ok { color: var(--ok); border-color: #1f4a35; background: #12251c; }
.pastille.warn, .apok-puce--warn { color: var(--warn); border-color: #5d4a25; background: #2b1f13; }
.pastille.bad, .apok-puce--bad { color: var(--bad); border-color: #5a2a2a; background: #2a1616; }

.apok-point {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--faible);
  flex: none;
}
.apok-point--ok { background: var(--ok); box-shadow: 0 0 8px #4bd58c66; }
.apok-point--warn { background: var(--warn); }
.apok-point--bad { background: var(--bad); }

/* ==========================================================================
   PANNEAUX, TITRES, CHAMPS
   ========================================================================== */

aside, .panneau {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  overflow: auto;
}

h2 {
  font-size: 10.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--faible);
  font-weight: 700;
  margin: 18px 0 8px;
}
h2:first-child { margin-top: 0; }

.champ, .rangee {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.rangee input[type=range] { flex: 1; }

input[type=text], input[type=number], input[type=search], input[type=password],
select, textarea {
  height: var(--h-controle);
  padding: 0 10px;
  background: var(--creux);
  border: 1px solid var(--line);
  border-radius: var(--rayon);
  outline: none;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--steel); }

input[type=range] {
  accent-color: var(--accent);
  height: 22px;
}

/* ==========================================================================
   TABLEAUX
   ========================================================================== */

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: right; padding: 6px 7px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; color: var(--muted); }
thead th {
  color: var(--faible);
  font-size: 10px;
  letter-spacing: .6px;
  text-transform: uppercase;
  font-weight: 700;
}

/* ==========================================================================
   VERDICTS, AIDES, DÉPÔT, ONGLETS
   ========================================================================== */

.gain { color: var(--ok); }
.perte { color: var(--bad); }
.muted, .aide { color: var(--muted); }
.aide { font-size: 11px; }

.verdict {
  border-radius: var(--rayon-large);
  padding: 11px 13px;
  margin: 10px 0;
  border: 1px solid var(--line);
  background: var(--panel2);
}
.verdict b { display: block; margin-bottom: 4px; }
.verdict ul { margin: 6px 0 0; padding-left: 17px; }
.verdict.ok { background: #12251c; border-color: #1f4a35; color: #a7e9c8; }
.verdict.warn { background: #2b1f13; border-color: #5d4a25; color: #f0d5a4; }
.verdict.bad { background: #2a1616; border-color: #5a2a2a; color: #f2b6b6; }

.avert {
  font-size: 11px;
  color: var(--warn);
  background: #2b1f13;
  border: 1px solid #5d4a25;
  border-radius: var(--rayon);
  padding: 8px 10px;
  margin-top: 7px;
}

.depot {
  border: 1.5px dashed var(--line-forte);
  border-radius: var(--rayon-large);
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
}
.depot.actif { border-color: var(--accent); background: var(--accent-sourd); }

.onglets { display: flex; gap: 5px; flex-wrap: wrap; }
.onglets button { flex: 1; min-width: 64px; padding: 0 8px; }
.onglets button.choisi {
  border-color: var(--accent);
  background: var(--accent-sourd);
  color: var(--text);
}

/* ==========================================================================
   TACTILE — au doigt, tout grandit d'un cran
   ========================================================================== */

/* `pointer: coarse` seul est vrai sur un portable a ecran tactile, ou l'on
 * travaille pourtant a la souris : la barre y passait en taille telephone et
 * debordait. `hover: none` ajoute la vraie question — le doigt est-il le SEUL
 * moyen de pointer ? */
@media (hover: none) and (pointer: coarse) {
  :root { --h-controle: 44px; --h-barre: 56px; }
  button { font-size: 13.5px; }
  input, select, textarea { font-size: 16px; }
  .apok-bouton--icone { width: 44px; font-size: 18px; }
}
