:root {
  --peach: #D9A78E;
  --peach-soft: #F4E3DA;
  --terra: #A4553A;
  --terra-dark: #7E3C27;
  --night: #1F1719;
  --night-2: #2B2023;
  --ink: #241C1D;
  --muted: #76696A;
  --line: #E7DDD7;
  --paper: #FAF6F3;
  --white: #fff;
  --ok: #2F6B4F;
  --ok-bg: #E3F1E8;
  --warn: #9A6A12;
  --warn-bg: #FBF0D9;
  --late: #A12A1F;
  --late-bg: #FBE6E3;
  --radius: 10px;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
.booting { min-height: 100vh; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #3a2a2c, var(--night)); padding: 16px; }
.login form { background: var(--white); border-radius: 16px; padding: 36px 32px; width: min(380px, 100%); box-shadow: 0 30px 60px rgba(0,0,0,.35); }
.login h1 { font-family: 'Cormorant Garamond', serif; font-size: 34px; margin: 0 0 4px; font-weight: 600; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login .error { color: var(--late); min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }

/* Structure */
.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.side { background: var(--night); color: #EDE3DE; padding: 26px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 0 12px 22px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 18px; }
.brand .name { font-family: 'Cormorant Garamond', serif; font-size: 30px; line-height: 1; color: var(--peach); font-weight: 600; }
.brand .sub { font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; margin-top: 8px; color: #BFAFA8; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; color: #E6DAD4; text-decoration: none; font-weight: 500; font-size: 15px; margin-bottom: 2px; }
.side nav a::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #8E7C77; }
.side nav a:hover { background: var(--night-2); }
.side nav a.active { background: var(--terra); color: #fff; }
.side nav a.active::before { background: #fff; }
.side .foot { margin-top: auto; padding: 16px 12px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #A8968F; }
.side .foot button { margin-top: 12px; background: none; border: 1px solid rgba(255,255,255,.2); color: #E6DAD4; border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px; letter-spacing: 0; text-transform: none; }

.top { background: linear-gradient(110deg, var(--night) 0%, #3b2a2b 70%, #5b3b33 100%); color: #fff; padding: 30px 32px 34px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; position: relative; }
.top::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: linear-gradient(90deg, var(--terra), var(--peach)); }
.top h1 { font-family: 'Cormorant Garamond', serif; font-weight: 600; font-size: 36px; margin: 0; line-height: 1; }
.top .date { font-size: 13px; color: #E6D6CF; margin-bottom: 10px; text-align: right; }
.main { min-width: 0; }
.content { padding: 24px 32px 60px; max-width: 1200px; }

/* Contrôles */
.btn { border: 1px solid var(--line); background: var(--white); border-radius: 8px; padding: 9px 14px; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cdbfb8; }
.btn.primary { background: var(--peach); border-color: var(--peach); color: var(--night); }
.btn.primary:hover { background: #e3b7a0; }
.btn.dark { background: var(--night); color: #fff; border-color: var(--night); }
.btn.danger { color: var(--late); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--white); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--peach); outline-offset: 0; border-color: var(--peach); }
label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }
label > input, label > select, label > textarea { margin-top: 6px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 400; font-size: 15px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar .search { flex: 1 1 260px; }
.seg { display: inline-flex; background: #EFE6E1; border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 13px; border-radius: 7px; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--night); color: #fff; }
.toolbar select { width: auto; }
.hint { color: var(--muted); font-size: 13px; margin: 2px 0 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 6px; }

/* Listes */
.list { display: flex; flex-direction: column; gap: 8px; }
.head-row, .row { display: grid; grid-template-columns: minmax(0, 2.4fr) 1.3fr 1fr 1fr 1fr 20px; gap: 14px; align-items: center; }
.head-row { font-size: 11.5px; font-weight: 700; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; padding: 0 16px 4px; }
.head-row .r, .row .r { text-align: right; }
.row { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; cursor: pointer; text-align: left; width: 100%; font-size: 14px; }
.row:hover { border-color: var(--peach); }
.row.late { border-color: #E3A39B; background: #FFF7F6; }
.who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 8px; background: var(--terra); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.who .t { font-weight: 700; text-transform: uppercase; font-size: 14px; }
.who .s { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who > div { min-width: 0; }
.amt { font-weight: 700; text-align: right; }
.chev { color: var(--muted); }
.pill { display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 12.5px; font-weight: 600; background: #EEE7E3; color: #5d5050; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.late { background: var(--late-bg); color: var(--late); }
.pill.off { background: #EEE; color: #8a8a8a; text-decoration: line-through; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); background: var(--white); border: 1px dashed var(--line); border-radius: var(--radius); }
.year-head { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 16px 8px; }
.year-head .y { color: var(--muted); font-size: 14px; }
.year-head .tot { font-size: 22px; font-weight: 700; }

/* Éditeur */
.card { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 22px; margin-bottom: 16px; }
.card h2 { margin: 0 0 16px; font-size: 17px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: left; padding: 0 6px 8px; }
.lines td { padding: 4px 6px; vertical-align: top; }
.lines td.num, .lines th.num { text-align: right; width: 130px; }
.lines td.qty, .lines th.qty { width: 90px; }
.lines .total td { border-top: 2px solid var(--ink); font-weight: 700; padding-top: 12px; font-size: 16px; }
.doc-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.doc-head h2 { margin: 0; font-size: 22px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.locked { background: var(--peach-soft); border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.pay-row { display: grid; grid-template-columns: 110px 1fr 1fr auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.balance { display: flex; gap: 24px; flex-wrap: wrap; margin: 6px 0 14px; font-size: 15px; }
.balance b { font-size: 18px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100% - 32px)); box-shadow: 0 30px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(31,23,25,.5); }
dialog form { padding: 24px; display: grid; gap: 14px; }
dialog h2 { margin: 0; font-size: 20px; }
dialog .actions { justify-content: flex-end; margin-top: 6px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--night); color: #fff; padding: 11px 18px; border-radius: 9px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; font-size: 14px; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--late); }
#print-area { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 14px 12px; }
  .brand { padding-bottom: 12px; margin-bottom: 10px; }
  .side nav { display: flex; overflow-x: auto; gap: 4px; }
  .side nav a { flex: none; }
  .side .foot { display: none; }
  .top { padding: 22px 16px 26px; }
  .top h1 { font-size: 28px; }
  .content { padding: 18px 16px 50px; }
  .head-row { display: none; }
  .row { grid-template-columns: 1fr auto; }
  .row > :nth-child(2), .row > :nth-child(3), .row .chev { display: none; }
  .row > :nth-child(4) { grid-row: 2; }
  .kv { grid-template-columns: 1fr; }
  .card { overflow-x: auto; padding: 16px; }
  .pay-row .actions { grid-column: 1 / -1; }
  .pay-row { grid-template-columns: 1fr auto; }
  .lines td.num, .lines th.num { width: 96px; }
  .lines td.qty, .lines th.qty { width: 60px; }
}

/* Impression : seul le document s'imprime, pleine page */
@media print {
  @page { size: letter; margin: 0; }
  :root, body { background: #fff; }
  #app, #toast, dialog { display: none !important; }
  #print-area { display: block; }
  .inv { min-height: 11in; }
}

/* Gabarit des documents (facture, devis, reçu) */
.inv { width: 816px; min-height: 1050px; background: #fff; color: #2a2a2a; font-family: Helvetica, Arial, Inter, sans-serif; font-size: 12px; line-height: 1.45; display: flex; flex-direction: column; position: relative; }
.inv-top { position: relative; height: 158px; }
.inv-tri { position: absolute; left: 0; top: 0; width: 450px; height: 158px; }
.inv-logo { position: absolute; left: 36px; top: 58px; width: 300px; }
.inv-biz { position: absolute; left: 472px; top: 30px; font-size: 11px; color: #333; }
.inv-bizname { font-size: 19px; font-weight: 700; letter-spacing: .02em; color: #222; margin-bottom: 8px; }
.inv-bar { height: 10px; background: #DCA48E; }
.inv-bar.thin { height: 6px; }
.inv-body { padding: 16px 56px 10px; flex: 1; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; }
.inv-title { font-size: 30px; font-weight: 800; letter-spacing: .01em; color: #1f1f1f; margin-top: 4px; }
.inv-meta { width: 230px; font-size: 11.5px; color: #333; line-height: 1.8; padding-top: 2px; }
.inv-to { margin-top: 4px; font-size: 12px; line-height: 1.4; }
.inv-to b { display: block; font-size: 10px; letter-spacing: .04em; margin-bottom: 8px; }
.inv-obj { margin: 16px 0 12px; }
.inv-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.inv-table th { background: #DCA48E; color: #2a2a2a; font-size: 10.5px; font-weight: 700; text-align: left; padding: 9px 12px; }
.inv-table td { padding: 12px 12px 13px; border-bottom: 1px solid #EFE4D6; vertical-align: top; }
.inv-table td > div + div { color: #444; }
.inv-table .n { text-align: left; }
.inv-tot { margin: 18px 0 0 auto; width: 300px; border-collapse: collapse; }
.inv-tot td { padding: 4px 0; font-weight: 700; font-size: 12px; }
.inv-tot td:last-child { text-align: right; white-space: nowrap; }
.inv-tot tr.big td { font-size: 12.5px; }
.inv-tot tr.pay td { font-weight: 400; color: #555; font-size: 11px; }
.inv-taxnote { margin-top: 10px; text-align: right; font-size: 10.5px; color: #777; }
.inv-stamp { display: inline-block; border: 2px solid #2F6B4F; color: #2F6B4F; padding: 4px 12px; font-weight: 700; letter-spacing: .1em; transform: rotate(-3deg); margin-top: 10px; }
.inv-notes { margin-top: 18px; white-space: normal; color: #444; }
.inv-pay { margin-top: 24px; font-size: 11.5px; color: #333; }
.inv-sec { margin-bottom: 2px; }
.inv-foot { margin-top: auto; }
.inv-photo { height: 82px; background: #2b2724 url('/assets/footer.jpg') center 38% / cover no-repeat; display: flex; align-items: center; justify-content: center; text-align: center; color: #EBD7C9; font-family: 'Cormorant Garamond', Georgia, serif; font-style: italic; font-size: 15px; line-height: 1.7; }
