:root{
  --ink:#0e1726;
  --ink-2:#3d4a5c;
  --muted:#8492a6;
  --line:#e3e8ef;
  --bg:#f4f6fa;
  --card:#ffffff;
  --brand:#0b6b5f;
  --brand-2:#0e8577;
  --brand-soft:#e6f4f1;
  --gold:#c9a227;
  --radius:14px;
  --shadow:0 1px 2px rgba(16,24,40,.05),0 12px 32px -12px rgba(16,24,40,.14);
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
  font-family:'Inter',system-ui,-apple-system,sans-serif;
  background:var(--bg);color:var(--ink);
  -webkit-font-smoothing:antialiased;
}

/* ---------- APPBAR ---------- */
.appbar{
  position:sticky;top:0;z-index:50;
  display:flex;align-items:center;justify-content:space-between;gap:16px;
  padding:12px 22px;background:rgba(255,255,255,.86);
  backdrop-filter:blur(14px);border-bottom:1px solid var(--line);flex-wrap:wrap;
}
.brand{display:flex;align-items:center;gap:12px}
.brand-mark{
  width:40px;height:40px;border-radius:11px;display:grid;place-items:center;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
  color:#fff;font-weight:800;font-size:19px;font-family:'Playfair Display',serif;
  box-shadow:0 6px 16px -6px rgba(11,107,95,.6);
}
.brand h1{font-size:16px;font-weight:700;letter-spacing:-.2px}
.brand span{font-size:11.5px;color:var(--muted)}
.actions{display:flex;gap:8px;flex-wrap:wrap}

.btn{
  display:inline-flex;align-items:center;gap:7px;
  font:inherit;font-size:13px;font-weight:600;cursor:pointer;
  padding:9px 14px;border-radius:10px;border:1px solid transparent;
  transition:.16s ease;white-space:nowrap;
}
.btn svg{width:16px;height:16px}
.btn.primary{background:linear-gradient(135deg,var(--brand),var(--brand-2));color:#fff;box-shadow:0 8px 20px -8px rgba(11,107,95,.65)}
.btn.primary:hover{transform:translateY(-1px);box-shadow:0 12px 26px -8px rgba(11,107,95,.7)}
.btn.ghost{background:#fff;border-color:var(--line);color:var(--ink-2)}
.btn.ghost:hover{border-color:#c7d0dd;color:var(--ink)}
.btn.outline{background:var(--brand-soft);color:var(--brand);border:1px dashed #a8d5cd;justify-content:center}
.btn.outline:hover{background:#d9ede9}
.btn.small{padding:6px 10px;font-size:12px}
.btn.full{width:100%}

/* ---------- LAYOUT ---------- */
.layout{
  display:grid;grid-template-columns:minmax(400px,1fr) minmax(520px,1.05fr);
  gap:22px;padding:22px;max-width:1680px;margin:0 auto;align-items:start;
}
.panel{min-width:0}

/* ---------- CARDS ---------- */
.card{
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  padding:18px;margin-bottom:16px;box-shadow:var(--shadow);
}
.card h2{
  font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.09em;
  color:var(--brand);margin-bottom:14px;display:flex;align-items:center;gap:8px;
}
.card h2::before{content:'';width:3px;height:14px;border-radius:2px;background:var(--brand)}

.grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.grid.grow{flex:1}
.span2{grid-column:span 2}
.field{display:flex;flex-direction:column;gap:5px}
.field>span{font-size:11.5px;font-weight:600;color:var(--ink-2)}
input,select,textarea{
  font:inherit;font-size:13.5px;color:var(--ink);
  padding:10px 12px;border:1px solid var(--line);border-radius:9px;
  background:#fbfcfe;transition:.15s;width:100%;
}
textarea{resize:vertical;font-size:13px}
input:focus,select:focus,textarea:focus{
  outline:none;border-color:var(--brand-2);background:#fff;
  box-shadow:0 0 0 3px rgba(14,133,119,.13);
}

/* logo */
.logo-row{display:flex;gap:14px;align-items:flex-start}
.logo-drop{
  width:92px;height:92px;flex:none;border-radius:12px;cursor:pointer;
  border:2px dashed #cfd8e3;background:#fbfcfe;display:grid;place-items:center;
  position:relative;overflow:hidden;text-align:center;
  font-size:11px;font-weight:600;color:var(--muted);transition:.16s;
}
.logo-drop:hover{border-color:var(--brand-2);color:var(--brand);background:var(--brand-soft)}
.logo-drop img{position:absolute;inset:0;width:100%;height:100%;object-fit:contain;display:none;background:#fff;padding:4px}

/* lignes */
.lines-head{display:grid;grid-template-columns:1fr 66px 116px 34px;gap:8px;padding:0 2px 7px;font-size:11px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.05em}
.line-row{display:grid;grid-template-columns:1fr 66px 116px 34px;gap:8px;margin-bottom:8px}
.line-row input{padding:9px 10px;font-size:13px}
.line-del{
  border:none;background:#fdecec;color:#c0392b;border-radius:9px;
  cursor:pointer;font-size:15px;font-weight:700;line-height:1;transition:.15s;
}
.line-del:hover{background:#f9d5d5}

/* ---------- APERÇU ---------- */
.preview-panel{
  position:sticky;top:78px;background:#fff;border:1px solid var(--line);
  border-radius:var(--radius);box-shadow:var(--shadow);overflow:hidden;
}
.preview-bar{
  display:flex;align-items:center;gap:6px;padding:11px 14px;
  border-bottom:1px solid var(--line);background:#fafbfd;
}
.dot{width:9px;height:9px;border-radius:50%;background:#dde3ec}
.dot:nth-child(1){background:#ff5f57}.dot:nth-child(2){background:#febc2e}.dot:nth-child(3){background:#28c840}
.preview-title{font-size:11.5px;color:var(--muted);font-weight:600;margin-left:8px;flex:1}
.preview-scroll{padding:20px;background:#eef1f6;max-height:calc(100vh - 150px);overflow:auto}

/* ---------- FEUILLE A4 ---------- */
.sheet{
  background:#fff;width:100%;max-width:794px;margin:0 auto;padding:38px 40px 30px;
  box-shadow:0 10px 34px -12px rgba(16,24,40,.3);border-radius:3px;
  font-size:12.3px;color:#1d2733;line-height:1.5;
  display:flex;flex-direction:column;min-height:1000px;
}
.sheet-head{display:flex;justify-content:space-between;align-items:flex-start;gap:20px;padding-bottom:18px;border-bottom:2px solid var(--brand)}
.sheet-co{display:flex;gap:13px;align-items:flex-start}
.sheet-logo{
  width:56px;height:56px;border-radius:10px;flex:none;display:none;
  background-size:contain;background-repeat:no-repeat;background-position:center;
  border:1px solid var(--line);
}
.sheet-co-name{font-size:16.5px;font-weight:800;letter-spacing:-.3px;color:#0e1726}
.sheet-co-line{font-size:11.5px;color:#5a6879;line-height:1.55}
.sheet-title{text-align:right}
.sheet-title h3{
  font-family:'Playfair Display',serif;font-size:27px;letter-spacing:2.5px;
  color:var(--brand);font-weight:700;line-height:1;
}
.sheet-num{font-size:11.5px;color:#5a6879;margin-top:6px;font-weight:600}

.sheet-meta{display:flex;justify-content:space-between;gap:24px;padding:20px 0 16px}
.meta-label{font-size:9.6px;font-weight:800;text-transform:uppercase;letter-spacing:.11em;color:var(--muted);margin-bottom:5px}
.meta-name{font-size:13.6px;font-weight:700;color:#0e1726}
.meta-line{font-size:11.5px;color:#5a6879;line-height:1.5}
.meta-block.right{min-width:220px}
.meta-block.right .kv{display:flex;justify-content:space-between;gap:14px;font-size:11.5px;padding:3.5px 0;border-bottom:1px dotted #e3e8ef}
.kv span{color:#5a6879}
.kv b{color:#0e1726;font-weight:700}

.sheet-table{width:100%;border-collapse:collapse;margin-top:6px}
.sheet-table th{
  background:var(--brand);color:#fff;font-size:10px;font-weight:700;
  text-transform:uppercase;letter-spacing:.09em;padding:9px 10px;
}
.sheet-table th:first-child{border-radius:7px 0 0 7px}
.sheet-table th:last-child{border-radius:0 7px 7px 0}
.sheet-table td{padding:9.5px 10px;border-bottom:1px solid #eef1f6;font-size:11.8px;vertical-align:top}
.sheet-table tbody tr:nth-child(even) td{background:#fafbfd}
.tl{text-align:left}.tc{text-align:center}.tr{text-align:right}
.col-desc{font-weight:600;color:#0e1726}

.sheet-bottom{display:flex;justify-content:space-between;gap:28px;margin-top:22px;align-items:flex-start}
.sheet-left{flex:1;min-width:0;display:flex;flex-direction:column;gap:14px}
.pay-block,.notes-block,.words-block{
  background:#f8fafc;border-left:3px solid var(--brand);border-radius:0 8px 8px 0;padding:10px 13px;
}
.words{font-size:11.3px;font-weight:600;color:#0e1726;font-style:italic;text-transform:capitalize}
.notes{font-size:11px;color:#5a6879;white-space:pre-wrap}
.sheet-totals{width:270px;flex:none}
.tot{display:flex;justify-content:space-between;gap:14px;padding:7px 12px;font-size:12px;border-bottom:1px solid #eef1f6}
.tot span{color:#5a6879}
.tot b{color:#0e1726;font-weight:700}
.tot.grand{
  background:linear-gradient(135deg,var(--brand),var(--brand-2));color:#fff;
  border-radius:9px;margin-top:8px;padding:12px 14px;border:none;
}
.tot.grand span{color:rgba(255,255,255,.85);font-weight:600;font-size:11.5px;text-transform:uppercase;letter-spacing:.05em}
.tot.grand b{color:#fff;font-size:17px;font-weight:800}

.sheet-sign{margin-top:26px;display:flex;justify-content:flex-end}
.sign-box{width:230px;text-align:center}
.sign-label{font-size:9.6px;font-weight:800;text-transform:uppercase;letter-spacing:.09em;color:var(--muted)}
.sign-space{height:56px;border-bottom:1px solid #cfd8e3;margin:8px 0 6px}
.sign-mention{font-size:10.5px;color:#8492a6;font-style:italic}

.sheet-foot{
  margin-top:auto;padding-top:16px;border-top:1px solid var(--line);
  display:flex;justify-content:space-between;gap:14px;font-size:9.8px;color:#98a6b8;
}

/* ---------- MODALE ---------- */
.modal{position:fixed;inset:0;background:rgba(14,23,38,.5);backdrop-filter:blur(3px);display:none;place-items:center;z-index:100;padding:20px}
.modal.open{display:grid}
.modal-box{background:#fff;border-radius:16px;width:100%;max-width:620px;max-height:80vh;overflow:hidden;display:flex;flex-direction:column;box-shadow:0 30px 70px -20px rgba(14,23,38,.5)}
.modal-head{display:flex;justify-content:space-between;align-items:center;padding:16px 20px;border-bottom:1px solid var(--line)}
.modal-head h3{font-size:15px;font-weight:700}
.modal-body{padding:14px 20px 20px;overflow:auto}
.inv-item{display:flex;align-items:center;gap:14px;padding:13px;border:1px solid var(--line);border-radius:11px;margin-bottom:9px;transition:.15s}
.inv-item:hover{border-color:var(--brand-2);background:#fafefd}
.inv-info{flex:1;min-width:0}
.inv-info b{display:block;font-size:13.5px;color:#0e1726}
.inv-info span{font-size:11.5px;color:var(--muted)}
.inv-amt{font-weight:800;font-size:13.5px;color:var(--brand);white-space:nowrap}
.empty{text-align:center;color:var(--muted);padding:34px 10px;font-size:13px}

/* ---------- TOAST ---------- */
.toast{
  position:fixed;bottom:24px;left:50%;transform:translate(-50%,120%);
  background:var(--ink);color:#fff;padding:12px 22px;border-radius:11px;
  font-size:13.5px;font-weight:600;box-shadow:0 16px 40px -12px rgba(0,0,0,.5);
  transition:.3s cubic-bezier(.2,.8,.3,1);z-index:200;pointer-events:none;
}
.toast.show{transform:translate(-50%,0)}

/* ---------- RESPONSIVE ---------- */
@media(max-width:1180px){
  .layout{grid-template-columns:1fr}
  .preview-panel{position:static}
  .preview-scroll{max-height:none}
}
@media(max-width:640px){
  .layout{padding:14px;gap:14px}
  .appbar{padding:10px 14px}
  .brand span{display:none}
  .actions .btn span{display:none}
  .grid{grid-template-columns:1fr}
  .span2{grid-column:span 1}
  .logo-row{flex-direction:column}
  .lines-head{grid-template-columns:1fr 52px 92px 30px;}
  .line-row{grid-template-columns:1fr 52px 92px 30px}
  .sheet{padding:26px 20px;min-height:auto}
  .sheet-bottom{flex-direction:column}
  .sheet-totals{width:100%}
  .sheet-head{flex-direction:column}
  .sheet-title{text-align:left}
}

/* ---------- IMPRESSION ---------- */
@media print{
  .appbar,.preview-bar,.form-panel,.toast,.modal{display:none!important}
  body{background:#fff}
  .layout{display:block;padding:0;max-width:none}
  .preview-panel{border:none;box-shadow:none;border-radius:0}
  .preview-scroll{padding:0;background:#fff;max-height:none;overflow:visible}
  .sheet{box-shadow:none;max-width:none;min-height:auto;padding:12mm 14mm}
  @page{size:A4;margin:0}
}
