:root {
  --bg: #eef2f6; --panel: #ffffff; --panel2: #f8fafc; --line: #dbe3ec; --line2: #e8edf3;
  --text: #0f172a; --muted: #64748b; --accent: #2563eb; --accent-bg: #dbeafe; --accent-dark: #1d4ed8;
  --danger: #dc2626; --ok: #16a34a; --warn: #d97706; --top: #0f2236; --topline: #1e3a56;
  --radius: 8px; --shadow: 0 8px 28px rgba(15, 23, 42, .22);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); font-size: 13px; }
body { display: grid; grid-template-rows: auto minmax(0, 1fr); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); background: transparent; }
.spacer { flex: 1; }
.help { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 6px 0; }
.ic { display: inline-flex; vertical-align: middle; }
.mobile-only { display: none; }

/* ---------- barre du haut ---------- */
#topbar { display: flex; align-items: center; gap: 10px; background: var(--top); color: #e2edf8; padding: 0 10px; height: 46px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; letter-spacing: .02em; color: #7dd3fc; padding-right: 4px; }
#menubar { display: flex; gap: 2px; }
.menu-btn { background: none; border: 0; color: #cfe0f1; padding: 7px 10px; border-radius: 6px; }
.menu-btn:hover, .menu-btn[aria-expanded=true] { background: var(--topline); color: #fff; }
#projectName { background: #16324b; border: 1px solid transparent; border-radius: 6px; color: #fff; padding: 6px 10px; width: min(280px, 20vw); min-width: 120px; font-weight: 600; }
#projectName:hover { border-color: #31567a; } #projectName:focus { border-color: #7dd3fc; outline: 0; background: #0b1b2c; }
.save { font-size: 11.5px; color: #8fb0cf; white-space: nowrap; } .save.ok { color: #86efac; } .save.err { color: #fca5a5; } .save.busy { color: #fcd34d; }
#topActions { display: flex; align-items: center; gap: 4px; }
.top-btn { display: inline-flex; align-items: center; gap: 6px; background: transparent; color: #dbe8f5; border: 1px solid transparent; padding: 6px 10px; border-radius: 7px; font-weight: 600; }
.top-btn:hover:not(:disabled) { background: var(--topline); }
.top-btn.primary { background: var(--accent); color: #fff; } .top-btn.primary:hover { background: var(--accent-dark); }
.top-btn.only-ic { padding: 6px 8px; }
.lang-sel { background: #16324b; color: #dbe8f5; border: 1px solid #31567a; border-radius: 7px; padding: 5px 6px; font-weight: 600; margin-right: 4px; cursor: pointer; } .lang-sel:hover { border-color: #7dd3fc; }
.sep { width: 1px; height: 22px; background: var(--topline); margin: 0 4px; }

.menu-panel, .ctx { position: fixed; z-index: 1000; min-width: 250px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.menu-panel button, .ctx button { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 24px; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; }
.menu-panel button:hover:not(:disabled), .ctx button:hover:not(:disabled) { background: var(--accent-bg); }
.menu-panel hr, .ctx hr { border: 0; border-top: 1px solid var(--line2); margin: 4px 2px; }

/* ---------- application ---------- */
#app { display: grid; grid-template-columns: 54px minmax(0, 1fr) 316px; min-height: 0; }
#toolbar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0; overflow-y: auto; }
#toolbar hr { width: 28px; border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.tool { position: relative; width: 40px; height: 40px; display: grid; place-items: center; background: none; border: 1px solid transparent; border-radius: 9px; color: #334155; }
.tool:hover { background: #eef4fb; } .tool.active { background: var(--accent-bg); color: var(--accent-dark); border-color: #93c5fd; }
.tool kbd { position: absolute; right: 3px; bottom: 1px; font-size: 9px; opacity: .7; }

#canvasArea { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#optionsBar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; background: var(--panel); border-bottom: 1px solid var(--line); padding: 6px 12px; min-height: 40px; }
#optionsBar { height: 40px; flex: none; overflow: hidden; }
.tool-name { min-width: 84px; padding-right: 10px; border-right: 1px solid var(--line); }
.opt { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; margin: 0; }
.opt.strong { color: var(--text); font-weight: 700; }
.opt input[type=text] { width: 64px; padding: 4px 6px; } .opt select { padding: 4px 6px; width: auto; } .opt em { font-style: normal; }
.opt input[type=color] { width: 30px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; }

#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #fff; touch-action: none; user-select: none; -webkit-user-select: none; outline: 0; }
#stage canvas, #stage > svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#stage > svg { overflow: hidden; }
#overlay { pointer-events: none; }
.ruler { z-index: 3; } .ruler.h { height: 22px !important; } .ruler.v { width: 22px !important; }
#stage.dropping::after { content: ''; position: absolute; inset: 0; border: 3px dashed var(--accent); background: rgba(37, 99, 235, .06); z-index: 20; pointer-events: none; }
.drop-msg { display: none; }
#stage.dropping .drop-msg { display: block; position: absolute; z-index: 21; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--accent); color: #fff; padding: 12px 20px; border-radius: 10px; font-weight: 600; pointer-events: none; }
#hint { position: absolute; left: 30px; bottom: 8px; max-width: calc(100% - 60px); background: rgba(15, 23, 42, .82); color: #fff; padding: 5px 10px; border-radius: 7px; font-size: 12px; pointer-events: none; z-index: 4; }
#hint:empty { display: none; }
.obj.locked, .locked * { pointer-events: none !important; }
.hit { fill: none; stroke: transparent; pointer-events: stroke; vector-effect: non-scaling-stroke; stroke-width: 12px; }
.draft { opacity: .75; pointer-events: none; }
.lenbox { position: absolute; z-index: 12; display: none; align-items: center; gap: 6px; background: #0f172a; color: #fff; padding: 6px 8px; border-radius: 8px; box-shadow: var(--shadow); }
.lenbox input { width: 90px; background: #fff; color: #0f172a; border: 0; border-radius: 5px; padding: 4px 6px; }
.textedit { position: absolute; z-index: 12; background: rgba(255, 255, 255, .92); border: 1px dashed var(--accent); border-radius: 3px; padding: 0 2px; resize: none; line-height: 1.2; font-family: Arial, Helvetica, sans-serif; overflow: hidden; outline: 0; margin: 0; }

#statusbar { display: flex; align-items: center; gap: 12px; background: var(--panel); border-top: 1px solid var(--line); padding: 3px 10px; height: 34px; flex-wrap: nowrap; overflow: hidden; }
.coords { min-width: 190px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: #334155; white-space: pre; }
.toggles { display: flex; gap: 4px; }
.toggle { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; font-size: 12px; color: var(--muted); }
.toggle[aria-pressed=true] { background: var(--accent-bg); border-color: #93c5fd; color: var(--accent-dark); font-weight: 600; }
.zoomctl { display: flex; align-items: center; gap: 2px; }
.zoomctl button { background: none; border: 1px solid transparent; border-radius: 6px; width: 28px; height: 26px; font-size: 16px; line-height: 1; }
.zoomctl button:hover { background: #eef4fb; } .zoomctl .zoombtn { width: 66px; font-size: 12px; font-variant-numeric: tabular-nums; border-color: var(--line); } .zoomctl .fit { font-size: 15px; }

/* ---------- panneau latéral ---------- */
#sidebar { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel2); }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 4px; color: var(--muted); font-weight: 600; font-size: 12px; }
.tabs button[aria-selected=true] { color: var(--accent-dark); border-bottom-color: var(--accent); background: var(--panel); }
.tabbody { flex: 1; overflow-y: auto; min-height: 0; }
[role=tabpanel] { padding: 10px 12px 24px; } [role=tabpanel][hidden] { display: none; }

.prop-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.badge { background: var(--accent-bg); color: var(--accent-dark); padding: 2px 9px; border-radius: 999px; font-weight: 700; font-size: 11.5px; } .badge.warn { background: #fef3c7; color: #92400e; }
.sec { border-top: 1px solid var(--line2); padding: 8px 0 4px; } .sec:first-child { border-top: 0; }
.sec h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.fld { display: block; margin: 0 0 8px; } .fld > span:first-child { display: block; color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.fld input:not([type=color]):not([type=checkbox]), .fld select, .fld textarea, #sidebar input[type=search], .layer-add input, .modal input:not([type=checkbox]):not([type=color]), .modal select { width: 100%; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; min-width: 0; }
.fld textarea { resize: vertical; }
.fld input:focus, .fld select:focus, .fld textarea:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.inp-u { display: flex; align-items: center; gap: 5px; } .inp-u em { font-style: normal; color: var(--muted); font-size: 11.5px; min-width: 18px; }
.inp-u input[type=color], .fld input[type=color] { width: 36px; height: 28px; padding: 0; border: 1px solid #cbd5e1; border-radius: 6px; background: none; }
.mini { border: 1px solid #cbd5e1; background: #fff; border-radius: 6px; width: 28px; height: 28px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.check { display: flex; align-items: center; gap: 4px; margin: 4px 0 8px; color: var(--text); font-size: 12.5px; }
.btnrow { display: flex; gap: 5px; margin-bottom: 5px; }
.btnrow button, button.wide { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: #fff; border: 1px solid #cbd5e1; border-radius: 7px; padding: 6px 8px; font-size: 12px; }
button.wide { width: 100%; margin-bottom: 5px; }
.btnrow button:hover:not(:disabled), button.wide:hover { background: #eef4fb; border-color: #93c5fd; }
.btnrow .ico { padding: 6px 0; }
button.danger { color: var(--danger); border-color: #fecaca !important; } button.danger:hover { background: #fef2f2 !important; }
button.ico { background: none; border: 1px solid transparent; border-radius: 6px; padding: 3px; display: inline-grid; place-items: center; } button.ico.sm { padding: 2px; }

/* calques */
.layer-row { display: flex; align-items: center; gap: 2px; padding: 3px 4px; border-radius: 7px; border: 1px solid transparent; cursor: pointer; }
.layer-row:hover { background: var(--panel2); } .layer-row.active { background: var(--accent-bg); border-color: #93c5fd; } .layer-row.off .lname { color: #94a3b8; text-decoration: line-through; }
.layer-row button.ico { color: #475569; } .layer-row button.ico:hover:not(:disabled) { background: #fff; border-color: var(--line); } .layer-row button[aria-pressed=false].ico:first-child { color: #94a3b8; }
.layer-row input[type=color] { width: 20px; height: 20px; padding: 0; border: 1px solid #cbd5e1; border-radius: 5px; background: none; flex: none; margin: 0 4px; }
.lname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; } .lcount { font-size: 11px; color: var(--muted); padding: 0 4px; }
.layer-add { display: flex; gap: 6px; margin: 10px 0; } .layer-add button { white-space: nowrap; background: #fff; border: 1px solid #cbd5e1; border-radius: 6px; padding: 5px 8px; }
/* objets / bibliothèque */
details { margin: 6px 0; } summary { cursor: pointer; font-weight: 700; font-size: 12px; padding: 5px 2px; color: #334155; user-select: none; } summary i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; vertical-align: middle; } summary em { font-style: normal; color: var(--muted); font-weight: 400; margin-left: 3px; }
.obj-item { display: flex; gap: 6px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 4px 6px; border-radius: 6px; font-size: 12px; } .obj-item:hover { background: var(--panel2); } .obj-item.sel { background: var(--accent-bg); }
.obj-item .tag { color: var(--muted); font-size: 10.5px; min-width: 58px; } .obj-item .on { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
.lib-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 6px 4px; text-align: center; }
.lib-item:hover { border-color: #93c5fd; background: #f1f7ff; } .lib-item .ln { font-size: 11px; line-height: 1.2; font-weight: 600; } .lib-item .ld { font-size: 10px; color: var(--muted); }
.lib-item .del { position: absolute; right: 3px; top: 1px; color: #94a3b8; font-size: 15px; } .lib-item .del:hover { color: var(--danger); }
#sidebar input[type=search] { margin: 4px 0 8px; }

/* ---------- boîtes de dialogue ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 14px; box-shadow: var(--shadow); width: min(480px, 94vw); max-height: 90vh; color: var(--text); }
dialog.modal.wide { width: min(1100px, 96vw); } dialog.modal::backdrop { background: rgba(15, 23, 42, .5); }
dialog.modal[open] { display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); } .modal-head h3 { margin: 0; font-size: 15px; }
.modal-head .icon { background: none; border: 0; font-size: 16px; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow: auto; } .modal-body label { display: block; margin-bottom: 8px; color: var(--muted); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel2); border-radius: 0 0 14px 14px; }
.modal-foot button { padding: 8px 14px; border: 1px solid #cbd5e1; background: #fff; border-radius: 8px; font-weight: 600; } .modal-foot button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.help-table { border-collapse: collapse; width: 100%; } .help-table th { text-align: left; vertical-align: top; padding: 7px 14px 7px 0; white-space: nowrap; color: var(--accent-dark); width: 150px; } .help-table td { padding: 7px 0; border-bottom: 1px solid var(--line2); line-height: 1.5; }
.projects .proj { display: flex; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 9px; margin-top: 8px; } .projects .proj.current { border-color: #93c5fd; background: #f1f7ff; }
.projects .pi { flex: 1; min-width: 0; display: flex; flex-direction: column; } .projects small { color: var(--muted); }
.projects button { background: #fff; border: 1px solid #cbd5e1; border-radius: 7px; padding: 5px 10px; }
.print-grid { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; min-height: 60vh; }
.print-side label { margin-bottom: 8px; } .print-side .check { color: var(--text); }
.print-preview { background: #cbd5e1; border-radius: 10px; padding: 14px; display: grid; place-items: center; min-height: 360px; max-height: 70vh; overflow: hidden; }
.print-warn { color: #b45309; background: #fffbeb; border-radius: 7px; padding: 0; font-size: 12px; margin: 6px 0; } .print-warn:not(:empty) { padding: 7px 9px; }
.print-info { color: var(--muted); font-size: 12px; }

.toasts { position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 3000; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 12px; align-items: center; background: #0f172a; color: #fff; padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow); max-width: min(560px, 92vw); transition: opacity .3s, transform .3s; }
.toast.ok { background: #14532d; } .toast.warn { background: #78350f; } .toast.error { background: #7f1d1d; } .toast.out { opacity: 0; transform: translateY(8px); }
.toast .link { background: none; border: 0; color: #7dd3fc; text-decoration: underline; }
#splash { position: fixed; inset: 0; background: var(--top); color: #cfe0f1; display: grid; place-items: center; z-index: 5000; transition: opacity .35s; text-align: center; } #splash.gone { opacity: 0; pointer-events: none; }
.spin { width: 34px; height: 34px; border: 3px solid #31567a; border-top-color: #7dd3fc; border-radius: 50%; margin: 0 auto 12px; animation: sp 0.8s linear infinite; } @keyframes sp { to { transform: rotate(360deg); } }

/* ---------- adaptatif ---------- */
@media (max-width: 1100px) { #app { grid-template-columns: 54px minmax(0, 1fr) 280px; } .top-btn .lbl { display: none; } #projectName { width: 160px; } }
@media (max-width: 900px) {
  .mobile-only { display: inline-flex; } #app { grid-template-columns: 50px minmax(0, 1fr); position: relative; }
  #sidebar { position: absolute; right: 0; top: 0; bottom: 0; width: min(330px, 92vw); z-index: 30; box-shadow: var(--shadow); transform: translateX(105%); transition: transform .2s; }
  #sidebar.open { transform: none; }
  .brand span, #saveState, .coords { display: none; } #menubar { display: none; }
  #projectName { flex: 1; width: auto; min-width: 0; }
  #topActions { flex: none; } .sep, #topActions .top-btn:not(.primary):not(.only-ic) { display: none; } .spacer { display: none; }
}

/* ---------- impression ---------- */
#printRoot { display: none; }
@media print {
  html, body { background: #fff !important; height: auto !important; overflow: visible !important; display: block !important; }
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block !important; }
  #printRoot svg { display: block; }
}

/* ---------- zones, couleurs, technique, récapitulatif ---------- */
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 0 0 8px; }
.sw { aspect-ratio: 1; border: 1px solid rgba(15, 23, 42, .25); border-radius: 6px; padding: 0; } .sw:hover { transform: scale(1.12); outline: 2px solid var(--accent); }
.connrow { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 8px; }
.cb { display: inline-flex; align-items: center; gap: 3px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px 2px 4px; font-size: 11.5px; color: var(--text); margin: 0; }
.cb:has(input:checked) { background: var(--accent-bg); border-color: #93c5fd; font-weight: 600; }
.cb-EF:has(input:checked) { background: #d8f4ff; border-color: #0284c7; } .cb-EC:has(input:checked) { background: #fee2e2; border-color: #dc2626; } .cb-EL:has(input:checked) { background: #fef3c7; border-color: #ca8a04; }
.help.sub { margin: 2px 0; }
.segs { display: flex; gap: 4px; margin: 4px 0 8px; } .seg { flex: 1; background: #fff; border: 1px solid #cbd5e1; border-radius: 7px; padding: 5px 6px; font-size: 12px; } .seg.on { background: var(--accent-bg); border-color: #93c5fd; color: var(--accent-dark); font-weight: 700; }
.zone-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.zone-chip { display: flex; align-items: center; gap: 7px; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; } .zone-chip:hover { border-color: #93c5fd; background: #f1f7ff; }
.zone-chip i { width: 16px; height: 16px; border-radius: 5px; border: 1px solid rgba(15, 23, 42, .25); flex: none; }
.opt input[type=range] { width: 90px; }
.summary h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent-dark); } .summary h4:first-child { margin-top: 0; }
.sum-table { width: 100%; border-collapse: collapse; font-size: 12.5px; } .sum-table th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 4px 8px; }
.sum-table td { padding: 5px 8px; border-bottom: 1px solid var(--line2); } .sum-table .num { text-align: right; font-variant-numeric: tabular-nums; } .sum-table tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 4px; vertical-align: -1px; border: 1px solid rgba(15, 23, 42, .25); }

.cart-prev { background: #e2e8f0; border-radius: 10px; padding: 10px; margin-bottom: 12px; } .cart-prev svg { width: 100%; height: auto; display: block; background: #fff; box-shadow: 0 1px 6px rgba(15, 23, 42, .2); }
.cart-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; } .cart-form .span2 { grid-column: span 2; }
.cart-form textarea { width: 100%; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; resize: vertical; }
.cart-dlg .btnrow { align-items: center; margin-top: 4px; } .cart-dlg .btnrow button { flex: none; }
.legend-rows { display: grid; gap: 5px; margin: 4px 0 8px; } .legend-row { display: grid; grid-template-columns: 30px 70px minmax(0, 1fr) 26px; gap: 4px; align-items: center; }
.legend-row input[type=color] { width: 30px; height: 26px; padding: 0; border: 1px solid #cbd5e1; border-radius: 5px; background: none; }
@media (max-width: 800px) { .cart-form { grid-template-columns: 1fr 1fr; } }

@media (max-width: 1450px) { #saveState { display: none; } }
