:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --ink: #1d2430;
  --muted: #6b7380;
  --line: #d9dde3;
  --accent: #0f5c8c;
  --accent-soft: #e3eff7;
  --field: rgba(255, 214, 64, .18);
  --field-line: rgba(196, 150, 0, .55);
  --filled: rgba(46, 160, 90, .10);
  --calc: rgba(15, 92, 140, .12);
  --danger: #b3261e;
  --k: 1.5; /* pixels par point PDF, mis à jour en JS */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 "Segoe UI", Tahoma, Arial, sans-serif; color: var(--ink); background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: var(--surface); border-bottom: 1px solid var(--line); height: 54px;
}
.brand { font-weight: 600; font-size: 16px; }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.back { text-decoration: none; font-size: 20px; color: var(--ink); padding: 0 6px; }
.title-input { font-size: 15px; font-weight: 600; border: 1px solid transparent; padding: 5px 8px; border-radius: 6px; width: 280px; }
.taxpayer-input { border: 1px solid transparent; padding: 5px 8px; border-radius: 6px; width: 200px; color: var(--muted); }
.title-input:hover, .taxpayer-input:hover { border-color: var(--line); }
.status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.status.dirty { color: #a66b00; }
.status.err { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  font: inherit; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #b7bec8; background: #f7f8fa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0c4d76; }
.btn.danger { color: var(--danger); }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.icon { padding: 4px 9px; }
.zoom { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.toggle { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* ---------- Accueil ---------- */
.home-main { max-width: 1100px; margin: 24px auto; padding: 0 16px; display: grid; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.new-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.new-form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.new-form input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font: inherit; min-width: 220px; }
.new-form input[type=number] { min-width: 90px; width: 90px; }
.list { width: 100%; border-collapse: collapse; }
.list th, .list td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.list th { font-size: 12px; color: var(--muted); font-weight: 600; }
.list a { color: var(--accent); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.actions form { margin: 0; }
.muted { color: var(--muted); }

/* ---------- Éditeur ---------- */
body.editor { overflow: hidden; }
.layout { display: grid; grid-template-columns: 74px 1fr 340px; height: calc(100vh - 54px); }
.thumbs { overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface); padding: 8px 6px; }
.thumb { display: block; width: 100%; margin-bottom: 6px; padding: 6px 0; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer; text-align: center; font: inherit; font-size: 12px; color: var(--ink); }
.thumb b { display: block; font-size: 15px; }
.thumb small { color: var(--muted); }
.thumb.current { border-color: var(--accent); background: var(--accent-soft); }

.pages { overflow: auto; padding: 18px; }
.page {
  position: relative; margin: 0 auto 18px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15);
  user-select: none;
}
.page > img { display: block; width: 100%; height: 100%; pointer-events: none; }
.page.adding { cursor: crosshair; }
.page .draw { position: absolute; border: 1.5px dashed var(--accent); background: rgba(15,92,140,.08); pointer-events: none; }

.static {
  position: absolute; pointer-events: none; direction: rtl; text-align: right;
  font-family: Arial, sans-serif; font-size: calc(var(--k) * 9.5px); line-height: 1;
  display: flex; align-items: center; padding: 0 calc(var(--k) * 3px); color: #000;
}
.static.border { border: calc(var(--k) * 0.6px) solid #000; }
.static.bold { font-weight: 700; }
.f {
  position: absolute; border: 1px solid var(--field-line); background: var(--field);
  font-family: Arial, sans-serif; font-size: calc(var(--k) * 8.5px); color: #0b2a6b;
  padding: 0 calc(var(--k) * 1.5px); margin: 0; outline: none; border-radius: 2px; line-height: 1;
}
.f:hover { border-color: #c48a00; }
.f:focus, .f.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(15,92,140,.35); background: #fff; z-index: 3; }
.f.has { background: var(--filled); border-color: rgba(46,160,90,.6); }
.f.calc { background: var(--calc); border-color: rgba(15,92,140,.6); font-weight: 600; }
.f.err { background: rgba(179,38,30,.12); border-color: var(--danger); }
.f.hiddenf { opacity: .35; border-style: dashed; }
.f.custom { border-style: dashed; }
input.f.box { text-align: center; font-weight: 700; font-size: calc(var(--k) * 10px); }
.comb { position: absolute; }
.comb input {
  position: absolute; top: 0; height: 100%; text-align: center; border: 1px solid var(--field-line);
  background: var(--field); font-family: Arial, sans-serif; font-size: calc(var(--k) * 9px); color: #0b2a6b;
  outline: none; padding: 0; border-radius: 2px;
}
.comb input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px rgba(15,92,140,.35); z-index: 3; }
.comb.has input { background: var(--filled); }
.comb.sel input { border-color: var(--accent); }
.comb.hiddenf { opacity: .35; }

.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 6px rgba(255,170,0,.8); } 100% { box-shadow: 0 0 0 0 rgba(255,170,0,0); } }

/* ---------- Panneau ---------- */
.panel { border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.inspector { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.inspector h3, .pagefields h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.inspector .lbl { font-size: 15px; direction: rtl; text-align: right; margin: 0 0 6px; font-weight: 600; min-height: 1em; }
.inspector .fid { font-size: 11px; color: var(--muted); font-family: Consolas, monospace; }
.inspector label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; }
.inspector input[type=text], .inspector textarea, .inspector select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit;
}
.inspector textarea { min-height: 54px; resize: vertical; }
.inspector .formula { font-family: Consolas, monospace; font-size: 13px; }
.inspector .row { display: flex; gap: 8px; }
.inspector .row > * { flex: 1; }
.inspector .result { margin-top: 6px; font-size: 13px; }
.inspector .result.err { color: var(--danger); }
.inspector .buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.inspector .help { font-size: 12px; color: var(--muted); margin-top: 6px; }
.inspector code { background: #f1f3f5; padding: 0 3px; border-radius: 3px; }

.pagefields { padding: 12px 16px; display: flex; flex-direction: column; min-height: 0; flex: 1; }
.pagefields input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; font: inherit; }
#fieldList { overflow-y: auto; flex: 1; }
.fl { display: grid; grid-template-columns: 1fr 120px; gap: 6px; align-items: center; padding: 4px 0; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.fl:hover { background: #f8f9fb; }
.fl .l { direction: rtl; text-align: right; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl .l small { color: var(--muted); font-family: Consolas, monospace; direction: ltr; unicode-bidi: isolate; }
.fl input { margin: 0 !important; padding: 3px 6px !important; font-size: 12px !important; width: 100%; }
.fl.calc input { background: var(--calc); font-weight: 600; }

/* ---------- Connexion ---------- */
.auth { max-width: 420px; margin: 12vh auto; padding: 0 16px; }
.auth .card { display: grid; gap: 12px; }
.auth h2 { margin: 0; }
.auth p { margin: 0; }
.auth label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.auth input[type=password] { padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 15px; }
.auth .btn { justify-content: center; padding: 9px 12px; }
.error { color: var(--danger); font-weight: 600; }
