:root {
  --bg: #0f0e13; --panel: #17161d; --panel2: #1e1d25; --line: #2a2932; --text: #ecebf0; --muted: #9a98a6;
  --gold: #e8b86b; --gold-d: #c9973f; --green: #5cc58a; --red: #e66a6a; --blue: #6aa6e6; --orange: #e6a06a;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif; }
a { color: var(--gold); text-decoration: none; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
input, select, textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #444; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; }
.btn.primary:hover { background: var(--gold-d); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }

/* Layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .05em; padding: 0 8px 20px; }
.logo img { width: 30px; }
.side a { color: var(--muted); padding: 8px 12px; border-radius: 8px; display: block; }
.side a:hover { color: var(--text); background: var(--panel2); }
.side a.active { color: var(--text); background: var(--panel2); box-shadow: inset 3px 0 0 var(--gold); }
.side .sep { font-size: 11px; color: #66646f; text-transform: uppercase; letter-spacing: .08em; padding: 16px 12px 4px; }
.side .who { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.side .who strong { color: var(--text); display: block; }
.main { padding: 28px 36px; max-width: 1200px; width: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.top .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--panel2); }
.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.search { max-width: 280px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); }
.badge.brouillon { color: var(--muted); }
.badge.envoye, .badge.emise { color: var(--blue); border-color: #2c4560; }
.badge.accepte, .badge.payee, .badge.signe, .badge.termine { color: var(--green); border-color: #2a5240; }
.badge.refuse, .badge.annulee, .badge.annule, .badge.retard { color: var(--red); border-color: #5a2c2c; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.full { grid-column: 1 / -1; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs .btn.on { border-color: var(--gold); color: var(--gold); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 10; }
.modal[hidden] { display: none; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 760px; padding: 24px; }
.dialog.wide { max-width: 980px; }
.dialog h1 { margin-bottom: 18px; }
.dialog .foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.dialog .foot .r { display: flex; gap: 8px; margin-left: auto; }
.lines-ed td { padding: 4px; border: 0; vertical-align: top; }
.lines-ed textarea { min-height: 40px; }
.lines-ed .q { width: 80px; } .lines-ed .p { width: 120px; }
.totals-box { margin-left: auto; width: 300px; margin-top: 10px; }
.totals-box div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals-box .g { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.note { background: #2a2416; border: 1px solid #4d3f20; color: #e9d3a6; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .dialog { max-width: 400px; }
.login .logo { justify-content: center; font-size: 24px; }
.login form > div { margin-bottom: 12px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 8px; z-index: 20; }
.toast.bad { border-color: var(--red); color: var(--red); }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .side .sep, .side .who { display: none; }
  .logo { padding: 0 8px; }
  .main { padding: 18px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  table.list .hide-m { display: none; }
}
