/* app.css — habillage de l'outil. Volontairement neutre et fixe : c'est l'apercu qui
   change de couleurs, pas l'outil. Toutes les classes sont prefixees cf- ; l'apercu
   (preview.css, prefixe pv-) n'herite de rien d'ici en dehors de la taille de reference. */

:root {
  --c-canvas: #dcdee3;
  --c-panel: #f6f7f8;
  --c-raised: #ffffff;
  --c-sunken: #eceef1;
  --c-ink: #16181d;
  --c-ink-2: #454a54;
  --c-ink-3: #5f6470;
  --c-line: #d3d6dc;
  --c-line-strong: #8a8f9a;
  --c-focus: #1d4ed8;
  --c-warn-bg: #fff3d1;
  --c-warn: #6b4700;
  --c-error-bg: #fdebe9;
  --c-error: #a8201a;
  --c-ok: #1b6b3a;
  --cf-font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --cf-mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --panel-w: 432px;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body.cf {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--c-panel);
  color: var(--c-ink);
  font-family: var(--cf-font);
  font-size: 14px;
  line-height: 1.45;
}
.cf-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.cf-skip { position: absolute; left: 8px; top: -60px; z-index: 50; padding: 10px 14px; border-radius: 6px; background: var(--c-ink); color: #fff; }
.cf-skip:focus { top: 8px; }
.cf :is(.cf-btn, .cf-tab, .cf-chip, .cf-preset, .cf-iconbtn, .cf-input, .cf-switch, .cf-color, .cf-json, .cf-panel, .cf-section):focus-visible,
.cf .cf-seg-input:focus-visible + :is(.cf-seg-face, .cf-tile-face) { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.cf-ic { width: 16px; height: 16px; flex: none; }
.cf [hidden] { display: none !important; }

/* ——— En-tete ——— */
.cf-top { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; padding: 10px 20px; border-bottom: 1px solid var(--c-line); background: var(--c-raised); }
.cf-brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.cf-title { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.cf-version { margin: 0; color: var(--c-ink-3); font-size: 13px; }
.cf-top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ——— Boutons ——— */
.cf-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 14px; border: 1px solid var(--c-line-strong); border-radius: 6px; background: var(--c-raised); color: var(--c-ink); font: inherit; font-weight: 550; cursor: pointer; }
.cf-btn:hover { background: var(--c-sunken); }
/* le nom du fichier suit le libelle du bouton, sans espace double */
.cf-wide-only { margin-left: -4px; }
.cf-btn--primary { border-color: var(--c-ink); background: var(--c-ink); color: #fff; }
.cf-btn--primary:hover { background: #2c3038; }
.cf-btn--quiet { border-color: var(--c-line); }
.cf-btn[aria-disabled='true'] { border-color: var(--c-line); background: var(--c-sunken); color: var(--c-ink-3); }
.cf-iconbtn { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--c-ink-2); cursor: pointer; }
.cf-iconbtn:hover { background: var(--c-sunken); color: var(--c-ink); }
.cf-iconbtn:disabled { color: #a9adb6; cursor: default; background: none; }

/* ——— Disposition ——— */
.cf-layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); min-height: 0; }
.cf-work { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--c-canvas); }
.cf-panel { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; border-left: 1px solid var(--c-line); background: var(--c-panel); scroll-padding-top: 60px; }
.cf-workbar { display: flex; align-items: center; justify-content: space-between; gap: 8px 20px; flex-wrap: wrap; padding: 0 20px; border-bottom: 1px solid var(--c-line); background: var(--c-panel); }
.cf-view { min-height: 0; padding: 20px; }
.cf-stage { display: grid; place-items: center; width: 100%; height: 100%; overflow: hidden; }
.cf-frame { position: relative; flex: none; overflow: hidden; border-radius: 8px; background: #fff; box-shadow: 0 0 0 1px rgb(22 24 29 / 0.14), 0 18px 44px -12px rgb(22 24 29 / 0.32); }
.cf-frame[data-viewport='mobile'] { border-radius: 26px; box-shadow: 0 0 0 1px rgb(22 24 29 / 0.3), 0 18px 44px -12px rgb(22 24 29 / 0.4); }
.cf-frame > .pv { position: absolute; top: 0; left: 0; }
.cf-view--file { overflow-y: auto; background: var(--c-panel); }

/* ——— Onglets ——— */
.cf-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.cf-tab { position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 44px; padding: 0 12px; border: 0; background: none; color: var(--c-ink-2); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.cf-tab:hover { color: var(--c-ink); }
.cf-tab[aria-selected='true'] { color: var(--c-ink); }
.cf-tab[aria-selected='true']::after { content: ''; position: absolute; left: 12px; right: 12px; bottom: 0; height: 2px; background: var(--c-ink); }
.cf-tab-dot { padding: 1px 6px; border-radius: 999px; background: var(--c-error-bg); color: var(--c-error); font-size: 11px; font-weight: 600; }
.cf-tabs--sections { position: sticky; top: 0; z-index: 3; flex: none; padding: 0 12px; border-bottom: 1px solid var(--c-line); background: var(--c-panel); }
.cf-tabs--sections .cf-tab { padding: 0 9px; }
.cf-tabs--sections .cf-tab[aria-selected='true']::after { left: 9px; right: 9px; }

/* ——— Panneau de reglages ——— */
.cf-presets-block { padding: 16px 20px 12px; }
.cf-panel-title { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--c-ink-2); }
.cf-presets { display: grid; gap: 6px; }
.cf-preset { display: grid; gap: 2px; padding: 9px 12px; border: 1px solid var(--c-line); border-radius: 6px; background: var(--c-raised); color: var(--c-ink); font: inherit; text-align: left; cursor: pointer; }
.cf-preset:hover { border-color: var(--c-line-strong); }
.cf-preset[aria-pressed='true'] { border-color: var(--c-ink); box-shadow: inset 0 0 0 1px var(--c-ink); }
.cf-preset-name { font-weight: 600; }
.cf-preset-text { color: var(--c-ink-2); font-size: 13px; }
.cf-section { padding: 4px 20px 32px; }
.cf-group { padding: 16px 0 4px; border-top: 1px solid var(--c-line); display: grid; gap: 16px; }
.cf-section > .cf-group:first-child, .cf-section > .cf-cost + .cf-group { border-top: 0; }
.cf-group-title { margin: 0; font-size: 15px; font-weight: 650; }
.cf-field { position: relative; display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.cf-label { margin: 0; padding: 0; font-weight: 600; color: var(--c-ink); }
.cf-help { margin: 0; color: var(--c-ink-2); font-size: 13px; }
.cf-group > .cf-help { margin-top: -10px; }
.cf-note { margin: 0; padding: 7px 10px; border-radius: 6px; font-size: 13px; }
.cf-note--rule { background: var(--c-sunken); color: var(--c-ink-2); border-left: 3px solid var(--c-line-strong); border-radius: 0 6px 6px 0; }
.cf-note--warn, .cf-note--warn-item { background: var(--c-warn-bg); color: var(--c-warn); }
.cf-note--error { background: var(--c-error-bg); color: var(--c-error); }
.cf-note--ok { padding: 0; color: var(--c-ok); }
.cf-input { width: 100%; min-height: 38px; padding: 6px 10px; border: 1px solid var(--c-line-strong); border-radius: 6px; background: var(--c-raised); color: var(--c-ink); font: inherit; }
.cf-input::placeholder { color: #6b707b; }
.cf-input:disabled { background: var(--c-sunken); color: var(--c-ink-3); border-color: var(--c-line); }
.cf-input[aria-invalid='true'] { border-color: var(--c-error); box-shadow: inset 0 0 0 1px var(--c-error); }

/* Groupes de boutons radio */
.cf-seg { display: flex; flex-wrap: wrap; gap: 4px; }
.cf-seg-item, .cf-tile { position: relative; display: flex; flex: 1 1 auto; cursor: pointer; }
.cf-seg-input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.cf-seg-face { display: flex; align-items: center; justify-content: center; flex: 1; min-height: 36px; padding: 4px 12px; border: 1px solid var(--c-line-strong); border-radius: 6px; background: var(--c-raised); font-weight: 550; text-align: center; }
.cf-seg-item:hover .cf-seg-face { background: var(--c-sunken); }
.cf-seg-input:checked + .cf-seg-face { border-color: var(--c-ink); background: var(--c-ink); color: #fff; }
.cf-seg-input:disabled { cursor: not-allowed; }
.cf-seg-input:disabled + .cf-seg-face { border-color: var(--c-line); background: var(--c-sunken); color: var(--c-ink-3); }
.cf-seg-input:disabled:checked + .cf-seg-face { border-color: var(--c-ink-3); background: var(--c-ink-3); color: #fff; }
.cf-seg--cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cf-seg--cards .cf-seg-face { padding: 8px 6px; }
.cf-shellcard { display: grid; justify-items: center; gap: 6px; font-size: 13px; line-height: 1.25; }

/* Schemas des coquilles (repere visuel ; une coquille inconnue garde le cadre vide) */
.cf-wire { position: relative; display: block; width: 46px; height: 30px; border: 1.5px solid currentColor; border-radius: 3px; opacity: 0.85; }
.cf-wire i { position: absolute; background: currentColor; }
.cf-wire--sidebar i:first-child { inset: 0 auto 0 0; width: 30%; opacity: 0.55; }
.cf-wire--topbar i:first-child { inset: 0 0 auto 0; height: 24%; opacity: 0.55; }
.cf-wire--rail i:first-child { inset: 0 auto 0 0; width: 13%; opacity: 0.55; }
.cf-wire--command i:first-child { inset: 0 0 auto 0; height: 24%; opacity: 0.25; }
.cf-wire--command i:last-child { top: 5%; left: 28%; width: 44%; height: 13%; border-radius: 2px; }
.cf-wire--dock i:first-child { bottom: 10%; left: 25%; width: 50%; height: 22%; border-radius: 3px; opacity: 0.6; }
.cf-wire--pending { border-style: dashed; }
.cf-wire--pending i:first-child { top: 50%; left: 50%; width: 5px; height: 5px; margin: -2.5px; border-radius: 50%; }

/* Outils de l'apercu */
.cf-tools { position: relative; display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; padding: 6px 0; }
.cf-tools .cf-field { display: flex; align-items: center; gap: 8px; }
.cf-tools .cf-label { font-size: 13px; font-weight: 500; color: var(--c-ink-2); white-space: nowrap; }
.cf-seg--tool { flex-wrap: nowrap; gap: 0; padding: 2px; border-radius: 7px; background: var(--c-sunken); border: 1px solid var(--c-line); }
.cf-seg--tool .cf-seg-face { min-height: 28px; padding: 2px 10px; border-color: transparent; background: none; font-size: 13px; white-space: nowrap; border-radius: 5px; }
.cf-seg--tool .cf-seg-item:hover .cf-seg-face { background: rgb(22 24 29 / 0.06); }
.cf-seg--tool .cf-seg-input:checked + .cf-seg-face { background: var(--c-raised); color: var(--c-ink); border-color: var(--c-line-strong); }
.cf-tools .cf-input { min-height: 32px; padding: 2px 8px; width: auto; }

/* Univers */
.cf-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.cf-chip { min-height: 30px; padding: 2px 11px; border: 1px solid var(--c-line-strong); border-radius: 999px; background: var(--c-raised); color: var(--c-ink); font: inherit; font-size: 13px; cursor: pointer; }
.cf-chip[aria-pressed='true'] { border-color: var(--c-ink); background: var(--c-ink); color: #fff; }
.cf-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-height: 292px; overflow-y: auto; padding: 3px; margin: -3px; }
.cf-tile-face { display: grid; gap: 4px; flex: 1; padding: 5px 5px 4px; border: 1px solid var(--c-line); border-radius: 7px; background: var(--c-raised); }
.cf-tile:hover .cf-tile-face { border-color: var(--c-line-strong); }
.cf-seg-input:checked + .cf-tile-face { border-color: var(--c-ink); box-shadow: inset 0 0 0 1px var(--c-ink); }
.cf-tile-name { font-size: 13px; font-weight: 550; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-seg-input:checked + .cf-tile-face .cf-tile-name { font-weight: 700; }
.cf-swatch { position: relative; display: block; height: 40px; border-radius: 4px; background: var(--sw-bg); box-shadow: inset 0 0 0 1px rgb(22 24 29 / 0.12); overflow: hidden; }
.cf-swatch-card { position: absolute; left: 14%; right: 14%; top: 28%; bottom: -10%; border: 1px solid var(--sw-border); border-radius: 3px 3px 0 0; background: var(--sw-surface); }
.cf-swatch-dot { position: absolute; left: 22%; top: 44%; width: 26%; height: 22%; border-radius: 2px; background: var(--sw-accent); }
.cf-detail { display: grid; gap: 4px; padding: 10px 12px; border-radius: 6px; background: var(--c-sunken); }
.cf-detail-title { margin: 0; }
.cf-detail-title span { color: var(--c-ink-2); }

/* Interrupteurs */
.cf-toggle { display: grid; gap: 6px; }
.cf-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 36px; }
.cf-toggle-text { display: grid; gap: 1px; cursor: pointer; flex: 1; }
.cf-switch { appearance: none; position: relative; flex: none; width: 42px; height: 24px; margin: 0; border: 1px solid var(--c-line-strong); border-radius: 999px; background: var(--c-raised); cursor: pointer; }
.cf-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--c-ink-3); }
.cf-switch:checked { border-color: var(--c-ink); background: var(--c-ink); }
.cf-switch:checked::after { left: 21px; background: #fff; }
.cf-switch:disabled { cursor: not-allowed; border-color: var(--c-line-strong); background: var(--c-sunken); }
.cf-switch:disabled:checked { background: var(--c-ink-3); border-color: var(--c-ink-3); }
.cf-accent-row { display: flex; gap: 8px; align-items: center; }
.cf-color { flex: none; width: 46px; height: 38px; padding: 2px; border: 1px solid var(--c-line-strong); border-radius: 6px; background: var(--c-raised); cursor: pointer; }
.cf-color:disabled { opacity: 0.45; cursor: not-allowed; }
.cf-input--hex { max-width: 130px; font-family: var(--cf-mono); }

/* Listes editables */
.cf-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.cf-list:empty { display: none; }
.cf-list-row { display: flex; align-items: center; gap: 2px; }
.cf-list-row .cf-input { flex: 1; min-width: 0; margin-right: 4px; }
.cf-list-index { flex: none; width: 20px; color: var(--c-ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.cf-field > .cf-btn { justify-self: start; }

/* Equipe et cout */
.cf-cost { display: grid; gap: 6px; margin-top: 16px; padding: 12px 14px; border: 1px solid var(--c-line); border-radius: 8px; background: var(--c-raised); }
.cf-cost-value { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.cf-cost-bar { position: relative; height: 8px; border-radius: 999px; background: var(--c-sunken); overflow: hidden; }
.cf-cost-fill { position: absolute; inset: 0 auto 0 0; background: var(--c-ink-2); border-radius: 999px; }
.cf-cost-mark { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: var(--c-raised); }
.cf-agent { display: grid; gap: 10px; padding: 12px 14px; border: 1px solid var(--c-line); border-radius: 8px; background: var(--c-raised); }
.cf-agent.is-off { background: var(--c-sunken); }
.cf-agent-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.cf-agent-name { margin: 0; font-weight: 650; }
.cf-agent-share { margin: 0; flex: none; color: var(--c-ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.cf-agent-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cf-agent .cf-label { font-weight: 500; font-size: 13px; color: var(--c-ink-2); }

/* ——— Fichier de configuration ——— */
.cf-view--file { display: grid; align-content: start; gap: 24px; padding: 24px clamp(20px, 4vw, 48px) 40px; }
.cf-out-block { display: grid; gap: 10px; max-width: 880px; width: 100%; }
.cf-out-title { margin: 0; font-size: 15px; font-weight: 650; }
.cf-summary { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 16px; margin: 0; }
.cf-summary dt { color: var(--c-ink-2); }
.cf-summary dd { margin: 0; }
.cf-issues { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.cf-json { margin: 0; max-height: 60vh; overflow: auto; padding: 14px 16px; border: 1px solid var(--c-line); border-radius: 8px; background: var(--c-raised); font-family: var(--cf-mono); font-size: 13px; line-height: 1.5; tab-size: 2; }
.cf-command-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cf-command { flex: 1 1 320px; min-width: 0; padding: 9px 12px; border: 1px solid var(--c-line); border-radius: 6px; background: var(--c-raised); font-family: var(--cf-mono); font-size: 13px; overflow-wrap: anywhere; }

/* ——— Barre d'etat ——— */
.cf-status { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; padding: 10px 20px; border-top: 1px solid var(--c-line); background: var(--c-raised); }
.cf-status-text { margin: 0; flex: 1 1 240px; color: var(--c-ok); font-weight: 550; }
.cf-status-text.is-error { color: var(--c-error); }
.cf-status-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cf-toast { position: absolute; right: 20px; bottom: calc(100% + 10px); max-width: min(520px, calc(100% - 40px)); margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--c-ink); color: #fff; box-shadow: 0 8px 24px -8px rgb(22 24 29 / 0.5); opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s; z-index: 20; }
.cf-toast.is-shown:not(:empty) { opacity: 1; visibility: visible; }
.cf-noscript { margin: 20px; padding: 12px 16px; background: var(--c-warn-bg); color: var(--c-warn); border-radius: 8px; }

/* ——— Ecrans etroits : apercu colle en haut, reglages dessous, export colle en bas ——— */
@media (max-width: 900px) {
  /* un controle atteint au clavier ne reste pas sous l'apercu colle ni sous la barre d'export */
  html { scroll-padding: calc(44svh + 20px) 0 84px; }
  body.cf { height: auto; min-height: 100dvh; display: block; padding-bottom: 64px; }
  .cf-layout { display: block; }
  .cf-work { display: contents; }
  .cf-top { padding: 10px 16px; }
  .cf-workbar { padding: 0 16px; }
  .cf-tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-bottom: 8px; }
  .cf-tools .cf-field { flex: none; }
  #view-apercu { position: sticky; top: 0; z-index: 6; height: 44svh; min-height: 250px; padding: 12px; background: var(--c-canvas); border-bottom: 1px solid var(--c-line); }
  .cf-view--file { padding: 20px 16px 28px; }
  .cf-panel { overflow: visible; border-left: 0; }
  .cf-presets-block, .cf-section { padding-left: 16px; padding-right: 16px; }
  .cf-tabs--sections { position: static; padding: 0 8px; }
  .cf-status { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 8px 12px; flex-wrap: nowrap; }
  .cf-status-text, .cf-wide-only { display: none; }
  .cf-status-actions { flex: 1; flex-wrap: nowrap; }
  .cf-status-actions .cf-btn { flex: 1; padding: 0 8px; min-height: 44px; font-size: 13px; }
  .cf-toast { right: 12px; left: 12px; max-width: none; }
  .cf-summary { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .cf-summary dd { margin-bottom: 8px; }
  .cf-iconbtn { width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) { .cf-toast { transition: none; } }
