:root {
  --accent: #f59e0b;       /* solaire */
  --accent-dark: #b45309;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
h2 { margin: 0 0 4px; }
h3 { margin: 0 0 12px; font-size: 15px; color: var(--accent-dark); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; background: #fff;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; }
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; }

main { max-width: 980px; margin: 0 auto; padding: 20px; }

/* ---------- Boutons ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
  font-weight: 600; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }

/* ---------- Cards & formulaires ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
input, textarea, select {
  width: 100%; margin-top: 5px; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; font-family: inherit;
  color: var(--ink); background: #fff;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

/* ---------- Éditeur ---------- */
.editor-toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.editor-toolbar .spacer { flex: 1; }
.doc-badge {
  background: var(--accent); color: #fff; font-weight: 800; padding: 6px 12px;
  border-radius: 8px; letter-spacing: .5px;
}
.doc-badge.bl { background: #0369a1; }
.doc-number { font-weight: 700; color: var(--muted); }

/* ---------- Table produits ---------- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
  text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase;
  padding: 6px 8px; border-bottom: 2px solid var(--line);
}
.items-table td { padding: 4px; vertical-align: middle; }
.items-table input { margin-top: 0; }
.items-table .line-total { font-weight: 700; text-align: right; padding-right: 8px; }
.items-table .idx { color: var(--muted); text-align: center; }
.btn-del {
  border: none; background: #fee2e2; color: #b91c1c; width: 30px; height: 30px;
  border-radius: 6px; cursor: pointer; font-weight: 700;
}
.btn-del:hover { background: #fecaca; }

/* ---------- Totaux ---------- */
.totals-box {
  margin-top: 16px; margin-left: auto; width: 320px; max-width: 100%;
}
.totals-box .row {
  justify-content: space-between; align-items: center;
  padding: 8px 4px; border-bottom: 1px solid var(--line);
}
.totals-box .discount-input { width: 120px; margin: 0; text-align: right; }
.totals-box .grand {
  border-bottom: none; font-size: 20px; color: var(--accent-dark); border-top: 2px solid var(--ink);
  margin-top: 4px; padding-top: 12px;
}

/* ---------- Historique ---------- */
.search { max-width: 320px; margin-bottom: 14px; }
.history-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
.history-table th, .history-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.history-table th { background: #fafafa; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.history-table .right { text-align: right; }
.history-table tr:hover { background: #fffbeb; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.pill.devis { background: #fef3c7; color: var(--accent-dark); }
.pill.bl { background: #e0f2fe; color: #0369a1; }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; padding: 5px 9px; font-size: 13px; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.danger:hover { border-color: #ef4444; color: #ef4444; }

.muted { color: var(--muted); }
.saved-msg { color: #16a34a; font-weight: 600; margin-left: 10px; }
#logoPreviewWrap { margin-top: 8px; }
#logoPreview { max-height: 70px; max-width: 200px; display: block; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 8px;
  font-weight: 600; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

/* ============ ZONE D'IMPRESSION ============ */
#print-area { display: none; }

.doc {
  width: 210mm; min-height: 297mm; padding: 16mm 15mm; margin: 0 auto;
  background: #fff; color: #111; font-size: 12px; line-height: 1.45;
}
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--accent); padding-bottom: 14px; }
.doc-company { max-width: 58%; }
.doc-company img { max-height: 70px; max-width: 220px; margin-bottom: 8px; display: block; }
.company-name { font-size: 20px; font-weight: 800; color: var(--accent-dark); }
.company-activity { font-size: 12px; color: #555; margin-bottom: 6px; }
.company-lines { font-size: 11px; color: #444; white-space: pre-line; }
.doc-meta { text-align: right; }
.doc-title { font-size: 26px; font-weight: 800; letter-spacing: 1px; color: #111; }
.doc-title.bl { color: #0369a1; }
.doc-meta table { margin-left: auto; margin-top: 10px; font-size: 12px; }
.doc-meta td { padding: 2px 6px; }
.doc-meta td.k { color: #666; text-align: right; }
.doc-meta td.v { font-weight: 700; }

.doc-client { margin: 18px 0; padding: 12px 14px; background: #f9fafb; border: 1px solid #eee; border-radius: 6px; }
.doc-client .label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #888; margin-bottom: 4px; }
.doc-client .cname { font-size: 14px; font-weight: 700; }
.doc-client .cline { color: #444; }

table.print-items { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.print-items th {
  background: var(--accent); color: #fff; padding: 8px 10px; font-size: 11px;
  text-transform: uppercase; text-align: left;
}
table.print-items th.num, table.print-items td.num { text-align: right; }
table.print-items th.center, table.print-items td.center { text-align: center; }
table.print-items td { padding: 8px 10px; border-bottom: 1px solid #eee; }
table.print-items tbody tr:nth-child(even) { background: #fafafa; }

.print-totals { margin-top: 14px; margin-left: auto; width: 46%; }
.print-totals .r { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px solid #eee; }
.print-totals .r.grand { border-bottom: none; border-top: 2px solid #111; font-size: 16px; font-weight: 800; color: var(--accent-dark); padding-top: 10px; }

.print-notes { margin-top: 18px; font-size: 11px; }
.print-notes .h { font-weight: 700; margin-bottom: 3px; }

.doc-footer { margin-top: 30px; display: flex; justify-content: space-between; align-items: flex-end; }
.signature { width: 45%; }
.signature .sig-label { font-weight: 700; margin-bottom: 46px; }
.signature .sig-line { border-top: 1px solid #999; }
.legal { font-size: 9px; color: #777; text-align: right; width: 52%; white-space: pre-line; }

/* ============ IMPRESSION ============ */
@media print {
  .no-print, .app { display: none !important; }
  body { background: #fff; }
  #print-area { display: block; }
  .doc { width: auto; min-height: auto; padding: 0; margin: 0; }
  @page { size: A4; margin: 12mm; }
}

@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; }
  .row { flex-direction: column; }
}
