:root {
  --navy: #0e1a28;
  --navy-2: #16263a;
  --navy-3: #22374f;
  --green: #5cbf4c;
  --green-d: #3c8f31;
  --green-l: #e8f5e5;
  --bg: #f2f5f8;
  --card: #ffffff;
  --line: #dbe2ea;
  --text: #15202c;
  --muted: #5e6f82;
  --warn: #b45309;
  --warn-l: #fef3c7;
  --danger: #b91c1c;
  --radius: 14px;
  --tap: 48px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green-d); }
[hidden] { display: none !important; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--navy); color: #fff;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  min-height: 60px;
}
.brand { display: flex; align-items: center; }
.brand img { height: 36px; display: block; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 10px; border: 0;
  background: var(--navy-2); color: #fff; font-size: 30px; line-height: 1; cursor: pointer;
}
.net { margin-left: auto; font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--navy-2); white-space: nowrap; }
.net.on::before { content: "● "; color: var(--green); }
.net.off::before { content: "● "; color: #f59e0b; }
.banner { background: var(--green-l); color: var(--text); padding: 10px 16px; text-align: center; }
.banner button { margin-left: 8px; }

/* Compte */
.user-btn { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 10px 0 4px; border: 0; border-radius: 99px; background: var(--navy-2); color: #fff; cursor: pointer; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--green); color: var(--navy); display: grid; place-items: center; font-weight: 800; }
.user-menu { position: absolute; right: 12px; top: calc(100% + 6px); width: 240px; background: #fff; color: var(--text); border-radius: 14px; padding: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.25); }
.topbar { position: sticky; }
@media (max-width: 480px) { .user-nom { display: none; } .user-btn { padding: 0 4px; } .net { font-size: 12px; padding: 4px 8px; } }

/* Mise en page */
.layout { display: flex; max-width: 1200px; margin: 0 auto; }
.main { flex: 1; min-width: 0; padding: 16px 16px 110px; }
.side { display: none; }
@media (min-width: 900px) {
  .side:not([hidden]) {
    display: block; width: 270px; flex: none;
    position: sticky; top: 60px; align-self: flex-start;
    max-height: calc(100vh - 60px); overflow: auto;
    padding: 16px 0 16px 16px;
  }
  .main { padding: 20px 24px 40px; max-width: 860px; }
  .steps { display: none !important; }
}
.side a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--text);
}
.side a.on { background: var(--navy); color: #fff; }
.side a:hover:not(.on) { background: #e3e9f0; }
.side h4 { margin: 18px 12px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side .sub { padding-left: 26px; font-size: 15px; }

/* Barre d'étapes mobile */
.steps {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--navy); padding-bottom: env(safe-area-inset-bottom);
}
.steps a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 10px; color: #b8c6d6; text-decoration: none; font-size: 12px;
}
.steps a b { font-size: 20px; line-height: 1.2; }
.steps a.on { color: #fff; box-shadow: inset 0 3px 0 var(--green); }

/* Blocs */
h1 { font-size: 24px; margin: 4px 0 4px; }
h2 { font-size: 19px; margin: 0 0 12px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--green); border-color: var(--green); color: #0b1a0a; }
.btn.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c4c4; }
.btn.block { width: 100%; }
.btn:active { transform: translateY(1px); }

/* Liste des études */
.etude {
  display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit;
}
.etude .pill { flex: none; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: #e3e9f0; color: var(--muted); }
.pill.gtb { background: var(--navy); color: #fff; }
.pill.res { background: var(--green-l); color: var(--green-d); }
.progress { height: 6px; background: #e3e9f0; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--green); }

/* Formulaire */
.q { padding: 12px 0; border-top: 1px solid #edf1f5; }
.q:first-child { border-top: 0; padding-top: 0; }
.q > label, .q > .label { display: block; font-weight: 600; margin-bottom: 8px; }
.q .req { color: var(--danger); }
.q .help { font-size: 14px; color: var(--muted); margin: -2px 0 8px; }
.q.new { animation: glow 1.2s ease-out; }
@keyframes glow { from { background: var(--green-l); } to { background: transparent; } }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid #c9d3de; border-radius: 10px; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
select {
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px;
}
select.empty { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(92,191,76,.35); border-color: var(--green-d); }
.unit { display: flex; align-items: center; gap: 8px; }
.unit input { max-width: 180px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 99px; cursor: pointer;
  border: 1px solid #c9d3de; background: #fff; text-align: left;
}
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.on::before { content: "✓ "; color: var(--green); font-weight: 700; }
.seg { display: inline-flex; border: 1px solid #c9d3de; border-radius: 12px; overflow: hidden; }
.seg button { min-height: 44px; min-width: 84px; border: 0; background: #fff; cursor: pointer; }
.seg button + button { border-left: 1px solid #c9d3de; }
.seg button.on { background: var(--navy); color: #fff; }

/* Lots */
.lots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lot {
  min-height: 72px; border-radius: 12px; border: 1px solid #c9d3de; background: #fff; cursor: pointer;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; text-align: left;
}
.lot span { font-size: 24px; flex: none; }
.lot { overflow-wrap: anywhere; hyphens: auto; line-height: 1.25; }
.lot.on { border-color: var(--green-d); background: var(--green-l); box-shadow: inset 0 0 0 1px var(--green-d); }
details.acc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
details.acc > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 700;
  display: flex; align-items: center; gap: 10px; min-height: 56px;
}
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .15s; }
details.acc:not([open]) > summary::after { transform: rotate(-90deg); }
details.acc > .body { padding: 0 16px 16px; }
.count { font-size: 13px; font-weight: 600; color: var(--muted); }

/* Photos */
.photos { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 10px; }
.thumbs button { padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; cursor: pointer; background: #dde4ec; position: relative; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs em { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; font-style: normal; color: #fff; background: rgba(0,0,0,.55); padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.viewer {
  position: fixed; inset: 0; z-index: 50; background: rgba(8,14,22,.94);
  display: flex; flex-direction: column; padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}
.viewer img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer .bar { display: flex; gap: 8px; margin-top: 10px; }
.viewer input { flex: 1; }

/* Zones */
.zone-item { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.zone-item .n { width: 40px; height: 40px; border-radius: 10px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.tag { display: inline-block; font-size: 12px; background: #eef2f6; border-radius: 6px; padding: 1px 6px; margin: 2px 2px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.notice { background: var(--warn-l); color: #78350f; border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }

/* Mise à jour des questions */
details.admin { margin-top: 18px; }
.result { border-radius: 12px; padding: 12px 14px; margin-top: 14px; font-size: 15px; }
.result ul { margin: 8px 0 0; padding-left: 20px; }
.result li { margin: 3px 0; }
.result.ok { background: var(--green-l); color: #1f4f19; }
.result.err { background: #fdecec; color: #7f1d1d; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--green-d); }

/* Enregistrement et reprise */
.save-pill { position: fixed; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 19; font-size: 12px; padding: 4px 10px; border-radius: 99px; background: rgba(14,26,40,.85); color: #fff; pointer-events: none; }
.save-pill.err { background: var(--danger); font-weight: 700; }
@media (min-width: 900px) { .save-pill { bottom: 16px; } }
a.card.reprise { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; border: 2px solid var(--green); }
.reprise-ico { width: 40px; height: 40px; border-radius: 50%; background: var(--green-l); color: var(--green-d); display: grid; place-items: center; font-size: 22px; font-weight: 700; flex: none; }
@media print { .save-pill { display: none !important; } }

/* Synthèse */
.syn h3 { margin: 18px 0 6px; font-size: 16px; color: var(--green-d); }
.syn table { width: 100%; border-collapse: collapse; font-size: 14px; }
.syn td { padding: 5px 6px; border-bottom: 1px solid #edf1f5; vertical-align: top; }
.syn td:first-child { color: var(--muted); width: 45%; }
.syn .pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-top: 8px; }
.syn figure { margin: 0; break-inside: avoid; }
.syn figure img { width: 100%; border-radius: 6px; display: block; }
.syn figcaption { font-size: 12px; color: var(--muted); }
.print-head { display: none; }

@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .topbar, .steps, .side, .no-print, .banner, .toast { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; padding: 0; }
  .print-head { display: flex; align-items: center; justify-content: space-between; background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-head img { height: 34px; }
  .syn section { break-inside: avoid-page; }
}
