:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e4e2dc;
  --accent: #e4572e;
  --accent-2: #2b7a78;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
  --status-novo: #6e6e73;
  --status-visitar: #3a6ea5;
  --status-visitado: #2b7a78;
  --status-favorito: #e0a100;
  --status-descartado: #b03a48;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --card: #1e1e21;
    --text: #f2f2f4;
    --muted: #9a9aa2;
    --line: #2c2c31;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: var(--accent); color: #fff; padding: 9px 14px; border-radius: 10px; font-weight: 600; }
button:hover { filter: brightness(1.05); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
input, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; }
.hidden { display: none !important; }

/* Topo */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.add-form { display: flex; gap: 8px; flex: 1; min-width: 240px; }
.add-form input { flex: 1; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.presence::before { content: "●"; color: #3cb371; margin-right: 4px; }
.presence:empty::before { content: none; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 2000;
  max-width: 90vw; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.err { background: var(--status-descartado); }

/* Abas (só mobile) */
.tabs { display: none; }

/* Layout */
.layout { flex: 1; display: grid; grid-template-columns: minmax(360px, 460px) 1fr; min-height: 0; }
.panel { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--bg); }
.filters { padding: 12px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.filters .row { display: flex; gap: 8px; }
.filter-foot { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.filter-foot button { padding: 6px 10px; }

.cards { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; cursor: pointer; border: 2px solid transparent; transition: border-color .15s;
}
.card.active { border-color: var(--accent); }
/* cards não podem encolher quando há muitos na lista (flex) */
.cards > .card { flex: none; }
.card .gallery { position: relative; aspect-ratio: 16 / 10; background: #ddd; overflow: hidden; }
.card .gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .nophoto { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 14px; }
.gnav {
  position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.45); color: #fff;
  width: 32px; height: 32px; border-radius: 50%; padding: 0; display: grid; place-items: center; font-size: 18px;
}
.gnav.prev { left: 8px; } .gnav.next { right: 8px; }
.counter { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.status-chip {
  position: absolute; left: 8px; top: 8px; color: #fff; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--status-novo);
}
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.card .price { font-size: 20px; font-weight: 700; }
.card .price small { font-size: 12px; font-weight: 500; color: var(--muted); }
.card .breakdown { font-size: 12px; color: var(--muted); }
.card .title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .loc { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.specs { display: flex; flex-wrap: wrap; gap: 6px; }
.spec { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; }
.card .foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.warn { color: var(--status-descartado); font-size: 12px; }
.stars { color: var(--status-favorito); letter-spacing: 1px; }

/* Mapa */
.map-wrap { position: relative; min-height: 0; }
#map { height: 100%; width: 100%; }
.map-fit { position: absolute; top: 12px; right: 12px; z-index: 500; background: var(--card); box-shadow: var(--shadow); }
.pin {
  background: var(--accent); color: #fff; font-weight: 700; font-size: 12px; white-space: nowrap;
  padding: 4px 8px; border-radius: 999px; box-shadow: 0 2px 6px rgba(0,0,0,.3); border: 2px solid #fff; transform: translate(-50%, -50%);
}
.pin.sel { background: var(--text); transform: translate(-50%, -50%) scale(1.12); }
.pin.s-visitar { background: var(--status-visitar); }
.pin.s-visitado { background: var(--status-visitado); }
.pin.s-favorito { background: var(--status-favorito); color: #222; }
.pin.s-descartado { background: var(--status-descartado); opacity: .75; }
.pin.s-novo { background: var(--accent); }

/* Modal */
.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 1000; padding: 12px; }
.modal-card { position: relative; background: var(--card); border-radius: 18px; width: min(860px, 100%); max-height: 94dvh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-card.small { width: min(420px, 100%); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-card.small h2 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.close { position: absolute; top: 10px; right: 10px; z-index: 5; background: rgba(0,0,0,.5); padding: 6px 10px; }
.d-gallery { position: relative; aspect-ratio: 16 / 9; background: #000; }
.d-gallery img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 8px; background: var(--bg); }
.thumbs img { height: 56px; width: 84px; object-fit: cover; border-radius: 6px; cursor: pointer; opacity: .6; flex: none; }
.thumbs img.on { opacity: 1; outline: 2px solid var(--accent); }
.d-body { padding: 16px 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.d-title { font-size: 20px; font-weight: 700; margin: 0; }
.d-price { font-size: 26px; font-weight: 800; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kv { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.kv b { display: block; font-size: 16px; }
.kv span { font-size: 12px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.statusbar { display: flex; flex-wrap: wrap; gap: 6px; }
.statusbar button { background: var(--bg); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.statusbar button.on { background: var(--accent-2); color: #fff; border-color: transparent; }
.ratings { display: flex; flex-wrap: wrap; gap: 14px; }
.rate { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.rate .star-row button { background: none; color: var(--line); padding: 0 2px; font-size: 24px; line-height: 1; }
.rate .star-row button.on { color: var(--status-favorito); }
textarea { width: 100%; min-height: 70px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); resize: vertical; }
.comment { background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.comment b { font-size: 13px; }
.comment small { color: var(--muted); margin-left: 6px; }
.comment-form { display: flex; gap: 8px; margin-top: 8px; }
.comment-form input { flex: 1; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; }
.d-actions .left, .d-actions .right { display: flex; gap: 8px; flex-wrap: wrap; }
.danger { background: var(--status-descartado); }
.edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.edit-grid label { font-size: 12px; }
.history { font-size: 12px; color: var(--muted); }

/* Celular */
@media (max-width: 860px) {
  body { height: 100dvh; }
  .topbar { padding: 8px 10px; }
  .add-form { order: 3; flex-basis: 100%; min-width: 0; }
  .tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); }
  .tabs button { flex: 1; background: transparent; color: var(--muted); border-radius: 0; font-weight: 600; padding: 10px; }
  .tabs button.active { color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
  .layout { display: flex; flex-direction: column; }
  .layout[data-tab="list"] .map-wrap { display: none; }
  .layout[data-tab="map"] .panel { display: none; }
  .layout[data-tab="map"] .map-wrap { flex: 1; }
  .panel { flex: 1; min-height: 0; border-right: 0; }
  .cards { padding: 10px; }
  .map-fit { top: 8px; right: 8px; }
  .gnav { width: 40px; height: 40px; }
}

/* Notas (Yuri e Lais) */
button:disabled { opacity: .45; cursor: default; filter: none; }
.person-picks { justify-content: stretch; }
.person-picks button { flex: 1; padding: 14px; font-size: 16px; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; padding-top: 18px; }
.check input { width: auto; }
.card .scores { display: flex; flex-wrap: wrap; gap: 6px; }
.sbadge { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; }
.sbadge.mine { border-color: var(--accent); }
.visit-chip {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.55); color: #fff;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
}
.avg-chip {
  position: absolute; right: 8px; top: 8px; color: #fff; font-weight: 800; font-size: 15px;
  padding: 4px 10px; border-radius: 999px; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.score-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .score-cols { grid-template-columns: 1fr; } }
.score-col { background: var(--bg); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.score-col.mine { box-shadow: inset 0 0 0 2px var(--accent); }
.score-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.score-head .big { font-size: 26px; font-weight: 800; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 4px; }
.emoji-row button, .num-row button {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  padding: 4px 0; border-radius: 8px; font-weight: 600; font-size: 16px; min-width: 0;
}
.emoji-row button { width: 40px; height: 40px; padding: 0; font-size: 20px; }
.emoji-row button.on, .num-row button.on { background: var(--accent-2); color: #fff; border-color: transparent; }
.num-row { display: grid; grid-template-columns: repeat(11, 1fr); gap: 3px; }
.num-row button { font-size: 12px; padding: 4px 0; }
.toggle-on { background: var(--accent-2) !important; color: #fff !important; border-color: transparent !important; }
.pin.short { outline: 3px solid #fff; }
.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500; background: var(--card);
  box-shadow: var(--shadow); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; gap: 4px; min-width: 180px;
}
.legend .grad {
  height: 10px; border-radius: 5px;
  background: linear-gradient(90deg, hsl(0 70% 42%), hsl(60 70% 42%), hsl(120 70% 42%));
}
.legend-scale { display: flex; justify-content: space-between; }
.legend-note { font-size: 11px; }

/* Importação em lote */
.modal-card.batch { width: min(620px, 100%); }
.modal-card.batch textarea { min-height: 140px; font-size: 14px; }
.batch-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.batch-list li { background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 13px; word-break: break-all; }
.batch-list li small { display: block; color: var(--muted); }

/* Seletor de quem entra na média (mapa) */
.who-filter {
  position: absolute; top: 12px; left: 12px; z-index: 500; background: var(--card);
  box-shadow: var(--shadow); border-radius: 12px; padding: 6px; display: flex; flex-wrap: wrap;
  gap: 4px; align-items: center; font-size: 12px; color: var(--muted); max-width: calc(100% - 180px);
}
.who-filter button { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 4px 9px; font-size: 12px; font-weight: 600; }
.who-filter button.on { background: var(--accent-2); color: #fff; border-color: transparent; }
.score-cols { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
@media (max-width: 560px) { .score-cols { grid-template-columns: 1fr; } }
.person-picks button.on { background: var(--accent-2); }

/* Agendamento de visitas */
.sched-box { background: var(--bg); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.sched-title { font-weight: 700; font-size: 14px; }
.who-checks { display: flex; flex-wrap: wrap; gap: 14px; }
.who-checks .check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.who-checks .check input { width: auto; }
.visit-actions { display: flex; gap: 6px; margin-top: 6px; }
.visit-actions button { padding: 5px 10px; font-size: 13px; }
.modal-card.agenda { width: min(640px, 100%); max-width: 640px; }
.agenda-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; font-size: 14px; }
.agenda-day { font-size: 14px; text-transform: capitalize; margin: 14px 0 6px; color: var(--accent-2); }
.agenda-item { display: flex; gap: 12px; background: var(--bg); border-radius: 12px; padding: 10px; }
.agenda-item .time { font-weight: 800; font-size: 18px; min-width: 56px; }
.agenda-body { display: flex; flex-direction: column; gap: 4px; font-size: 14px; min-width: 0; }
.agenda-body .muted { font-size: 13px; }
.travel { font-size: 13px; color: var(--muted); padding: 4px 0 4px 68px; }
.linkish { background: none; color: var(--accent); padding: 0; text-align: left; font-weight: 700; font-size: 15px; }
.sbadges { display: flex; flex-wrap: wrap; gap: 4px; }
.small { font-size: 12px; }
#agendaBtn { padding: 8px 12px; }

/* Etiquetas com nome (seleção múltipla) */
.tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }
.tag {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  padding: 6px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tag.on { background: var(--accent-2); color: #fff; border-color: transparent; }
.tag:disabled { opacity: 1; }
.tag:disabled.on { opacity: .9; }
.num-row button:disabled { opacity: 1; }
.num-row button:disabled.on { opacity: .9; }

/* Informações faltando */
.incomplete { font-weight: 600; }
.banner-warn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: #fff4e5; color: #8a4b00; border-radius: 12px; padding: 10px 12px; font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .banner-warn { background: #3a2a14; color: #ffc98a; }
}
.edit-grid + .full, label.full { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-top: 8px; }
label.full textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font: inherit; }
.batch-list li button { margin-top: 6px; padding: 5px 10px; font-size: 12px; }

/* Filtros recolhíveis (celular) */
.filters-toggle { display: none; }

/* Card do pino no mapa */
.map-card {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 600;
  background: var(--card); border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  display: flex; gap: 12px; overflow: hidden; max-width: 560px; margin: 0 auto;
}
.map-card[hidden] { display: none; }
.map-card img { width: 140px; height: 140px; object-fit: cover; flex: none; }
.mc-nophoto { width: 140px; min-height: 140px; display: grid; place-items: center; color: var(--muted); background: var(--bg); font-size: 13px; flex: none; }
.mc-body { display: flex; flex-direction: column; gap: 4px; padding: 12px 12px 12px 0; min-width: 0; flex: 1; }
.mc-price { font-size: 20px; font-weight: 800; }
.mc-price small { font-size: 12px; font-weight: 500; color: var(--muted); }
.mc-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-loc { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-open { margin-top: auto; align-self: flex-start; padding: 7px 12px; font-size: 13px; }
.mc-close { position: absolute; top: 8px; right: 8px; z-index: 2; background: rgba(0,0,0,.55); color: #fff; padding: 4px 8px; font-size: 12px; }
.map-card { position: absolute; }

@media (max-width: 860px) {
  .filters-toggle {
    display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 8px;
    background: var(--bg); color: var(--text); border: 1px solid var(--line); font-weight: 600; font-size: 14px;
  }
  .filters.collapsed > *:not(.filters-toggle) { display: none; }
  .filters { padding: 10px; gap: 6px; }
  .filters .row { gap: 6px; }
  .map-card { left: 8px; right: 8px; bottom: 8px; }
  .map-card img, .mc-nophoto { width: 110px; height: 120px; min-height: 120px; }
  .mc-body { padding-right: 36px; }
}

/* Notas dos outros: recolhidas por padrão */
details.score-col.other { padding: 0; }
details.score-col.other > summary { cursor: pointer; list-style: none; padding: 10px; font-size: 14px; }
details.score-col.other > summary::-webkit-details-marker { display: none; }
details.score-col.other > summary::after { content: " ▾"; color: var(--muted); }
details.score-col.other[open] > summary::after { content: " ▴"; }
details.score-col.other > :not(summary) { margin: 0 10px 10px; }
details.score-col.other > summary + * { margin-top: 0; }

/* Mini mapa no detalhe do apartamento */
.d-map { height: 220px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); margin-bottom: 6px; }

/* Etiquetas compartilhadas: largura total, acima das notas */
.tag-grid-full { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; width: 100%; }
.tag-grid-full .tag small { font-size: 10px; opacity: .9; margin-left: 2px; }
.score-cols { width: 100%; }
