:root {
  --bg: #fafafa;
  --surface: #fff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e6e6e6;
  --accent: #0a7;
  --accent-dark: #086;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --radius: 10px;

  --badge-gray: #6b6b6b;
  --badge-blue: #2563eb;
  --badge-purple: #7c3aed;
  --badge-amber: #d97706;
  --badge-green: #059669;
  --badge-red: #dc2626;
  --badge-teal: #0891b2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  /* 16px mantém input zoom desligado no iOS Safari ao focar campos. */
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; height: auto; }
.container { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: .75rem;
  flex-wrap: wrap;
}
.page-header h1 { color: var(--accent); margin: 0; font-size: 1.75rem; }
.page-header > a,
.page-header > .btn-primary,
.page-header > .btn-ghost { flex: 0 0 auto; }

/* Botões — touch targets de ao menos 44x44 no mobile (Apple HIG). */
.btn-primary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1.1rem;
  min-height: 44px;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface); }

/* Filtros */
.filtros {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem 1rem;
  align-items: end;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}
.filtros .field { display: flex; flex-direction: column; gap: .25rem; }
.filtros .field > span,
.filtros .field > legend { font-size: .8rem; color: var(--muted); font-weight: 500; }
.filtros input,
.filtros select {
  padding: .55rem .65rem;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  /* mantém font-size de body (16px) — evita iOS zoom no foco */
}
.filtros input:focus,
.filtros select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filtros .actions {
  grid-column: 1 / -1;
  display: flex;
  gap: .5rem;
}
.filtros .status-field {
  grid-column: 1 / -1;
  border: 1px dashed var(--border);
  padding: .5rem .75rem;
  border-radius: 8px;
  margin: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: .5rem .75rem;
  align-items: center;
}
.filtros .check {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  cursor: pointer;
  user-select: none;
}
.filtros .check input { margin: 0; }

/* Badge */
.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: var(--badge-gray);
  color: #fff;
  white-space: nowrap;
}
.badge-gray   { background: var(--badge-gray); }
.badge-blue   { background: var(--badge-blue); }
.badge-purple { background: var(--badge-purple); }
.badge-amber  { background: var(--badge-amber); }
.badge-green  { background: var(--badge-green); }
.badge-red    { background: var(--badge-red); }
.badge-teal   { background: var(--badge-teal); }

/* Erros / contagem */
.errors {
  list-style: none;
  padding: .75rem 1rem;
  border: 1px solid var(--badge-red);
  background: #fdecec;
  color: var(--badge-red);
  border-radius: 8px;
  margin: 0 0 1rem;
}
.errors li { margin: 0; }
.result-count { color: var(--muted); margin: 0 0 .75rem; font-size: .9rem; }
.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Cards */
.cards {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.card-photo {
  aspect-ratio: 16 / 10;
  background: #eee;
  overflow: hidden;
  position: relative;
}
.card-photo img,
.card-photo video,
.card-photo .slide {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.card-photo .slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
}
.card-photo .slide.active { opacity: 1; z-index: 1; }

.card-video-badge {
  position: absolute;
  bottom: .5rem;
  right: .5rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: .85rem;
  padding-left: 2px;
  pointer-events: none;
  z-index: 4;
}

/* Link clicável sobre as mídias (decorativo, navegação no body) */
.card-photo-link {
  display: block;
  position: absolute;
  inset: 0;
  text-decoration: none;
  color: inherit;
}
.card-body-link { display: block; color: inherit; text-decoration: none; }

/* Carrossel — setas e contador sobrepostos ao card-photo */
.card-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background .15s, transform .15s;
  user-select: none;
}
.card-nav:hover { background: rgba(0, 0, 0, .85); }
.card-nav:active { transform: translateY(-50%) scale(.92); }
.card-nav-prev { left: .5rem; }
.card-nav-next { right: .5rem; }
.card-counter {
  position: absolute;
  top: .5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: .75rem;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-weight: 500;
  pointer-events: none;
}
.card-photo-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  color: #bbb;
  background: linear-gradient(135deg, #f3f3f3, #e5e5e5);
}
.card-body { padding: .85rem 1rem 1rem; }
.card-header {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  justify-content: space-between;
  margin: 0 0 .35rem;
}
.card-title { font-size: 1.05rem; margin: 0; line-height: 1.25; }
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  margin: 0 0 .65rem;
  font-size: .9rem;
}
.card-meta .avaliacao { color: var(--badge-amber); letter-spacing: 1px; }
.card-meta .avaliacao .muted { color: #ddd; }
.card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin: 0;
}
.card-stats > div { display: flex; flex-direction: column; }
.card-stats dt { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.card-stats dd { margin: 0; font-size: .95rem; }
.card-stats dd.strong { font-weight: 700; color: var(--accent-dark); }

/* Detalhe */
.detalhe { display: flex; flex-direction: column; gap: 1.25rem; }
.detalhe-topo { display: flex; align-items: flex-start; gap: .75rem; justify-content: space-between; flex-wrap: wrap; }
.detalhe-titulo { margin: 0; font-size: 1.65rem; color: var(--accent); }
.detalhe-localizacao { margin: 0; font-size: 1.05rem; }
.detalhe-localizacao .muted { color: var(--muted); font-size: .9rem; }
.badge-lg { font-size: .85rem; padding: .3rem .75rem; }

.galeria {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .5rem;
}
.galeria li { position: relative; }
.galeria-link {
  display: block;
  position: relative;
}
.galeria img,
.galeria video {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  display: block;
  pointer-events: none; /* clique sempre vai pro <a> pai → abre em nova aba */
}
.galeria-video-badge {
  position: absolute;
  bottom: .5rem;
  right: .5rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .7);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: .95rem;
  padding-left: 3px;
  pointer-events: none;
}
.galeria figcaption {
  font-size: .8rem;
  color: var(--muted);
  margin-top: .25rem;
  text-align: center;
}
.galeria-vazia {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.dados-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}
.dados-bloco {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 1.15rem;
}
.dados-bloco h3 { margin: 0 0 .65rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.dados-bloco dl { margin: 0; }
.dados-bloco dl > div { display: flex; justify-content: space-between; padding: .25rem 0; border-top: 1px solid var(--border); }
.dados-bloco dl > div:first-child { border-top: 0; }
.dados-bloco dt { color: var(--muted); }
.dados-bloco dd { margin: 0; text-align: right; }
.dados-bloco dd.strong { font-weight: 700; color: var(--accent-dark); }

.descricao { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; }
.descricao h3 { margin: 0 0 .5rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.descricao p { margin: 0; white-space: pre-wrap; }

.avaliacao-grande { margin: 0; }
.estrelas-grande { color: var(--badge-amber); font-size: 1.25rem; letter-spacing: 2px; }
.estrelas-grande .muted { color: #ddd; }

.acoes { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; }
.acoes h3 { margin: 0 0 .5rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; width: 100%; }
.acao-status { display: flex; align-items: end; gap: .5rem; flex-wrap: wrap; }
.acao-status label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.acao-status select { padding: .55rem .65rem; min-height: 40px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font: inherit; }
.acao-excluir { margin-left: auto; }

.btn-danger { background: var(--badge-red); border-color: var(--badge-red); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-link { background: none; border: 0; color: var(--badge-red); cursor: pointer; padding: 0; font: inherit; font-size: .85rem; text-decoration: underline; }

.comentarios { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; }
.comentarios h3 { margin: 0 0 .75rem; }
.comentarios-lista { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: .75rem; }
.comentarios-lista li { border-left: 3px solid var(--border); padding: .35rem .75rem; position: relative; }
.comentario-meta { color: var(--muted); font-size: .75rem; }
.comentario-texto { margin: .15rem 0; white-space: pre-wrap; }
.comentario-remover { display: inline; }
.comentario-form { display: flex; flex-direction: column; gap: .5rem; }
.comentario-form label { display: flex; flex-direction: column; gap: .25rem; }
.comentario-form textarea { padding: .6rem; min-height: 88px; border: 1px solid var(--border); border-radius: 6px; font: inherit; resize: vertical; }
.comentario-form button { align-self: flex-start; }

/* Flash */
.flash { padding: .65rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.flash-ok { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Page header actions */
.page-header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Importar de texto */
.importar-form { display: flex; flex-direction: column; gap: 1rem; max-width: 720px; }
.importar-form textarea {
  width: 100%;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}
.importar-form .field-full { display: flex; flex-direction: column; gap: .35rem; }
.importar-form .field-full > span { font-size: .85rem; color: var(--muted); font-weight: 500; }
.importar-form .hint { color: var(--muted); margin: 0; }

/* Form imóvel */
.imovel-form { display: flex; flex-direction: column; gap: 1rem; }
.imovel-form fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 1.15rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem 1rem;
}
.imovel-form legend {
  padding: 0 .35rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  font-size: .85rem;
}
.imovel-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.imovel-form label > span { font-size: .8rem; color: var(--muted); font-weight: 500; }
.imovel-form .field-full { grid-column: 1 / -1; }
.imovel-form input,
.imovel-form select,
.imovel-form textarea {
  padding: .6rem .7rem;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font: inherit; /* 16px — sem iOS zoom */
}
.imovel-form input:focus,
.imovel-form select:focus,
.imovel-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.imovel-form textarea { resize: vertical; }
.imovel-form .hint { color: var(--muted); font-size: .75rem; margin-top: .1rem; }
.fotos-existentes { grid-column: 1 / -1; }
.fotos-existentes-section {
  margin-top: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.fotos-existentes-section h3 {
  margin: 0 0 .75rem;
  font-size: .9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 600;
}
.fotos-grade {
  list-style: none;
  padding: 0;
  margin: .35rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .5rem;
}
.fotos-grade li { display: flex; flex-direction: column; align-items: center; gap: .25rem; }
.fotos-grade img,
.fotos-grade video {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}
.form-actions { display: flex; gap: .5rem; }

.muted { color: var(--muted); }

/* Comparar */
.card { position: relative; }
.card-check {
  position: absolute;
  top: .55rem;
  right: .55rem;
  z-index: 2;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .3rem .65rem .3rem .45rem;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.card-check input { margin: 0; cursor: pointer; }
.card-check input:checked + .card-check-label { color: var(--accent-dark); font-weight: 600; }

.comparar-form { display: flex; flex-direction: column; gap: 1rem; }
.comparar-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: sticky;
  bottom: .75rem;
  z-index: 5;
  flex-wrap: wrap;
}
.comparar-bar .hint { color: var(--muted); font-size: .85rem; }

.comparar-wrap { overflow-x: auto; }
.comparar {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.comparar thead th {
  vertical-align: top;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: #f5f5f5;
  text-align: center;
  font-weight: 500;
}
.comparar thead th:first-child { background: var(--surface); }
.comparar-coluna { min-width: 200px; }
.comparar-coluna img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: .5rem;
}
.comparar-foto-vazia {
  aspect-ratio: 16 / 10;
  background: #eee;
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: #bbb;
  border-radius: 6px;
  margin-bottom: .5rem;
}
.comparar-titulo {
  display: block;
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
  margin-bottom: .35rem;
}
.comparar-titulo:hover { text-decoration: underline; }
.comparar-meta { display: flex; align-items: center; justify-content: center; gap: .5rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }

.comparar tbody th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: .65rem 1rem;
  border-top: 1px solid var(--border);
  background: #fafafa;
}
.comparar tbody td {
  padding: .65rem 1rem;
  text-align: right;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.comparar tbody td.best {
  background: #d1fae5;
  font-weight: 700;
  color: #065f46;
}

/* Mobile (≤ 480px) */
@media (max-width: 480px) {
  .container { margin: .75rem auto; padding: 0 .75rem; }
  .page-header h1 { font-size: 1.4rem; }
  .card-stats { grid-template-columns: repeat(3, auto); }
  .detalhe-titulo { font-size: 1.35rem; }
  .acoes { flex-direction: column; align-items: stretch; }
  .acao-excluir { margin-left: 0; }
  .acao-status { flex-direction: column; align-items: stretch; }
  .acao-status .btn-primary { width: 100%; }
  /* Form: cada fieldset vira coluna única no celular */
  .imovel-form fieldset { grid-template-columns: 1fr; }
  /* Filtros: stack mais compacto */
  .filtros { grid-template-columns: 1fr 1fr; }
  .filtros .actions { flex-direction: column; }
  .filtros .actions .btn-primary,
  .filtros .actions .btn-ghost { width: 100%; }
  /* Botões na ação de detalhe e form ocupam linha inteira */
  .form-actions { flex-direction: column; }
  .form-actions .btn-primary,
  .form-actions .btn-ghost { width: 100%; }
}

/* Mobile estreito (≤ 380px) — iPhone SE etc */
@media (max-width: 380px) {
  .container { padding: 0 .6rem; }
  .page-header h1 { font-size: 1.25rem; }
  .filtros { grid-template-columns: 1fr; }
  .dados-bloco { padding: .85rem 1rem; }
  .card-stats dd { font-size: .85rem; }
  .badge-lg { font-size: .8rem; padding: .25rem .6rem; }
  .galeria { grid-template-columns: 1fr 1fr; }
}
