:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1d2733; --muted: #6b7785; --line: #e1e6ec;
  --brand: #12406b; --brand-2: #1d6fb8; --ok: #1f8a4c; --warn: #c27c0e; --bad: #c0392b;
  --radius: 10px; font-size: 15px;
}
* { 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: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
nav.side { background: var(--brand); color: #fff; padding: 1.2rem .8rem; display: flex; flex-direction: column; gap: .2rem; }
nav.side .logo { font-weight: 700; font-size: 1.1rem; padding: 0 .6rem 1.2rem; }
nav.side .logo small { display: block; font-weight: 400; opacity: .7; font-size: .8rem; }
nav.side a { color: #dbe7f3; padding: .55rem .7rem; border-radius: 8px; }
nav.side a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
nav.side a.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
nav.side .bottom { margin-top: auto; font-size: .85rem; opacity: .85; padding: .6rem; }
nav.side .bottom button { margin-top: .4rem; }
main { padding: 1.6rem 2rem; max-width: 1250px; width: 100%; }
.bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.bar h1 { margin: 0; margin-right: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.kpi .v { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f0f5fb; }
td.n, th.n { text-align: right; white-space: nowrap; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--card); }
.empty { color: var(--muted); padding: 1.2rem; text-align: center; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: .45rem .85rem; border-radius: 8px; cursor: pointer; }
button:hover { border-color: #b9c4d0; }
button.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
button.primary:hover { background: var(--brand); }
button.danger { color: var(--bad); }
button.small { padding: .25rem .55rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid #cfd7e0; border-radius: 7px; padding: .42rem .55rem; background: #fff; width: 100%; color: var(--ink); }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc5ec; border-color: var(--brand-2); }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem 1rem; }
.form .full { grid-column: 1 / -1; }
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e8edf3; color: #3d4a58; white-space: nowrap; }
.b-ok { background: #e1f4e8; color: var(--ok); } .b-warn { background: #fdf0d9; color: var(--warn); }
.b-bad { background: #fbe3e0; color: var(--bad); } .b-info { background: #e1edf9; color: var(--brand-2); }
.muted { color: var(--muted); } .bad { color: var(--bad); } .ok { color: var(--ok); }
.lines input, .lines select { padding: .3rem .4rem; }
.lines td { padding: .3rem .35rem; }
.totaux { margin-left: auto; width: 320px; margin-top: .8rem; }
.totaux div { display: flex; justify-content: space-between; padding: .25rem 0; }
.totaux .ttc { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .4rem; }
.search { max-width: 280px; }
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,45,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 1rem; z-index: 20; overflow: auto; }
.modal { background: #fff; border-radius: 12px; padding: 1.3rem 1.4rem; width: 100%; max-width: 720px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
#toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: #1d2733; color: #fff; padding: .7rem 1.1rem; border-radius: 9px; z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
#toast.err { background: var(--bad); }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #12406b, #1d6fb8); }
.login .card { width: 360px; padding: 2rem; }
.login h1 { text-align: center; } .login .sub { text-align: center; color: var(--muted); margin: -.6rem 0 1.4rem; }
.login form { display: grid; gap: .9rem; }
.tabs { display: flex; gap: .3rem; margin-bottom: .8rem; flex-wrap: wrap; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.statuts { display: flex; gap: .35rem; flex-wrap: wrap; }
.statuts button.on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem 1rem; }

/* La feuille imprimable d'un document */
.feuille { background: #fff; max-width: 820px; margin: 1rem auto; padding: 2.2rem 2.4rem; border: 1px solid var(--line); font-size: 13px; color: #111; }
.feuille .tete { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.feuille .emetteur b { font-size: 1.15rem; color: var(--brand); }
.feuille .titre { text-align: right; }
.feuille .titre h2 { margin: 0; font-size: 1.6rem; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.feuille .dest { margin-left: auto; width: 46%; border: 1px solid #ccd; border-radius: 6px; padding: .8rem 1rem; margin-bottom: 1.6rem; }
.feuille table th { color: #fff; background: var(--brand); text-transform: none; font-size: .82rem; letter-spacing: 0; }
.feuille table td, .feuille table th { padding: .4rem .5rem; }
.feuille .pied { margin-top: 2rem; font-size: 11px; color: #444; border-top: 1px solid #ccc; padding-top: .7rem; white-space: pre-line; }
.feuille .bon { margin-top: 2rem; display: flex; justify-content: flex-end; }
.feuille .bon div { border: 1px solid #aab; width: 46%; height: 90px; padding: .4rem .6rem; font-size: 11px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  nav.side { flex-direction: row; flex-wrap: wrap; padding: .6rem; }
  nav.side .logo { padding: .4rem .6rem; width: 100%; }
  nav.side .bottom { margin: 0; }
  main { padding: 1rem; }
  .grid2 { grid-template-columns: 1fr; }
}
@media print {
  body { background: #fff; }
  nav.side, .no-print, #toast { display: none !important; }
  .layout { display: block; } main { padding: 0; max-width: none; }
  .feuille { border: 0; margin: 0; padding: 0; max-width: none; }
  @page { margin: 14mm; }
}
