/* Police Ubuntu embarquee (Ubuntu Font Licence 1.0). */
@font-face { font-family: Ubuntu; font-weight: 400; font-style: normal; font-display: swap; src: url(/static/fonts/Ubuntu-Regular.ttf) format('truetype'); }
@font-face { font-family: Ubuntu; font-weight: 400; font-style: italic; font-display: swap; src: url(/static/fonts/Ubuntu-Italic.ttf) format('truetype'); }
@font-face { font-family: Ubuntu; font-weight: 500; font-style: normal; font-display: swap; src: url(/static/fonts/Ubuntu-Medium.ttf) format('truetype'); }
@font-face { font-family: Ubuntu; font-weight: 700; font-style: normal; font-display: swap; src: url(/static/fonts/Ubuntu-Bold.ttf) format('truetype'); }

/* Charte Capgemini : bleu #0070AD, bleu vif #12ABDB, violet profond #2B0A3D, police Ubuntu.
   --accent (orange) reste reserve a la piece en mouvement, comme dans la vue 3D. */
:root {
  --ink: #2b0a3d;
  --ink-soft: #5b4a68;
  --line: #d3dde6;
  --surface: #ffffff;
  --canvas: #f0f5f9;
  --brand: #0070ad;
  --brand-dark: #005a8c;
  --brand-vivid: #12abdb;
  --brand-tint: #e6f2f8;
  --accent: #d9560b;
  --warn-bg: #fff6e5;
  --warn-line: #e3b34a;
  --radius: 8px;
  --header: 56px;
  font: 14px/1.45 Ubuntu, Verdana, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--ink-soft); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Commandes */
button, .button, select, input, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { border-color: var(--brand); color: var(--brand); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--brand-dark); color: #fff; }
button.link { border: 0; background: none; padding: 4px 0; color: var(--brand); text-decoration: underline; }
button.wide { width: 100%; padding: 10px; }
:focus-visible { outline: 2px solid var(--brand-vivid); outline-offset: 2px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 10px; }
label.button { display: inline-flex; margin: 0; font-size: inherit; font-weight: 400; color: inherit; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px; font-weight: 400;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
textarea { resize: vertical; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.hint { font-size: 12px; color: var(--ink-soft); margin-bottom: 10px; }
.status { min-height: 1.4em; margin-top: 10px; font-size: 13px; color: var(--ink-soft); }
.status.error { color: #a12a12; font-weight: 600; }

/* Structure */
.app-header {
  position: sticky; top: 0; z-index: 5; height: var(--header); display: flex; align-items: center;
  gap: 16px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand strong { color: var(--brand); }
.brand > div { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { gap: 14px; }
.brand-logo { height: 28px; max-width: 150px; object-fit: contain; flex: none; }
.view-tabs, .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.view-tabs button, .segmented button { border: 0; border-radius: 0; }
.view-tabs button[aria-pressed=true], .segmented button[aria-pressed=true] { background: var(--brand); color: #fff; }
.layout { display: grid; grid-template-columns: 300px 380px minmax(0, 1fr); min-height: calc(100vh - var(--header)); }
.sidebar, .tree-col { background: var(--surface); border-right: 1px solid var(--line); }

/* Arborescence des pieces */
.tree-col { padding: 16px 12px; min-width: 0; }
.tree-col h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.tree details { margin: 0; }
.tree details details, .tree details > .tree-row { margin-left: 12px; }
.tree summary { margin: 0 0 4px; padding: 4px 2px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.tree-row { display: flex; align-items: center; gap: 4px; padding: 3px 4px; border: 1px solid transparent; border-radius: 6px; }
.tree-row:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); }
.tree-pick { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; margin: 0; font-size: 13px; font-weight: 400; color: var(--ink); cursor: pointer; }
.tree-pick input { width: auto; margin: 0; flex: none; accent-color: var(--brand); }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row.figee .tree-name { font-weight: 600; }
.tree-row.cachee .tree-name { color: var(--ink-soft); text-decoration: line-through; }
.tree-row.cachee .swatch { opacity: .3; }
.chip { flex: none; padding: 3px 8px; font-size: 11px; border-radius: 999px; }
.chip[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip[aria-pressed=true]:hover:not(:disabled) { color: #fff; }
.tree-help { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--canvas); font-size: 12px; color: var(--ink-soft); }
.tree-help p + p { margin-top: 4px; }
.target-label { margin-bottom: 12px; padding: 8px 12px; border: 1px solid var(--brand); border-radius: 6px; background: var(--brand-tint); font-weight: 600; }
.workspace { padding: 16px; min-width: 0; }

/* Panneau lateral */
.panel-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.panel-tab { border: 0; border-radius: 0; border-bottom: 3px solid transparent; padding: 12px 8px; font-weight: 600; }
.panel-tab span {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--canvas); font-size: 12px;
}
.panel-tab[aria-pressed=true] { border-bottom-color: var(--brand); color: var(--brand); }
.panel-tab[aria-pressed=true] span { background: var(--brand); color: #fff; }
.panel { padding: 16px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 8px; }
.panel h2:first-child { margin-top: 0; }
.dropzone {
  display: flex; flex-direction: column; gap: 4px; padding: 16px; margin-bottom: 6px; cursor: pointer;
  border: 1.5px dashed var(--brand-vivid); border-radius: var(--radius); background: var(--canvas); text-align: center;
}
.dropzone strong { color: var(--ink); font-size: 14px; }
.dropzone span { font-weight: 400; }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-tint); }
.swatch { opacity: .3; }
.chip { flex: none; padding: 3px 8px; font-size: 11px; border-radius: 999px; }
.chip[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip[aria-pressed=true]:hover:not(:disabled) { color: #fff; }
.tree-help { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--canvas); font-size: 12px; color: var(--ink-soft); }
.tree-help p + p { margin-top: 4px; }
.target-label { margin-bottom: 12px; padding: 8px 12px; border: 1px solid var(--brand); border-radius: 6px; background: var(--brand-tint); font-weight: 600; }
.workspace { padding: 16px; min-width: 0; }

/* Panneau lateral */
.panel-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.panel-tab { border: 0; border-radius: 0; border-bottom: 3px solid transparent; padding: 12px 8px; font-weight: 600; }
.panel-tab span {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--canvas); font-size: 12px;
}
.panel-tab[aria-pressed=true] { border-bottom-color: var(--brand); color: var(--brand); }
.panel-tab[aria-pressed=true] span { background: var(--brand); color: #fff; }
.panel { padding: 16px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 8px; }
.panel h2:first-child { margin-top: 0; }
.dropzone {
  display: flex; flex-direction: column; gap: 4px; padding: 16px; margin-bottom: 6px; cursor: pointer;
  border: 1.5px dashed var(--brand-vivid); border-radius: var(--radius); background: var(--canvas); text-align: center;
}
.dropzone strong { color: var(--ink); font-size: 14px; }
.dropzone span { font-weight: 400; }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-tint); }
.parts { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.part {
  display: flex; align-items: center; gap: 8px; margin: 0; padding: 7px 9px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; font-size: 14px; font-weight: 400; color: var(--ink);
}
.part input { width: auto; margin: 0; }
.part:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); font-weight: 600; }
.part input { accent-color: var(--brand); }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgb(0 0 0 / .25); }
.notice-warning, .warning {
  padding: 8px 10px; margin-bottom: 12px; border: 1px solid var(--warn-line);
  border-radius: 6px; background: var(--warn-bg); font-size: 12px;
}
.toolbox { padding: 12px; margin: 4px 0 8px; border-radius: var(--radius); background: var(--canvas); }
details summary { cursor: pointer; margin: 10px 0 8px; font-size: 13px; color: var(--brand); }

/* Vue 3D */
.welcome { max-width: 620px; margin: 8vh auto; padding: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.welcome h1 { font-size: 24px; letter-spacing: -.02em; margin-bottom: 16px; color: var(--brand); }
.welcome li { margin: 8px 0; }
.stage { position: relative; height: clamp(320px, 58vh, 640px); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #eef3f6; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#scene { touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }
#overlay { pointer-events: none; }
.stage-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; }
.stage-tools button { padding: 6px 10px; font-size: 12px; background: rgb(255 255 255 / .9); }
.stage-hint { position: absolute; left: 12px; bottom: 8px; font-size: 12px; color: var(--ink-soft); pointer-events: none; }
.busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgb(255 255 255 / .78); font-weight: 600; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Resultats */
.card { margin-top: 16px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.player { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.motion { flex: 1; min-width: 200px; font-weight: 600; color: var(--accent); }
.summary { margin: 14px 0 8px; }
.summary.error { padding: 10px; border: 1px solid var(--warn-line); border-radius: 6px; background: var(--warn-bg); }
.sequence { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.sequence li { counter-increment: step; margin: 4px 0; }
.sequence button { width: 100%; justify-content: flex-start; white-space: normal; text-align: left; padding: 9px 12px; }
.sequence button::before {
  content: counter(step); display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px;
  border-radius: 50%; background: var(--canvas); font-size: 12px; font-weight: 700;
}
.sequence button[aria-current=step] { border-color: var(--accent); background: #fff3ea; color: var(--ink); }
.sequence button[aria-current=step]::before { background: var(--accent); color: #fff; }
.tests { margin: 0; padding-left: 18px; color: var(--ink-soft); }

/* Notice (ecran et impression) */
/* Charte Capgemini : bleu #0070AD, bleu vif #12ABDB, violet profond #2B0A3D, police Ubuntu. */
.sheet {
  --doc-primary: #0070ad; --doc-accent: #12abdb; --doc-dark: #2b0a3d; --doc-tint: #e6f2f8;
  max-width: 210mm; margin: 0 auto; padding: 14mm; background: #fff; border: 1px solid var(--line);
  box-shadow: 0 2px 12px rgb(0 0 0 / .08); font: 10.5pt/1.45 Ubuntu, Verdana, Arial, sans-serif; color: var(--doc-dark);
}
.cartouche { display: grid; grid-template-columns: 42mm 1fr; border: 1.5px solid var(--doc-primary); margin-bottom: 5mm; }
.cart-company { grid-row: span 2; display: flex; flex-direction: column; gap: 2mm; align-items: center; justify-content: center; padding: 3mm; border-right: 1.5px solid var(--doc-primary); font-weight: 700; text-align: center; color: var(--doc-primary); }
.cart-logo { max-width: 100%; max-height: 16mm; object-fit: contain; }
.cart-title { padding: 3mm 4mm; border-bottom: 1px solid var(--doc-primary); }
.cart-title h1 { font-size: 15pt; color: var(--doc-primary); }
.cart-title p { font-size: 9pt; color: #444; }
.cart-grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.cart-cell { display: flex; flex-direction: column; padding: 1.5mm 3mm; border-right: 1px solid var(--doc-primary); }
.cart-cell:last-child { border-right: 0; }
.cart-label { font-size: 7pt; text-transform: uppercase; letter-spacing: .06em; color: #555; }
.cart-value { font-weight: 600; }
.sheet .warning { font-size: 9pt; margin-bottom: 4mm; }
.doc-section h2 { font-size: 12pt; margin: 6mm 0 2.5mm; padding-bottom: 1mm; color: var(--doc-primary); border-bottom: 1.5px solid var(--doc-accent); break-after: avoid; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.sheet th, .sheet td { padding: 1.5mm 2mm; border: 1px solid #999; text-align: left; vertical-align: top; }
.sheet th { background: var(--doc-primary); color: #fff; font-size: 8.5pt; }
.sheet tbody tr:nth-child(even) td { background: var(--doc-tint); }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; }
.tools h3 { font-size: 10pt; margin-bottom: 1mm; }
.tools ul { margin: 0; padding-left: 5mm; }
.step { display: grid; grid-template-columns: 78mm 1fr; gap: 5mm; padding: 3mm 0; border-bottom: 1px solid #ccc; break-inside: avoid; }
.step-figure img { display: block; width: 100%; border: 1px solid #bbb; }
.step h3 { display: flex; gap: 2.5mm; align-items: flex-start; font-size: 10.5pt; margin-bottom: 2mm; }
.step-number { display: inline-grid; place-items: center; flex: none; width: 6.5mm; height: 6.5mm; border-radius: 50%; background: var(--doc-primary); color: #fff; font-size: 9.5pt; }
.step dl { display: grid; grid-template-columns: 38mm 1fr; gap: .8mm 3mm; margin: 0; font-size: 9.5pt; }
.step dt { color: #444; }
.step dd { margin: 0; white-space: pre-line; }
.missing { color: #a04a00; font-style: italic; font-weight: 400; }
.signatures td { height: 18mm; color: #999; font-size: 8pt; }
.doc-footer { margin-top: 6mm; padding-top: 2mm; border-top: 1mm solid var(--doc-accent); font-size: 8pt; color: #555; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .workspace { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar, .tree-col { border-right: 0; border-bottom: 1px solid var(--line); }
}

@page { size: A4; margin: 12mm 12mm 16mm; }
@media print {
  body { background: #fff; }
  .app-header, .sidebar, .tree-col, #view3d { display: none !important; }
  .layout { display: block; min-height: 0; }
  .workspace { padding: 0; }
  #viewNotice { display: block !important; }
  .sheet { max-width: none; padding: 0; border: 0; box-shadow: none; }
  .sheet, .sheet * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
