:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e0e2e7;
  --text: #22262b;
  --muted: #6b7280;
  --accent: #2f6f4f;
  --accent-dark: #1f4d36;
  --new: #2f6f4f;
  --gone: #b3474d;
  --radius: 10px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 24px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

.refresh-row { display: flex; align-items: center; gap: 12px; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 14px;
  background: var(--accent);
  color: white;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.6; cursor: wait; }

.link-btn {
  background: none;
  color: var(--accent-dark);
  padding: 4px 0;
  text-decoration: underline;
}
.link-btn:hover { background: none; }

.secondary-btn { background: #33445c; }
.secondary-btn:hover { background: #22304a; }

.hint-text { font-size: 12px; color: var(--muted); align-self: center; }
.card-market { font-size: 12px; }
.card-market.above { color: var(--gone); }
.card-market.below { color: var(--new); }

#refresh-status { font-size: 13px; color: var(--muted); }
#refresh-summary { margin-top: 10px; font-size: 13px; color: var(--muted); }
#refresh-summary .err { color: var(--gone); }

main { padding: 24px 32px; max-width: 1100px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
  margin-bottom: 10px;
}
.filter-group:last-child { margin-bottom: 0; }
.filter-group label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.filter-group.checkboxes label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
input, select {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  min-width: 120px;
}

#listings {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.card.masque { opacity: 0.5; }
.card.favori { border-color: var(--accent); }

.card-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef1ee;
  color: var(--muted);
}
.badge.nouveau { background: var(--new); color: white; }
.badge.disparue { background: var(--gone); color: white; }
.badge.source { background: #e5e9f0; color: #33445c; }

.card-photo {
  width: calc(100% + 32px);
  margin: -16px -16px 0;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius) var(--radius) 0 0;
}

.card-price { font-size: 20px; font-weight: 600; }
.card-price-m2 { font-size: 13px; font-weight: 400; color: var(--muted); }
.card-price-history:empty { display: none; }
.card-price-history { font-size: 12px; color: var(--gone); }
.card-meta { font-size: 13px; color: var(--muted); }
.card-desc { font-size: 13px; color: var(--text); max-height: 4.5em; overflow: hidden; }
.card-agence { font-size: 12px; color: var(--muted); }
.card-duplicates:empty { display: none; }
.card-duplicates { font-size: 12px; color: var(--muted); }
.card-duplicates a { color: #33445c; }

.card-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }
.card-actions button {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  background: #eef1ee;
  color: var(--text);
}
.card-actions button.active { background: var(--accent); color: white; }
.card-actions a {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 6px;
  background: #33445c;
  color: white;
  text-decoration: none;
}

#manual-form { margin-top: 12px; }

.empty-state { color: var(--muted); padding: 40px; text-align: center; }

.new-banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--new);
  color: white;
  font-size: 14px;
  font-weight: 600;
}

.view-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.view-toggle button { background: #e5e9f0; color: var(--text); }
.view-toggle button.active { background: var(--accent); color: white; }

#map {
  height: 520px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.map-popup { font-size: 13px; }
.map-popup a { color: #33445c; }

.card-compare-row {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.compare-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 500;
}
.compare-bar button { padding: 8px 14px; font-size: 13px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 100%;
  max-height: 90vh;
  overflow: auto;
}
.compare-table { border-collapse: collapse; width: 100%; }
.compare-table th, .compare-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}
.compare-table th { background: #eef1ee; }

.market-duration { font-size: 12px; color: var(--muted); }

#visit-modal .modal { width: 520px; }
#visit-title { font-size: 16px; margin: 4px 0 12px; }
.visit-date-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.visit-section { margin-bottom: 12px; }
.visit-section h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.visit-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
}
#visit-notes { width: 100%; margin-top: 4px; font-family: inherit; }
#visit-save-btn { margin-top: 12px; }
#visit-save-status { margin-left: 10px; }

.card-visit-badge { font-size: 12px; color: var(--accent-dark); }
