:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1c2530; --muted: #6b7684; --line: #d9dee4;
  --dark: #1f2a37; --tile: #525f6e; --accent: #3b4fd8; --danger: #c0392b; --ok: #1e8e5a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: inherit; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 54px; background: var(--dark); color: #fff; }
.brand { font-weight: 700; text-decoration: none; font-size: 18px; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a { text-decoration: none; padding: 8px 12px; border-radius: 8px; color: #c9d1db; white-space: nowrap; }
.topbar nav a.on { background: rgba(255,255,255,.14); color: #fff; }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 120px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
input, select, textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); width: 100%; }
textarea { min-height: 110px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 10px 16px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-decoration: none; }
a.item:hover { border-color: var(--accent); }
.letter { margin: 14px 4px 2px; font-weight: 700; color: var(--muted); }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.badge.en_cours { background: #fff1d6; color: #9a6200; }
.badge.facture { background: #d8f3e6; color: var(--ok); }
.price { font-weight: 700; white-space: nowrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile .body { padding: 14px; flex: 1; }
.tile .nom { font-weight: 600; text-transform: uppercase; font-size: 14px; }
.tile .tarif { font-size: 18px; font-weight: 700; margin-top: 4px; }
.tile .foot { background: var(--tile); padding: 10px 12px; }
.stepper { display: inline-flex; align-items: center; background: #fff; border-radius: 99px; padding: 2px; }
.stepper button { width: 40px; height: 38px; border: 0; background: none; font-size: 22px; cursor: pointer; border-radius: 99px; }
.stepper span { min-width: 30px; text-align: center; font-weight: 600; }
.cols { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.pec-num { font-size: 26px; font-weight: 800; }
.line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.line.piece { margin-left: 28px; font-style: italic; }
.line .tools { display: flex; gap: 8px; align-items: center; }
.total-line { display: flex; justify-content: space-between; font-size: 20px; font-weight: 800; padding-top: 14px; }
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #fff; border-top: 1px solid var(--line); padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bar .total { font-size: 22px; font-weight: 800; }
.menu-wrap { position: relative; }
.menu { display: none; position: absolute; right: 0; bottom: 100%; padding-bottom: 8px; min-width: 240px; }
.menu-inner { background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.15); overflow: hidden; }
.menu-wrap:hover .menu, .menu-wrap.open .menu { display: block; }
.menu button, .menu a { display: block; width: 100%; text-align: left; font: inherit; padding: 12px 16px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: var(--ink); }
.menu button:hover, .menu a:hover { background: var(--bg); }
.menu .danger { color: var(--danger); }
.sticky-tools { position: sticky; top: 54px; background: var(--bg); padding: 10px 0; z-index: 5; }
.inline-form { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--dark); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50; }

/* ---------- facture ---------- */
.invoice-actions { margin-bottom: 14px; display: flex; gap: 10px; }
.invoice { background: #fff; max-width: 800px; margin: 0 auto; padding: 40px; border: 1px solid var(--line); color: #000; }
.invoice .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 2px solid #000; padding-bottom: 14px; margin-bottom: 20px; }
.invoice .head h1 { margin: 0; font-size: 26px; }
.invoice .body { display: grid; grid-template-columns: 1.6fr 1fr; gap: 30px; }
.invoice .client { font-size: 14px; line-height: 1.5; }
.invoice .client .com { margin-top: 12px; padding-top: 10px; border-top: 1px solid #ccc; white-space: pre-wrap; font-size: 13px; }
.invoice .sub { font-weight: 700; margin: 14px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.invoice .line { font-size: 14px; }

@media (max-width: 760px) {
  .cols { grid-template-columns: 1fr; }
  .cols .side { order: -1; }
  .inline-form { grid-template-columns: 1fr 90px; }
  .inline-form .btn { grid-column: 1 / -1; }
  .invoice { padding: 20px; }
  .invoice .body { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .invoice-actions, .bar, .no-print { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .invoice { border: 0; padding: 0; max-width: none; }
  .report-page { break-inside: avoid; }
}
