:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #714b67; --accent-ink: #fff; --ok: #1f7a4d; --bad: #b42318; --info: #2459a8;
  --chip: #eef0f3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1e26; --card: #262a36; --text: #e4e4e4; --muted: #9aa1ad; --line: #353a48;
    --accent: #a0789a; --chip: #333848; --ok: #4fc08d; --bad: #f07a6e; --info: #79a8f0;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
h1 { font-size: 22px; margin: 0 0 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
h3 { font-size: 13px; margin: 12px 0 6px; color: var(--muted); }
.muted { color: var(--muted); }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--accent); color: var(--accent-ink); flex-wrap: wrap; }
.top a { color: var(--accent-ink); }
.brand { font-weight: 700; font-size: 16px; }
.brand small { font-weight: 400; opacity: .75; font-size: 11px; margin-left: 4px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 12px; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.18); text-decoration: none; }
.logout { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.logout .muted { color: rgba(255,255,255,.8); }
button.link { background: none; border: 0; color: var(--accent-ink); cursor: pointer; text-decoration: underline; padding: 0; font: inherit; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; overflow-x: auto; }
.head { margin-bottom: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.grid3 .card p { margin: 0 0 8px; }

table { border-collapse: collapse; width: 100%; }
.list th, .list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.list tbody tr[data-href] { cursor: pointer; }
.list tbody tr[data-href]:hover { background: var(--chip); }
.num { text-align: right !important; white-space: nowrap; }
.totals { width: auto; margin: 12px 0 0 auto; min-width: 300px; }
.totals th { text-align: left; font-weight: 400; padding: 4px 16px 4px 0; color: var(--muted); }
.totals td { text-align: right; padding: 4px 0; white-space: nowrap; }
.totals .grand th, .totals .grand td { font-weight: 700; color: var(--text); border-top: 1px solid var(--line); padding-top: 8px; font-size: 15px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--muted); vertical-align: middle; }
.badge.ok { color: var(--ok); } .badge.bad { color: var(--bad); } .badge.info { color: var(--info); }

.opts { margin: 4px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: 12px; }
.opts dt { color: var(--muted); }
.opts dd { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters label, .login label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
input, select { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); min-width: 140px; }
.filters input[name=q] { min-width: 280px; }
button, .btn { font: inherit; padding: 8px 16px; border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-ink); cursor: pointer; display: inline-block; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.reset { padding: 8px 4px; }

.bigsearch { display: flex; gap: 10px; margin: 10px 0 18px; }
.bigsearch input { flex: 1; font-size: 16px; padding: 12px 14px; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; min-width: 150px; color: var(--muted); }
.stat b { display: block; font-size: 22px; color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--accent); }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 4px 0; }
ul.history { list-style: none; margin: 0; padding: 0; }
ul.history li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment { margin-top: 4px; white-space: normal; }
.addr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.addr { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }

.pager { display: flex; gap: 14px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.alert { background: rgba(180, 35, 24, .1); color: var(--bad); padding: 8px 12px; border-radius: 6px; }
.err { white-space: pre-wrap; color: var(--bad); }

.login { max-width: 380px; margin: 10vh auto 0; }
.login form { display: flex; flex-direction: column; gap: 12px; }

/* Facture (écran) */
.invoice { color: var(--text); }
.inv-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 18px; }
.inv-meta h1 { margin-bottom: 6px; }
.inv-meta th { text-align: left; font-weight: 400; color: var(--muted); padding: 2px 14px 2px 0; }
.inv-addr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.inv-addr h3:first-child { margin-top: 0; }
.inv-taxes { color: var(--muted); font-size: 12px; margin-top: 18px; }

@media (max-width: 700px) {
  .inv-addr { grid-template-columns: 1fr; }
  .filters input[name=q] { min-width: 0; width: 100%; }
  .logout { margin-left: 0; }
}

/* Produits */
.kv { width: 100%; }
.kv th { text-align: left; font-weight: 400; color: var(--muted); padding: 3px 12px 3px 0; white-space: nowrap; vertical-align: top; width: 1%; }
.kv td { padding: 3px 0; }
.gallery { display: flex; gap: 10px; flex-wrap: wrap; }
.gallery img { width: 140px; height: 140px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.desc { max-height: 420px; overflow-y: auto; }

/* Fichiers joints */
a.filelink { white-space: nowrap; }
.filethumb { display: block; max-width: 160px; max-height: 120px; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
