:root {
  --bg: #f5f6f8; --panel: #ffffff; --line: #e3e6ea; --text: #1f2328; --muted: #6b7280;
  --accent: #2f7de1; --accent-soft: #e8f1fd; --danger: #c43d3d;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: grid; grid-template-rows: 52px 1fr 30px; background: var(--bg); overflow: hidden; }
button { font: inherit; color: inherit; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover:not(:disabled) { border-color: #c4cad2; background: #fafbfc; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #2569c3; }
button.danger { color: var(--danger); }
input, select { font: inherit; color: inherit; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 8px; }

/* ---------------------------------------------------------------- barre du haut */
.top { display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; border: 0; background: none; padding: 4px 6px; }
button.brand:hover { background: var(--accent-soft); }
.proj-name { border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; font-weight: 600; width: 260px; background: transparent; }
.proj-name:hover, .proj-name:focus { border-color: var(--line); background: #fff; outline: none; }
.save-state { color: var(--muted); font-size: 12px; min-width: 60px; }
.group { display: flex; gap: 6px; }
.top .group:first-of-type { margin-left: auto; }
body.at-home .proj-only { display: none !important; }
body.at-home .account { margin-left: auto; }
.views { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.views button { border: 0; border-radius: 0; padding: 6px 12px; }
.views button + button { border-left: 1px solid var(--line); }
.views button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; min-width: 250px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------------------------------------------------------------- panneaux */
main { display: grid; grid-template-columns: 268px 1fr 280px; min-height: 0; }
aside { background: var(--panel); overflow-y: auto; padding: 0 14px 14px; }
.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.right { border-left: 1px solid var(--line); }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tools button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px 5px; font-size: 11px; }
.tools svg { width: 22px; height: 22px; fill: #3d434b; stroke: #3d434b; }
.tools button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tools button.on svg { fill: var(--accent); stroke: var(--accent); }
.lib { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.lib input[type=search] { width: 100%; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; }
.cats { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.cats button { padding: 3px 8px; font-size: 12px; border-radius: 12px; }
.cats button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.lib-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lib-item { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; text-align: center; }
.lib-item canvas, .lib-item img { width: 100%; max-width: 108px; aspect-ratio: 4 / 3; height: auto; border-radius: 4px; }
.lib-item { position: relative; }
.lib-item .del { position: absolute; top: 2px; right: 6px; color: var(--muted); font-size: 16px; line-height: 1; }
.lib-item .del:hover { color: var(--danger); }
.lib-item span { font-size: 12px; line-height: 1.2; }
.lib-item em { font-style: normal; font-size: 11px; color: var(--muted); }

.right .f { display: flex; flex-direction: column; gap: 3px; margin-bottom: 9px; }
.right .f > span { font-size: 12px; color: var(--muted); }
.right .f input[type=text], .right .f select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; width: 100%; }
.right .f input[type=color] { width: 100%; height: 31px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; }
.in { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.in input { border: 0; padding: 5px 8px; width: 100%; min-width: 0; outline: none; }
.in em { font-style: normal; color: var(--muted); padding: 0 8px; font-size: 12px; }
.in:focus-within { border-color: var(--accent); }
.f.info { flex-direction: row; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.sub { margin: -6px 0 10px; color: var(--muted); font-size: 12px; }
.tip { color: var(--muted); font-size: 12px; line-height: 1.45; }
.rooms { list-style: none; padding: 0; margin: 0; }
.rooms li { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.rooms li:hover { background: var(--accent-soft); }
.rooms em { font-style: normal; color: var(--muted); }

/* ---------------------------------------------------------------- scène */
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
.stage canvas[hidden] { display: none; }
.hud { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 10px; align-items: center; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px 6px 12px; font-size: 12px; color: #374151; }
.hud[hidden] { display: none; }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 32px; height: 32px; padding: 0; font-size: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
body.in3d #btnZoomIn, body.in3d #btnZoomOut { display: none; }

/* ---------------------------------------------------------------- barre d'état */
.status { display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.status #stTool { overflow: hidden; text-overflow: ellipsis; }
.status .spacer { flex: 1; }
.status label { display: flex; align-items: center; gap: 4px; }
.status select { font-size: 12px; padding: 1px 2px; }
#stPos { min-width: 150px; font-variant-numeric: tabular-nums; white-space: pre; }

/* ---------------------------------------------------------------- dialogues */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0 18px 16px; width: min(560px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(20,24,30,.35); }
dialog header { display: flex; justify-content: space-between; align-items: center; }
dialog h2 { font-size: 17px; }
dialog .close { border: 0; font-size: 20px; }
dialog .f { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 12px; }
dialog .f span { font-size: 12px; color: var(--muted); }
dialog .f input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; }
.open-list { max-height: 60vh; overflow-y: auto; }
.proj { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.proj > div { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.proj em { font-style: normal; font-size: 12px; color: var(--muted); }

.toasts { position: fixed; top: 62px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; }
.toast { background: #1f2937; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }

/* ---------------------------------------------------------------- revêtements, finitions, IA, compte */
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.swatch { padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; line-height: 0; }
.swatch canvas { width: 100%; aspect-ratio: 1; height: auto; display: block; }
.swatch.on { border-color: var(--accent); }
.finishes { display: flex; flex-wrap: wrap; gap: 6px; }
.finish { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.finish.on { box-shadow: 0 0 0 2px var(--accent); }
.ai-btn { width: 100%; margin-bottom: 8px; background: linear-gradient(90deg, #2f7de1, #7b5cd6); color: #fff; border: 0; font-weight: 600; padding: 8px; }
.ai-btn:hover:not(:disabled) { background: linear-gradient(90deg, #2569c3, #6a4cc4); }
dialog.ai { width: min(640px, 94vw); }
dialog.ai textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.ai-preview { width: 100%; height: 320px; display: block; border-radius: 10px; margin-top: 8px; background: #dbe5ef; }
.account[hidden] { display: none !important; }
.account { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- connexion */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; overflow: auto; }
.login-box .tip { margin: 4px 0 14px; }
.login-box { display: block; grid-template-columns: none; min-height: 0; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px 30px; width: min(380px, 92vw); box-shadow: 0 12px 40px rgba(0,0,0,.08); }
.login-box .brand { font-size: 20px; margin-bottom: 6px; }
.login-box .f { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; }
.login-box .f span { font-size: 12px; color: var(--muted); }
.login-box input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.login-box button { width: 100%; padding: 9px; margin-top: 6px; }
.login-error { color: var(--danger); font-size: 13px; }

/* ---------------------------------------------------------------- accueil : mes projets */
.home { position: fixed; inset: 52px 0 0 0; z-index: 15; background: var(--bg); overflow-y: auto; }
.home[hidden] { display: none; }
.home-in { max-width: 1180px; margin: 0 auto; padding: 26px 28px 60px; }
.home-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.home-head h1 { font-size: 24px; margin: 0; flex: 1; }
.home-head input { width: 260px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; }
.home h2 { font-size: 15px; margin: 34px 0 12px; color: #374151; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.pcard:hover { box-shadow: 0 10px 28px rgba(0,0,0,.1); transform: translateY(-2px); }
.pcard .pic { aspect-ratio: 3 / 2; background: #eef1f4; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pcard .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.pcard .body b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .body em { font-style: normal; font-size: 12px; color: var(--muted); }
.pcard .acts { display: flex; gap: 4px; margin-top: 8px; }
.pcard .acts button { font-size: 12px; padding: 3px 8px; }
.pcard.new .pic { font-size: 54px; color: var(--accent); background: var(--accent-soft); font-weight: 300; }
.pcard.draft { border-style: dashed; }

.lib-list .fam { grid-column: 1 / -1; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 8px 0 0; }
.hud-top { top: 12px; bottom: auto; }
