:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #121826;
  --muted: #5b6474;
  --border: #e3e6eb;
  --brand: #13294b;
  --brand-contrast: #ffffff;
  --accent: #c8752e;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --warn: #9a5a00;
  --warn-bg: #fdf1dc;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c222b;
    --text: #e8ebf0;
    --muted: #9aa4b2;
    --border: #2a313c;
    --brand: #8fb3e8;
    --brand-contrast: #0d1117;
    --accent: #e3995a;
    --ok: #5bc48f;
    --ok-bg: #12291e;
    --warn: #f0b45c;
    --warn-bg: #2e2312;
    --danger: #ff7b72;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

.topo {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.topo h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topo .lado { width: 72px; display: flex; }
.topo .lado.dir { justify-content: flex-end; }

.btn-texto {
  background: none;
  border: 0;
  padding: 8px 4px;
  color: var(--brand);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 110px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 14px; }

.imovel-item {
  display: flex;
  gap: 12px;
  padding: 10px;
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.imovel-item img, .thumb-vazia {
  width: 92px;
  height: 92px;
  flex: none;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
}
.imovel-item .info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.imovel-item .titulo { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.muted { color: var(--muted); font-size: 14px; }
.preco { font-weight: 700; }

.etiqueta {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.etiqueta.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.etiqueta.alerta { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

.vazio { text-align: center; padding: 48px 16px; color: var(--muted); }
.vazio p { margin: 8px 0 20px; }

label { display: block; font-size: 14px; font-weight: 500; color: var(--muted); margin: 12px 0 6px; }
label:first-child { margin-top: 0; }

input[type='text'], input[type='tel'], input[type='url'], input[type='month'], input[type='password'],
input[inputmode], select, textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* evita zoom no iPhone */
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
textarea { min-height: 96px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: var(--brand-contrast);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: 0.55; }
.btn.secundario { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.perigo { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn.pequeno { width: auto; padding: 8px 12px; font-size: 14px; }

.barra-acao {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.barra-acao > div { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }

.segmentado {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.segmentado button {
  padding: 9px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 500;
  cursor: pointer;
}
.segmentado button.ativo { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; color: var(--brand); }
@media (prefers-color-scheme: dark) {
  .segmentado button.ativo { background: #2a3340; }
}

.contador { display: flex; align-items: center; gap: 12px; }
.contador button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.contador output { min-width: 40px; text-align: center; font-size: 22px; font-weight: 700; }

.proposta {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 12px;
  background: var(--surface-2);
}
.proposta .cab { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grade-2 label { margin-top: 12px; }

.dados-imovel { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.dado { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.dado span { display: block; font-size: 12px; color: var(--muted); }
.dado strong { font-size: 15px; }

.foto-capa { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); display: block; }

.mercado-resumo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.similar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.similar input { width: 20px; height: 20px; flex: none; accent-color: var(--brand); }
.similar .s-info { flex: 1; min-width: 0; }
.similar .s-m2 { text-align: right; font-weight: 600; white-space: nowrap; }
.similar.excluido { opacity: 0.45; }

.lista-relatorios a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}
.lista-relatorios a:first-child { border-top: 0; }
.seta { color: var(--muted); }

.aviso { padding: 10px 12px; border-radius: 10px; font-size: 14px; background: var(--warn-bg); color: var(--warn); margin-bottom: 12px; }
.erro-msg { color: var(--danger); font-size: 14px; margin-top: 8px; }
.salvo { font-size: 13px; color: var(--muted); text-align: center; margin: 4px 0 0; min-height: 18px; }

.folha-fundo {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.folha {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.folha h3 { margin: 0 0 4px; text-align: center; }
.folha p { margin: 0 0 6px; text-align: center; color: var(--muted); font-size: 14px; }

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

/* Login */
.login-pagina { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-caixa { width: 100%; max-width: 360px; }
.login-caixa h1 { font-size: 24px; margin: 0 0 4px; }
.login-caixa p { color: var(--muted); margin: 0 0 24px; }
.login-caixa .btn { margin-top: 16px; }
