/* Visites techniques PPF – inspiré du PV de réception PPF : jaune PPF, cartouches crème, champs arrondis */
:root {
  --yellow: #FBBA08;
  --yellow-deep: #8A6200;
  --yellow-soft: #FFF4D2;
  --cream: #FBEECF;
  --ink: #1D1B16;
  --ink-2: #5B564A;
  --ink-3: #8C877B;
  --line: #CFC7B3;
  --line-strong: #3C3932;
  --paper: #FFFFFF;
  --ground: #F2F0EA;
  --ok: #2F6B2A;
  --ok-soft: #E3F0DC;
  --danger: #A8261D;
  --danger-soft: #FBE5E2;
  --display: Verdana, "DejaVu Sans", Geneva, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --r: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 16px/1.5 var(--body);
  -webkit-tap-highlight-color: transparent;
}
body.noscroll { overflow: hidden; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.12rem; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.grow { flex: 1 1 auto; }
.muted { color: var(--ink-2); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
[hidden] { display: none !important; }

/* Barre supérieure */
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--paper);
  border-bottom: 3px solid var(--yellow);
  padding-top: env(safe-area-inset-top, 0px);
}
.bar-in {
  max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.bar-logo { height: 30px; width: auto; }
.bar-title { font-family: var(--display); font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.wrap {
  max-width: 1040px; margin: 0 auto;
  padding-block: 20px calc(40px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 18px;
}

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1.5px solid var(--line-strong); background: var(--paper); color: var(--ink);
  font-weight: 600; font-size: 0.95rem; text-decoration: none; cursor: pointer; white-space: nowrap;
  position: relative; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: var(--ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(29, 27, 22, 0.06); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 38px; padding: 0 13px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.45; cursor: default; }
.link { background: none; border: 0; padding: 8px 4px; min-height: 40px; color: var(--yellow-deep); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--danger); }
.icon {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line-strong);
  background: var(--paper); cursor: pointer; font-size: 1rem; line-height: 1;
}
.icon.danger { color: var(--danger); border-color: var(--danger); }
.icon:disabled { opacity: 0.3; cursor: default; }

/* Accueil */
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.search {
  width: 100%; min-height: 48px; padding: 0 18px; border-radius: 24px;
  border: 1.5px solid var(--line); background: var(--paper); font-size: 1rem;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 16px 18px;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--r);
  cursor: pointer; min-width: 0;
}
.card:hover { border-color: var(--yellow); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-name { font-family: var(--display); font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }
.card-addr { color: var(--ink-2); font-size: 0.92rem; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-3); font-size: 0.82rem; }
.badge {
  flex: none; padding: 2px 10px; border-radius: 12px; font-size: 0.78rem; font-weight: 700;
  background: var(--yellow-soft); color: var(--yellow-deep); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.empty {
  background: var(--paper); border: 1.5px dashed var(--line); border-radius: var(--r);
  padding: 32px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty p { max-width: 52ch; margin: 0; color: var(--ink-2); }
.empty.small { padding: 22px; }

/* Panneaux */
.panel {
  background: var(--cream); border: 1.2px solid var(--line-strong); border-radius: 14px;
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer; width: 100%;
}
.panel-head > span:first-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.panel-head .muted { overflow-wrap: anywhere; }
.chev {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--line-strong);
  display: grid; place-items: center; font-weight: 700; background: var(--paper);
}
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f.span2 { grid-column: span 2; }
.f > span { font-size: 0.86rem; font-weight: 600; color: var(--ink-2); }
.f input, input[type="text"]#ask-input, .annot-text input {
  min-height: 46px; padding: 0 14px; border-radius: 10px; border: 1.2px solid var(--line-strong);
  background: var(--paper); font-size: 1rem; width: 100%;
}
textarea {
  width: 100%; min-height: 120px; padding: 12px 14px; border-radius: 10px;
  border: 1.2px solid var(--line-strong); background: var(--paper);
  font-size: 1.02rem; line-height: 1.5; resize: vertical;
}
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel .sec-head { margin-bottom: 0; }

/* Versions */
.versions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 38px; min-width: 52px; padding: 0 12px; border-radius: 19px;
  border: 1.5px solid var(--line-strong); background: var(--paper); font-weight: 700; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.banner {
  background: var(--yellow-soft); border-left: 5px solid var(--yellow); border-radius: 0;
  padding: 12px 14px; margin: 0; font-size: 0.95rem;
}
.banner.ok { background: var(--ok-soft); border-left-color: var(--ok); }
.motif { margin: -6px 0 0; color: var(--ink-2); font-style: italic; }

/* Lots */
.lot { display: flex; flex-direction: column; gap: 12px; margin-bottom: 26px; }
.lot-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.lot-name {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
  background: var(--yellow); border-radius: 18px; padding: 7px 16px; min-width: 0; max-width: 100%;
}
.lot-cat { font-family: var(--display); font-weight: 700; text-transform: uppercase; font-size: 0.86rem; letter-spacing: 0.04em; }
.lot-sub { font-size: 0.95rem; }
.lot-tools { display: flex; gap: 8px; }
.items { display: flex; flex-direction: column; gap: 12px; }
.item {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 16px;
  background: var(--cream); border: 1.2px solid var(--line-strong); border-radius: 14px; padding: 14px;
}
.ph {
  position: relative; border-radius: 10px; background: var(--paper); min-height: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.ph.empty { border: 1.5px dashed var(--line-strong); padding: 18px; }
.ph.none { border: 1.2px solid var(--line); }
.ph.has { border: 1.2px solid var(--line); overflow: hidden; justify-content: flex-start; padding: 0; }
.ph.has img { width: 100%; max-height: 380px; object-fit: contain; background: #fff; }
.ph-tools { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; width: 100%; border-top: 1px solid var(--line); justify-content: center; }
.it-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.it-label { font-weight: 700; font-size: 0.88rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
.it-text textarea { flex: 1 1 auto; min-height: 180px; }
.item-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ro-text { background: var(--paper); border: 1.2px solid var(--line); border-radius: 10px; padding: 12px 14px; min-height: 60px; overflow-wrap: anywhere; }
.btn.add { align-self: flex-start; border: 1.5px dashed var(--line-strong); }
.foot-actions { display: flex; justify-content: center; padding-top: 10px; }

/* Signatures affichées */
.sig-view { display: flex; flex-wrap: wrap; gap: 16px; }
.sig-view figure { margin: 0; background: var(--paper); border: 1.2px solid var(--line); border-radius: 10px; padding: 10px; flex: 1 1 240px; }
.sig-view img { max-height: 110px; margin: 0 auto; }
.sig-view figcaption { font-size: 0.86rem; color: var(--ink-2); margin-top: 6px; }

/* Réglages */
.cats { display: flex; flex-direction: column; gap: 12px; }
.cat { background: var(--paper); border: 1.2px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.cat-head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-family: var(--display); }
.cat ul { list-style: none; margin: 6px 0 8px; padding: 0; }
.cat li { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; border-top: 1px solid var(--ground); padding: 2px 0; }
.cat li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Fenêtres */
.ov {
  position: fixed; inset: 0; z-index: 50; background: rgba(29, 27, 22, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet {
  background: var(--paper); border-radius: 18px; width: min(560px, 100%); max-height: 100%; overflow: auto;
  padding: 22px; display: flex; flex-direction: column; gap: 14px; border-top: 6px solid var(--yellow);
  -webkit-overflow-scrolling: touch;
}
.sheet.small { width: min(440px, 100%); }
.sheet.wide { width: min(760px, 100%); }
.sheet p { margin: 0; }
.ask { font-size: 1.05rem; }
.m-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.err { color: var(--danger); font-size: 0.9rem; font-weight: 600; }
.busy { display: flex; align-items: center; gap: 14px; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--yellow-soft); border-top-color: var(--yellow); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.pick fieldset { margin: 0; border: 1.2px solid var(--line); border-radius: 12px; padding: 8px 12px 6px; min-width: 0; }
.pick legend { font-family: var(--display); font-weight: 700; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--yellow-deep); flex: none; }
.sig-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.sig-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sig-col .link { align-self: flex-start; }
.sig-pad { position: relative; height: 170px; border: 1.5px solid var(--line-strong); border-radius: 12px; background: #fff; }
.sig-pad canvas { width: 100%; height: 100%; display: block; touch-action: none; border-radius: 12px; }
.sig-hint { position: absolute; inset: auto 0 10px; text-align: center; color: var(--ink-3); pointer-events: none; font-size: 0.9rem; }
.file-line { overflow-wrap: anywhere; }
.sel { user-select: all; -webkit-user-select: all; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 80; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  max-width: min(90vw, 520px); font-size: 0.95rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2); transition: opacity 0.35s;
}
.toast.out { opacity: 0; }

/* Éditeur d'annotation */
.annot {
  position: fixed; inset: 0; z-index: 60; background: #24221d; display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.annot-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; background: var(--paper);
  padding-block: 8px; border-bottom: 3px solid var(--yellow);
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
}
.seg { display: flex; gap: 4px; background: var(--ground); border-radius: 22px; padding: 3px; }
.tb {
  min-height: 40px; padding: 0 12px; border-radius: 20px; border: 0; background: transparent;
  font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.tb[aria-pressed="true"] { background: var(--ink); color: #fff; }
.tb:disabled { opacity: 0.35; }
.sw { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: var(--sw); cursor: pointer; }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.annot-end { display: flex; gap: 8px; margin-left: auto; }
.annot-stage { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 0; }
.annot-stage canvas { touch-action: none; background: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15); }
.annot-text {
  display: flex; gap: 8px; align-items: center; background: var(--paper);
  padding-block: 10px;
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px));
}
.annot-confirm { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; padding: 16px; }

@media (max-width: 760px) {
  .item, .sig-grid, .pick { grid-template-columns: minmax(0, 1fr); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .f.span2 { grid-column: auto; }
  .bar-logo { display: none; }
  .bar-in .btn { padding: 0 12px; }
  .bar-in .lg { display: none; }
  .bar-in { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .toast { transition: none; }
}
