:root {
  --fundo: #F4EFE6; --papel: #FBF8F2; --tinta: #1E2A38; --suave: #6E6A60;
  --linha: #E1D8C8; --oliva: #4E5D36; --navy: #24364E; --areia: #C9B48F;
  --areia-clara: #EDE4D3; --perigo: #8A3B2E;
  --sombra: 0 1px 2px rgba(30,42,56,.06), 0 10px 28px -18px rgba(30,42,56,.35);
  --serif: "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #141A22; --papel: #1B232E; --tinta: #ECE6DA; --suave: #9C978C;
    --linha: #2B3542; --oliva: #9DB07A; --navy: #C9D5E6; --areia: #B9A27A;
    --areia-clara: #26303C; --perigo: #D98A78;
    --sombra: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -18px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo); color: var(--tinta); font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- topo ---------- */
.topo {
  padding: calc(18px + env(safe-area-inset-top)) 18px 10px;
  display: flex; align-items: baseline; gap: 12px; max-width: 960px; margin: 0 auto;
}
.topo h1 { font-family: var(--serif); font-weight: 400; font-size: 28px; margin: 0; letter-spacing: -.01em; }
.subtitulo { color: var(--suave); font-size: 14px; font-variant-numeric: tabular-nums; }
.vista { max-width: 960px; margin: 0 auto; padding: 0 16px 24px; }

/* ---------- pesquisa e filtros ---------- */
.barra { position: sticky; top: 0; z-index: 4; background: var(--fundo); padding: 8px 0 10px; }
.pesquisa {
  width: 100%; border: 1px solid var(--linha); background: var(--papel); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; outline: none;
}
.pesquisa:focus { border-color: var(--areia); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--linha); background: var(--papel); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; white-space: nowrap;
}
.chip .n { color: var(--suave); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: var(--fundo); }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }

.procura { display: flex; gap: 8px; }
.alternar {
  flex: none; width: 44px; border: 1px solid var(--linha); background: var(--papel); border-radius: 10px;
  display: grid; place-items: center; color: var(--suave);
}
.alternar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }

/* ---------- lista compacta de peças ---------- */
.linhas { display: flex; flex-direction: column; border: 1px solid var(--linha); border-radius: 12px; background: var(--papel); overflow: hidden; margin-top: 6px; }
.peca-linha {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  border: 0; border-top: 1px solid var(--linha); background: none; padding: 9px 12px;
}
.peca-linha:first-child { border-top: 0; }
.miniatura { flex: none; width: 44px; height: 55px; border-radius: 7px; overflow: hidden; background: var(--areia-clara); display: block; }
.miniatura img, .miniatura .amostra { width: 100%; height: 100%; object-fit: cover; display: block; }
.amostra { border: 1px solid rgba(0,0,0,.08); border-radius: 7px; }
.peca-linha .texto { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.peca-linha .nome { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peca-linha .detalhe { font-size: 13px; color: var(--suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- grelha de peças ---------- */
.grelha { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 6px; }
@media (min-width: 640px) { .grelha { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grelha { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.cartao {
  text-align: left; border: 1px solid var(--linha); background: var(--papel); border-radius: 12px;
  padding: 0; overflow: hidden; box-shadow: var(--sombra); display: flex; flex-direction: column;
}
.cartao:active { transform: scale(.985); }
.imagem {
  aspect-ratio: 4 / 5; width: 100%; background: var(--areia-clara); display: grid; place-items: center;
  position: relative; overflow: hidden;
}
.imagem img { width: 100%; height: 100%; object-fit: cover; display: block; }
.inicial { font-family: var(--serif); font-size: 34px; color: var(--areia); }
.cartao .texto { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cartao .nome { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cartao .detalhe { font-size: 13px; color: var(--suave); display: flex; align-items: center; gap: 6px; min-width: 0; }
.cartao .detalhe span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ponto { width: 10px; height: 10px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.15); }
.vazio { color: var(--suave); text-align: center; padding: 40px 10px; }

/* ---------- wishlist ---------- */
.secao { margin: 18px 0 6px; font-family: var(--serif); font-size: 19px; font-weight: 400; display: flex; gap: 8px; align-items: baseline; }
.secao .n { font-family: var(--sans); font-size: 13px; color: var(--suave); }
.lista { display: flex; flex-direction: column; border: 1px solid var(--linha); border-radius: 12px; background: var(--papel); overflow: hidden; }
.linha {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline; text-align: left;
  border: 0; border-top: 1px solid var(--linha); background: none; padding: 12px 14px; width: 100%;
}
.linha:first-child { border-top: 0; }
.linha .nome { font-size: 15px; }
.linha .valor { font-size: 13.5px; color: var(--suave); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- números ---------- */
.total { font-family: var(--serif); font-size: 48px; line-height: 1; margin: 12px 0 2px; }
.total-legenda { color: var(--suave); margin: 0 0 8px; }
.barras { display: flex; flex-direction: column; gap: 8px; background: var(--papel); border: 1px solid var(--linha); border-radius: 12px; padding: 14px; }
.barra-linha { display: grid; grid-template-columns: 9.5em 1fr 2.2em; gap: 10px; align-items: center; font-size: 14px; }
.barra-linha .rotulo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-linha .faixa { height: 8px; background: var(--areia-clara); border-radius: 4px; overflow: hidden; }
.barra-linha .faixa i { display: block; height: 100%; background: var(--oliva); border-radius: 4px; }
.barra-linha .conta { text-align: right; font-variant-numeric: tabular-nums; color: var(--suave); }
.discreto {
  margin: 28px auto 0; display: block; border: 1px solid var(--linha); background: none; border-radius: 999px;
  padding: 8px 18px; color: var(--suave); font-size: 14px;
}

/* ---------- abas e botão + ---------- */
.abas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--papel) 92%, transparent); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--linha);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.abas button {
  flex: 1; max-width: 160px; border: 0; background: none; display: flex; flex-direction: column;
  align-items: center; gap: 2px; padding: 6px 0; color: var(--suave); font-size: 12px;
}
.abas svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.abas button[aria-current="page"] { color: var(--navy); font-weight: 600; }
.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 5;
  width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--navy); color: var(--fundo);
  box-shadow: 0 8px 22px -8px rgba(30,42,56,.6); display: grid; place-items: center;
}
.fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---------- folha (diálogo) ---------- */
.folha {
  border: 0; padding: 0; width: 100%; max-width: 620px; max-height: 92dvh; margin: auto auto 0;
  border-radius: 18px 18px 0 0; background: var(--papel); color: var(--tinta);
}
@media (min-width: 680px) { .folha { margin: auto; border-radius: 18px; } }
.folha::backdrop { background: rgba(20,26,34,.45); }
.folha-cab {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 12px 14px; background: var(--papel); border-bottom: 1px solid var(--linha);
}
.folha-cab h2 { font-family: var(--serif); font-weight: 400; font-size: 20px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folha-corpo { padding: 14px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.botao {
  border: 1px solid var(--linha); background: var(--papel); border-radius: 10px; padding: 9px 14px; font-size: 15px;
}
.botao.principal { background: var(--navy); border-color: var(--navy); color: var(--fundo); font-weight: 600; }
.botao.perigo { color: var(--perigo); border-color: color-mix(in srgb, var(--perigo) 40%, var(--linha)); }
.botao:disabled { opacity: .5; }
.acoes { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.acoes .botao { flex: 1; }

.campo { display: flex; flex-direction: column; gap: 4px; }
.campo > span { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--suave); }
.campo input, .campo select, .campo textarea {
  border: 1px solid var(--linha); background: var(--fundo); border-radius: 9px; padding: 10px 11px;
  font-size: 16px; width: 100%; outline: none;
}
.campo textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.campo input:focus, .campo select:focus, .campo textarea:focus { border-color: var(--areia); }
.duas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.fotos { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 2px; }
.foto { position: relative; flex: none; width: 120px; aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; background: var(--areia-clara); }
.foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto .tirar {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: rgba(20,26,34,.65); color: #fff; font-size: 16px; line-height: 28px; padding: 0;
}
.foto.nova {
  display: grid; place-items: center; border: 1.5px dashed var(--areia); background: none; color: var(--suave);
  font-size: 13px; text-align: center; padding: 8px; cursor: pointer;
}
.foto.nova input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.foto.carregar::after {
  content: ""; position: absolute; inset: 0; background: rgba(251,248,242,.6);
}
.ampliada { width: 100%; border-radius: 12px; display: block; }

/* ---------- entrada ---------- */
.entrada { max-width: 380px; margin: 8vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.entrada p { color: var(--suave); margin: 0; }
.erro { color: var(--perigo); font-size: 14px; min-height: 1.2em; }

/* ---------- aviso ---------- */
.aviso {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom));
  z-index: 20; background: var(--tinta); color: var(--fundo); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--sombra); max-width: calc(100vw - 32px);
}
@media (prefers-reduced-motion: no-preference) { .cartao { transition: transform .12s ease; } }
