:root {
  --bg: #f4f5f7;
  --panel: #fff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #dfe3ea;
  --brand: #0b3d91;
  --brand-2: #e8eefb;
  --ok: #157347;
  --ok-bg: #e6f4ec;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand); }

.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--brand); color: #fff; padding: 0 20px; height: 52px;
  position: sticky; top: 0; z-index: 10;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; letter-spacing: .5px; }
.brand span { font-weight: 400; opacity: .8; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #fff; text-decoration: none; padding: 6px 12px; border-radius: 6px; opacity: .85; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.15); opacity: 1; }
.user { font-size: 13px; opacity: .8; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 80px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); border-color: var(--brand); }
input[type=checkbox] { width: auto; margin-right: 6px; }
.check { display: flex; align-items: center; font-size: 14px; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 500; margin: 0; cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button, .btn {
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--brand); }
.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.success { background: var(--ok); color: #fff; border-color: var(--ok); }
.danger { color: var(--danger); border-color: #f3c3bd; }
.small { padding: 4px 8px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; padding: 10px; border-bottom: 2px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f8faff; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--brand-2); color: var(--brand); }
.badge.BROUILLON { background: var(--warn-bg); color: var(--warn); }
.badge.VALIDE { background: var(--ok-bg); color: var(--ok); }
.badge.ANNULE { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: #eef0f3; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

/* éditeur de lignes */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.lines td { padding: 4px; vertical-align: top; }
table.lines td.amount { padding-top: 12px; white-space: nowrap; }
table.lines input, table.lines select, table.lines textarea { padding: 6px 8px; }
.col-ref { width: 140px; } .col-qte { width: 80px; } .col-pu { width: 120px; } .col-rem { width: 70px; } .col-tva { width: 80px; } .col-mt { width: 120px; } .col-x { width: 36px; }

.totals { margin-left: auto; width: 320px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .net { font-weight: 700; font-size: 17px; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; }
.lettres { color: var(--muted); font-style: italic; font-size: 13px; margin-top: 8px; }

.notice { padding: 10px 14px; border-radius: 6px; background: var(--brand-2); color: var(--brand); margin-bottom: 16px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } .topbar nav a { padding: 6px; } .user { display: none; } }

dialog { border: none; border-radius: var(--radius); padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,25,40,.45); }
dialog form { padding: 20px; }
dialog h2 { margin-top: 0; }
dialog .row { margin-bottom: 12px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }

[dir=auto] { unicode-bidi: plaintext; }
