:root {
  --paper: #F4F4F1; --card: #FBFBF9; --ink: #141414; --muted: #5B5A56; --rule: #D6D5CF; --red: #C8161D; --band: #F1F0EC;
  --display: "Archivo", system-ui, sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #0F0F0E; --card: #191917; --ink: #EDECE7; --muted: #A5A39C; --rule: #34332F; --band: #20201D; }
}
* { box-sizing: border-box; margin: 0; }
body { background: var(--paper) var(--grain); color: var(--ink); font: 400 16px/1.55 var(--display); padding: 0 16px 64px; }
.top { max-width: 920px; margin: 0 auto; padding: 22px 0; border-bottom: 3px solid var(--red); display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.top .acc { font: 500 13px/1 var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--ink); text-decoration: none; border: 1.5px solid var(--ink); padding: 9px 12px; white-space: nowrap; }
.top .acc:hover { background: var(--ink); color: var(--paper); }
@media print { .top .acc { display: none; } }
.mark { font: 800 22px/1 var(--display); font-stretch: 125%; text-transform: uppercase; color: var(--ink); text-decoration: none; letter-spacing: .02em; }
.mark i { font-style: normal; color: var(--red); }
main { max-width: 920px; margin: 28px auto 0; display: grid; gap: 22px; }
.eyebrow, .lbl { font: 500 11px/1.3 var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.mono { font-family: var(--mono); font-weight: 500; }
.red { color: var(--red); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 20px; letter-spacing: .06em; }
.tools { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
.toolrow { display: flex; gap: 10px; align-items: center; }
select { font: 500 14px var(--display); padding: 9px 10px; border: 1.5px solid var(--ink); background: var(--card); color: var(--ink); border-radius: 0; }
.btn { display: inline-flex; align-items: center; min-height: 44px; padding: 0 20px; background: var(--red); color: #fff; font: 800 14px/1 var(--display); font-stretch: 112%; text-transform: uppercase; letter-spacing: .06em; text-decoration: none; border: 0; }
.btn.line { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }
.switch { display: inline-flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; }
.track { width: 42px; height: 24px; border: 1.5px solid var(--ink); position: relative; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; background: var(--ink); transition: transform .2s; }
.switch.on .track { background: var(--red); border-color: var(--red); }
.switch.on .track::after { transform: translateX(18px); background: #fff; }
.share { display: flex; flex: 1 1 300px; min-width: 0; border: 1.5px solid var(--ink); background: var(--card); }
.share input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: 500 13px var(--mono); padding: 0 12px; }
.share button { border: 0; border-left: 1.5px solid var(--ink); background: var(--ink); color: var(--card); font: 700 13px var(--display); padding: 0 16px; min-height: 42px; cursor: pointer; }
#status { flex-basis: 100%; }
.sheet { background: var(--card); border: 1px solid var(--rule); box-shadow: 0 30px 60px -40px rgba(0,0,0,.55); padding: clamp(18px, 4vw, 44px); display: grid; gap: 18px; position: relative; min-width: 0; }
.sheet.narrow { max-width: 640px; width: 100%; justify-self: center; }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2.5px solid var(--red); padding-bottom: 10px; }
h1 { font: 800 clamp(26px, 5vw, 40px)/1.05 var(--display); font-stretch: 125%; text-transform: uppercase; overflow-wrap: anywhere; }
h2 { font: 800 18px/1.2 var(--display); font-stretch: 118%; text-transform: uppercase; margin-top: 10px; }
h2 small { font: 500 12px var(--mono); color: var(--muted); text-transform: none; margin-left: 8px; letter-spacing: .04em; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 24px; }
.facts div { display: grid; gap: 3px; align-content: start; padding: 10px 0; border-bottom: 1px dashed var(--rule); min-width: 0; }
.facts strong { overflow-wrap: anywhere; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: var(--ink); color: var(--card); font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; text-align: left; padding: 8px 10px; }
td { padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
tbody tr:nth-child(even) td { background: var(--band); }
td.code { font: 500 13px var(--mono); white-space: nowrap; }
td.cat { color: var(--muted); font-size: 13px; }
.odo { font-weight: 600; }
.odo.ok::before { content: "✓ "; color: #2E7D32; }
.odo.warn { color: var(--red); }
.sim { background: var(--red); color: #fff; font-weight: 700; font-size: 14px; padding: 8px 12px; }
.badge { justify-self: start; border: 1.5px solid #2E7D32; color: #2E7D32; font: 700 13px var(--display); text-transform: uppercase; letter-spacing: .08em; padding: 6px 10px; }
.sheet-foot { display: flex; gap: 16px; align-items: flex-start; border-top: 1.5px solid var(--ink); padding-top: 16px; margin-top: 8px; }
.qr { width: 92px; height: 92px; flex: 0 0 auto; background: #fff; padding: 4px; }
.wait { text-align: left; }
.engine { display: flex; gap: 8px; height: 46px; align-items: flex-end; }
.engine i { width: 18px; background: var(--ink); animation: pist .9s ease-in-out infinite alternate; }
.engine i:nth-child(even) { background: var(--red); animation-delay: .45s; }
.engine i:nth-child(3), .engine i:nth-child(4) { animation-delay: .22s; }
.engine.off i { animation: none; height: 12px; opacity: .4; }
@keyframes pist { from { height: 12px; } to { height: 46px; } }
@media (prefers-reduced-motion: reduce) { .engine i { animation: none; height: 30px; } }
@media (max-width: 560px) { .sheet-foot { flex-direction: column; } .opts td.cat, .opts th:last-child { display: none; } }
.hero-img { margin: 4px 0 0; display: grid; gap: 6px; }
.hero-img img { width: 100%; max-height: 420px; object-fit: contain; background: var(--band); border: 1px solid var(--rule); }
.hold { border-left: 4px solid #2E7D32; padding: 10px 14px; background: var(--band); font-weight: 600; }
#nf { display: grid; gap: 12px; }
#nf[hidden] { display: none; }
[hidden] { display: none !important; }

/* Version imprimée (PDF généré par le navigateur du serveur) */
@page { size: A4; }
body.print { background: #fff; padding: 0; color-scheme: light; --paper: #fff; --card: #fff; --ink: #141414; --muted: #5B5A56; --rule: #D6D5CF; --band: #F1F0EC; }
body.print .tools { display: none; }
body.print .top { padding: 0 0 10px; margin-bottom: 14px; }
body.print .sheet-head { border-bottom: 0; padding-bottom: 0; }
body.print main { margin: 0; max-width: none; }
body.print .sheet { box-shadow: none; border: 0; padding: 0; }
body.print .hero-img img { max-height: 260px; }
body.print table { font-size: 12.5px; }
body.print tr, body.print .facts div, body.print .sheet-foot { break-inside: avoid; }
body.print thead { display: table-header-group; }
@media print { .tools { display: none; } .sheet { box-shadow: none; border: 0; } }

/* Écriture de droite à gauche : VIN, codes, chiffres et valeurs latines gardent leur sens de lecture */
.mono, td.code, .facts strong, .sheet-head .mono, #shareUrl { unicode-bidi: plaintext; }
.mono.big, td.code { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .facts strong.mono { direction: ltr; text-align: right; }
[dir="rtl"] .facts strong { text-align: right; }
body.print h2, body.print .odo { break-after: avoid; }

.tech summary { cursor: pointer; list-style: none; }
.tech summary::-webkit-details-marker { display: none; }
.tech summary h2::after { content: " +"; color: var(--red); }
.tech[open] summary h2::after { content: " –"; }
.tech table { font-size: 12.5px; }
.tech td { color: var(--muted); padding: 6px 10px; }

.hsum { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.hsum li { padding-inline-start: 14px; position: relative; font-weight: 600; }
.hsum li::before { content: ""; position: absolute; inset-inline-start: 0; top: .6em; width: 6px; height: 6px; background: var(--red); }
table.hist td.acts { white-space: pre-line; font-size: 13px; }
table.hist td.where { font-size: 13px; color: var(--muted); min-width: 160px; }
table.hist td.km { white-space: normal; min-width: 92px; }
body.print table.hist { font-size: 11.5px; }
body.print table.hist td.acts, body.print table.hist td.where { font-size: 11px; }
.foot { max-width: 920px; margin: 40px auto 0; padding-top: 14px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--muted); }
.foot a, .linkbtn { color: var(--muted); }
.linkbtn { font: inherit; background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
body.print .foot { display: none; }
.legal h2 { font-size: 15px; margin-top: 6px; }
.legal p { color: var(--ink); max-width: 70ch; }

/* Historique sur téléphone : une carte par passage (date et kilométrage, atelier, opérations) */
@media (max-width: 560px) {
  table.hist thead { display: none; }
  table.hist, table.hist tbody, table.hist td { display: block; }
  table.hist tr { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 10px; border-bottom: 1px solid var(--rule); }
  table.hist tbody tr:nth-child(even) { background: var(--band); }
  table.hist td, table.hist tbody tr:nth-child(even) td { padding: 0; border: 0; background: none; }
  table.hist td.code:first-child { font-weight: 600; }
  table.hist td.km { text-align: end; min-width: 0; }
  table.hist td.where, table.hist td.acts { grid-column: 1 / -1; min-width: 0; }
  table.hist td.acts { margin-top: 4px; }
}

/* Options : intertitre de catégorie */
table.opts tr.grp td { background: none !important; padding: 16px 10px 6px; border-bottom: 1.5px solid var(--ink); font: 700 12px/1.2 var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--red); }
table.opts tr.grp td span { color: var(--muted); font-weight: 500; margin-inline-start: 6px; }
table.opts tbody tr:not(.grp) td { background: none; }
body.print table.opts tr.grp { break-after: avoid; }

/* Complément historique et tarif comparaison */
.upbox { border: 1.5px solid var(--ink); padding: 18px 20px; margin: 22px 0; background: var(--band, #F1F0EC); }
.upbox h2 { margin-top: 0; }
.upbox .cf-check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin: 10px 0; }
.upbox .cf-check input { margin-top: 3px; flex: none; }
.upbox .btn[disabled] { opacity: .45; cursor: not-allowed; }
.cmp { border-left: 4px solid var(--red); padding: 10px 14px; background: var(--card, #fff); font-weight: 600; font-size: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn.small { padding: 8px 12px; font-size: 13px; min-height: 0; }
@media print { .upbox, .cmp { display: none; } }
