:root {
  --bg: #f4f2ef; --surface: #ffffff; --ink: #1f2328; --muted: #646b73; --line: #e2ddd6;
  --accent: #b4532a; --accent-ink: #ffffff; --accent-soft: #f6e7df;
  --ok: #2f7d4f; --ok-soft: #e3f2e8; --warn: #a86a00; --warn-soft: #fbf0d9; --bad: #b42323; --bad-soft: #f9e1e1;
  --info: #2b5d8a; --info-soft: #e2ecf6; --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c; --surface: #1f2226; --ink: #e9e7e3; --muted: #9aa1a8; --line: #33373c;
    --accent: #d9774c; --accent-ink: #17191c; --accent-soft: #3a2a22;
    --ok: #6cc28f; --ok-soft: #1f3327; --warn: #e0a940; --warn-soft: #3a3020; --bad: #ec7b7b; --bad-soft: #3d2223;
    --info: #7fb2e0; --info-soft: #1f2e3c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* Barre du haut */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: 0 16px; height: 54px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--accent); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: .25rem; flex: 1; }
.nav a, .linkbtn { color: var(--muted); padding: .4rem .6rem; border-radius: 6px; font-size: .92rem; }
.nav a:hover, .linkbtn:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--ink); background: var(--accent-soft); font-weight: 600; }
.nav-sep { flex: 1; }
.linkbtn { background: none; border: 0; cursor: pointer; font: inherit; }
.navtoggle, .burger { display: none; }
@media (max-width: 860px) {
  .burger { display: flex; flex-direction: column; gap: 4px; margin-left: auto; cursor: pointer; padding: 8px; }
  .burger span { width: 20px; height: 2px; background: var(--ink); }
  .nav { display: none; position: absolute; top: 54px; left: 0; right: 0; flex-direction: column; align-items: stretch; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 16px 12px; }
  .navtoggle:checked ~ .nav { display: flex; }
  .nav a, .nav .linkbtn { padding: .7rem .5rem; text-align: left; width: 100%; }
  .nav-sep { display: none; }
}

.page { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.page.narrow { max-width: 440px; padding-top: 10vh; }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Cartes et grilles */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; }
.stat .v { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .v { color: var(--bad); }

/* Tableaux */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-accent { background: var(--accent-soft); color: var(--accent); }

/* Formulaires */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.field { margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.help { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
form.inline { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 160px; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }
.chips a { padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: .88rem; background: var(--surface); }
.chips a.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chips a:hover { text-decoration: none; }

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; background: var(--ok-soft); color: var(--ok); font-weight: 500; }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.notice { padding: .75rem 1rem; border-radius: var(--radius); background: var(--info-soft); color: var(--info); margin-bottom: 1rem; font-size: .92rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

/* Fiche */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }

/* Lignes de devis/facture */
.lines td { padding: .35rem .3rem; }
.lines textarea { min-height: 38px; height: 38px; }
.lines .c-q { width: 90px; } .lines .c-u { width: 95px; } .lines .c-pu { width: 120px; } .lines .c-t { width: 100px; } .lines .c-tot { width: 110px; } .lines .c-x { width: 36px; }
.totals { margin-left: auto; width: 340px; max-width: 100%; }
.totals .grand span:last-child { margin-left: 1rem; }
.totals div { display: flex; justify-content: space-between; padding: .25rem 0; font-variant-numeric: tabular-nums; }
.totals #t-tva { display: block; padding: 0; }
.totals .grand { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--line); padding-top: .5rem; margin-top: .25rem; }
@media (max-width: 860px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .lines td { border: 0; padding: 0; width: auto !important; }
  .lines td.c-d { grid-column: 1 / -1; }
  .lines td.c-tot { align-self: center; }
}

/* Pipeline */
.pipeline { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: color-mix(in srgb, var(--line) 35%, transparent); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { display: flex; justify-content: space-between; }
.pcard { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; color: var(--ink); }
.pcard:hover { border-color: var(--accent); text-decoration: none; }
.pcard .t { font-weight: 600; font-size: .9rem; }

/* Connexion */
.login-card { padding: 28px; }
.login-card .brand { justify-content: center; font-size: 1.4rem; margin-bottom: 1rem; }
.secret { font-family: ui-monospace, Consolas, monospace; background: var(--bg); padding: .6rem; border-radius: 6px; word-break: break-all; user-select: all; }
