:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e3e6ea; --text: #1d2330; --muted: #6b7380; --brand: #1f6feb; --brand-soft: #e7f0ff;
  --ok: #1a7f37; --err: #c62828; --warn: #b26a00; --billed: #dfe7f3; --billed-text: #33507a; --period: #f3ecdc; --sel: #1f6feb; --we: #f1f2f4;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --panel: #171b23; --line: #2a303b; --text: #e6e9ef; --muted: #98a1b0; --brand: #4d8dff; --brand-soft: #1b2a45;
    --ok: #46c46a; --err: #ff6b6b; --warn: #e0a040; --billed: #22324b; --billed-text: #a9c3ec; --period: #3a3221; --sel: #4d8dff; --we: #141821;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { overflow-x: hidden; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0; }
button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.ghost { background: transparent; }
.small { font-size: 12.5px; }
.danger { color: var(--err); }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.err { color: var(--err); }
.spacer { flex: 1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; margin: 10px 0; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.logo { font-size: 16px; white-space: nowrap; }
.logo span { color: var(--brand); }
#nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
#nav button { border: 0; background: transparent; color: var(--muted); white-space: nowrap; }
#nav button[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
main { padding: 18px 20px 40px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; }
.narrow { max-width: 560px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 input, .row3 input, .row2 select, .row3 select, .card input, .card select, .card textarea { width: 100%; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.span2 { grid-column: span 2; }

/* calendrier */
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav b { min-width: 150px; text-align: center; font-size: 16px; text-transform: capitalize; }
.cal-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.year-strip { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; margin-bottom: 10px; }
.ym { flex-direction: column; gap: 0; padding: 4px 2px; font-size: 11px; color: var(--muted); }
.ym b { font-size: 13px; color: var(--text); }
.ym i { font-style: normal; color: var(--sel); font-weight: 600; }
.ym.has { background: var(--billed); }
.ym.cur { outline: 2px solid var(--brand); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.day { min-height: 74px; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 2px; padding: 6px; border-radius: 8px; position: relative; }
.day .num { font-weight: 600; }
.day.empty { border: 0; background: transparent; }
.day.we { background: var(--we); }
.day.period { background: repeating-linear-gradient(135deg, var(--period), var(--period) 6px, transparent 6px, transparent 12px); }
.day.billed, .day.billed:disabled { background: var(--billed); color: var(--billed-text); opacity: 1; }
.day.billed-half { background: linear-gradient(135deg, var(--billed) 50%, transparent 50%); }
.day.sel { background: var(--sel); border-color: var(--sel); color: #fff; }
.day.sel-half { background: linear-gradient(135deg, var(--sel) 50%, var(--panel) 50%); border-color: var(--sel); }
.day.today .num { text-decoration: underline; }
.day .tag { font-size: 11px; background: rgba(0, 0, 0, .06); border-radius: 4px; padding: 0 4px; }
.day .tag.soft { background: transparent; color: var(--warn); }
.day .pick { font-size: 11px; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 12px; color: var(--muted); }
.lg { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--line); }
.lg.sel { background: var(--sel); } .lg.billed { background: var(--billed); } .lg.we { background: var(--we); }
.lg.period { background: repeating-linear-gradient(135deg, var(--period), var(--period) 3px, transparent 3px, transparent 6px); }
.new-invoice { position: sticky; top: 70px; }
.total-box { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px; border-radius: 8px; background: var(--brand-soft); }
.total-box b { font-size: 20px; }

/* tableaux */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.grid tfoot td { font-weight: 600; border-bottom: 0; }
.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--brand-soft); }
.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--we); margin-left: 4px; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.late { background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); }
.pill.soft { color: var(--warn); }

/* statistiques */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stats-grid .wide { grid-column: span 2; }
.bars td { border: 0; padding: 4px 6px; }
.bar-cell { width: 45%; }
.bar { height: 10px; border-radius: 5px; background: var(--brand); min-width: 2px; }
.year-block h4 { margin: 8px 0 2px; }

.two-cols { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.stamp-preview { max-width: 160px; }

/* fiche */
dialog { border: 0; border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(760px, 96vw); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.dlg header { display: flex; justify-content: space-between; align-items: center; }
.dlg header h3 { margin: 0; }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.facts > div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.facts > div.full { grid-column: 1 / -1; }
.facts span { display: block; font-size: 12px; color: var(--muted); }
.files { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

.login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 50; }

@media (max-width: 900px) {
  main { padding: 12px 16px 30px; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  #nav { order: 3; flex-basis: 100%; }
  .cal-layout, .two-cols, .stats-grid { grid-template-columns: 1fr; }
  .stats-grid .wide { grid-column: auto; }
  .new-invoice { position: static; }
  .year-strip { grid-template-columns: repeat(6, 1fr); }
  .day { min-height: 54px; padding: 4px; }
  .day .tag { display: none; }
  .facts { grid-template-columns: 1fr 1fr; }
  .row3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}
