:root {
  --bg: #f3f5f8; --card: #fff; --text: #1d2733; --muted: #6b7785; --line: #e1e6ec;
  --primary: #1f4e79; --primary-2: #2c6aa3; --danger: #c0392b; --warn: #d68910; --ok: #1e8449; --info: #2471a3;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 0 0 .7em; }
h3 { font-size: 1rem; margin: 1.2em 0 .5em; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Barre de navigation */
.topbar { background: var(--primary); color: #fff; display: flex; align-items: center; flex-wrap: wrap; padding: 0 16px; position: sticky; top: 0; z-index: 10; }
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; padding: 14px 0; margin-right: 20px; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; flex: 1; }
.mainnav a, .mainnav .linkbtn { color: #dbe7f3; padding: 8px 10px; border-radius: 6px; }
.mainnav a.active, .mainnav a:hover, .mainnav .linkbtn:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.burger { display: none; }
input.navtoggle { display: none !important; }
@media (max-width: 860px) {
  .burger { display: block; margin-left: auto; font-size: 1.6rem; cursor: pointer; padding: 6px 4px; }
  .mainnav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
  .navtoggle:checked ~ .mainnav { display: flex; }
  .mainnav a, .mainnav .linkbtn { padding: 10px; text-align: left; }
}

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.container.narrow { max-width: 440px; padding-top: 8vh; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; border: 1px solid var(--line); }
.card.auth h1 { text-align: center; }
.card.empty { text-align: center; padding: 30px; }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.actions.sep { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 16px; }
.page-head .actions { margin: 0; }

/* Formulaires */
label { display: block; margin-bottom: 12px; font-weight: 500; font-size: .92rem; }
label small { font-weight: 400; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid #c8d0da; border-radius: 7px; font: inherit; background: #fff; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); outline-offset: -1px; border-color: var(--primary-2); }
input[type=checkbox], input[type=radio] { display: inline; width: auto; margin: 0 6px 0 0; }
label.check { font-weight: 400; display: flex; align-items: center; margin-bottom: 8px; }
fieldset.choice { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 6px 0 12px; }
fieldset.choice legend { font-weight: 600; padding: 0 6px; }
.indent { margin: 0 0 10px 26px; }
.indent select { margin-bottom: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid2.top { align-items: start; gap: 0 18px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 12px; margin-top: 10px; }
.span4 { grid-column: 1 / -1; }
@media (max-width: 760px) { .grid2, .grid4 { grid-template-columns: 1fr; } }
@media (min-width: 761px) and (max-width: 1000px) { .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.inline { display: inline; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; flex: 1 1 160px; margin: 0; }

.btn { display: inline-block; background: var(--primary); color: #fff; border: 0; border-radius: 7px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.btn:hover { background: var(--primary-2); text-decoration: none; }
.btn.secondary { background: #e7edf4; color: var(--primary); }
.btn.secondary:hover { background: #d7e2ee; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 11px; font-size: .88rem; }
.btn.full { width: 100%; padding: 11px; }
.btn[disabled] { opacity: .6; cursor: wait; }
.linkbtn { background: none; border: 0; font: inherit; cursor: pointer; color: var(--primary-2); padding: 0; }
.danger-text { color: var(--danger); }
.danger-zone { border-color: #f1c4bf; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash.succes { background: #e9f7ef; border-color: #a9dfbf; color: #145a32; }
.flash.erreur { background: #fdedec; border-color: #f5b7b1; color: #78281f; }
.flash.info { background: #eaf2f8; border-color: #aed6f1; color: #1b4f72; }

/* Statistiques en tête */
.stats-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 760px) { .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; color: var(--text); box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; }
.stat-val { font-size: 1.45rem; font-weight: 700; }
.stat-lbl { color: var(--muted); font-size: .85rem; }
.stat.warn { border-left: 4px solid var(--warn); }
.stat.danger { border-left: 4px solid var(--danger); }

/* Véhicules */
.vehicle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 18px; }
.vehicle-card { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; color: var(--text); box-shadow: var(--shadow); }
.vehicle-card:hover { border-color: var(--primary-2); text-decoration: none; }
.vinfo { display: flex; flex-direction: column; font-size: .92rem; }
.vphoto { width: 84px; height: 64px; border-radius: 8px; background: #e7edf4; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 2rem; flex-shrink: 0; }
.vphoto img { width: 100%; height: 100%; object-fit: cover; }
.vphoto.big { width: 120px; height: 90px; font-size: 2.6rem; }
.vhead { display: flex; gap: 14px; align-items: center; }
.vhead h1 { margin: 0; }
.vhead p { margin: 2px 0; }

/* Alertes */
.alerts { list-style: none; padding: 0; margin: 0 0 10px; }
.alert-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 20px; white-space: nowrap; background: #e7edf4; color: var(--primary); }
.badge.depasse, .badge.st-erreur { background: #fadbd8; color: #922b21; }
.badge.bientot, .badge.st-a_valider { background: #fdebd0; color: #9c640c; }
.badge.ok, .badge.st-valide { background: #d5f5e3; color: #196f3d; }
.badge.inconnu { background: #eceff1; color: #546e7a; }
.badge.st-traitement, .badge.st-en_attente { background: #d6eaf8; color: #1a5276; }
details { margin-top: 8px; }
details summary { cursor: pointer; color: var(--primary-2); font-weight: 500; padding: 4px 0; }
.edit-rem { margin: 0 0 8px; padding-left: 8px; }
.edit-rem summary { font-size: .85rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .02em; }
td.num, th.num { text-align: right; white-space: nowrap; }
tfoot th { color: var(--text); font-size: .92rem; text-transform: none; }
td .path { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.plain { list-style: none; padding: 0; margin: 6px 0; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* Téléversement */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; border: 2px dashed #b6c3d1; border-radius: 10px; padding: 22px; text-align: center; cursor: pointer; background: #f8fafc; font-weight: 400; }
.dropzone.drag { border-color: var(--primary-2); background: #eaf2f8; }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dz-files { margin-top: 6px; font-size: .85rem; }

/* Page document */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 960px) { .doc-layout { grid-template-columns: 1fr; } }
.preview iframe { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 6px; background: #fafafa; }
.preview img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 6px; }
@media (max-width: 960px) { .preview iframe { height: 50vh; } }
pre.extracted { white-space: pre-wrap; font-size: .8rem; background: #f6f8fa; padding: 10px; border-radius: 6px; max-height: 400px; overflow: auto; }

.chart-box { position: relative; height: 300px; }
