/* DPE Alerts — feuille de style unique, mobile d'abord, sans dépendance. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1c2733;
  --muted: #5f6f7f;
  --accent: #1f6feb;
  --accent-dark: #1a5cc4;
  --warn-bg: #fff5e0;
  --warn-border: #e9b949;
  --error-bg: #fdecec;
  --error-border: #d64545;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .08);

  /* Échelle officielle des étiquettes DPE (A vert → G rouge). */
  --dpe-a: #319834;
  --dpe-b: #33cc31;
  --dpe-c: #cbfc34;
  --dpe-d: #fbfe06;
  --dpe-e: #fbcc05;
  --dpe-f: #fc9935;
  --dpe-g: #fd0d15;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; }
a { color: var(--accent); }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand h1 { font-size: 1.25rem; letter-spacing: -.02em; }
.tagline { margin: .15rem 0 0; font-size: .8rem; color: var(--muted); }

.sync {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .3rem .7rem;
}
.sync-dot {
  width: .6rem; height: .6rem; border-radius: 50%;
  background: var(--muted); flex: none;
}
.sync-dot.ok { background: #2ea043; }
.sync-dot.warn { background: var(--warn-border); }
.sync-dot.err { background: var(--error-border); }

main { padding: 1rem; max-width: 1100px; margin: 0 auto; display: grid; gap: 1rem; }

/* Compteurs */
.counters {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .6rem;
}
.counter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .75rem;
  display: flex; flex-direction: column; gap: .15rem;
}
.counter-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.counter-label { font-size: .78rem; color: var(--muted); }

/* Panneaux */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .6rem; flex-wrap: wrap;
}
.panel h2 { margin-bottom: .6rem; }
.panel-head h2 { margin-bottom: 0; }

/* Formulaires */
.filters { display: grid; grid-template-columns: 1fr; gap: .7rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label, .field legend { font-size: .78rem; font-weight: 600; color: var(--muted); }
fieldset.field { border: 0; padding: 0; margin: 0; }

input[type="text"], input[type="date"], input[type="number"], select {
  font: inherit;
  padding: .5rem .6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 42px; /* cible tactile confortable */
  width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.actions { flex-direction: row; gap: .5rem; flex-wrap: wrap; }
.btn {
  font: inherit;
  font-weight: 600;
  padding: .55rem 1rem;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: .3rem .6rem; min-height: 34px; font-size: .8rem; }
.btn.danger { color: var(--error-border); border-color: #f0c0c0; }

/* Puces d'étiquettes */
.label-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  color: #1c2733;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { border-color: var(--text); box-shadow: 0 0 0 2px rgba(28,39,51,.15); }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip[data-label="A"] { background: var(--dpe-a); color: #fff; }
.chip[data-label="B"] { background: var(--dpe-b); }
.chip[data-label="C"] { background: var(--dpe-c); }
.chip[data-label="D"] { background: var(--dpe-d); }
.chip[data-label="E"] { background: var(--dpe-e); }
.chip[data-label="F"] { background: var(--dpe-f); }
.chip[data-label="G"] { background: var(--dpe-g); color: #fff; }

.bbox-toggle { font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }

/* Carte */
#map {
  height: 380px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #e8edf2;
  z-index: 0; /* garde les popups Leaflet sous les panneaux */
}
#map.unavailable { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 0; font-size: .75rem; color: var(--muted); }
.legend .swatch {
  display: inline-flex; align-items: center; gap: .25rem;
}
.legend .dot { width: .7rem; height: .7rem; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }

/* Messages */
.warning, .notice, .error, .loader {
  margin: 0 0 .6rem;
  padding: .55rem .7rem;
  border-radius: 8px;
  font-size: .85rem;
  border: 1px solid;
}
.warning { background: var(--warn-bg); border-color: var(--warn-border); }
.notice { background: #eef4ff; border-color: #c5d8f7; }
.error { background: var(--error-bg); border-color: var(--error-border); color: #8a1f1f; }
.loader { background: #eef4ff; border-color: #c5d8f7; color: var(--muted); }
[aria-busy="true"] { opacity: .92; }

/* Tableau */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.results { width: 100%; border-collapse: collapse; font-size: .85rem; }
.results th, .results td {
  text-align: left; padding: .5rem .4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.results th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.results td.addr { white-space: normal; min-width: 200px; }
.results tbody tr:hover { background: var(--bg); }
.results tbody tr { cursor: pointer; }
.results tbody tr:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px;
  font-weight: 700; font-size: .8rem;
  border: 1px solid rgba(0,0,0,.15);
}
.badge[data-label="A"] { background: var(--dpe-a); color: #fff; }
.badge[data-label="B"] { background: var(--dpe-b); }
.badge[data-label="C"] { background: var(--dpe-c); }
.badge[data-label="D"] { background: var(--dpe-d); }
.badge[data-label="E"] { background: var(--dpe-e); }
.badge[data-label="F"] { background: var(--dpe-f); }
.badge[data-label="G"] { background: var(--dpe-g); color: #fff; }
.badge[data-label=""] { background: var(--bg); color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .7rem; }

.detail-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.detail-section { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; background: var(--bg); }
.detail-section h3 { margin: 0 0 .45rem; font-size: .9rem; }
.detail-kv { display: grid; grid-template-columns: minmax(120px, 45%) 1fr; gap: .25rem .6rem; font-size: .84rem; }
.detail-kv dt { color: var(--muted); }
.detail-kv dd { margin: 0; font-weight: 600; min-width: 0; word-break: break-word; }
.detail-raw { white-space: pre-wrap; font: .75rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 220px; overflow: auto; }

/* Règles */
.rules { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .5rem; }
.rule {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .7rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  background: var(--bg);
}
.rule.disabled { opacity: .6; }
.rule-main { flex: 1 1 220px; min-width: 0; }
.rule-name { font-weight: 600; }
.rule-meta { font-size: .78rem; color: var(--muted); }
.rule-actions { display: flex; gap: .35rem; }

.muted { color: var(--muted); }
.small { font-size: .75rem; }
.footer { font-size: .78rem; color: var(--muted); padding: 0 .25rem 1rem; }
.footer p { margin: .3rem 0; }

/* Écrans larges */
@media (min-width: 640px) {
  .counters { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: repeat(2, 1fr); }
  .filters .labels, .filters .actions { grid-column: 1 / -1; }
  #map { height: 460px; }
}
@media (min-width: 900px) {
  .filters { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
