:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1d2731;
  --ink-2: #4b5864;
  --ink-3: #7d8994;
  --line: #e2e0d9;
  --line-2: #eeece6;
  --accent: #2e5e6e;
  --accent-ink: #ffffff;
  --accent-soft: #e4eef0;
  --ok: #2f7a4f;   --ok-soft: #e3f2e8;
  --warn: #9a6400; --warn-soft: #fbf0d9;
  --bad: #b23a32;  --bad-soft: #f9e3e1;
  --info: #2c5d8f; --info-soft: #e3edf7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(29, 39, 49, .06), 0 2px 8px rgba(29, 39, 49, .04);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191d; --surface: #1c2328; --ink: #e8ecee; --ink-2: #b3bec6; --ink-3: #85919a;
    --line: #2d363d; --line-2: #252d33; --accent: #6fb3c4; --accent-ink: #0d1a1e; --accent-soft: #20343a;
    --ok: #7bc896; --ok-soft: #1f3327; --warn: #e2b45c; --warn-soft: #3a3020; --bad: #ef8a80; --bad-soft: #3d2422;
    --info: #8db8e3; --info-soft: #1f2d3b; --shadow: none;
  }
}
* { 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.55rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; }
p { margin: .4rem 0 .8rem; }
small, .small { font-size: .84rem; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: .9em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* Structure */
.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; padding: .2rem .5rem 1rem; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: .82rem; letter-spacing: .02em; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: .5rem .65rem; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--line-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav .sep { height: 1px; background: var(--line); margin: .6rem .4rem; }
.nav .new { margin: .2rem 0 .8rem; }
.main { padding: 1.6rem 2rem 4rem; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.page-head .sub { color: var(--ink-3); margin-top: .2rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.topbar { display: none; }

@media (max-width: 860px) {
  .app { display: block; }
  .side { display: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); padding: .6rem 1rem; }
  .topbar details { position: relative; }
  .topbar summary { list-style: none; cursor: pointer; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 8px; font-weight: 600; }
  .topbar summary::-webkit-details-marker { display: none; }
  .topbar .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: .4rem; width: 240px; }
  .main { padding: 1.1rem 1rem 4rem; }
  h1 { font-size: 1.3rem; }
}

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.card > h2:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .7rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 680px) { .grid-2, .grid-4 { grid-template-columns: minmax(0, 1fr); } .span-2 { grid-column: auto; } }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .label { font-size: .8rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: .82rem; color: var(--ink-3); margin-top: .1rem; }
.meter { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin-top: .5rem; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: .5rem .55rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: .62rem .55rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click:hover td { background: var(--line-2); cursor: pointer; }
table.t tfoot td { font-weight: 700; border-top: 1px solid var(--line); }
table.t .num { text-align: right; }
.empty { text-align: center; color: var(--ink-3); padding: 1.6rem .5rem; }

/* Badges */
.badge { display: inline-block; font-size: .76rem; font-weight: 600; padding: .14rem .55rem; border-radius: 99px; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: var(--line-2); color: var(--ink-3); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .04em; padding: .08rem .42rem; border-radius: 5px; border: 1px solid var(--line); color: var(--ink-2); }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: 600 .9rem var(--font); padding: .55rem .95rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.linkbtn.danger { color: var(--bad); }
form.inline { display: inline; }

/* Formulaires */
label { display: block; font-size: .86rem; font-weight: 600; color: var(--ink-2); margin-bottom: .3rem; }
.field { margin-bottom: .9rem; }
.field .help { font-size: .8rem; color: var(--ink-3); margin-top: .25rem; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=url], input[type=tel], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); vertical-align: -2px; margin-right: .35rem; }
.check { font-weight: 500; color: var(--ink); display: flex; align-items: flex-start; gap: .1rem; }
.row { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg label { margin: 0; padding: .5rem .9rem; cursor: pointer; font-weight: 600; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--accent); }
.seg label:has(input:checked) { background: var(--accent-soft); }

/* Lignes de document */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); text-align: left; padding: .35rem .3rem; }
.lines td { padding: .3rem; vertical-align: top; }
.lines textarea { min-height: 42px; height: 42px; }
.lines .c-qty { width: 84px; } .lines .c-unit { width: 130px; } .lines .c-price { width: 120px; } .lines .c-vat { width: 80px; } .lines .c-total { width: 110px; } .lines .c-del { width: 36px; }
.lines .total { padding-top: .85rem; font-weight: 600; }
.del-line { border: 0; background: none; color: var(--ink-3); font-size: 1.2rem; cursor: pointer; padding: .4rem; }
.del-line:hover { color: var(--bad); }
@media (max-width: 760px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; margin-bottom: .6rem; }
  .lines td { display: block; padding: 0; width: auto !important; }
  .lines td.c-desc { grid-column: 1 / -1; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--ink-3); text-transform: uppercase; }
}
.totals-box { margin-left: auto; width: 300px; max-width: 100%; }
.totals-box div { display: flex; justify-content: space-between; padding: .3rem 0; }
.totals-box .grand { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .55rem; font-weight: 700; font-size: 1.08rem; }

/* Alertes */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.flash.info { background: var(--info-soft); color: var(--info); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash ul { margin: .3rem 0 0; padding-left: 1.2rem; }

/* Divers */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; overflow-x: auto; }
.tabs a { padding: .55rem .85rem; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .9rem; }
.filters select, .filters input { width: auto; min-width: 120px; }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 150px; margin-top: .4rem; }
.bars .bar { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bars .bar span { display: block; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar .ae { background: var(--accent); }
.bars .bar .aa { background: #c08a3e; }
.bars-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; font-size: .72rem; color: var(--ink-3); text-align: center; margin-top: .3rem; }
.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.qr { background: #fff; padding: 10px; display: inline-block; border-radius: 8px; border: 1px solid var(--line); }
.qr img, .qr canvas { display: block; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: 100%; max-width: 400px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .4rem 0; border-bottom: 1px solid var(--line-2); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.notice { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: .7rem .9rem; border-radius: 0 8px 8px 0; margin: .6rem 0; font-size: .92rem; }
.notice.warn { border-color: var(--warn); background: var(--warn-soft); }
.stack > * + * { margin-top: .6rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.nav .navlink { padding: .5rem .65rem; display: block; }
.legend i.ae-c { background: var(--accent); }
.legend i.aa-c { background: #c08a3e; }
[hidden] { display: none !important; }
.settings-logo { max-height: 70px; max-width: 220px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }
.color-input { width: 70px !important; height: 40px; padding: 2px !important; }
.grid { margin-bottom: 1.1rem; }
.grid > .card { margin-bottom: 0; }
.bars .bar span[data-h="0"] { min-height: 0; }
.page-head select { width: auto; }
.page-head form.actions { flex-wrap: nowrap; }
@media (max-width: 680px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .value { font-size: 1.15rem; }
  .stat { padding: .75rem .8rem; }
}
