:root {
  --bg: #f5f6f8; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-dark: #1d4ed8; --danger: #dc2626; --ok: #16a34a; --warn: #f59e0b;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: .5rem 0 .25rem; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; padding: .6rem 1rem; background: #111827; color: #fff; }
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: center; margin-left: auto; }
.topbar nav a { color: #d1d5db; text-decoration: none; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; }
.topbar nav button.link { color: #d1d5db; }
.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.container.wide { max-width: none; }
.city { display: inline-block; padding: .05rem .55rem; border-radius: 999px; border: 1px solid #0002; color: var(--text); font-size: .8rem; font-weight: 500; vertical-align: middle; }
.warn-box { background: #fff7ed; border-left: 4px solid var(--warn); padding: .5rem .75rem; border-radius: 6px; font-size: .9rem; }
.button.small { padding: .2rem .5rem; font-size: .85rem; }
h2 a.small { font-weight: 400; margin-left: .5rem; }

/* Fiche logement : pleine largeur, fil de suivi collant à droite (ADR 0014) */
/* Photos toujours en tête de la fiche, quelle que soit la largeur. */
.listing-layout { display: grid; gap: 1rem; align-items: start; grid-template-columns: minmax(0, 1fr) minmax(380px, 36%); grid-template-areas: "photos thread" "side thread" "main thread"; }
.l-photos { grid-area: photos; min-width: 0; }
.l-photos .inline-form { margin-bottom: 0; }
.l-main { grid-area: main; min-width: 0; }
.l-side { grid-area: side; min-width: 0; }
.l-thread { grid-area: thread; position: sticky; top: 1rem; max-height: calc(100vh - 2rem); display: flex; flex-direction: column; margin-bottom: 0; }
.thread-messages { flex: 1 1 auto; overflow-y: auto; min-height: 120px; }
.l-thread .composer { flex: 0 0 auto; margin-top: .5rem; padding-top: .75rem; }
.l-thread #editor { min-height: 80px; max-height: 30vh; overflow-y: auto; }
.l-thread .dropzone { margin: .5rem 0; padding: .5rem; font-size: .85rem; }
@media (min-width: 1500px) {
  .listing-layout { grid-template-columns: minmax(0, 1fr) 340px minmax(420px, 32%); grid-template-areas: "photos side thread" "main side thread"; }
}
@media (max-width: 900px) {
  .listing-layout { grid-template-columns: 1fr; grid-template-areas: "photos" "side" "main" "thread"; }
  /* Bandeau de photos à faire défiler du doigt : visible d'emblée sans repousser la fiche. */
  .l-photos .gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: .5rem; padding-bottom: .25rem; }
  .l-photos .gallery figure { flex: 0 0 82%; scroll-snap-align: start; }
  .l-photos .gallery img { height: 230px; }
  .l-thread { position: static; max-height: none; }
  .thread-messages { overflow: visible; }
}

/* Diaporama */
.lightbox { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(0, 0, 0, .92); color: #fff; }
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: rgba(0, 0, 0, .6); }
.lightbox img { max-width: 92vw; max-height: 88vh; object-fit: contain; }
.lightbox button { position: absolute; background: rgba(255, 255, 255, .12); border: 0; color: #fff; font-size: 2.2rem; line-height: 1; padding: .4rem .9rem; border-radius: 8px; }
.lightbox button:hover, .lightbox button:focus-visible { background: rgba(255, 255, 255, .28); }
.lightbox .lb-close { top: 1rem; right: 1rem; font-size: 1.4rem; }
.lightbox .lb-prev { left: 1rem; top: 50%; transform: translateY(-50%); }
.lightbox .lb-next { right: 1rem; top: 50%; transform: translateY(-50%); }
.lightbox .lb-counter { position: absolute; bottom: 1rem; left: 0; right: 0; text-align: center; margin: 0; }

.share-box { border-top: 1px solid var(--line); margin-top: .75rem; padding-top: .5rem; }
.share-list { list-style: none; padding: 0; margin: .5rem 0; display: grid; gap: .5rem; }
.share-item { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; background: #fafafa; }
.share-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .75rem; margin-bottom: .4rem; }
.visits { background: #dbeafe; color: #1e3a8a; border-radius: 999px; padding: 0 .55rem; font-size: .85rem; }
.copy-row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.copy-row input { margin: 0 !important; font-size: .85rem; flex: 1 1 14rem; min-width: 0; font-family: ui-monospace, Consolas, monospace; }
.inline-form label.grow { flex: 1; min-width: 14rem; }
.profile-head { display: flex; gap: 1rem; align-items: center; }
.profile-head h2 { margin-bottom: .2rem; }
.avatar { width: 64px; height: 64px; aspect-ratio: 1; padding: 0; border-radius: 50%; object-fit: cover; flex: 0 0 auto; background: #e5e7eb; display: inline-flex; align-items: center; justify-content: center; font-size: 1.8rem; }
.avatar.big { width: 132px; height: 132px; border: 4px solid #fff; box-shadow: 0 2px 10px #0002; }
.profile-box { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem; margin: .75rem 0; }
.profile-box summary { cursor: pointer; }
.profile-form { margin-top: .5rem; }
.profile-form .bio-editor { min-height: 140px; background: #fff; margin-bottom: .75rem; }

/* Page publique de partage */
.share-page { max-width: 860px; margin: 0 auto; }
.share-hero { display: flex; gap: 1.5rem; align-items: center; background: linear-gradient(135deg, #eff6ff, #fdf2f8); border: 0; padding: 1.5rem; }
.share-hero h1 { font-size: 2rem; margin: 0 0 .5rem; }
.share-for { margin: 0 0 .5rem; }
.share-hero .eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--muted); }
.share-bio .ql-editor { padding: 0; font-size: 1rem; line-height: 1.6; }
.share-docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .5rem 1.5rem; }
.doc-open { background: none; border: 0; padding: .2rem 0; color: var(--primary); text-align: left; cursor: pointer; }
.doc-open:hover { text-decoration: underline; background: none; }
.viewer { width: min(1060px, 100vw); height: 100vh; max-height: none; margin: 0 auto; padding: 0; border: 0; background: #374151; }
.viewer::backdrop { background: rgba(0, 0, 0, .7); }
.viewer[open] { display: flex; flex-direction: column; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem 1rem; background: #111827; color: #fff; }
.viewer-bar button { color: #fff; background: transparent; border-color: #fff6; }
.viewer-pages { flex: 1; overflow-y: auto; padding: 1rem .5rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; user-select: none; -webkit-user-select: none; }
.viewer-pages canvas { max-width: 100%; background: #fff; box-shadow: 0 2px 8px #0006; }
.viewer-pages .muted { color: #d1d5db; }
.viewer-status { display: flex; align-items: center; gap: .75rem; padding: .5rem 1rem; background: #1f2937; color: #e5e7eb; font-size: .9rem; }
.viewer-status[hidden] { display: none; }
.viewer-status progress { flex: 1; height: .6rem; accent-color: #60a5fa; }
.viewer-status span { min-width: 16rem; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .viewer-status { flex-wrap: wrap; } .viewer-status span { min-width: 0; text-align: left; } }
@media print { .viewer, .share-page { display: none !important; } }
@media (max-width: 600px) { .share-hero { flex-direction: column; text-align: center; } }

/* Navigation sans rechargement (ADR 0023) */
.nav-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 1000; background: linear-gradient(90deg, #60a5fa, #2563eb); box-shadow: 0 0 6px #2563eb88; pointer-events: none; opacity: 0; }
form.is-busy { opacity: .75; }
.upload-progress { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; font-size: .9rem; color: var(--muted); flex-basis: 100%; }
.upload-progress progress { flex: 1; height: .7rem; accent-color: var(--primary); }
.upload-progress.error { color: var(--danger); }
main:focus { outline: none; }

/* Avancement des démarches incrusté en bas des tuiles */
.tile-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; background: rgba(15, 23, 42, .08); }
.tile-progress span { display: block; height: 100%; border-radius: 0 4px 4px 0; transition: width .4s ease; }

.footer { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .85rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 520px; margin: 1rem auto; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .5rem 1rem; margin-bottom: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.inline { display: inline; }
.hint { background: #eff6ff; border-left: 4px solid var(--primary); padding: .5rem .75rem; border-radius: 6px; }
.flash { padding: .6rem .9rem; border-radius: 8px; margin: 0 0 1rem; }
.flash.ok { background: #dcfce7; color: #14532d; }
.flash.error { background: #fee2e2; color: #7f1d1d; }
ul.flash { padding-left: 2rem; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

label { display: block; margin-bottom: .75rem; font-weight: 500; }
label small { display: block; font-weight: 400; color: var(--muted); }
label.check { display: inline-flex; gap: .4rem; align-items: center; font-weight: 400; margin-right: .75rem; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
input[type=color] { padding: .15rem; height: 2.4rem; }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 .75rem; padding: .5rem 1rem; }
legend { font-weight: 600; padding: 0 .4rem; }
button, .button { display: inline-block; padding: .5rem .9rem; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { background: #f1f5f9; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 0; color: var(--primary); text-decoration: underline; cursor: pointer; }
button.link.danger { color: var(--danger); }
label.link { display: inline; font-weight: 400; color: var(--primary); text-decoration: underline; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid fieldset { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 1rem; }
.stack > * + * { margin-top: .5rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0 1rem; }
.inline-form label { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { margin: 0; font-size: .9rem; }
.filters select { min-width: 140px; max-width: 16rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 1rem; }
.grid.persons { grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); align-items: start; }
.grid > * { min-width: 0; }
.score { display: inline-flex; align-items: center; justify-content: center; min-width: 2.4rem; height: 2.4rem; padding: 0 .4rem; border-radius: 999px; font-weight: 700; color: #fff; background: #9ca3af; flex-shrink: 0; }
/* Tuile : photo en tête avec score et temps à pied en surimpression, texte dessous sans chevauchement. */
.card.listing { position: relative; overflow: hidden; display: flex; flex-direction: column; padding: 0 0 7px; margin: 0; }
.listing .thumb { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 10; background: #e5e7eb; text-decoration: none; }
.listing .thumb .nophoto { font-size: 2.5rem; }
.listing .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.listing .thumb .score { position: absolute; top: .5rem; left: .5rem; font-size: 1rem; box-shadow: 0 0 0 3px rgba(255, 255, 255, .85), 0 2px 6px rgba(0, 0, 0, .25); }
.walk-badge { position: absolute; top: .55rem; right: .5rem; padding: .2rem .55rem; border-radius: 999px; background: #dcfce7; color: #14532d; border: 1px solid #86efac; font-size: .85rem; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.walk-badge.approx { background: #fef3c7; color: #78350f; border-color: #fcd34d; }
.walk-badge.none { background: #f8fafc; color: var(--muted); border-color: #cbd5e1; font-weight: 400; }
.listing .body { display: flex; flex-direction: column; gap: .35rem; padding: .7rem .85rem .6rem; flex: 1; min-width: 0; }
.listing h2 { font-size: 1rem; line-height: 1.3; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.listing h2 a { color: var(--text); text-decoration: none; }
.listing h2 a:hover { text-decoration: underline; }
.listing .price { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .5rem; }
.listing .price strong { font-size: 1.1rem; }
.listing .ppm { margin-left: auto; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.specs { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem; }
.specs li { padding: .05rem .45rem; border-radius: 6px; background: rgba(255, 255, 255, .7); border: 1px solid rgba(15, 23, 42, .1); font-size: .82rem; white-space: nowrap; }
.specs li.pinel { background: #ede9fe; color: #5b21b6; border-color: #c4b5fd; }
.meta { margin: 0; display: flex; flex-wrap: wrap; gap: .35rem .5rem; align-items: center; font-size: .85rem; }
.meta .stars { color: #f59e0b; letter-spacing: .05em; }
.listing .foot .where { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listing .foot .where strong { color: var(--text); font-weight: 600; }
.listing .foot { margin: auto 0 0; padding-top: .2rem; display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; color: var(--muted); }
.score.good { background: var(--ok); }
.score.mid { background: var(--warn); }
.score.bad { background: var(--danger); }
.step, .tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 18%, white); color: var(--c); border: 1px solid var(--c); font-size: .8rem; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: #ede9fe; color: #5b21b6; font-size: .8rem; }
.tags { color: var(--muted); }

.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; margin-bottom: .5rem; }
.gallery figure { margin: 0; position: relative; }
.gallery img { width: 100%; height: 130px; object-fit: cover; border-radius: 8px; display: block; }
.gallery form { position: absolute; top: 4px; right: 6px; }
.gallery button { color: #fff; text-shadow: 0 0 3px #000; text-decoration: none; }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .5rem 1rem; margin: 0; }
.facts-grid dt { color: var(--muted); font-size: .8rem; }
.facts-grid dd { margin: 0; font-weight: 600; }
.facts-grid .span-all { grid-column: 1 / -1; }
.address-form { display: flex; gap: .4rem; margin: .2rem 0; }
.address-form input { margin: 0 !important; font-weight: 400; }
.address-form button { white-space: nowrap; }
.geo-hint { display: block; font-size: .8rem; font-weight: 400; color: var(--muted); }
.geo-hint.approx { color: #b45309; }
.description { white-space: normal; }
.score-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.score-table th { text-align: left; font-weight: 500; padding: .25rem 0; }
.score-table td { padding: .25rem .25rem; white-space: nowrap; }
.score-table tr.muted { color: var(--muted); }
meter { width: 70px; vertical-align: middle; }
meter.wide { width: 100%; height: 1rem; }
.rating { display: flex; align-items: center; gap: .1rem; margin: .75rem 0; }
.star { background: none; border: 0; font-size: 1.5rem; color: #d1d5db; padding: 0 .1rem; cursor: pointer; }
.star.on { color: #f59e0b; }

.thread .message { border-top: 1px solid var(--line); padding: .75rem 0; }
.thread .message header { display: flex; gap: .5rem; align-items: baseline; font-size: .9rem; margin-bottom: .25rem; }
.thread .message header time { color: var(--muted); }
.thread .message.event { color: var(--muted); font-style: italic; }
.thread .message .body img { max-width: 100%; height: auto; }
.attachment { display: inline-block; margin: .25rem .5rem .25rem 0; }
.attachment.image img { max-height: 160px; border-radius: 6px; }
.email { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem; margin: .5rem 0; background: #fafafa; }
.email-body { white-space: pre-wrap; font: inherit; font-size: .9rem; max-height: 300px; overflow: auto; }
.composer { border-top: 2px solid var(--line); padding-top: 1rem; margin-top: 1rem; }
#editor { min-height: 140px; background: #fff; }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: #cbd5e1; }
.ql-toolbar.ql-snow { border-radius: 6px 6px 0 0; }
.ql-container.ql-snow { border-radius: 0 0 6px 6px; }
.dropzone { border: 2px dashed #cbd5e1; border-radius: 8px; padding: .75rem; margin: .75rem 0; color: var(--muted); text-align: center; }
.dropzone.over { border-color: var(--primary); background: #eff6ff; }
.filelist { list-style: none; padding: 0; margin: .5rem 0 0; text-align: left; font-size: .9rem; color: var(--text); }
.filelist li { display: flex; justify-content: space-between; gap: .5rem; }

.doctype { border-top: 1px solid var(--line); padding: .5rem 0; }
.doclist { list-style: none; padding: 0; margin: 0 0 .25rem; }
.doclist li { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; overflow-wrap: anywhere; }
.doclist li a { min-width: 0; }
.inline-form input[type=file] { max-width: 100%; }
.doc-row { flex-wrap: nowrap !important; margin: .2rem 0; }
.rename-form { display: flex; gap: .25rem; flex: 1; min-width: 0; }
.doc-row > a { text-decoration: none; }
.rename-form input { margin: 0 !important; padding: .25rem .45rem !important; font-size: .9rem; border-color: transparent !important; border-bottom: 1px dashed #cbd5e1 !important; border-radius: 4px 4px 0 0 !important; background: transparent !important; }
.rename-form input:hover, .rename-form input:focus { border-color: #cbd5e1 !important; background: #fff !important; }
.rename-form button { padding: .15rem .5rem; visibility: hidden; }
.rename-form:focus-within button, .rename-form:hover button { visibility: visible; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td.actions { white-space: nowrap; }
.swatch { display: inline-block; width: 1em; height: 1em; border-radius: 3px; vertical-align: middle; border: 1px solid #0002; }
.admin-list { columns: 2; list-style: none; padding: 0; }
.admin-list li { padding: .3rem 0; }
kbd { background: #eee; border: 1px solid #ccc; border-radius: 3px; padding: 0 .3em; font-size: .9em; }

@media (max-width: 800px) {
  .topbar nav { margin-left: 0; font-size: .9rem; }
  .listing .thumb { aspect-ratio: 16 / 8; }
  .card { padding: .9rem; }
  .cols { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .admin-list { columns: 1; }
}
