:root {
  --brand: #0b4f6c;
  --brand-dark: #073246;
  --brand-soft: #e1f1f6;
  --teal: #13a39b;
  --orange: #f28000;
  --orange-soft: #fff1e0;
  --green: #00a85a;
  --green-soft: #e3f6ec;
  --red: #e2264d;
  --red-soft: #fde8ec;
  --yellow: #a36100;
  --yellow-soft: #fff6de;
  --olx: #6e0ad6;
  --wm: #d6173c;
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b76;
  --line: #e4e7ec;
  --shadow: 0 1px 3px rgba(0, 30, 50, .08), 0 1px 2px rgba(0, 30, 50, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: #12303d;
    --orange-soft: #3a2510;
    --green-soft: #133024;
    --red-soft: #3a1a1f;
    --yellow: #f2c14e;
    --yellow-soft: #342a12;
    --olx: #b98cff;
    --wm: #ff6b85;
    --bg: #101315;
    --card: #1b1f22;
    --text: #f1f1f4;
    --muted: #a0a6ad;
    --line: #2b3136;
    --shadow: none;
    color-scheme: dark;
  }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
/* O documento nunca rola: cabeçalho, conteúdo (#view, que rola por dentro) e
   menu inferior são uma coluna do tamanho da tela. Com a página inteira rolando,
   o iPhone deslocava a área visível e o menu e a barra "Abrir na OLX" saíam do
   lugar e andavam junto com a rolagem. Mesmo esquema do app "OLX no celular". */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
/* No app instalado do iPhone, height: 100% fica ~55pt menor que a tela e sobrava
   uma faixa vazia embaixo do menu. Preso nas quatro bordas, o body ocupa a tela toda. */
body { position: fixed; inset: 0; }
/* A faixa embaixo do menu (app instalado no iPhone) fica fora da área da página:
   não dá pra pôr nada nela, mas com a cor do menu ela parece parte dele. */
html { background: var(--card); }
/* Sem zoom na página (pinça nem dois toques) — só as fotos em tela cheia ampliam,
   pelo próprio app (ver pincaNaFoto no app.js). O iPhone ignora o user-scalable=no
   do viewport; isto e o bloqueio dos eventos "gesture*" no app.js cobrem ele. */
html, body { touch-action: pan-x pan-y; }
body {
  font-family: "Nunito Sans", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  display: flex; flex-direction: column;
}
#view {
  flex: 1; min-height: 0; width: 100%;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
a { color: inherit; text-decoration: none; }
button, select { font: inherit; cursor: pointer; }

/* Topbar */
.topbar {
  flex: none; position: relative; z-index: 20;
  background: var(--brand);
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  color: #fff;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.logo { font-weight: 900; font-size: 23px; letter-spacing: -.5px; }
.logo-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); margin-left: 2px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 99px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #ccc; }
.live.on i { background: #3ef08e; animation: pulse 1.6s infinite; }
.live.off i { background: #ff6b81; }
.live.meio i { background: #ffd23f; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(62,240,142,.7); } 70% { box-shadow: 0 0 0 8px rgba(62,240,142,0); } 100% { box-shadow: 0 0 0 0 rgba(62,240,142,0); } }
.search { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 8px; padding: 0 12px; height: 42px; }
.search svg { width: 20px; height: 20px; fill: #8a8a95; flex: none; }
.search input { border: 0; outline: 0; flex: 1; font: inherit; background: transparent; color: #1a1a1a; min-width: 0; }

/* Chips de lista/filtro */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 14px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .n { opacity: .7; font-weight: 600; margin-left: 4px; }
.barra-ordem { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 16px 2px; font-size: 13px; color: var(--muted); }
.barra-ordem select { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.filtro-ativo { color: var(--brand); font-weight: 800; }
@media (prefers-color-scheme: dark) { .filtro-ativo { color: #5fd0e8; } }

/* Lista de anúncios */
.list { display: flex; flex-direction: column; gap: 10px; padding: 8px 12px 16px; }
.card {
  display: flex; gap: 12px; background: var(--card); border-radius: 10px; padding: 10px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.card.nv-oportunidade { outline: 2px solid var(--orange); }
.card-new { animation: slidein .35s ease; }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.thumb { flex: none; width: 128px; height: 96px; border-radius: 8px; background: var(--brand-soft); position: relative; overflow: hidden; display: grid; place-items: center; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 40px; height: 40px; fill: var(--brand); opacity: .4; }
.selo { position: absolute; left: 5px; top: 5px; font-size: 11px; font-weight: 900; padding: 2px 6px; border-radius: 5px; background: rgba(0,0,0,.65); color: #fff; }
.nv-oportunidade .selo { background: var(--orange); }
.nv-bom .selo { background: var(--green); }
.nv-suspeito .selo { background: #ffd23f; color: #1a1a1a; }
.nv-acima .selo { background: rgba(0,0,0,.65); color: #ff9aa9; }
.badge-new { position: absolute; bottom: 5px; left: 5px; background: var(--teal); color: #fff; font-size: 10px; font-weight: 900; padding: 2px 6px; border-radius: 4px; letter-spacing: .3px; }
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-right: 22px; }
.title { font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 0; font-weight: 700; }
.price-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.price { font-size: 19px; font-weight: 900; }
.old { font-size: 12px; color: var(--muted); text-decoration: line-through; }
.ref { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ref b { font-weight: 800; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.specs { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.anunciado { font-size: 12px; color: var(--muted); margin-top: 2px; }
.meta { margin-top: auto; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; align-items: center; }
.meta .local { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fonte { flex: none; font-size: 10px; font-weight: 900; padding: 1px 6px; border-radius: 4px; color: #fff; letter-spacing: .3px; }
.fonte.olx { background: var(--olx); }
.fonte.webmotors { background: var(--wm); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; max-height: 40px; overflow: hidden; }
.tag { font-size: 10.5px; font-weight: 800; padding: 1px 6px; border-radius: 4px; background: var(--line); color: var(--text); white-space: nowrap; }
.tag.ruim { background: var(--red-soft); color: var(--red); }
.tag.aviso { background: var(--yellow-soft); color: var(--yellow); }
.tag.bom { background: var(--green-soft); color: var(--green); }
.fav-btn { position: absolute; top: 6px; right: 6px; background: transparent; border: 0; padding: 6px; }
.fav-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; }
.fav-btn.on svg { fill: var(--red); stroke: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.more { display: block; margin: 0 auto 16px; background: transparent; border: 1px solid var(--brand); color: var(--brand); padding: 10px 20px; border-radius: 99px; font-weight: 800; }

/* Detalhe */
.detail { background: var(--card); padding-bottom: 16px; flex: 1 0 auto; }
/* anúncio curto: o detalhe estica e a barra de botões fica sempre embaixo */
#view.tela-anuncio { display: flex; flex-direction: column; }
/* Carrossel de fotos do anúncio (desliza pro lado; tocar abre em tela cheia) */
.fotos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 12px 12px 0; scrollbar-width: none; }
.fotos::-webkit-scrollbar { display: none; }
.fotos img, .fotos .sem-foto {
  flex: none; width: 86%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; scroll-snap-align: center;
  background: var(--brand-soft); display: flex; align-items: center; justify-content: center;
}
.fotos .sem-foto { width: 100%; }
.fotos .sem-foto svg { width: 72px; height: 72px; fill: var(--brand); opacity: .4; }
.fotos img { cursor: zoom-in; }
.fotos-dica { margin: 6px 16px 0; font-size: 12px; color: var(--muted); }
/* Dentro do anúncio o deslize horizontal é do app (voltar); o carrossel de
   fotos continua deslizando pro lado */
#view.tela-anuncio { touch-action: pan-y; }
#view.tela-anuncio .fotos { touch-action: pan-x pan-y; }

/* Fotos em tela cheia */
#galeria { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.gal-topo {
  display: flex; align-items: center; justify-content: space-between; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  color: #fff; font-weight: 700; font-size: 15px;
}
.gal-x { background: rgba(255, 255, 255, .14); border: 0; color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 18px; }
.gal-trilho { flex: 1; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; padding-bottom: env(safe-area-inset-bottom); }
/* O arrasto vertical é do app (fecha a foto): sem isso o iPhone assume o gesto
   como rolagem e cancela os eventos de toque — a foto não acompanharia o dedo. */
#galeria { touch-action: none; }
/* cada foto (.gal-slide tem overflow) conta como área de rolagem própria — a
   regra precisa estar nela e na imagem, não só no trilho */
.gal-trilho, .gal-slide, .gal-slide img { touch-action: pan-x; }
.gal-slide.zoom, .gal-slide.zoom img { touch-action: pan-x pan-y; }
.gal-trilho::-webkit-scrollbar { display: none; }
.gal-slide { flex: none; width: 100%; height: 100%; scroll-snap-align: center; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.gal-slide img { max-width: 100%; max-height: 100%; object-fit: contain; }
.gal-slide.zoom { overflow: auto; display: block; }
.gal-slide.zoom img { max-width: none; max-height: none; width: 250%; }
.detail .body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.detail h1 { font-size: 20px; line-height: 1.3; margin: 0; }
.detail .price { font-size: 28px; }
.nivel-box { border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.nivel-box.nv-oportunidade { background: var(--orange-soft); border: 1.5px solid var(--orange); }
.nivel-box.nv-bom { background: var(--green-soft); }
.nivel-box.nv-suspeito { background: var(--yellow-soft); }
.nivel-box strong { font-size: 16px; }
.refs-tab { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 12px; font-size: 14px; align-items: baseline; }
.refs-tab span:first-child { color: var(--muted); }
.refs-tab small { color: var(--muted); font-size: 11.5px; grid-column: 1 / -1; margin-top: -4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; color: var(--muted); }
.kv b { color: var(--text); font-weight: 700; }
.msg { white-space: pre-wrap; word-break: break-word; background: var(--bg); border-radius: 8px; padding: 12px; font-size: 14px; line-height: 1.45; }
.detail .tags { max-height: none; }
.detail .tag { font-size: 12px; padding: 3px 8px; }
.btn { border: 0; border-radius: 8px; padding: 12px 16px; font-weight: 800; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
@media (prefers-color-scheme: dark) { .btn-ghost { color: #5fd0e8; border-color: #5fd0e8; } }
.btn-olx { background: var(--olx); color: #fff; }
.btn-webmotors { background: var(--wm); color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
/* Gruda no rodapé da área que rola (#view), logo acima do menu — sem "fixed",
   que no iPhone descolava junto com a rolagem */
.cta-bar {
  position: sticky; bottom: 0; z-index: 15;
  background: var(--card); border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px;
}
.cta-bar .btn { flex: 1; }
.cta-bar .btn.quadrado { flex: 0 0 48px; padding: 12px 0; }

/* Painéis (filtros / ajustes) */
.panel { background: var(--card); margin: 12px; border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel p { margin: 4px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; font-weight: 800; color: var(--muted); }
.field input, .field select { width: 100%; min-width: 0; height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; font: inherit; background: var(--bg); color: var(--text); outline: none; }
.field input:focus { border-color: var(--brand); }
.grade2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grade2 > * { min-width: 0; }   /* sem isso o campo não encolhe e passa da borda */
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.toggle-row:first-of-type { border-top: 0; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #c8c8d0; border-radius: 99px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }
.opcoes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.opcoes .chip { padding: 8px 14px; }
.code { font-family: ui-monospace, Consolas, monospace; background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 13px; word-break: break-all; }
.fonte-status { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.fonte-status:first-of-type { border-top: 0; }
.fonte-status b { color: var(--text); }

/* Bottom nav */
.bottomnav {
  flex: none; position: relative; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex;
  /* a barrinha do iPhone (home indicator) fica bem embaixo: não precisa de toda a área segura */
  padding-bottom: max(8px, calc(env(safe-area-inset-bottom) / 2 - 10px));
}
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; font-weight: 700; color: var(--muted); }
.bottomnav svg { width: 24px; height: 24px; fill: currentColor; }
.bottomnav a.active { color: var(--brand); }
@media (prefers-color-scheme: dark) { .bottomnav a.active { color: #5fd0e8; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 50;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 700;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.new-banner {
  position: sticky; top: 8px; z-index: 10; margin: 8px auto 0; display: block;
  background: var(--orange); color: #fff; border: 0; border-radius: 99px; padding: 8px 18px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(242,128,0,.4);
}
.aviso { margin: 10px 12px 0; padding: 10px 12px; border-radius: 8px; background: var(--orange-soft); color: var(--text); font-size: 13px; line-height: 1.4; border: 1px solid var(--orange); }
.versao { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 20px; }
.qr { display: grid; place-items: center; margin-top: 14px; padding: 12px; background: #fff; border-radius: 10px; }
.leitor { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.leitor video { width: 100%; border-radius: 10px; background: #000; }

@media (min-width: 760px) {
  main { max-width: 760px; margin: 0 auto; }
  .list { display: grid; grid-template-columns: 1fr 1fr; }
  .cta-bar { max-width: 760px; margin: 0 auto; }
}
