:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --panel: #ffffff;
  --ink: #202925;
  --ink-2: #3b463f;
  --muted: #737e77;
  --line: #e3e7e1;
  --grid: #e8ebe6;
  --baseline: #c3c8c1;
  --green: #23634b;
  --green-dark: #184a38;
  --green-soft: #e9f2ec;
  --view-bg: #fcfcfb;
  --air-zone: #eef3f7;
  --solid-zone: #ddd5c6;
  --mesh-line: rgba(40, 60, 50, 0.32);
  --axis-line: #9aa39c;
  --vector: #17241d;
  --warn: #9a5a37;
  --warn-soft: #fbf0e9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; font-size: 13px; }
button, input, select { font: inherit; }
[hidden] { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* --- En-tête --------------------------------------------------------------- */
.top { display: flex; align-items: center; gap: 18px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--green); color: #fff; display: grid; place-items: center; }
.brand-mark svg { width: 21px; height: 21px; }
.brand-name { display: block; font-weight: 750; letter-spacing: -.03em; font-size: 15px; }
.brand-sub { display: block; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.top-nav { display: flex; gap: 4px; }
.top-nav a { padding: 7px 11px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 600; }
.top-nav a:hover { background: var(--green-soft); }
.top-nav a[aria-current="page"] { background: var(--green-soft); color: var(--green); }
.top-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.btn { border: 1px solid #d7dfd8; border-radius: 8px; height: 32px; padding: 0 12px; background: #fff; color: var(--ink-2); cursor: pointer; font-weight: 650; font-size: 12px; white-space: nowrap; }
.btn:hover { border-color: #b9cec0; color: var(--green); }
.btn:focus-visible, .tree button:focus-visible, .tabs button:focus-visible { outline: 3px solid #cfe3d5; outline-offset: 1px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); color: #fff; }
.btn.small { height: 26px; padding: 0 9px; font-size: 11px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* --- Espace de travail ------------------------------------------------------- */
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 190px 340px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 160px; gap: 10px; padding: 10px; }
.tree, .panel, .view, .console { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; min-height: 0; }
.tree { grid-row: 1 / span 2; padding: 10px 8px; overflow-y: auto; }
.tree-group + .tree-group { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.tree h2 { margin: 0 8px 6px; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.tree button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; padding: 7px 9px; border-radius: 7px; color: var(--ink-2); cursor: pointer; font-weight: 550; }
.tree button::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #cfd6d0; flex: 0 0 auto; }
.tree button.done::before { background: var(--green); }
.tree button.warn::before { background: #c98500; }
.tree button:hover { background: #f3f6f2; }
.tree button[aria-current="true"] { background: var(--green-soft); color: var(--green); }

.panel { overflow-y: auto; padding: 14px 16px 18px; }
.panel h2 { margin: 0; font-size: 15px; letter-spacing: -.02em; }
.panel .lead { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 6px 0 12px; }
.panel h3 { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 16px 0 8px; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) 110px; align-items: center; gap: 8px; margin: 7px 0; }
.field label { color: var(--ink-2); font-size: 12px; line-height: 1.3; }
.field .unit { color: var(--muted); font-size: 10px; margin-left: 3px; }
.field input, .field select { width: 100%; height: 30px; border: 1px solid #dfe5de; border-radius: 7px; padding: 0 8px; background: #fcfdfb; color: var(--ink); font-size: 12px; }
.field input { text-align: right; font-variant-numeric: tabular-nums; }
.field input:focus, .field select:focus { outline: none; border-color: #84aa92; box-shadow: 0 0 0 3px #eaf2ec; }
.field input:invalid { border-color: #d9a184; background: var(--warn-soft); }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; color: var(--ink-2); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.note { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: #f4f7f3; border: 1px solid #e3ebe3; color: #4d5c52; font-size: 11px; line-height: 1.5; }
.note.warn { background: var(--warn-soft); border-color: #f0dccd; color: var(--warn); }
.zone { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin-top: 10px; }
.zone-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.zone-head strong { font-size: 12px; }
.zone-head span { color: var(--muted); font-size: 10px; }
.stats { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.stats th, .stats td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.stats th:first-child, .stats td:first-child { text-align: left; font-weight: 500; color: var(--ink-2); }
.stats thead th { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.stats td.delta-bad { color: var(--warn); }
.progress { height: 6px; border-radius: 6px; background: #edf0ec; overflow: hidden; margin-top: 10px; }
.progress div { height: 100%; width: 0; background: var(--green); transition: width .2s; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.kpi { border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; }
.kpi span { display: block; font-size: 10px; color: var(--muted); }
.kpi strong { display: block; font-size: 17px; margin-top: 3px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* --- Fenêtre graphique ------------------------------------------------------ */
.view { display: flex; flex-direction: column; overflow: hidden; }
.view-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 6px 11px; border-radius: 7px; font-weight: 650; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--green-soft); color: var(--green); }
.run-quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 20px; padding: 5px 10px; font-size: 11px; color: var(--ink-2); background: #fafbf9; }
.chip.running { color: var(--green); border-color: #cfe3d5; background: #f2f8f3; }
.chip.error { color: var(--warn); border-color: #f0dccd; background: var(--warn-soft); }
.view-pane { position: relative; flex: 1; min-height: 0; }
#view-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: var(--view-bg); touch-action: none; cursor: grab; }
#view-canvas:active { cursor: grabbing; }
.view-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.view-hint { position: absolute; left: 12px; bottom: 6px; margin: 0; color: var(--muted); font-size: 10px; pointer-events: none; }
.legend { position: absolute; left: 12px; top: 10px; width: 230px; background: rgba(255, 255, 255, .92); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.legend-title { font-size: 11px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
.legend-bar { height: 10px; border-radius: 3px; }
.legend-ticks { display: flex; justify-content: space-between; margin-top: 4px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.probe, .tooltip { position: absolute; pointer-events: none; background: #1f2d26; color: #fff; border-radius: 8px; padding: 7px 9px; font-size: 11px; line-height: 1.45; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); white-space: nowrap; z-index: 2; }
.probe b, .tooltip b { font-variant-numeric: tabular-nums; margin-left: 8px; }
.tt-head { color: #c9d4cd; margin-bottom: 3px; }
.tt-row { display: flex; align-items: center; gap: 6px; }
.tt-row b { margin-left: auto; padding-left: 12px; }
.tt-key { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 14px 0; font-size: 11px; color: var(--ink-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-box { position: absolute; inset: 34px 6px 6px 6px; }
.chart-box canvas, .panel-chart canvas { width: 100%; height: 100%; display: block; }
.panel-chart { position: relative; height: 330px; margin-top: 10px; }
.cycle-pane { overflow-y: auto; padding: 6px 10px 10px; }
.cycle-chart h3 { margin: 10px 4px 0; font-size: 12px; color: var(--ink-2); }
.cycle-chart .chart-legend { padding: 6px 4px 0; }
.cycle-box { position: relative; height: 210px; }
.cycle-box canvas { width: 100%; height: 100%; display: block; }
.cycle-empty { color: var(--muted); font-size: 12px; margin: 14px 6px; }
.hour-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.hour-row input[type=range] { flex: 1; accent-color: var(--green); }
.hour-row strong { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }

/* --- Console ---------------------------------------------------------------- */
.console { grid-column: 2 / span 2; display: flex; flex-direction: column; overflow: hidden; }
.console-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.console h2 { margin: 0; font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
#console { flex: 1; margin: 0; padding: 8px 12px; overflow: auto; font: 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; color: #33413a; background: #fbfcfa; white-space: pre; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); max-width: calc(100vw - 32px); padding: 10px 14px; border-radius: 10px; background: #1f2d26; color: #fff; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 5; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* --- Petits écrans ---------------------------------------------------------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 170px 300px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  body { height: auto; }
  .workspace { display: flex; flex-direction: column; }
  .tree { display: flex; gap: 6px; overflow-x: auto; padding: 8px; }
  .tree-group { display: flex; gap: 4px; align-items: center; }
  .tree-group + .tree-group { margin: 0; padding: 0 0 0 8px; border-top: 0; border-left: 1px solid var(--line); }
  .tree h2 { display: none; }
  .tree button { white-space: nowrap; width: auto; }
  .panel { max-height: none; }
  .view { height: 70vh; min-height: 420px; }
  .console { height: 200px; }
  .legend { width: 190px; }
  .top-actions { margin-left: 0; }
}
