:root {
  --navy: #122549;
  --navy-light: #1f3a5f;
  --bg: #f3eddc;
  --surface: #fbf7ec;
  --cream: #EEE8D1;
  --text: #122549;
  --text-muted: #5b6b7e;
  --border: #cdd5dd;
  --accent: #DA4431;
  --accent-pale: #f3cabf;
  --header-sub: #8fa0b8;
  --shadow: 0 1px 3px rgba(18, 37, 73, 0.07);
  --shadow-lg: 0 12px 40px rgba(18, 37, 73, 0.3);
  --green: #4e8c4e;
  --green-accent: #66A266;
  --green-bg: #e7efe2;
  --red: #c0392b;
  --red-bg: #f3cabf;
  --fav: #DA4431;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  line-height: 1.5;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy);
  border-bottom: 1px solid var(--navy-light);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.1rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

h1 {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  color: var(--cream);
}

.badge-demo {
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--cream);
  border: 1px solid var(--cream);
  border-radius: 999px;
}

.subtitle {
  margin: 0.3rem 0 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--header-sub);
}

.maj {
  margin: 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--header-sub);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* Stats */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat {
  flex: 1 1 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
}

.stat-label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

/* Filtres */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.filter label {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.filter input,
.filter select,
.filter button {
  width: 100%;
  padding: 0.45rem 0.55rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.filter input[type="range"] {
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}

.filter-reset { align-self: end; }

.filter button {
  cursor: pointer;
  background: var(--surface);
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--navy);
}

.filter button:hover { border-color: var(--accent); color: var(--accent); }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 0;
}

/* Grille de cartes */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
}

.card:hover, .card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(18, 37, 73, 0.14);
}

.card-photo {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--border);
  overflow: hidden;
}

.card-photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.card-photo .no-photo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.card-body {
  padding: 0.75rem 0.9rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}

.card-price {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
}

.card-price small {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

.card-city {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Badges */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--cream);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.badge-ecart-neg { background: var(--green-bg); color: var(--green); border-color: var(--green-accent); }
.badge-ecart-pos { background: var(--red-bg); color: var(--red); border-color: transparent; }

.badge-dpe {
  font-weight: 700;
  color: #fff;
  border: none;
  min-width: 1.6em;
  text-align: center;
}

.dpe-A { background: #009a3d; }
.dpe-B { background: #52b153; }
.dpe-C { background: #a5cc3f; color: #223; }
.dpe-D { background: #f4e300; color: #223; }
.dpe-E { background: #f0b40f; color: #223; }
.dpe-F { background: #e8731a; }
.dpe-G { background: #d7231e; }

/* Panneau de détail */
[hidden] { display: none !important; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 37, 73, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.panel {
  background: var(--surface);
  border-radius: 10px;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.panel-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  width: 2.2rem;
  height: 2.2rem;
  border: none;
  border-radius: 50%;
  background: rgba(18, 37, 73, 0.6);
  color: var(--cream);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.panel-photo {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--border);
}

.panel-photo img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: cover;
  display: block;
}

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2.4rem;
  height: 2.4rem;
  border: none;
  border-radius: 50%;
  background: rgba(18, 37, 73, 0.6);
  color: var(--cream);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.nav-prev { left: 0.6rem; }
.nav-next { right: 0.6rem; }

.photo-counter {
  position: absolute;
  bottom: 0.6rem;
  right: 0.6rem;
  background: rgba(18, 37, 73, 0.6);
  color: var(--cream);
  font-family: 'DM Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 1px;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.panel-body { padding: 1rem 1.25rem 1.25rem; }

.panel-body h2 {
  margin: 0 0 0.25rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--navy);
}

.panel-price {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--navy);
}

.panel-price small { font-size: 0.8rem; font-weight: 400; color: var(--text-muted); }

.panel-loc { margin: 0.15rem 0 0.6rem; color: var(--text-muted); }

.panel-body h3 {
  margin: 1rem 0 0.4rem;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
}

.sources {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sources a {
  color: var(--navy-light);
  text-decoration: none;
  word-break: break-all;
  font-size: 0.9rem;
}

.sources a:hover { color: var(--accent); text-decoration: underline; }

/* Onglets d'affichage */
.view-tabs {
  display: flex;
  gap: 1.1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.view-tab {
  padding: 0.5rem 0.2rem 0.55rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
}

.view-tab:hover { color: var(--navy); }

.view-tab.active {
  background: transparent;
  color: var(--navy);
  border-bottom-color: var(--accent);
}

/* Boutons d'action (cartes + panneau) */
.action-btn {
  padding: 0.4rem 0.7rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
  white-space: nowrap;
}

.action-btn:hover { border-color: var(--accent); }

.fav-btn:hover { background: var(--accent-pale); }

.fav-btn.active {
  background: var(--fav);
  border-color: var(--fav);
  color: var(--cream);
}

.fav-btn.active:hover { background: var(--fav); }

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.35rem;
}

.card-actions .action-btn { flex: 1; text-align: center; }

/* Carte favorite : liseré + badge */
.card-favori {
  border-color: var(--fav);
  box-shadow: 0 0 0 1px var(--fav), var(--shadow);
}

.card-fav-badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: var(--fav);
  color: var(--cream);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

/* Carte écartée */
.card-excluded { opacity: 0.6; }

.card-excluded .card-photo img { filter: grayscale(1); }

.card-reasons {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Section « Écartées » */
.excluded-section { margin-top: 2rem; }

.excluded-section summary {
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  padding: 0.5rem 0;
}

.excluded-section summary:hover { color: var(--navy); }

.excluded-grid { margin-top: 1rem; }

/* Actions du panneau */
.panel-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0 0.25rem;
}

.panel-reasons {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Dialogue d'exclusion */
.overlay-dialog { z-index: 60; }

.dialog {
  background: var(--surface);
  border-radius: 10px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
}

.dialog h2 {
  margin: 0 0 0.25rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--navy);
}

.dialog-sub {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.dialog-reasons {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.dialog-reasons label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.dialog-reasons input { accent-color: var(--accent); }

.dialog-comment {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.dialog-comment input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.45rem 0.55rem;
  font-family: 'Syne', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dialog-actions button {
  padding: 0.45rem 0.9rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
}

#exclude-confirm {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--cream);
}

/* Pied de page */
.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  text-align: center;
}

.offline-note {
  margin: 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

@media (max-width: 480px) {
  .header-inner { flex-direction: column; }
  .stats { gap: 0.5rem; }
  .stat { padding: 0.6rem 0.75rem; }
}

/* Sources des annonces sur les cartes */
.card-sources { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.source-chip {
  font-family: 'DM Mono', monospace;
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 20px; padding: 2px 9px;
}
.source-chip.source-ea {
  color: var(--text); font-weight: 500;
  border-color: #b8963e; background: rgba(212, 175, 55, 0.16);
}

/* Ligne de tri dédiée */
.sort-bar {
  display: flex; align-items: center; gap: 0.7rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 0.55rem 1rem; box-shadow: var(--shadow);
}
.sort-bar label {
  font-family: 'DM Mono', monospace;
  font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--text-muted);
}
.sort-bar select {
  font: inherit; font-size: 0.9rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.35rem 0.6rem;
}

/* Rond de score en surimpression photo (haut droite) */
.card-score {
  position: absolute; top: 0.5rem; right: 0.5rem;
  width: 2.7rem; height: 2.7rem; border-radius: 50%;
  background: #ffffff; color: #1c2330;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3);
  border: 3px solid transparent;
}
.card-score.s-haut { border-color: #1a9d5c; }
.card-score.s-moyen { border-color: #d99a20; }
.card-score.s-bas { border-color: #c05b4d; }
