:root {
  --navy: #111111; --teal: #15a336; --brand: #18c23a; --bg: #f2f5f7; --card: #fff; --ink: #1b2530; --mut: #66737f;
  --line: #dde3e8; --warn: #b26a00; --err: #b42318; --ok: #2f7d4a; --r: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f161c; --card: #17212a; --ink: #e6ecf1; --mut: #93a1ad; --line: #26333e; --navy: #e8ece9; --teal: #2cc44f; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--teal); text-decoration: none; }
h1 { font-size: 1.35rem; margin: .2rem 0 .3rem; }
.h { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); margin: 1.4rem 0 .6rem; font-weight: 600; }
.muted { color: var(--mut); } .small { font-size: .85rem; }
main { max-width: 860px; margin: 0 auto; padding: 14px 16px calc(96px + var(--safe-b)); }

/* barre du haut */
.top { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: #111; color: #fff; border-bottom: 3px solid var(--brand); }
.home { color: #fff; display: flex; align-items: center; gap: 8px; } .home img { display: block; } .home span { opacity: .7; font-size: .95rem; }
.sync { display: flex; gap: 7px; align-items: center; background: rgba(255,255,255,.1); color: #fff; border: 0; border-radius: 99px; padding: 6px 12px; font-size: .82rem; }
.sync i { width: 9px; height: 9px; border-radius: 50%; background: #9aa; }
.sync i.ok { background: #4ade80; } .sync i.pending { background: #fbbf24; } .sync i.off { background: #f87171; }
.sync i.busy { background: #60a5fa; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3 } }

/* éléments */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .55; }
.link { background: none; border: 0; padding: 6px 0; font: inherit; font-size: .88rem; color: var(--teal); cursor: pointer; }
.danger { color: var(--err); }
.back { display: inline-block; margin: 2px 0 8px; font-weight: 600; }
.bar { display: flex; gap: 8px; }
.bar input { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.empty { color: var(--mut); text-align: center; padding: 24px 0; }
.banner { background: #fff4e0; color: #7a4a00; border-radius: 10px; padding: 10px 12px; font-size: .9rem; }

input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; margin-top: 4px; }
textarea { resize: vertical; min-height: 88px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: .82rem; color: var(--mut); font-weight: 600; margin-bottom: 10px; }

/* cartes */
.list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; color: var(--ink); }
.card:active { transform: scale(.99); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .03em; color: var(--navy); }
.code.big { font-size: 1rem; font-weight: 700; }
.pill { font-style: normal; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--mut); white-space: nowrap; }
.pill.s-finalise { background: #e0f2fe; color: #075985; } .pill.s-envoye { background: #dcfce7; color: #166534; }
.pill.s-modifie, .pill.warn { background: #fef3c7; color: #92400e; }
.warn-t { color: var(--warn); }
.head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }

/* éditeur */
.meta-edit, .grid { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .meta-edit, .grid { grid-template-columns: 1fr 1fr; } }
.grid label:has(textarea) { grid-column: 1 / -1; }
details { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin: 8px 0; overflow: hidden; }
summary { list-style: none; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-weight: 700; cursor: pointer; min-height: 52px; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "›"; font-size: 1.3rem; color: var(--mut); transform: rotate(90deg); transition: .15s; margin-left: 8px; }
details[open] summary::after { transform: rotate(-90deg); }
summary span { flex: 1; }
.cnt { font-style: normal; font-size: .75rem; background: var(--teal); color: #fff; border-radius: 99px; padding: 1px 8px; }
.cnt:empty { display: none; }
.body { padding: 0 16px 14px; }
.item { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px 2px; margin-bottom: 10px; }
.sticky-actions { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px + var(--safe-b)); background: var(--card); border-top: 1px solid var(--line); z-index: 9; }
.danger-zone { text-align: center; margin-top: 24px; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; background: var(--line); display: block; }
.photos input, .photos select { min-height: 38px; padding: 6px 8px; font-size: .88rem; }
.photo-add { cursor: pointer; }

/* rapport */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 16px 14px; margin: 12px 0; }
.hist { font-size: .88rem; padding: 6px 0; border-bottom: 1px solid var(--line); }
.hist a { margin-left: 6px; }

/* dialogue */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(520px, 94vw); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(5, 20, 32, .55); }
dialog form { padding: 18px; }
dialog h2 { margin: 0 0 12px; font-size: 1.1rem; }

#toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s;
  background: #1b2530; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 50; max-width: 90vw; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* connexion */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: #111; }
.login-card { background: var(--card); padding: 28px 22px; border-radius: 16px; width: min(380px, 100%); }
.login-card h1 { font-size: 1.1rem; margin-bottom: 18px; }
.login-card .btn { width: 100%; margin-top: 6px; }
.logo-mark img { height: 34px; margin-bottom: 8px; }
.err { color: var(--err); font-size: .9rem; }

/* plan de ports */
.ports-head { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 0; }
.port { display: grid; grid-template-columns: 2.6em 1fr 3.4em 3.9em; gap: 4px; margin-bottom: 6px; }
.port input, .port select { min-height: 38px; padding: 6px 5px; margin: 0; font-size: .9rem; }
.port.hdr { font-size: .72rem; color: var(--mut); font-weight: 600; margin-bottom: 2px; }

/* blocs photos par rubrique */
.ph-block { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.ph-block h4 { margin: 4px 0 8px; font-size: .85rem; color: var(--mut); }
.ph-img { position: relative; }
.ph-n { position: absolute; top: 6px; left: 6px; background: var(--brand); color: #fff; font-weight: 800; font-size: .8rem; border-radius: 99px; min-width: 24px; height: 24px; display: grid; place-items: center; }
.ph-a { position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: .68rem; padding: 2px 6px; border-radius: 6px; }
.ph-tools { display: flex; gap: 10px; flex-wrap: wrap; }
.photos.seq { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* annotation plein écran */
.annot { position: fixed; inset: 0; z-index: 100; background: #0c0c0c; display: flex; flex-direction: column; padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0); }
.annot-bar { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; align-items: center; }
.annot-bar button { flex: none; background: #222; color: #eee; border: 1px solid #333; border-radius: 8px; padding: 8px 10px; font: inherit; font-size: .85rem; }
.annot-bar button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.annot-bar .sw { width: 34px; height: 34px; padding: 0; border-radius: 50%; background: var(--c); border: 2px solid #444; }
.annot-bar .sw.on { background: var(--c); border-color: #444; outline: 3px solid #fff; outline-offset: 1px; }
.annot-bar .sp { flex: 1; }
.annot-bar.end { justify-content: space-between; }
.annot-bar.end .btn { min-width: 120px; }
.annot-stage { flex: 1; display: grid; place-items: center; overflow: hidden; touch-action: none; }
.annot-stage canvas { touch-action: none; border-radius: 4px; }

/* signatures */
.sig { margin: 10px 0; }
.sig canvas { width: 100%; height: 150px; background: #fff; border: 1px dashed var(--mut); border-radius: 10px; touch-action: none; display: block; margin-top: 4px; }

/* photos par élément (bornes) */
.item-ph { display: grid; grid-template-columns: 1fr; gap: 6px 12px; margin: 4px 0 6px; padding-top: 6px; border-top: 1px dashed var(--line); }
@media (min-width: 640px) { .item-ph { grid-template-columns: 1fr 1fr; } }
.item-ph h4 { margin: 4px 0; font-size: .8rem; color: var(--mut); }
.item-ph .photos { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

/* plans d'implantation */
.pl-wrap { position: relative; display: inline-block; max-width: 100%; line-height: 0; }
.pl-wrap img { width: 100%; height: auto; display: block; border-radius: 6px; }
.plan-prev .pl-wrap { width: 100%; margin: 6px 0; }
.mk { position: absolute; transform: translate(-50%, -50%); min-width: 22px; height: 22px; padding: 0 5px; border-radius: 99px;
  background: var(--c, #18c23a); color: #fff; font: 800 12px/22px -apple-system, sans-serif; text-align: center; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45); pointer-events: auto; }
.mk.big { min-width: 28px; height: 28px; line-height: 28px; font-size: 14px; cursor: pointer; }
.mk em { position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 4px; white-space: nowrap; font: 700 11px/1 -apple-system, sans-serif;
  color: #111; background: rgba(255,255,255,.9); padding: 3px 5px; border-radius: 5px; font-style: normal; }
.mk.sel { outline: 3px solid #fff; box-shadow: 0 0 0 6px rgba(24,194,58,.55); }
.placer .pl-stage { place-items: start center; overflow: auto; touch-action: pan-x pan-y; padding: 8px; }
.placer .pl-wrap.big { max-width: none; }
.chips .chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chips .chip i { font-style: normal; background: var(--c); color: #fff; border-radius: 99px; min-width: 20px; height: 20px; line-height: 20px; text-align: center; font-weight: 800; font-size: .75rem; padding: 0 4px; }
.chips .chip.on { background: #fff; color: #111; border-color: #fff; }
.chips .chip.placed:not(.on) { opacity: .75; }
.chips .chip.add { border-style: dashed; }
