/* Ydra — feuille de style unique */
:root {
  --bed: #e8ece9;          /* fond : plateau */
  --surface: #f8faf8;
  --surface-2: #eef2ef;
  --ink: #1c2b29;
  --muted: #5d6b68;
  --line: #cfd7d3;
  --line-strong: #9fb0aa;
  --action: #2442c2;
  --action-ink: #ffffff;
  --action-soft: #e3e8fb;
  --skin: #3e4c4a;
  --wave: #2442c2;
  --wall: #a35a06;
  --rail: #0f766e;
  --warn: #b42318;
  --warn-soft: #fdecea;
  --ok: #17663a;
  --ok-soft: #e4f3ea;
  --amber-soft: #fbf0dc;
  --r-field: 4px;
  --r-panel: 10px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bed: #121a19; --surface: #1a2423; --surface-2: #213029; --ink: #e3ebe8; --muted: #9aaba6;
    --line: #2f3e3b; --line-strong: #4a5d58; --action: #7d93ff; --action-ink: #0d1530; --action-soft: #22305e;
    --skin: #aab9b5; --wave: #7d93ff; --wall: #e09a3e; --rail: #3fc1b0; --warn: #ff8a7a; --warn-soft: #3a1d1a;
    --ok: #6fd39a; --ok-soft: #173426; --amber-soft: #3a2c13;
  }
}
:root[data-theme="dark"] {
  --bed: #121a19; --surface: #1a2423; --surface-2: #213029; --ink: #e3ebe8; --muted: #9aaba6;
  --line: #2f3e3b; --line-strong: #4a5d58; --action: #7d93ff; --action-ink: #0d1530; --action-soft: #22305e;
  --skin: #aab9b5; --wave: #7d93ff; --wall: #e09a3e; --rail: #3fc1b0; --warn: #ff8a7a; --warn-soft: #3a1d1a;
  --ok: #6fd39a; --ok-soft: #173426; --amber-soft: #3a2c13;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bed); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  font-variation-settings: "wdth" 100;
}
a { color: var(--action); }
h1, h2, h3 { font-weight: 650; line-height: 1.15; margin: 0; }
h1 { font-size: 1.75rem; font-variation-settings: "wdth" 118; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-variation-settings: "wdth" 112; }
h3 { font-size: 1rem; font-variation-settings: "wdth" 108; }
p { margin: 0 0 0.75rem; }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

/* ---------------------------------------------------------------- barre */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: 0.7rem clamp(16px, 3vw, 32px);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.55rem; color: var(--ink); text-decoration: none; }
.brand svg { display: block; }
.brand span { font-size: 1.25rem; font-weight: 700; font-variation-settings: "wdth" 125; letter-spacing: 0.01em; }
.topbar nav { display: flex; gap: 1.1rem; align-items: center; flex: 1; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--action); }
.topbar .who { margin-left: auto; display: flex; gap: 0.9rem; align-items: center; color: var(--muted); font-size: 0.88rem; }
.topbar .who button { background: none; border: 0; color: var(--muted); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.machine {
  display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted);
}
.machine i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.machine.busy i { background: var(--wall); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .machine.busy i { animation: none; } }

.page { max-width: 1240px; margin: 0 auto; padding: clamp(16px, 3vw, 32px); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head p { margin: 0.35rem 0 0; color: var(--muted); max-width: 70ch; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 0.4rem 1rem; }
  .topbar nav { order: 3; width: 100%; flex: none; }
  .topbar .who { margin-left: auto; gap: 0.7rem; }
  .topbar .who .email { display: none; }
  .verdict { gap: 0.3rem 1.2rem; }
}

/* ---------------------------------------------------------------- boutons, champs */
button, .btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 1rem; border-radius: var(--r-field); border: 1px solid var(--action);
  background: var(--action); color: var(--action-ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--warn); border-color: var(--warn); }
.btn-small { padding: 0.3rem 0.65rem; font-size: 0.86rem; }
.icon-btn { padding: 0.3rem 0.5rem; background: transparent; color: var(--muted); border-color: transparent; }
.icon-btn:hover { color: var(--warn); }

label.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.86rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-field); padding: 0.45rem 0.55rem; width: 100%; min-width: 0;
  font-variant-numeric: tabular-nums;
}
input:disabled { background: var(--surface-2); color: var(--muted); }
input[type="checkbox"] { width: auto; }
.unit { position: relative; }
.unit input { padding-right: 2.6rem; }
.unit::after { content: attr(data-unit); position: absolute; right: 0.55rem; bottom: 0.5rem; font-size: 0.8rem; color: var(--muted); pointer-events: none; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 1.1rem 1.2rem; }
.panel + .panel { margin-top: 1rem; }
.panel > h2 { margin-bottom: 0.8rem; }
.grid { display: grid; gap: 0.8rem; }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 640px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.note { padding: 0.65rem 0.85rem; border-radius: var(--r-field); background: var(--surface-2); font-size: 0.9rem; margin: 0.6rem 0; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.amber { background: var(--amber-soft); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.error-text { color: var(--warn); }

/* ---------------------------------------------------------------- connexion */
.auth {
  min-height: calc(100vh - 60px); display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(320px, 420px);
  align-items: center; gap: clamp(24px, 5vw, 72px); max-width: 1100px; margin: 0 auto; padding: 32px clamp(16px, 4vw, 40px);
}
.auth-art svg { width: 100%; height: auto; display: block; }
.auth-art p { color: var(--muted); max-width: 46ch; margin-top: 1rem; }
.auth form { display: grid; gap: 0.9rem; }
.auth h1 { margin-bottom: 0.4rem; }
@media (max-width: 820px) { .auth { grid-template-columns: 1fr; } .auth-art { order: 2; } }

/* ---------------------------------------------------------------- projets */
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.pitem { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); display: flex; flex-direction: column; }
.pitem a.main { display: flex; gap: 0.9rem; padding: 1rem; color: inherit; text-decoration: none; flex: 1; }
.pitem a.main:hover h3 { color: var(--action); }
.pitem svg { flex: none; }
.pitem .meta { font-size: 0.86rem; color: var(--muted); margin-top: 0.2rem; }
.pitem .foot { display: flex; gap: 0.25rem; border-top: 1px solid var(--line); padding: 0.4rem 0.6rem; justify-content: flex-end; }
.status { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-top: 0.45rem; }
.status.s-gcode_ready, .status.s-apercu_ok { background: var(--ok-soft); color: var(--ok); }
.status.s-calcul_apercu, .status.s-calcul_gcode { background: var(--amber-soft); color: var(--wall); }
.status.s-error { background: var(--warn-soft); color: var(--warn); }
.empty { border: 1.5px dashed var(--line-strong); border-radius: var(--r-panel); padding: 2.5rem 1.5rem; text-align: center; }
.empty p { color: var(--muted); }

/* ---------------------------------------------------------------- éditeur */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1.25rem; align-items: start; }
.editor .side { position: sticky; top: 1rem; }
@media (max-width: 980px) { .editor { grid-template-columns: 1fr; } .editor .side { position: static; } }
.name-input { font-size: 1.5rem; font-weight: 650; font-variation-settings: "wdth" 118; border: 0; border-bottom: 1.5px solid var(--line-strong); border-radius: 0; background: transparent; padding: 0.15rem 0; }
.name-input:focus { border-bottom-color: var(--action); outline: none; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; margin-top: 0.8rem; }
details.more[open] > summary { margin-bottom: 0.7rem; }

.obj {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 0.9rem; align-items: start;
  padding: 0.9rem 0; border-top: 1px solid var(--line);
}
.obj:first-of-type { border-top: 0; }
.obj .thumb { width: 64px; height: 64px; border-radius: var(--r-field); background: var(--surface-2); display: grid; place-items: center; }
.obj .row1 { display: grid; grid-template-columns: minmax(70px, 0.7fr) minmax(130px, 1.3fr) repeat(3, minmax(64px, 0.7fr)); gap: 0.55rem; }
.obj .row2 { display: grid; grid-template-columns: repeat(5, minmax(64px, 1fr)); gap: 0.55rem; margin-top: 0.55rem; }
.obj .src { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.55rem; flex-wrap: wrap; }
.obj .src .lab { font-size: 0.9rem; }
@media (max-width: 720px) {
  .obj { grid-template-columns: 48px minmax(0, 1fr); }
  .obj .thumb { width: 48px; height: 48px; }
  .obj .del { grid-column: 2; justify-self: end; }
  .obj .row1, .obj .row2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.add-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.8rem; }

.scale-card svg { width: 100%; height: auto; display: block; }
.fill { margin-top: 0.8rem; }
.fill .bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; position: relative; }
.fill .bar b { display: block; height: 100%; background: var(--wall); border-radius: 999px; transition: width 0.25s ease; }
.fill .bar i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--warn); left: 75%; }
.fill .legend { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); margin-top: 0.35rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 1rem; font-size: 0.9rem; margin: 0.8rem 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.save-bar { display: flex; gap: 0.6rem; margin-top: 1rem; flex-wrap: wrap; }

/* ---------------------------------------------------------------- projet */
.steps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
@media (max-width: 760px) { .steps { grid-template-columns: 1fr; } }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 1rem 1.15rem; display: flex; flex-direction: column; gap: 0.5rem; }
.step h2 { display: flex; align-items: baseline; gap: 0.6rem; }
.step h2 small { font-size: 0.85rem; color: var(--muted); font-weight: 500; font-variation-settings: "wdth" 100; }
.step .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: auto; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress b { display: block; height: 100%; background: var(--wall); transition: width 0.4s ease; }
.progress.indet b { width: 30%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .progress.indet b { animation: none; width: 100%; opacity: 0.4; } }
pre.log { background: var(--surface-2); border-radius: var(--r-field); padding: 0.6rem 0.75rem; font-size: 0.8rem; max-height: 220px; overflow: auto; white-space: pre-wrap; margin: 0; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

.viewer-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.viewer-tools { display: flex; gap: 0.9rem; flex-wrap: wrap; align-items: center; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.viewer-tools label { display: inline-flex; gap: 0.35rem; align-items: center; cursor: pointer; }
.viewer-tools .sw { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.viewer-tools .spacer { flex: 1; }
.viewer { position: relative; height: min(74vh, 760px); min-height: 380px; background: var(--surface); touch-action: none; }
.viewer svg { width: 100%; height: 100%; display: block; cursor: grab; }
.viewer svg.dragging { cursor: grabbing; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); font-size: 0.82rem; padding: 0.4rem 0.6rem; border-radius: var(--r-field); max-width: 260px; display: none; z-index: 3; }
.verdict { display: flex; gap: 1.4rem; flex-wrap: wrap; padding: 0.75rem 0.9rem; border-top: 1px solid var(--line); font-size: 0.9rem; }
.verdict b { font-variant-numeric: tabular-nums; }
.verdict .good { color: var(--ok); }
.verdict .bad { color: var(--warn); }
.result-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
@media (max-width: 900px) { .result-grid { grid-template-columns: 1fr; } }
.result-grid img { width: 100%; height: auto; border-radius: var(--r-field); border: 1px solid var(--line); background: #fff; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.summary-table th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 0.35rem 0.4rem; }
.summary-table td { border-bottom: 1px solid var(--line); padding: 0.35rem 0.4rem; }

/* ---------------------------------------------------------------- esquisse (dialogue) */
dialog.sk {
  width: min(1180px, 96vw); height: min(820px, 94vh); padding: 0; border: 1px solid var(--line-strong);
  border-radius: var(--r-panel); background: var(--surface); color: var(--ink);
}
dialog.sk::backdrop { background: rgba(16, 26, 24, 0.55); }
.sk-body { display: grid; grid-template-columns: minmax(0, 1fr) 330px; height: 100%; }
.sk-canvas { position: relative; background: var(--surface-2); border-right: 1px solid var(--line); min-height: 0; touch-action: none; }
.sk-canvas svg { width: 100%; height: 100%; display: block; }
.sk-canvas .hint { position: absolute; left: 12px; bottom: 10px; font-size: 0.8rem; color: var(--muted); background: var(--surface); padding: 0.25rem 0.5rem; border-radius: var(--r-field); }
.sk-side { display: flex; flex-direction: column; min-height: 0; }
.sk-side header { padding: 0.9rem 1rem 0.6rem; border-bottom: 1px solid var(--line); }
.sk-scroll { overflow: auto; padding: 0.8rem 1rem; flex: 1; display: grid; gap: 0.9rem; align-content: start; }
.sk-side footer { padding: 0.75rem 1rem; border-top: 1px solid var(--line); display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.sk-sec h3 { margin-bottom: 0.45rem; font-size: 0.95rem; }
.sk-warn { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; font-size: 0.85rem; }
.sk-warn li { padding: 0.45rem 0.6rem; border-radius: var(--r-field); background: var(--amber-soft); cursor: pointer; }
.sk-warn li.err { background: var(--warn-soft); color: var(--warn); }
.sk-stats { font-size: 0.86rem; }
.sk-stats .kv { grid-template-columns: 1fr; gap: 0; }
.sk-stats .kv dd { text-align: left; margin-bottom: 0.3rem; color: var(--ink); }
.sk-side .unit input { padding-right: 2rem; }
@media (max-width: 820px) {
  .sk-body { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .sk-canvas { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* bibliothèque */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
.lib-item { border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--surface); padding: 0.6rem; display: flex; flex-direction: column; gap: 0.35rem; text-align: left; color: var(--ink); font-weight: 500; cursor: pointer; }
button.lib-item { font: inherit; }
.lib-item:hover, .lib-item[aria-pressed="true"] { border-color: var(--action); }
.lib-item svg { width: 100%; height: 96px; }
.lib-item .nm { font-size: 0.88rem; line-height: 1.25; }
.lib-item .au { font-size: 0.76rem; color: var(--muted); }
.lib-filter { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.lib-filter input { max-width: 260px; }
.lib-filter select { max-width: 220px; }
dialog.pick { width: min(860px, 94vw); max-height: 86vh; border: 1px solid var(--line-strong); border-radius: var(--r-panel); background: var(--surface); color: var(--ink); padding: 1.1rem; }
dialog.pick::backdrop { background: rgba(16, 26, 24, 0.55); }
dialog.pick .lib-grid { max-height: 58vh; overflow: auto; padding: 2px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 0.6rem 1rem; border-radius: var(--r-field); font-size: 0.9rem; z-index: 50; display: none; }
@media (max-width: 820px) { .sk-canvas .hint { display: none; } }
