:root {
  --blue: #0d5a9e; --blue-dark: #0a4478; --light: #eef4fa; --line: #dbe3ec; --text: #1f2937; --muted: #6b7280;
  --ok: #15803d; --warn: #b45309; --err: #b91c1c;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: #f5f7fa; }
a { color: var(--blue); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; } h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; color: var(--blue-dark); }
.card > h2:first-child { margin-top: 0; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; }

.topbar { display: flex; align-items: center; gap: 1.2rem; background: #fff; border-bottom: 2px solid var(--blue); padding: .5rem 1.2rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--blue); font-weight: 700; font-size: 1.15rem; }
.brand img { height: 38px; } .brand small { color: var(--muted); font-weight: 400; font-size: .75rem; }
.topbar nav { display: flex; gap: .2rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: .4rem .7rem; border-radius: 6px; color: var(--text); }
.topbar nav a:hover { background: var(--light); text-decoration: none; }
.topbar nav a.on { background: var(--blue); color: #fff; }
.logout { display: flex; align-items: center; gap: .6rem; margin: 0; color: var(--muted); font-size: .85rem; }

.container { max-width: 1100px; margin: 1.4rem auto; padding: 0 1rem 3rem; }
.container.narrow { max-width: 420px; margin-top: 8vh; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.3rem; margin-bottom: 1.1rem; }
.card.center { text-align: center; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.pagehead h1, .pagehead h2 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; } .actions form { margin: 0; }
.muted { color: var(--muted); } .pre { white-space: pre-wrap; } .r { text-align: right; }

.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text); padding: .45rem .9rem; border-radius: 7px; cursor: pointer; font: inherit; }
.btn:hover { background: var(--light); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; } .btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--err); border-color: #f0c4c4; } .btn.danger:hover { background: #fdf0f0; }
.btn.ghost { background: transparent; } .btn.small { padding: .2rem .55rem; font-size: .85rem; } .btn.block { width: 100%; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #ecfdf3; border-color: #a7e3bd; color: #14532d; }
.flash.err { background: #fef2f2; border-color: #f3b4b4; color: #7f1d1d; }
.flash.warn { background: #fffbeb; border-color: #f3d68a; color: #78350f; }
.flash ul { margin: .3rem 0 0 1.1rem; padding: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
th.r, td.r { text-align: right; }
.table-scroll { overflow-x: auto; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e5e7eb; color: #374151; vertical-align: middle; }
.b-actif, .b-payee, .b-accepte { background: #dcfce7; color: #166534; }
.b-envoye, .b-emise { background: #dbeafe; color: #1e40af; }
.b-refuse, .b-annulee, .b-resilie { background: #fee2e2; color: #991b1b; }
.b-termine { background: #ede9fe; color: #5b21b6; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 1rem; color: var(--text); display: flex; flex-direction: column; gap: .2rem; }
.stat:hover { text-decoration: none; border-color: var(--blue); }
.stat b { font-size: 1.9rem; color: var(--blue); line-height: 1.1; } .stat span { color: var(--muted); font-size: .9rem; } .stat.warn b { color: var(--warn); }
.quick { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.1rem; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1; min-width: 200px; }

label { display: block; font-weight: 600; font-size: .88rem; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea { font-weight: 400; width: 100%; padding: .5rem .6rem; border: 1px solid #c8d2de; border-radius: 7px; font: inherit; background: #fff; margin-top: .25rem; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc4e8; border-color: var(--blue); }
input[readonly] { background: #f3f5f8; }
textarea { resize: vertical; }
.form label { margin-bottom: .8rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.grid .span2 { grid-column: span 2; }
@media (max-width: 560px) { .grid .span2 { grid-column: span 1; } }
label.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.inline, .inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form select, .inline-form input { width: auto; margin: 0; } .only-paid { display: inline-flex; gap: .5rem; }

table.items input, table.items textarea { margin: 0; padding: .35rem .45rem; }
.w50 { width: 60px; } .w60 { width: 70px; } .w70 { width: 90px; } .w90 { width: 110px; }
table.items td { padding: .35rem .3rem; } table.items td.line-total { white-space: nowrap; padding-top: .7rem; }
table.items th:first-child { min-width: 240px; }

.totals { margin: 1rem 0 1rem auto; width: 300px; max-width: 100%; }
.totals > div { display: flex; justify-content: space-between; align-items: center; padding: .25rem .6rem; gap: 1rem; }
.totals > div > input { width: 110px; margin: 0; text-align: right; }
.totals .grand { background: var(--blue); color: #fff; border-radius: 6px; font-size: 1.05rem; margin-top: .3rem; padding: .5rem .6rem; }
#t-vat { padding: 0; display: block; }
#t-vat > div { display: flex; justify-content: space-between; padding: .25rem .6rem; }

dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: .4rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }
@media (max-width: 560px) { dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dd { margin-bottom: .5rem; } }

.login { text-align: center; } .login h1 { margin-bottom: 1rem; } .login form { text-align: left; }
.login label { margin-bottom: 1rem; } .login-logo { height: 90px; }
