:root {
  --bg: #f4f6f9; --surface: #ffffff; --ink: #1b2430; --muted: #5d6b7c; --line: #dde3ea;
  --brand: #1f3a5f; --brand-2: #2c5282; --accent: #0e7c66; --warn: #b7791f; --danger: #b42318;
  --ok-bg: #e7f5ef; --err-bg: #fdecea; --warn-bg: #fdf6e3; --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 12.5px; }

/* Barre supérieure */
.topbar { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 54px; flex-wrap: wrap; }
.topbar .brand { font-weight: 600; letter-spacing: .2px; color: #fff; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #d5e1f0; padding: 6px 10px; border-radius: 6px; }
.topbar nav a:hover, .topbar nav a.on { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #d5e1f0; }
.topbar .who form { margin: 0; }
.topbar .who button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; padding: 4px 10px; }

main { max-width: 1360px; margin: 0 auto; padding: 24px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .n { font-size: 28px; font-weight: 600; }
.stat .l { color: var(--muted); }
.stat.alert { border-color: #f0c674; background: var(--warn-bg); }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; white-space: nowrap; }
th a { color: var(--muted); }
tbody tr:hover { background: #f8fafc; }
td.num { text-align: right; }
tr.inactive td { color: #8a96a3; }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #edf2f7; color: #2d3748; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: #0b5e4c; }
.badge.warn { background: var(--warn-bg); color: #8a5a00; }
.badge.err { background: var(--err-bg); color: var(--danger); }
.badge.off { background: #eceff3; color: #6b7785; }

/* Formulaires */
form.inline { display: inline; }
label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; color: #33404f; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #c7d0db; border-radius: 6px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9ab6dd; outline-offset: 0; border-color: var(--brand-2); }
textarea { min-height: 90px; resize: vertical; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.fields .wide { grid-column: 1 / -1; }
.help { font-size: 12px; color: var(--muted); margin-top: 3px; }
button, .btn {
  display: inline-block; border: 1px solid var(--brand-2); background: var(--brand-2); color: #fff; padding: 7px 14px;
  border-radius: 6px; font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary, button.secondary { background: #fff; color: var(--brand-2); }
.btn.danger, button.danger { background: var(--danger); border-color: var(--danger); }
.btn.small, button.small { padding: 3px 9px; font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; align-items: end; }
.filters .row2 { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, 1fr) auto; gap: 10px; align-items: end; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.check input { width: auto; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: var(--ok-bg); border-color: #a7dcc6; color: #0b5e4c; }
.flash.err { background: var(--err-bg); border-color: #f4b4ad; color: var(--danger); }
.flash.warn { background: var(--warn-bg); border-color: #f0c674; color: #7a5200; }
.secret-box { background: #0f1b2b; color: #e6f0ff; padding: 12px 14px; border-radius: 6px; word-break: break-all; font-family: Consolas, monospace; }

.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; }
.bars .bar { display: grid; grid-template-columns: 140px 1fr 50px; gap: 10px; align-items: center; margin-bottom: 8px; }
.bars .track { background: #edf2f7; height: 10px; border-radius: 5px; overflow: hidden; }
.bars .fill { background: var(--brand-2); height: 100%; }
.w0{width:0}.w5{width:5%}.w10{width:10%}.w15{width:15%}.w20{width:20%}.w25{width:25%}.w30{width:30%}.w35{width:35%}.w40{width:40%}.w45{width:45%}.w50{width:50%}.w55{width:55%}.w60{width:60%}.w65{width:65%}.w70{width:70%}.w75{width:75%}.w80{width:80%}.w85{width:85%}.w90{width:90%}.w95{width:95%}.w100{width:100%}

.history li { padding: 8px 0; border-bottom: 1px dashed var(--line); list-style: none; }
.history { padding: 0; margin: 0; max-height: 640px; overflow: auto; }
.danger-zone { border-color: #f4b4ad; }

/* Pages d'authentification */
.auth { max-width: 400px; margin: 9vh auto; }
.auth .card { padding: 28px; }
.auth h1 { margin-bottom: 18px; }
.auth .field { margin-bottom: 14px; }
.qr svg { width: 200px; height: 200px; display: block; margin: 10px 0; }

@media (max-width: 900px) {
  .filters, .filters .row2 { grid-template-columns: 1fr 1fr; }
  .kv { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .g2 { grid-template-columns: 1fr; }
}
a.stat, a.bar { display: block; color: inherit; text-decoration: none; }
a.bar { display: grid; }
a.stat:hover { border-color: var(--brand-2); }
.bars .track, .bars .fill { display: block; }
.topbar .who a, .topbar .who a.muted { color: #d5e1f0; }
.grid { margin-bottom: 18px; }
.grid > .card { margin-bottom: 0; }
td:first-child a { white-space: nowrap; }
@media (max-width: 900px) {
  .topbar { height: auto; padding: 10px 16px; gap: 8px; }
  .topbar nav { flex-basis: 100%; order: 3; }
}
/* Déclaration mobile */
.mobile-form { max-width: 560px; margin: 0 auto; }
.mobile-form .field { margin-bottom: 14px; }
.mobile-form input, .mobile-form select { font-size: 16px; padding: 10px; }
.row2f { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wide-btn { width: 100%; padding: 13px; font-size: 16px; margin-bottom: 10px; }
.poster { text-align: center; }
.poster ol { text-align: left; max-width: 620px; margin: 10px auto; }
.qr-big svg { width: 300px; height: 300px; margin: 16px auto; }
@media print {
  .topbar, .noprint, .flash { display: none !important; }
  body { background: #fff; }
  .card { border: none; }
}
