/* Plateforme BMR : INGENIERIE.COM */
:root {
  --pri: #1F4E79; --pri-ink: #fff; --pri-soft: #e8eef5; --accent: #C72538;
  --ink: #1C1C1C; --mut: #5f6b7a; --bg: #f2f4f7; --card: #fff; --line: #dfe3e9; --field: #f7f8fa;
  --s-brouillon: #6b7280; --s-en_revue: #a16207; --s-soumis: #1F4E79; --s-valide: #2f7d32; --s-a_reprendre: #c2410c;
  --g0: #4d8f3e; --g1: #c98a00; --g2: #c53b2b;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pri: #4a86c5; --pri-soft: #1b2a3b; --ink: #e8eaf0; --mut: #9aa3b2; --bg: #111418; --card: #1a1e24; --line: #2b313a; --field: #14181d;
    --s-soumis: #4a86c5; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --pri: #4a86c5; --pri-soft: #1b2a3b; --ink: #e8eaf0; --mut: #9aa3b2; --bg: #111418; --card: #1a1e24; --line: #2b313a; --field: #14181d;
  --s-soumis: #4a86c5; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 Aptos, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { padding-top: env(safe-area-inset-top, 0px); }
a { color: var(--pri); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

#app { min-height: 100vh; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.wrap.narrow { max-width: 780px; }
.pad-bottom { padding-bottom: 96px; }

/* ------------------------------------------------ barre supérieure */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.top::after { content: ""; display: block; height: 3px; background: linear-gradient(90deg, var(--pri) 0 78%, var(--accent) 78% 100%); }
.top-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.top-in.narrow { max-width: 780px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; color: inherit; }
.brand img { height: 30px; width: auto; background: #fff; border-radius: 6px; padding: 2px 4px; }
.brand .t { font-weight: 700; font-size: 16px; line-height: 1.15; }
.brand .s { color: var(--mut); font-size: 12px; }
.top .grow { flex: 1; min-width: 0; }
.top .title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; color: var(--mut); padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.nav a.on { color: var(--pri); background: var(--pri-soft); }
.iconbtn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; color: var(--ink); flex: none; }
.iconbtn:hover { background: var(--bg); }
.iconbtn svg { width: 22px; height: 22px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; cursor: pointer; border: 0; flex: none; }

/* ------------------------------------------------ éléments */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow); }
.card > h2, .sec-title { font-size: 13px; margin: 0 0 12px; color: var(--pri); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.card > h2 .n { color: var(--mut); font-weight: 600; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.between { justify-content: space-between; }
.sub { color: var(--mut); font-size: 13px; }
.hint { color: var(--mut); font-size: 13px; margin: 6px 0; }
.empty { color: var(--mut); text-align: center; padding: 28px 10px; }
.muted { color: var(--mut); }
.mt { margin-top: 12px; }
.sep { height: 1px; background: var(--line); margin: 12px 0; border: 0; }

.btn { border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-size: 14.5px; font-weight: 600; cursor: pointer; background: var(--bg); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; white-space: nowrap; min-height: 42px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--pri); color: var(--pri-ink); }
.btn.dark { background: #1C1C1C; color: #fff; }
.btn.ok { background: var(--s-valide); color: #fff; }
.btn.warn { background: var(--s-a_reprendre); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.link { background: transparent; color: var(--pri); padding-left: 6px; padding-right: 6px; }
.btn.small { padding: 6px 11px; font-size: 13px; min-height: 34px; }
.btn.block { width: 100%; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .iconbtn:focus-visible, .chip:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--pri); outline-offset: 1px; }

.fld { display: block; margin: 0 0 12px; }
.fld > span { display: block; font-size: 12.5px; color: var(--mut); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea, .inp {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); color: var(--ink); min-height: 42px; }
textarea { resize: vertical; }
input:disabled, select:disabled, textarea:disabled { opacity: .75; }
.inp.sm, .mini { padding: 7px 10px; font-size: 13.5px; min-height: 36px; margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.chk { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.chk.top { align-items: flex-start; border-bottom: 1px solid var(--line); }
.chk input { width: 20px; height: 20px; flex: none; accent-color: var(--pri); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-brouillon { color: var(--s-brouillon); background: color-mix(in srgb, var(--s-brouillon) 12%, transparent); }
.st-en_revue { color: var(--s-en_revue); background: color-mix(in srgb, var(--s-en_revue) 13%, transparent); }
.st-soumis { color: var(--s-soumis); background: color-mix(in srgb, var(--s-soumis) 13%, transparent); }
.st-valide { color: var(--s-valide); background: color-mix(in srgb, var(--s-valide) 13%, transparent); }
.st-a_reprendre { color: var(--s-a_reprendre); background: color-mix(in srgb, var(--s-a_reprendre) 13%, transparent); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: var(--mut); border: 1px solid var(--line); }
.tag.warn { color: #9a3412; background: #fff1e6; border-color: #fed7aa; }
.tag.err { color: #fff; background: var(--accent); border-color: var(--accent); }
.tag.cl { color: var(--ink); font-weight: 800; }
.g-Faible { color: var(--g0); } .g-Moyenne { color: var(--g1); } .g-Élevée { color: var(--g2); }

/* ------------------------------------------------ connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--pri) 0 38%, var(--bg) 38%); }
.login .box { width: 100%; max-width: 400px; background: var(--card); border-radius: 16px; padding: 26px; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.login .logos { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 20px; }
.login .logos img { height: 36px; background: #fff; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login .err { color: var(--accent); font-size: 14px; min-height: 20px; margin: 6px 0; }

/* ------------------------------------------------ synchronisation */
.syncbar { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; font-size: 13.5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--s-valide); flex: none; }
.dot.off { background: var(--s-brouillon); }
.dot.busy { background: var(--s-en_revue); animation: pulse 1s infinite; }
.dot.err { background: var(--accent); }
@keyframes pulse { 50% { opacity: .35; } }
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 14px; border: 1px solid; }
.banner.warn { background: #fff7ed; border-color: #fdba74; color: #7c2d12; }
.banner.info { background: var(--pri-soft); border-color: color-mix(in srgb, var(--pri) 35%, transparent); color: var(--ink); }
.banner.err { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }
.banner b { display: block; margin-bottom: 4px; }
.banner .row { margin-top: 8px; }

/* ------------------------------------------------ tableau de bord */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; text-align: left; box-shadow: var(--shadow); border-top: 3px solid var(--c, var(--pri)); }
.kpi .v { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12.5px; color: var(--mut); font-weight: 600; }
.kpi.on { outline: 2px solid var(--c, var(--pri)); outline-offset: -1px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 240px; }
.filters select { width: auto; flex: 0 1 190px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--mut); min-height: 40px; }
.seg button.on { background: var(--pri); color: #fff; }

table.list { width: 100%; border-collapse: collapse; background: var(--card); }
.tablebox { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--card); box-shadow: var(--shadow); }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--mut); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--field); position: sticky; top: 0; white-space: nowrap; cursor: pointer; user-select: none; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: var(--pri-soft); }
table.list .th-thumb { width: 52px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.thumb { width: 44px; height: 44px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; overflow: hidden; flex: none; color: var(--mut); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 22px; height: 22px; }
.items { display: grid; gap: 10px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow); }
.item .thumb { width: 56px; height: 56px; }
.item b { font-size: 15px; }
.item .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--field); }
.leaflet-popup-content { font: 13.5px/1.4 Aptos, "Segoe UI", Arial, sans-serif; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--mut); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* ------------------------------------------------ éditeur (onglets bas) */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabs-in { max-width: 780px; margin: 0 auto; display: flex; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 2px 9px; font-size: 11.5px; color: var(--mut); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; font-weight: 600; position: relative; }
.tabs button svg { width: 21px; height: 21px; }
.tabs .on { color: var(--pri); }
.tabs .on::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--pri); }
.tabs .pill { position: absolute; top: 4px; right: calc(50% - 20px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; }

.lvlh { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--ink); padding: 2px 0; cursor: pointer; text-align: left; }
.lvlh b { font-size: 16px; flex: 1; }
.lvlb { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chips.sm { margin: 4px 0 0; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 11px; font-size: 13px; cursor: pointer; }
.chips.sm .chip { padding: 3px 8px; font-size: 11.5px; }
.chip.on { background: var(--pri); border-color: var(--pri); color: #fff; }
.prow { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; }
.ptitle { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.gseg { display: flex; gap: 6px; }
.gseg button { flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 7px; font-size: 13px; cursor: pointer; color: var(--ink); }
.gseg .on.g0 { background: var(--g0); color: #fff; border-color: var(--g0); }
.gseg .on.g1 { background: var(--g1); color: #fff; border-color: var(--g1); }
.gseg .on.g2 { background: var(--g2); color: #fff; border-color: var(--g2); }
.phs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 10px; }
.ph { position: relative; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: var(--card); }
.ph img { width: 100%; height: 130px; object-fit: cover; border-radius: 7px; background: var(--bg); display: block; cursor: zoom-in; }
.ph .x { position: absolute; top: 10px; right: 10px; border: 0; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; }
.ph .n { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.prev { width: 100%; max-height: 300px; object-fit: contain; border-radius: 10px; background: var(--bg); margin: 6px 0; display: block; }
.step { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.step:first-of-type { border-top: 0; padding-top: 0; }
.step .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.step .n.ok { background: var(--s-valide); color: #fff; }
.docs { display: grid; gap: 10px; }
.doc { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; flex-wrap: wrap; }
.doc .grow b { display: block; }
.sigs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sigbox { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 12.5px; text-align: center; }
.sigbox img { width: 100%; height: 60px; object-fit: contain; background: #fff; border-radius: 6px; }

/* ------------------------------------------------ fiche (lecture) */
.kv { display: grid; grid-template-columns: minmax(130px, 34%) 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.kv > div { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv > div:nth-child(odd) { background: var(--field); color: var(--mut); font-weight: 600; font-size: 13px; }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.lvlcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.lvlcard h3 { margin: 0 0 8px; font-size: 15px; }
.lvlcard ul { margin: 0; padding-left: 18px; }
.lvlcard li { margin: 3px 0; }
.hero { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
.hero .facade { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; background: var(--bg); display: block; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: var(--card); border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
.actionbar .in { max-width: 780px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.toc { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 14px; padding-bottom: 2px; }
.toc a { white-space: nowrap; text-decoration: none; font-size: 13px; font-weight: 600; color: var(--mut); border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; }

/* ------------------------------------------------ suivi */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .pt { position: absolute; left: 0; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); border: 3px solid var(--pri); }
.timeline .who { font-weight: 700; font-size: 14px; }
.timeline .when { color: var(--mut); font-size: 12.5px; }
.timeline .cm { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 6px; white-space: pre-wrap; font-size: 14px; }

/* ------------------------------------------------ fenêtres */
.modal { position: fixed; inset: 0; background: rgba(10,15,25,.6); display: grid; place-items: center; z-index: 40; padding: 14px; }
.mbox { background: var(--card); border-radius: 16px; padding: 18px; width: 100%; max-width: 540px; display: flex; flex-direction: column; gap: 12px; max-height: 94vh; overflow: auto; }
.mbox h3 { margin: 0; font-size: 17px; }
.mbox canvas.sig { width: 100%; height: auto; background: #fff; border: 2px dashed #9aa3b2; border-radius: 10px; touch-action: none; }
.triimg { width: 100%; max-height: 40vh; object-fit: contain; background: #000; border-radius: 10px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; gap: 10px; }
.lightbox img { max-width: 100%; max-height: 82vh; object-fit: contain; }
.lightbox .cap { color: #eee; font-size: 14px; text-align: center; white-space: pre-line; }
.menu { position: absolute; right: 12px; top: 56px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 240px; padding: 6px; z-index: 30; }
.menu .hd { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu a, .menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); cursor: pointer; font-size: 14px; }
.menu a:hover, .menu button:hover { background: var(--bg); }

#toast { position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); background: #1C1C1C; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 92%; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.foot { text-align: center; color: var(--mut); font-size: 12px; margin: 22px 0 8px; }
.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; min-height: 60vh; color: var(--mut); gap: 10px; }

/* ------------------------------------------------ responsive */
@media (max-width: 980px) { .kpis { grid-template-columns: repeat(3, 1fr); } .hero { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .wrap { padding: 12px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .v { font-size: 22px; }
  .nav { display: none; }
  .brand .s { display: none; }
  .grid3 { grid-template-columns: 1fr; }
  .sigs { grid-template-columns: 1fr; }
  #map { height: 62vh; }
  .hide-sm { display: none !important; }
  .filters select { flex: 1 1 45%; }
}
@media (min-width: 721px) { .show-sm { display: none !important; } }
@media print { .top, .tabs, .actionbar, .btn, #toast { display: none !important; } body { background: #fff; } .card { box-shadow: none; } }
