/* Gardien : feuille de style unique, mobile d'abord. */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d2421;
  --muted: #5d6762;
  --line: #e2ded5;
  --primary: #1f5f4a;
  --primary-ink: #ffffff;
  --good: #2e7d4f;
  --warn: #b5651d;
  --info: #2f5f9e;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131815;
    --surface: #1c2320;
    --ink: #e9eeeb;
    --muted: #a3ada8;
    --line: #2d3632;
    --primary: #4fa883;
    --primary-ink: #0d1411;
    --good: #5cbf85;
    --warn: #e19a54;
    --info: #7fa9e3;
    --danger: #ef7a72;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.45rem; margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 .5rem; }
a { color: var(--primary); }
img { max-width: 100%; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.switch-link { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; min-width: 0; overflow: hidden; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); flex: none; }
.topnav { display: flex; gap: 4px; flex: none; }
.nav-link { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: .92rem; white-space: nowrap; }
/* Mobile : le menu passe sur sa propre ligne et défile horizontalement si besoin */
@media (max-width: 699px) {
  .topnav.topnav-many { flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; margin: 0 -8px; padding: 0 4px; }
  .topnav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 7px 10px; font-size: .9rem; }
}
.nav-link.active, .nav-link:hover { color: var(--ink); background: var(--bg); }

.container { max-width: 720px; margin: 0 auto; padding: 16px; }
.container.narrow { max-width: 480px; }
.stack > * + * { margin-top: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.center { text-align: center; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .88rem; }
.back { color: var(--muted); text-decoration: none; font-size: .95rem; }
.links { font-size: .95rem; color: var(--muted); }

/* Messages */
.flash { margin: 12px 16px 0; padding: 12px 14px; border-radius: 10px; max-width: 688px; }
@media (min-width: 752px) { .flash { margin-left: auto; margin-right: auto; } }
.flash-notice { background: color-mix(in srgb, var(--good) 14%, var(--surface)); }
.flash-alert { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.errors { margin: 0; padding: 12px 12px 12px 30px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.notice-box { padding: 10px 12px; border-radius: 10px; background: var(--bg); color: var(--muted); }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.auth { margin-top: 24px; }
.list { display: grid; gap: 12px; }
.list .card { margin-bottom: 0; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.incident-card { padding: 0; overflow: hidden; border-left: 5px solid var(--line); }
/* Deux couleurs : orange = signalé (pas encore pris en charge), bleu = en cours (intervention ou réglé proposé) */
.incident-card.status-open, .incident-card.status-pending-moderation { border-left-color: var(--warn); }
.incident-card.status-in-progress, .incident-card.status-resolution-proposed { border-left-color: var(--info); }
.incident-card.status-resolved { border-left-color: var(--good); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .85rem; color: var(--muted); margin: -2px 0 12px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .legend-open::before { background: var(--warn); }
.legend .legend-progress::before { background: var(--info); }
.incident-link { display: flex; gap: 12px; padding: 14px; color: inherit; text-decoration: none; }
.thumb { width: 76px; height: 76px; flex: none; border-radius: 10px; overflow: hidden; background: var(--bg); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-icon { font-size: 2rem; }
.incident-body { min-width: 0; flex: 1; }
.incident-body h2 { margin: 4px 0 2px; font-size: 1.02rem; }
.desc { color: var(--muted); font-size: .92rem; margin: 0; }
.category { font-size: .85rem; color: var(--muted); }
.meta-line { font-size: .85rem; color: var(--muted); margin: 4px 0 0; }
.incident-card .actions { padding: 0 14px 14px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--warn); }
.badge-info { background: color-mix(in srgb, var(--info) 16%, var(--surface)); color: var(--info); }
.badge-good { background: color-mix(in srgb, var(--good) 16%, var(--surface)); color: var(--good); }
.badge-muted { background: var(--bg); color: var(--muted); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: not-allowed; font-weight: 500; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions form { margin: 0; }
/* Page détail : boutons pleine largeur sur mobile, alignés à droite sur grand écran */
.actions-detail { justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 14px; }
.actions-detail form, .actions-detail > .btn { flex: 1 1 100%; }
.actions-detail form .btn { width: 100%; }
@media (min-width: 600px) {
  .actions-detail form, .actions-detail > .btn { flex: 0 0 auto; }
  .actions-detail form .btn { width: auto; min-width: 180px; }
}
.actions-list { justify-content: flex-end; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input[type=text] { flex: 1; min-width: 160px; }
button.btn[form], form.button_to { display: inline; }

.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: 14px 20px; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink);
  font-weight: 700; text-decoration: none; box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
}
.fab span { font-size: 1.3rem; line-height: 1; }

/* Filtres */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.tab { flex: 1; text-align: center; padding: 9px 6px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--primary); color: var(--primary-ink); }
.tab-count { display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: .8rem; line-height: 20px; }
.tab.active .tab-count { background: rgba(255, 255, 255, .22); color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .88rem; }
.chip.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.building-switch select { width: 100%; margin-bottom: 10px; }

/* Formulaires */
label { display: block; font-weight: 600; font-size: .95rem; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=url], input[type=search], textarea, select {
  display: block; width: 100%; margin-top: 6px;
  padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 400;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
fieldset { border: 0; padding: 0; margin: 0; }
fieldset + fieldset, fieldset + div { margin-top: 18px; }
legend { font-weight: 700; margin-bottom: 8px; }
.category-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.category-option { position: relative; }
.category-option input { position: absolute; opacity: 0; inset: 0; }
.category-option span { display: block; text-align: center; padding: 12px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; font-size: .85rem; line-height: 1.6; }
.category-option input:checked + span { border-color: var(--primary); outline: 2px solid var(--primary); }
.category-option input:focus-visible + span { outline: 2px solid var(--primary); }
.file-input { padding: 14px; border: 1px dashed var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--surface); }
.file-input input { display: block; margin-top: 8px; width: 100%; font-weight: 400; }
.similar { border: 1px solid var(--warn); border-radius: 12px; padding: 12px; margin-top: 14px; background: color-mix(in srgb, var(--warn) 7%, var(--surface)); }
.similar-item { display: grid; gap: 4px; padding: 8px 0; border-top: 1px solid var(--line); }
.similar-item:first-of-type { border-top: 0; }

/* Détail */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.gallery.small { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
.video { width: 100%; border-radius: 12px; background: #000; max-height: 420px; }
.description p { margin: 0 0 .5rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline li.tone-info::before { background: var(--info); }
.timeline li.tone-warn::before { background: var(--warn); }
.timeline li.tone-good::before { background: var(--good); }
.timeline li a { color: inherit; }
.timeline time { color: var(--muted); font-size: .85rem; margin-right: 6px; }
.comment { padding: 10px 0; border-top: 1px solid var(--line); }
.comment time { color: var(--muted); font-size: .8rem; margin-left: 6px; }
.comment p { margin: 4px 0 0; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.big-code { font-size: 1.6rem; letter-spacing: .12em; }
.danger-zone summary { cursor: pointer; color: var(--danger); }
.steps { text-align: left; padding-left: 20px; }
.steps li { margin-bottom: 6px; }
.app-icon img { border-radius: 22px; }
.prose p { max-width: 62ch; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.inactive td { color: var(--muted); }

.building-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: inherit; text-decoration: none; }
.building-card:hover { border-color: var(--primary); }
.building-card.has-open { border-left: 4px solid var(--warn); }
.building-card-text { display: grid; gap: 2px; min-width: 0; }
.to-moderate { font-size: .85rem; font-weight: 600; color: var(--info); }
.bubble { flex: none; display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0 10px; border-radius: 999px; font-weight: 700; font-size: 1.05rem; }
.bubble-alert { background: var(--warn); color: #fff; }
.bubble-calm { background: var(--bg); color: var(--muted); }

.contact-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }

.password-form { margin-top: 12px; }
details > summary.btn { list-style: none; }
details > summary.btn::-webkit-details-marker { display: none; }

.search-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.search-bar input[type=search] { margin-top: 0; flex: 1; }

.badge-dark { background: var(--ink); color: var(--surface); }
.avatar { flex: none; display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: 1.4rem; }
.avatar-small { width: 44px; height: 44px; font-size: 1rem; }
.account-head { display: flex; align-items: center; gap: 16px; }
.account-id h1 { margin: 0; }
.account-id p { margin: 2px 0 8px; word-break: break-all; }
.account-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.account-foot form { margin: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.danger-zone summary { font-weight: 600; }
.danger-zone[open] summary { margin-bottom: 10px; }
.grid-2 { display: grid; gap: 12px; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.form-end { display: flex; justify-content: flex-end; }
@media (max-width: 599px) { .form-end .btn { width: 100%; } }
.chip-ghost { border-style: dashed; color: var(--muted); }
.user-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.user-row.inactive { opacity: .6; }
.user-main { flex: 1; min-width: 200px; }
.user-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.user-line { margin: 2px 0 0; font-size: .92rem; word-break: break-word; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.user-actions form { margin: 0; }
@media (max-width: 599px) { .user-actions { width: 100%; justify-content: flex-end; } }

.install-slot { padding-bottom: 0; }
.install-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--primary) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--line)); }
.install-banner[hidden] { display: none; }
.install-card { background: var(--surface); border-color: var(--line); margin-bottom: 14px; text-align: left; }
.install-icon img { display: block; border-radius: 10px; }
.install-text { flex: 1; min-width: 180px; display: grid; gap: 2px; }
.install-text .muted { font-size: .88rem; }
.install-actions { display: flex; gap: 8px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.ios-guide { width: min(440px, calc(100vw - 32px)); border: 0; border-radius: 18px; padding: 22px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.ios-guide::backdrop { background: rgba(0, 0, 0, .45); }
.ios-guide h2 { margin-bottom: 14px; }
.guide-steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 12px; display: grid; gap: 12px; }
.guide-steps li { display: flex; align-items: center; gap: 12px; }
.step-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--bg); color: var(--info); }
.step-icon img { border-radius: 6px; }
.step-text { font-weight: 700; font-size: .8rem; color: var(--info); }

.removed-list summary { cursor: pointer; font-weight: 600; }
.removed-list[open] summary { margin-bottom: 6px; }

.media-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; position: relative; }
.camera-menu > summary { list-style: none; height: 100%; }
.camera-menu > summary::-webkit-details-marker { display: none; }
.camera-menu[open] > summary { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent); }
.camera-choices { position: absolute; left: 0; right: 0; top: calc(100% + 8px); z-index: 5; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.camera-choices .media-btn { min-height: 56px; }
.media-btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.media-btn:active { transform: scale(.98); }
.media-btn-main { min-height: 64px; background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-size: 1.05rem; position: relative; }
.media-btn-alt { background: var(--surface); border-color: var(--primary); color: var(--ink); }
.media-btn:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.media-icon { font-size: 1.3rem; line-height: 1; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.preview-tile { position: relative; width: 92px; height: 92px; border-radius: 12px; overflow: hidden; background: var(--bg); }
.preview-tile img, .preview-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-remove { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .65); color: #fff; font-size: 1.1rem; line-height: 1; cursor: pointer; }
.tile-badge { position: absolute; left: 4px; bottom: 4px; padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: .72rem; }
.hint-alert { color: var(--danger); font-weight: 600; }
.building-pill { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--bg); margin-bottom: 4px; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 28px 0 4px; text-align: center; }
.auth-brand img { border-radius: 18px; }
.auth-brand p { margin: 0; color: var(--muted); }
.poster-code { font-size: 1.2rem; margin-top: 6px; }
.poster-code strong { letter-spacing: .15em; font-family: ui-monospace, monospace; }

.empty-card { color: var(--muted); text-align: center; }
.auth-links { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

/* Affiche QR code (A4) */
.print-page { background: #fff; color: #111; padding: 0; }
.poster { max-width: 680px; margin: 0 auto; padding: 40px 32px; text-align: center; }
.poster-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.4rem; font-weight: 700; color: #1f5f4a; margin-bottom: 18px; }
.poster-brand img { border-radius: 10px; }
.poster h1 { font-size: 2.4rem; margin-bottom: 12px; }
.poster-sub { font-size: 1.25rem; color: #333; }
.qr { width: 340px; max-width: 80vw; margin: 28px auto; }
.qr svg { width: 100%; height: auto; }
.poster-steps { font-size: 1.15rem; }
.poster-url { font-family: ui-monospace, monospace; color: #555; word-break: break-all; }
.poster-foot { margin-top: 28px; color: #555; }
@media print {
  .no-print { display: none; }
  @page { size: A4; margin: 12mm; }
}
