:root {
  --red: #c62828; --red-d: #8e0000;
  --navy: #1f2a37; --navy-2: #2b3a4b;
  --bg: #f3f4f6; --panel: #ffffff; --line: #dfe3e8; --line-2: #eceff3;
  --text: #1f2933; --muted: #6b7785;
  --accent: #1565c0; --ok: #2e7d32; --warn: #e65100;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { margin: 0; font-size: 22px; }
h3 { font-size: 16px; margin: 22px 0 8px; }
h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); }
.grow { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
kbd { background: #f1f3f5; border: 1px solid #d0d5db; border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; font-size: 12px; font-family: inherit; }

/* ---------- en-tête */
#header { display: flex; align-items: center; gap: 18px; height: 48px; padding: 0 16px; background: var(--navy); color: #fff; }
#header:empty { display: none; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff !important; font-weight: 700; font-size: 17px; text-decoration: none !important; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--red); color: #fff; font-weight: 800; }
.logo.big { width: 52px; height: 52px; font-size: 28px; border-radius: 12px; }
#header nav { display: flex; gap: 4px; }
#header nav a { color: #cfd6de; padding: 6px 12px; border-radius: 6px; text-decoration: none; }
#header nav a:hover { background: var(--navy-2); color: #fff; }
#header nav a.active { background: var(--navy-2); color: #fff; box-shadow: inset 0 -2px 0 var(--red); }
.user-menu { display: flex; gap: 6px; }
body.editor-mode #header { display: none; }

/* ---------- boutons & champs */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 6px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: #b8c0ca; background: #fafbfc; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.danger { background: #b71c1c; border-color: #b71c1c; color: #fff; }
.btn.danger-outline { color: #b71c1c; }
.btn.danger-outline:hover { border-color: #b71c1c; background: #fff5f5; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost.light { color: #cfd6de; }
.btn.ghost.light:hover { color: #fff; background: var(--navy-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 3px 6px; border-radius: 4px; color: var(--muted); font-size: 14px; }
.icon-btn:hover { background: #eef1f4; color: var(--text); }
.icon-btn.off { opacity: .45; }
.icon-btn.on { color: var(--warn); }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(21,101,192,.25); border-color: var(--accent); }
input[type=color] { padding: 2px; height: 30px; width: 44px; }
input[type=checkbox], input[type=radio] { accent-color: var(--red); }
.search { width: 260px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 600; color: #46525f; }
.field small { color: var(--muted); font-size: 11.5px; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0 12px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2 .span2 { grid-column: 1 / -1; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #e3f2fd; color: #0d47a1; }
.badge.done { background: #e8f5e9; color: #1b5e20; }
.badge.arch { background: #eceff1; color: #546e7a; }
.tag { font-size: 10.5px; padding: 1px 6px; border-radius: 8px; background: #fff3e0; color: #e65100; margin-left: 6px; white-space: nowrap; }

/* ---------- pages */
.page { max-width: 1280px; margin: 0 auto; padding: 22px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.toolbar-row { display: flex; gap: 10px; align-items: center; margin: 12px 0 16px; flex-wrap: wrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); grid-column: 1/-1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.affaire-card { padding: 14px 16px; color: inherit; text-decoration: none !important; display: flex; flex-direction: column; gap: 3px; transition: border-color .15s, transform .15s; }
.affaire-card:hover { border-color: var(--red); transform: translateY(-1px); }
.affaire-card h3 { margin: 6px 0 2px; }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.num { font-variant-numeric: tabular-nums; }
.card-top .num { font-weight: 700; color: var(--red); }
.card-foot { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line-2); font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.tabs a { padding: 9px 16px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--red); font-weight: 600; }
.tab-body.drop { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 6px; }
.plans { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.plan-card { display: flex; flex-direction: column; overflow: hidden; }
.thumb { height: 190px; background: #f7f8fa; display: grid; place-items: center; border-bottom: 1px solid var(--line-2); overflow: hidden; }
.thumb canvas { max-width: 100%; max-height: 186px; box-shadow: 0 1px 4px rgba(0,0,0,.15); background: #fff; }
.blank-thumb { font-size: 46px; color: #b0bec5; }
.plan-info { padding: 10px 14px 4px; }
.plan-name { font-weight: 600; font-size: 15px; color: var(--text); }
.plan-actions { display: flex; gap: 6px; padding: 8px 14px 12px; flex-wrap: wrap; }
.spinner { width: 26px; height: 26px; border: 3px solid #cfd8dc; border-top-color: var(--red); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.info-table { border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); min-width: 520px; }
.info-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 9px 16px; width: 200px; border-bottom: 1px solid var(--line-2); }
.info-table td { padding: 9px 16px; border-bottom: 1px solid var(--line-2); white-space: pre-wrap; }

/* tableaux */
.qt { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.qt th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; background: #f8f9fb; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.qt td { padding: 7px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.qt .num { text-align: right; white-space: nowrap; }
.qt tr.cat td { background: #fafbfc; font-weight: 600; font-size: 12px; color: #46525f; }
.qt tfoot td { font-weight: 700; background: #f8f9fb; }
.qt td.ico { width: 46px; text-align: center; color: #1a237e; }
.qt td.ico svg { display: block; margin: auto; }
.qt.compact td { padding: 5px 6px; font-size: 12.5px; }
.qt tr.clickable { cursor: pointer; }
.qt tr.clickable:hover td { background: #fff8e1; }
.lib-table td { font-size: 13px; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1f2a37 0%, #2b3a4b 60%, #4a1c1c 100%); }
.login-card { width: 380px; background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-logo { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.login-logo h1 { margin: 0; font-size: 24px; }
.login-logo p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.login-error { color: #b71c1c; min-height: 20px; margin-bottom: 8px; font-size: 13px; }

/* modales / toasts */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,32,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 10px; width: 460px; max-width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: 720px; }
.modal.xwide { width: 1120px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px; overflow: auto; }
.modal-body p:first-child { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line-2); background: #fafbfc; border-radius: 0 0 10px 10px; }
#toasts { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; align-items: center; }
.toast { background: #263238; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 560px; transition: opacity .3s; }
.toast.success { background: #1b5e20; }
.toast.error { background: #b71c1c; }
.toast.out { opacity: 0; }
.print-info { background: #f1f8e9; border: 1px solid #c5e1a5; padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 6px; }

/* ---------- éditeur */
body.editor-mode { overflow: hidden; }
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--navy); color: #fff; flex-wrap: wrap; min-height: 48px; }
.ed-title { display: flex; flex-direction: column; line-height: 1.2; margin-right: 8px; max-width: 260px; }
.ed-title a { color: #9fb3c8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-title .muted { color: #9fb3c8; font-size: 12px; }
.tb-group { display: flex; gap: 2px; padding: 0 6px; border-left: 1px solid #3a4b5e; align-items: center; }
.tool { width: 34px; height: 32px; border: 1px solid transparent; background: transparent; color: #dfe6ee; border-radius: 6px; cursor: pointer; font-size: 16px; display: grid; place-items: center; }
.tool:hover { background: var(--navy-2); }
.tool.active { background: var(--red); color: #fff; }
.tool.toggle.on { border-color: #64b5f6; color: #90caf9; }
.btn.tb { background: var(--navy-2); color: #e3e9ef; border-color: #3a4b5e; }
.btn.tb:hover { background: #34475c; }
.btn.tb.primary { background: var(--red); border-color: var(--red); color: #fff; }
.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; top: 34px; left: 0; background: #fff; color: var(--text); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 290px; z-index: 50; padding: 5px; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 5px; cursor: pointer; font: inherit; }
.dropdown-menu button:hover { background: #f1f4f7; }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--line-2); margin: 4px 0; }
.save-state { font-size: 12px; padding: 4px 10px; border-radius: 12px; }
.save-state.ok { color: #a5d6a7; }
.save-state.warn { color: #ffcc80; }
.save-state.busy { color: #90caf9; }
.save-state.err { background: #b71c1c; color: #fff; }
.ed-main { flex: 1; display: flex; min-height: 0; }
.ed-left { width: 236px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.ed-left > input { margin: 0 8px 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 10px 8px; font-weight: 600; }
.palette-list { overflow: auto; flex: 1; padding: 0 6px 20px; }
.pal-sec { margin-bottom: 4px; }
.pal-sec summary { cursor: pointer; font-size: 12px; font-weight: 600; color: #46525f; padding: 6px 4px; text-transform: uppercase; letter-spacing: .04em; }
.pal-grid { display: flex; flex-direction: column; gap: 1px; }
.pal-item { display: flex; align-items: center; gap: 8px; border: 1px solid transparent; background: none; padding: 3px 6px; border-radius: 6px; cursor: pointer; text-align: left; font: inherit; font-size: 12.5px; color: var(--text); }
.pal-item:hover { background: #f3f6f9; }
.pal-item.active { background: #ffebee; border-color: #ef9a9a; }
.pal-icon { width: 30px; height: 30px; display: grid; place-items: center; color: #1a237e; flex: none; }
.pal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-center { flex: 1; position: relative; min-width: 0; overflow: hidden; }
.ed-canvas { display: block; touch-action: none; outline: none; }
.ed-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(255,243,224,.97); border: 1px solid #ffcc80; color: #7a3d00; padding: 7px 14px; border-radius: 8px; font-size: 13px; display: none; pointer-events: none; max-width: 80%; text-align: center; }
.ed-input { position: absolute; top: 10px; left: 10px; background: #fff; border: 1px solid var(--accent); border-radius: 8px; padding: 6px 8px; gap: 8px; align-items: center; box-shadow: var(--shadow); }
.ed-input input { width: 100px; }
.ed-right { width: 290px; background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.right-tabs { display: flex; border-bottom: 1px solid var(--line); }
.right-tabs button { flex: 1; border: 0; background: none; padding: 10px 4px; cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.right-tabs button.active { color: var(--text); border-bottom-color: var(--red); font-weight: 600; }
.ed-right-body { overflow: auto; flex: 1; padding: 4px 12px 30px; }
.prop { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 6px; margin-bottom: 7px; font-size: 13px; }
.prop > span { color: #46525f; font-size: 12px; }
.prop small { grid-column: 2; color: var(--muted); font-size: 11px; margin-top: -4px; }
.prop input, .prop select { width: 100%; padding: 4px 7px; }
.prop .inline { display: flex; align-items: center; gap: 4px; }
.prop-head { display: flex; gap: 10px; align-items: center; margin: 12px 0; color: #1a237e; }
.prop-head b { color: var(--text); }
.prop-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 6px; }
.metric { font-size: 13px; margin: 4px 0 8px; padding: 6px 8px; background: #f5f8fb; border-radius: 6px; }
.tips { padding-left: 18px; margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.layers { display: flex; flex-direction: column; gap: 2px; }
.layer-row { display: flex; align-items: center; gap: 4px; padding: 3px 4px; border-radius: 6px; }
.layer-row.current { background: #fff3e0; }
.layer-row input[type=color] { width: 26px; height: 22px; border: 0; padding: 0; }
.layer-name { flex: 1; cursor: default; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.ed-status { display: flex; gap: 18px; align-items: center; height: 26px; padding: 0 12px; background: #fff; border-top: 1px solid var(--line); font-size: 12px; color: #46525f; white-space: nowrap; overflow: hidden; }
.ed-status .grow { overflow: hidden; text-overflow: ellipsis; }
.ed-status .link { cursor: pointer; }
.ed-status .link:hover { text-decoration: underline; }
.ed-status .warn { color: var(--warn); font-weight: 600; }

/* éditeur de symbole */
.sym-editor { display: grid; grid-template-columns: 1fr 330px; gap: 18px; }
.sym-left { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sym-tools { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.sym-tools .btn.active { background: var(--red); color: #fff; border-color: var(--red); }
.sym-canvas { width: 100%; aspect-ratio: 1; max-height: 62vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: crosshair; }
.sym-right { min-width: 0; }
.sym-preview { width: 70px; height: 70px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; }
.sym-items { display: flex; flex-direction: column; gap: 2px; max-height: 160px; overflow: auto; margin-bottom: 8px; }
.sym-item { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 5px; cursor: pointer; font-size: 12.5px; }
.sym-item span:first-child { flex: 1; }
.sym-item:hover { background: #f3f6f9; }
.sym-item.sel { background: #fff3e0; }
.sym-right textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 12px; }

@media (max-width: 1100px) {
  .ed-right { width: 240px; }
  .ed-left { width: 200px; }
  .sym-editor { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .ed-left, .ed-right { display: none; }
  .page { padding: 16px 12px 40px; }
  .search { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
}
@media print { #header { display: none; } }
.field input, .field select, .field textarea { width: 100%; }
.sym-canvas { display: block; margin: 0 auto; width: auto; height: min(62vh, 640px); max-width: 100%; }
