:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #16202a;
  --muted: #66727f;
  --accent: #1f6feb;
  --priority: #16a34a;
  --viewing: #2563eb;
  --shortlist: #d97706;
  --match: #6b7280;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.brand .sub { color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.stats { color: var(--muted); font-size: 12px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.search { flex: 1 1 260px; min-width: 200px; }
#archiveUnmarked { margin-left: auto; }
input[type="search"], select, .token {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  color: inherit;
}
.token { width: 130px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }

.btn {
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.btn:hover { border-color: #c9d0d8; }
.btn.ghost { background: transparent; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.flag.active[data-flag="approved_martins"] { background: var(--priority); border-color: var(--priority); }
.btn.flag.active[data-flag="approved_anete"] { background: var(--priority); border-color: var(--priority); }
.btn.flag.active[data-flag="viewing"] { background: var(--viewing); border-color: var(--viewing); }
.btn.flag.archive { color: var(--muted); }
.btn.flag.archive.active { background: #5b6572; border-color: #5b6572; color: #fff; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 44%);
  gap: 14px;
  padding: 14px 16px 40px;
  align-items: start;
}

.list { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.mapside { position: sticky; top: 74px; }
#map {
  height: calc(100vh - 210px);
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #e9edf1;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--match); }
.dot.priority { background: var(--priority); }
.dot.viewing { background: var(--viewing); }
.dot.shortlist { background: var(--shortlist); }
.dot.match { background: var(--match); }
.dot.approx { background: transparent; border: 1px dashed var(--match); }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 12px 2px 2px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.section-title strong { color: var(--text); font-size: 14px; letter-spacing: 0; text-transform: none; }
.section-title .count { font-size: 12px; }

.card {
  display: flex;
  gap: 12px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card.priority { border-color: #b7e0c4; box-shadow: inset 3px 0 0 var(--priority); }
.card.viewing { border-color: #bcd0f7; box-shadow: inset 3px 0 0 var(--viewing); }
.card.shortlist { border-color: #f2d9b0; box-shadow: inset 3px 0 0 var(--shortlist); }
.card.filtered { opacity: 0.7; }
.card.highlight { outline: 2px solid var(--accent); outline-offset: 1px; }

.thumb {
  position: relative;
  flex: 0 0 148px;
  height: 108px;
  border-radius: 8px;
  overflow: hidden;
  background: #eef1f4;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .nophoto {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: #9aa4af;
  font-size: 11px;
}
.thumb.empty img { display: none; }
.thumb.empty .nophoto { display: flex; }

.body { min-width: 0; flex: 1; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.price { font-size: 17px; font-weight: 650; }
.badge {
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #38424d;
}
.badge.points { background: #e8f0fe; color: #174ea6; font-weight: 600; }
.badge.points.neg { background: #fdecec; color: #a61b1b; }
.meta { color: var(--muted); font-size: 12px; }

.title {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.title:hover { color: var(--accent); }

.reasons { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reasons .chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #f1f4f7;
  color: #47515c;
  white-space: nowrap;
}
.reasons .chip.pos { background: #e9f7ee; color: #14683a; }
.reasons .chip.neg { background: #fdeeee; color: #a02020; }
.reasons .chip.warn { background: #fff5e5; color: #8a5100; }
.detail { color: var(--muted); font-size: 12px; margin-top: 5px; }
.detail.excluded { color: #a02020; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 9px; }
.actions .geo { margin-left: auto; }

.empty-state { color: var(--muted); padding: 24px 4px; }

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .mapside { position: static; order: -1; }
  #map { height: 300px; }
  .thumb { flex-basis: 110px; height: 88px; }
}
