/* Luce di Vita — interface de gestion */
:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #faf8f4; --line: #e7e2d8; --line-strong: #d6cfc1;
  --ink: #1f1d1a; --ink-2: #57524a; --ink-3: #8a8378;
  --brand: #1c1b19; --brand-ink: #ffffff; --brand-soft: #ece5d8; --brand-2: #c9b48e;
  --ok: #2f7d4f; --ok-soft: #e3f2e8; --warn: #a76a00; --warn-soft: #fbefd6; --bad: #b3362b; --bad-soft: #fbe5e2; --info: #2c5d8f; --info-soft: #e3edf7;
  --side: #1f1c18; --side-ink: #d9d2c5; --side-ink-2: #8d857a; --side-active: #2f2a24;
  --radius: 10px; --shadow: 0 1px 2px rgba(30,25,15,.06), 0 4px 16px rgba(30,25,15,.05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f; --surface: #1d1a16; --surface-2: #221f1a; --line: #332e27; --line-strong: #453e35;
    --ink: #eee8de; --ink-2: #bdb4a5; --ink-3: #8a8275; --brand: #ece5d8; --brand-ink: #16140f; --brand-soft: #2c2820; --brand-2: #c9b48e;
    --ok: #6cc28f; --ok-soft: #1d3326; --warn: #e3ae4b; --warn-soft: #3a2e15; --bad: #ef7d70; --bad-soft: #3d1f1b; --info: #7fb0e3; --info-soft: #1b2a3a;
    --side: #100e0b; --side-active: #26221c; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15130f; --surface: #1d1a16; --surface-2: #221f1a; --line: #332e27; --line-strong: #453e35;
  --ink: #eee8de; --ink-2: #bdb4a5; --ink-3: #8a8275; --brand: #ece5d8; --brand-ink: #16140f; --brand-soft: #2c2820; --brand-2: #c9b48e;
  --ok: #6cc28f; --ok-soft: #1d3326; --warn: #e3ae4b; --warn-soft: #3a2e15; --bad: #ef7d70; --bad-soft: #3d1f1b; --info: #7fb0e3; --info-soft: #1b2a3a;
  --side: #100e0b; --side-active: #26221c; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--ink-3); } .small { font-size: 12px; } .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }

/* ---------- Disposition ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 22px 18px 10px; text-align: center; border-bottom: 1px solid #2c2822; margin: 0 12px; }
.brand img { width: 150px; max-width: 100%; height: auto; filter: invert(1) brightness(.92) sepia(.15); }
.brand span { display: block; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--side-ink-2); margin-top: 6px; }
.nav { padding: 6px 10px 20px; flex: 1; }
.nav .grp { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--side-ink-2); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--side-ink); font-size: 13.5px; }
.nav a:hover { background: var(--side-active); text-decoration: none; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand-2); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.side-foot { padding: 12px 16px; border-top: 1px solid #2c2822; font-size: 12px; color: var(--side-ink-2); }
.side-foot b { color: var(--side-ink); font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.topbar .title { font-weight: 600; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.burger { display: none; }
.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Composants ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.card-b { padding: 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)); }
.g-side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; }
.kpi { padding: 16px; } .kpi .l { font-size: 12px; color: var(--ink-3); } .kpi .v { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.bad .v { color: var(--bad); } .kpi.ok .v { color: var(--ok); }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn svg { width: 15px; height: 15px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; } .badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-color: var(--brand); } .tabs a:hover { text-decoration: none; color: var(--ink); }

/* Tableaux */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 9px 12px;
  border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; cursor: pointer; user-select: none; }
.tbl th.num { text-align: right; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--surface-2); } .tbl tr.click { cursor: pointer; }
.tbl tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--line-strong); }
.tbl .empty { text-align: center; color: var(--ink-3); padding: 30px; }
.toolbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 360px; }

/* Formulaires */
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
label.f.full { grid-column: 1 / -1; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; width: 100%; min-height: 34px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 0; border-color: var(--brand); }
input[type=checkbox] { width: auto; min-height: 0; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form h3 { grid-column: 1 / -1; margin-top: 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }

/* Lignes de document */
.lines input, .lines select { min-height: 30px; padding: 4px 7px; }
.lines td { padding: 5px 6px; } .lines .del { color: var(--ink-3); cursor: pointer; border: 0; background: none; font-size: 18px; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 24px; font-variant-numeric: tabular-nums; }
.totals .big { font-size: 18px; font-weight: 700; color: var(--brand); }

/* Modale & notifications */
.modal-bg { position: fixed; inset: 0; background: rgba(20,16,10,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 940px; }
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 18px; } .modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-size: 13px; }
.toast.err { background: var(--bad); color: #fff; }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; margin-bottom: 14px; }
.alert.info { background: var(--info-soft); color: var(--info); } .alert.bad { background: var(--bad-soft); color: var(--bad); }

/* Graphique */
.chart { width: 100%; height: 220px; } .chart text { fill: var(--ink-3); font-size: 11px; }
.chart .bar { fill: var(--brand); } .chart .bar2 { fill: var(--brand-2); } .chart .axis { stroke: var(--line); }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; } .meter i { display: block; height: 100%; background: var(--brand); }
.list { list-style: none; margin: 0; padding: 0; } .list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; } dl.kv dt { color: var(--ink-3); } dl.kv dd { margin: 0; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 80% -10%, var(--brand-soft), transparent), var(--bg); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .logo { display: block; width: 210px; max-width: 70%; margin: 0 auto 6px; }
.login h1 { text-align: center; } .login .card > .muted { text-align: center; }
:root[data-theme="dark"] .login .logo, :root[data-theme="dark"] .logo-adapt { filter: invert(1) brightness(.92); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .login .logo, :root:not([data-theme="light"]) .logo-adapt { filter: invert(1) brightness(.92); } }
.login h1 { margin: 14px 0 4px; } .login form { display: grid; gap: 14px; margin-top: 18px; }

/* Impression des documents */
.doc { background: #fff; color: #111; width: 210mm; min-height: 297mm; margin: 0 auto; padding: 14mm 14mm 18mm; font-size: 11.5px; box-shadow: var(--shadow); }
.doc .hd { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #1c1b19; padding-bottom: 10px; }
.doc .hd .ent b { font-size: 17px; letter-spacing: .03em; } .doc .hd .ent div { line-height: 1.5; }
.doc .ttl { text-align: right; } .doc .ttl h1 { font-size: 22px; color: #1c1b19; text-transform: uppercase; letter-spacing: .06em; }
.doc .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 0; }
.doc .box { border: 1px solid #ccc; border-radius: 6px; padding: 8px 10px; line-height: 1.55; }
.doc .box .t { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #777; margin-bottom: 3px; }
.doc table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.doc th { background: #f1ece3; border: 1px solid #bbb; padding: 5px 6px; font-size: 10.5px; text-align: left; }
.doc td { border: 1px solid #ccc; padding: 5px 6px; }
.doc td:nth-child(2) { white-space: nowrap; font-size: 10.5px; }
.doc .tot { display: grid; grid-template-columns: 1fr 260px; gap: 16px; margin-top: 12px; }
.doc .tot table td { padding: 4px 8px; } .doc .tot .net td { font-weight: 700; font-size: 13px; background: #f1ece3; }
.doc .lettres { border: 1px dashed #aaa; padding: 8px 10px; border-radius: 6px; margin-top: 12px; }
.doc .sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 28px; } .doc .sign div { height: 80px; border-top: 1px solid #999; padding-top: 4px; font-size: 10.5px; color: #555; }
.doc .foot { margin-top: 24px; border-top: 1px solid #ccc; padding-top: 6px; font-size: 9.5px; color: #666; text-align: center; line-height: 1.5; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; } .side, .topbar, .no-print, .toasts { display: none !important; }
  .app { display: block; } .content { padding: 0; max-width: none; } .doc { box-shadow: none; margin: 0; }
  .card { box-shadow: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 980px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .burger { display: inline-flex; }
  .topbar { padding: 0 12px; padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .content { padding: 16px 12px 80px; }
  .g2, .g3, .g4, .g-side, .form, .form.three { grid-template-columns: 1fr; }
  .g4.kpis { grid-template-columns: 1fr 1fr; }
  .kpi .v { font-size: 18px; }
  .doc { width: 100%; min-height: 0; padding: 14px; } .doc .parties, .doc .tot { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 120px 1fr; }
}

/* Logo sur les documents imprimés */
.doc .hd .logo-doc { height: 105px; width: auto; display: block; margin-bottom: 6px; }
.doc .hd .ent { display: flex; gap: 14px; align-items: flex-start; }
.print-only, .print-head.print-only { display: none; }
.print-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #1c1b19; padding-bottom: 8px; margin-bottom: 14px; }
.print-head img { height: 70px; }
@media print { .print-only { display: block; } .print-head.print-only { display: flex; } }
.logo-preview { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.logo-preview img { height: 90px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
