:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #ffffff;
  --ink: #17181a;
  --ink-2: #52514e;
  --muted: #76746e;
  --line: #e1e0d9;
  --line-2: #c3c2b7;
  --accent: #1c5cab;
  --accent-soft: #e8f0fa;
  --good: #006300;
  --good-soft: #e6f4e6;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --bad: #b32424;
  --bad-soft: #fbe9e9;
  --side: #1b2430;
  --side-ink: #d5dbe3;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 0 18px 14px; display: block; color: #fff; text-decoration: none; }
.brand strong { display: block; font-size: 17px; }
.brand span { font-size: 12px; color: #9fabb9; }
.side nav { flex: 1; }
.nav-group { padding: 12px 18px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #8f9cab; }
.side nav a { display: block; padding: 6px 18px; color: var(--side-ink); text-decoration: none; border-left: 3px solid transparent; }
.side nav a:hover { background: #263140; }
.side nav a.active { background: #263140; color: #fff; border-left-color: #6da7ec; font-weight: 600; }
.me { padding: 12px 18px 0; border-top: 1px solid #303c4b; font-size: 13px; }
.me a { color: #fff; display: block; font-weight: 600; text-decoration: none; }
.me span { color: #9fabb9; font-size: 12px; }
.linklike { background: none; border: 0; padding: 4px 0 0; color: #9ec5f4; cursor: pointer; font: inherit; display: block; }
main { padding: 20px 24px 48px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
h1 { font-size: 21px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 6px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
a { color: var(--accent); }
.btn, button.btn { display: inline-block; background: var(--surface); border: 1px solid var(--line-2); color: var(--ink); padding: 6px 12px; border-radius: 6px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f1f0ec; }
.btn-primary, button.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #184f95; }
.btn-danger { color: var(--bad); border-color: #e2b4b4; }
.btn-sm { padding: 2px 8px; font-size: 13px; }
input, select, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--line-2); border-radius: 5px; background: #fff; color: var(--ink); max-width: 100%; }
input:focus, select:focus, textarea:focus, a:focus-visible, button:focus-visible, .hit:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { color: var(--ink-2); font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
.grid-2 > .card { min-width: 0; margin-bottom: 0; }
.stack { display: grid; gap: 16px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; }
.form-grid input, .form-grid select { width: 100%; }
.form-wide { grid-column: 1 / -1; }
.form-actions { margin-top: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile strong { font-size: 22px; font-weight: 650; }
.tile-detail { color: var(--muted); font-size: 12.5px; }
.tile.bad { border-color: #e2b4b4; background: var(--bad-soft); }
.tile.good { border-color: #b4d9b4; background: var(--good-soft); }
.flash { padding: 9px 12px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.flash-ok { background: var(--good-soft); border-color: #b4d9b4; color: #0c4a0c; }
.flash-warn { background: var(--warn-soft); border-color: #eed49a; color: #5e3f00; }
.flash-error { background: var(--bad-soft); border-color: #e2b4b4; color: #861a1a; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.card .table-wrap { border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #f1f1ed; font-weight: 600; color: #33332f; vertical-align: bottom; }
th small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.wrap { white-space: normal; min-width: 180px; }
tfoot td, tr.total td, tr.total th { font-weight: 700; background: #f1f1ed; border-top: 2px solid var(--line-2); }
tr.subtotal td { font-weight: 600; background: #fafaf7; }
tbody tr:hover td { background: #fafaf4; }
.ecart { color: var(--bad); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #ecebe6; color: #45443f; white-space: nowrap; }
.badge-ok { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-2); margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.daybar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }

/* Brouillard */
.bq-wrap { overflow: auto; max-height: calc(100vh - 290px); min-height: 280px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.bq th { position: sticky; top: 0; z-index: 3; }
.bq .entry td { position: sticky; top: 45px; z-index: 2; background: var(--accent-soft); padding: 3px; border-bottom: 2px solid var(--accent); }
.bq .entry input, .bq .entry select { width: 100%; min-width: 0; padding: 3px 5px; font-size: 13px; border-radius: 3px; }
.bq .entry input.n { text-align: right; font-variant-numeric: tabular-nums; }
.bq td.w-sm, .bq th.w-sm { min-width: 78px; }
.bq td.w-md, .bq th.w-md { min-width: 110px; }
.bq td.w-lg, .bq th.w-lg { min-width: 160px; }
.bq .sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.bq th.sticky-col { z-index: 4; background: #f1f1ed; }
.bq .entry td.sticky-col { z-index: 4; background: var(--accent-soft); }
.bq tbody.rows tr { cursor: pointer; }
.bq tbody.rows tr.has-ecart td { background: var(--bad-soft); }
.bq tbody.rows tr.editing td { background: #fff7d6; }
.bq td.dup { background: var(--warn-soft) !important; color: var(--warn); font-weight: 600; }
.bq tfoot td { position: sticky; bottom: 0; z-index: 2; }
.bq tfoot td.sticky-col { z-index: 3; background: #f1f1ed; }
.calc { font-weight: 600; text-align: right; padding: 0 4px; font-variant-numeric: tabular-nums; }
.calc.nok { color: var(--bad); }
.bq-msg { min-height: 22px; font-size: 13px; }
.bq-msg.err { color: var(--bad); font-weight: 600; }
.bq-msg.ok { color: var(--good); }
.billets { max-width: 420px; }
.billets input { width: 90px; text-align: right; }
.closed-note { padding: 8px 12px; background: var(--good-soft); border: 1px solid #b4d9b4; border-radius: 6px; margin-bottom: 12px; color: #0c4a0c; }

/* Graphiques */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-2); stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .hit:hover, .chart .hit:focus { fill: rgba(11, 11, 11, .05); outline: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.tip { position: fixed; z-index: 50; background: #1b2430; color: #fff; padding: 6px 9px; border-radius: 6px; font-size: 12.5px; white-space: pre-line; pointer-events: none; max-width: 300px; font-variant-numeric: tabular-nums; }
.meter { height: 8px; background: #ecebe6; border-radius: 4px; overflow: hidden; min-width: 90px; }
.meter i { display: block; height: 100%; background: #2a78d6; border-radius: 0 4px 4px 0; }
.delta-up { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }

/* Connexion et installation */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--side); }
.auth .card { width: 100%; max-width: 420px; margin: 0; }
.auth h1 { margin-bottom: 2px; }
.auth label { display: block; margin-top: 12px; }
.auth input { width: 100%; margin-top: 3px; }
.auth button { width: 100%; margin-top: 16px; padding: 9px; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; }
  .side nav { display: flex; flex-wrap: wrap; }
  .nav-group { width: 100%; }
  .side nav a { padding: 5px 10px; }
  main { padding: 16px; }
  .bq-wrap { max-height: none; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

@media print {
  body { background: #fff; font-size: 11px; }
  .app { display: block; }
  .no-print, .side, .entry, .bq-msg, .form-actions { display: none !important; }
  main { padding: 0; }
  .card, .table-wrap, .bq-wrap, .tile { border: 0; box-shadow: none; max-height: none; overflow: visible; }
  th, td { padding: 2px 4px; font-size: 9.5px; }
  .bq th, .bq tfoot td, .bq .sticky-col { position: static; }
  .print-only { display: block !important; }
  @page { size: landscape; margin: 10mm; }
}
.print-only { display: none; }
