:root {
  --card-border: #c3ccd8;
  --head-bg: #eaf0f7;
  --head-text: #1f3a5f;
  --item-bg: #f6f8fb;
  --item-border: #b9c4d2;
  --bg: #e4e9ef;
  --card: #ffffff;
  --text: #17202c;
  --muted: #5f6b7a;
  --line: #dde2e9;
  --brand: #1f3a5f;
  --brand-2: #2c5d94;
  --accent: #ff9f1c;
  --ok: #1f9d55;      --ok-bg: #e3f6ea;
  --verif: #b86e00;   --verif-bg: #fff1d6;
  --bad: #d62f2f;     --bad-bg: #fde4e4;
  --na: #5f6b7a;      --na-bg: #eceff3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
/* Thème sombre : choisi dans Paramètres, ou « auto » quand le téléphone est en mode sombre. */
:root[data-theme="dark"] {
  --card-border: #344255; --head-bg: #1f2a38; --head-text: #cfe0f5; --item-bg: #1d2633; --item-border: #3a495d;
  --bg: #0b1016; --card: #18202b; --text: #e8edf3; --muted: #9aa6b5; --line: #2a3542;
  --brand: #16283f; --brand-2: #5b9bea;
  --ok-bg: #12321f; --verif-bg: #3a2a0c; --bad-bg: #3d1616; --na-bg: #232c38;
  --ok: #4fd18a; --verif: #ffb547; --bad: #ff6b6b; --na: #9aa6b5;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --card-border: #344255; --head-bg: #1f2a38; --head-text: #cfe0f5; --item-bg: #1d2633; --item-border: #3a495d;
    --bg: #0b1016; --card: #18202b; --text: #e8edf3; --muted: #9aa6b5; --line: #2a3542;
    --brand: #16283f; --brand-2: #5b9bea;
    --ok-bg: #12321f; --verif-bg: #3a2a0c; --bad-bg: #3d1616; --na-bg: #232c38;
    --ok: #4fd18a; --verif: #ffb547; --bad: #ff6b6b; --na: #9aa6b5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand-2); }
h1, h2, h3 { line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: 6px 0; }
[hidden] { display: none !important; }

/* ---------- En-tête ---------- */
header.top {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  background: var(--brand); color: #fff; min-height: 56px;
}
header.top h1 { flex: 1; font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; border-radius: 10px; color: #fff; text-decoration: none; font-size: 1.3rem;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.icon-btn.back { font-size: 2rem; line-height: 1; padding-bottom: 4px; }
.logo { padding: 0 6px; font-size: 1.3rem; }
.save-state { font-size: .8rem; opacity: .8; white-space: nowrap; }
.save-state.saved { color: #9ff0bf; }
.gnss-state { font-size: .78rem; white-space: nowrap; opacity: .9; display: inline-flex; align-items: center; gap: 4px; }
.gnss-dot { width: 9px; height: 9px; border-radius: 50%; background: #8a94a6; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.gnss-dot.ok { background: #3ddc84; } .gnss-dot.verif { background: #ffb020; } .gnss-dot.bloquant { background: #ff5a5a; }
.net { font-size: .72rem; padding: 2px 8px; border-radius: 99px; margin-right: 4px; }
.net.on { background: rgba(79, 209, 138, .25); }
.net.off { background: rgba(255, 159, 28, .35); }

main { max-width: 760px; margin: 0 auto; padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); }

/* ---------- Cartes / listes ---------- */
.card {
  display: block; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--card-border);
  padding: 14px; margin-bottom: 16px; color: inherit; text-decoration: none;
}
/* Tuile avec bandeau de titre : le bandeau délimite nettement chaque cadre. */
.card:has(> .card-head) { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; background: var(--head-bg); border-bottom: 1px solid var(--card-border);
  border-left: 5px solid var(--brand-2);
}
.card-head h2 { margin: 0; font-size: 1rem; color: var(--head-text); }
.card-body { padding: 12px 14px 14px; }
.conclusion-card .card-head { border-left-color: var(--accent); }
.sub-title { font-size: .92rem; margin: 18px 0 6px; padding-top: 12px; border-top: 1px dashed var(--card-border); }
label.sub { display: block; font-weight: 600; font-size: .92rem; margin: 6px 0 4px; }
.points { list-style: none; padding-left: 0 !important; }
.points li { margin: 4px 0; }
.ico { width: 1.15em; height: 1.15em; vertical-align: -0.2em; }
.item-icon .ico, .type-btn .ico { width: 1.6rem; height: 1.6rem; }
.pop-ico .ico { width: 1.1em; height: 1.1em; }
.site-card:active { transform: scale(.99); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.notes { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 99px; background: var(--na-bg); color: var(--muted); font-size: .8rem; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.empty { text-align: center; padding: 40px 16px; }

.list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 10px; }
.list { gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  background: var(--item-bg); border: 1px solid var(--item-border); border-left: 5px solid var(--item-border);
  border-radius: 10px; text-decoration: none; color: inherit; box-shadow: 0 1px 2px rgba(16,24,40,.08);
}
/* Bord gauche coloré selon le pré-avis de l'accès. */
.item.lvl-ok { border-left-color: var(--ok); }
.item.lvl-verif { border-left-color: var(--verif); }
.item.lvl-bloquant { border-left-color: var(--bad); }
.item.lvl-na { border-left-color: var(--na); }
.item.lvl-mat { border-left-color: var(--brand); }
.item:active { background: var(--bg); }
.item-icon { font-size: 1.4rem; width: 38px; text-align: center; flex-shrink: 0; }
.mat-tag { font-size: .85rem; font-weight: 700; background: var(--brand); color: #fff; border-radius: 8px; padding: 6px 0; }
.item-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.item-body .chips { margin-top: 4px; }
.item-meta { color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* ---------- Badges verdict ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.verif { background: var(--verif-bg); color: var(--verif); }
.badge.bloquant { background: var(--bad-bg); color: var(--bad); }
.badge.na { background: var(--na-bg); color: var(--na); }
.verdict-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.verdict-row:last-of-type { border-bottom: 0; }
.verdict-row ul { margin: 4px 0 0; padding-left: 20px; font-size: .88rem; color: var(--muted); }
.verdict-card { border-left: 4px solid var(--accent); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { filter: brightness(.95); transform: translateY(1px); }
.btn:disabled { opacity: .6; }
.btn.block { display: flex; width: 100%; margin: 8px 0; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: .9rem; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad-bg); background: transparent; }
.btn.ghost { background: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 > .btn { width: 100%; }
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 400;
  min-height: 56px; padding: 0 22px; border: 0; border-radius: 28px;
  background: var(--accent); color: #1b1300; font: inherit; font-weight: 700; font-size: 1rem;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
.fab-space { height: 80px; }

/* ---------- Formulaires ---------- */
.field { margin-bottom: 12px; }
.field > label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.unit { color: var(--muted); font-weight: 400; }
.req { color: var(--bad); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=tel], input[type=email], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font: inherit; font-size: 16px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; }
.with-unit { position: relative; }
.with-unit input { padding-right: 46px; font-size: 1.15rem; font-weight: 600; }
.with-unit span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.check input { width: 22px; height: 22px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  flex: 1 1 auto; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: .92rem;
}
.seg-btn.on { background: var(--brand-2); border-color: var(--brand-2); color: #fff; font-weight: 600; }

.gps-value { min-height: 28px; margin-bottom: 6px; word-break: break-all; }

/* ---------- Photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; margin-bottom: 8px; }
.thumb {
  position: relative; aspect-ratio: 1; border: 0; border-radius: 10px; padding: 0;
  background: var(--na-bg) center / cover no-repeat;
}
.has-legend { position: absolute; right: 4px; bottom: 4px; font-size: .8rem; }
.viewer {
  position: fixed; inset: 0; z-index: 2000; background: #000; display: flex; flex-direction: column;
}
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer-bar { background: var(--card); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.viewer-bar textarea { min-height: 60px; margin-bottom: 4px; }

/* ---------- Feuille de choix ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 1500; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 760px; max-height: 88vh; overflow: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
}
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 8px; }
.type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; min-height: 84px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font: inherit; font-size: .88rem;
}
.type-btn span { font-size: 1.6rem; }

/* ---------- Carte ---------- */
.map { height: calc(100vh - 220px); min-height: 320px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 2px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; border: 2px solid #fff; box-shadow: 0 0 0 1px #999; }
.dot.site { background: #1f5fbf; } .dot.ok { background: #1f9d55; } .dot.verif { background: #e08a00; } .dot.bloquant { background: #d62f2f; }
.dot.mat { background: var(--brand); border-radius: 3px; }
.mat-marker {
  background: #1f3a5f; color: #fff; font-weight: 700; font-size: 12px; line-height: 22px; text-align: center;
  border-radius: 6px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  z-index: 3000; max-width: 90vw; padding: 10px 16px; border-radius: 10px; background: #222b36; color: #fff;
  font-size: .92rem; opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Appareil photo intégré ---------- */
.camera { position: fixed; inset: 0; z-index: 2500; background: #000; color: #fff; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-top {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: linear-gradient(rgba(0,0,0,.65), transparent);
}
.cam-compass svg { width: 46px; height: 46px; transition: transform .15s linear; }
.cam-info { font-weight: 700; text-shadow: 0 1px 3px #000; }
.cam-heading { font-size: 1.15rem; }
.cam-gps { font-size: .85rem; }
.cam-gps.ok { color: #6ee7a0; } .cam-gps.verif { color: #ffc65c; } .cam-gps.bloquant { color: #ff8a8a; }
.cam-title { margin-left: auto; font-size: .85rem; opacity: .85; text-align: right; max-width: 40%; }
.cam-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-around;
  padding: 16px 12px calc(22px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.7));
}
.cam-shutter { width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.35); }
.cam-shutter:active { background: #fff; }
.cam-btn { width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(255,255,255,.2); color: #fff; font-size: 1.3rem; }
.cam-count { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(255,159,28,.85); font-weight: 700; }
.cam-hint { position: absolute; left: 12px; right: 12px; bottom: calc(118px + env(safe-area-inset-bottom)); text-align: center; font-size: .75rem; opacity: .75; text-shadow: 0 1px 2px #000; }
.camera video.mirror { scale: -1 1; }
.cam-tools { position: absolute; left: 0; right: 0; bottom: calc(160px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 12px; }
.cam-zoom { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.45); border-radius: 99px; padding: 4px; }
.cam-zoom button { min-width: 42px; height: 34px; border-radius: 99px; border: 0; background: transparent; color: #fff; font-weight: 700; font-size: .85rem; }
.cam-zoom button.on { background: rgba(255,255,255,.9); color: #000; }
.cam-zoom-val { font-size: .8rem; opacity: .85; padding: 0 6px 0 2px; min-width: 34px; }
.cam-switch { height: 42px; border-radius: 99px; border: 0; background: rgba(0,0,0,.45); color: #fff; font-weight: 600; font-size: .85rem; padding: 0 12px; }
/* Téléphone tenu en paysage : les boutons tournent pour rester lisibles. */
.cam-btn, .cam-count, .cam-zoom button, .cam-switch { transition: rotate .2s; }
.camera[data-rot="90"] :is(.cam-btn, .cam-count, .cam-zoom button, .cam-switch) { rotate: 90deg; }
.camera[data-rot="180"] :is(.cam-btn, .cam-count, .cam-zoom button, .cam-switch) { rotate: 180deg; }
.camera[data-rot="270"] :is(.cam-btn, .cam-count, .cam-zoom button, .cam-switch) { rotate: -90deg; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.on { animation: flash .25s ease-out; }
@keyframes flash { from { opacity: .8; } to { opacity: 0; } }

.has-heading { position: absolute; left: 4px; top: 4px; width: 22px; height: 22px; line-height: 22px; text-align: center; font-size: .8rem; border-radius: 50%; background: rgba(0,0,0,.55); color: #ff9f1c; }
.viewer-meta { margin-bottom: 6px; }

/* ---------- Photos sur la carte ---------- */
.photo-marker { background: none; border: 0; }
.photo-marker svg { display: block; overflow: visible; }
.dot.photo { background: #7b3fe4; }
.map-photo img { width: 100%; max-height: 160px; object-fit: cover; border-radius: 6px; display: block; margin-bottom: 4px; }
.map-photo { font-size: .85rem; }
.dot.acc { background: rgba(224,138,0,.15); border: 1px dashed #e08a00; box-shadow: none; }

/* ---------- Export ---------- */
.contact-row { gap: 8px; }
.contact-item { width: 100%; font: inherit; text-align: left; cursor: pointer; }
.seg-mini { flex-wrap: nowrap; gap: 4px; }
.seg-mini .seg-btn { flex: 0 0 auto; min-width: 42px; min-height: 40px; padding: 6px 8px; }
/* Fenêtre ouverte en bas : le message passe en haut pour ne pas masquer les boutons. */
body:has(.sheet-backdrop) #toast { bottom: auto; top: calc(70px + env(safe-area-inset-top)); }

/* ---------- Page d'installation ---------- */
.install { max-width: 480px; text-align: center; padding-top: calc(40px + env(safe-area-inset-top)); }
.install h1 { margin: 12px 0 4px; font-size: 1.6rem; color: var(--head-text); }
.install-icon { width: 96px; height: 96px; border-radius: 22px; box-shadow: var(--shadow); }
.install-btn { min-height: 60px; font-size: 1.15rem; margin: 24px 0 16px; }
.install-help { text-align: left; margin-top: 16px; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; font-size: .9rem; padding: 12px; margin-top: 8px; cursor: pointer; }

/* ---------- Tableau des UC ---------- */
.table-wrap { overflow-x: auto; }
.uc-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.uc-table th, .uc-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.uc-table thead th { color: var(--head-text); }
.uc-table td { white-space: nowrap; font-weight: 600; }
.uc-table tbody th { font-weight: 400; color: var(--muted); }
.uc-table tr.grp th { background: var(--head-bg); color: var(--head-text); font-weight: 600; font-size: .82rem; }

/* Valeurs calculées (conicité du mât) */
.calc { background: var(--head-bg); border: 1px solid var(--card-border); border-radius: 10px; padding: 8px 10px; margin: 0 0 12px; font-size: .9rem; }
.calc ul { margin: 4px 0 0; padding-left: 20px; }
.calc li { margin: 2px 0; }
.sub-title.first { margin-top: 0; padding-top: 0; border-top: 0; }
.invalid { border-color: #d62f2f !important; }
