:root {
  --linho: #ECEFEA; --folha: #FBFCFA; --tinta: #18221F; --suave: #56635D; --risca: #D3D9D3;
  --pano: #1E4B43; --pano-2: #153630;
  --cinza: #8A958F; --azul: #3E6FA3; --mostarda: #C9A227; --verde: #2E7D5B; --vinho: #A23B4A;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--linho); color: var(--tinta); font: 16px/1.45 var(--sans);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--azul); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); opacity: 0; }
.fino { font-size: .82rem; color: var(--suave); }
h2 { font: 600 1.15rem var(--serif); margin: 26px 0 10px; }

/* topo */
.topo {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 18px 10px; background: var(--pano); color: var(--linho);
}
.topo h1 { margin: 0; font: 600 1.4rem var(--serif); letter-spacing: .01em; }
.resumo { font-size: .85rem; opacity: .85; }
main { max-width: 640px; margin: 0 auto; padding: 16px; }

/* ações da aba Escanear */
.acao {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 76px; margin-bottom: 12px;
  padding: 16px 18px; text-align: left; border-radius: 14px; border: 2px solid var(--pano);
  background: var(--folha); color: var(--pano-2);
}
.acao.principal { min-height: 108px; background: var(--pano); color: var(--linho); }
.acao:focus-within { outline: 3px solid var(--azul); outline-offset: 2px; }
.acao svg { flex: none; width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.acao strong { display: block; font: 600 1.25rem var(--serif); }
.acao small { display: block; margin-top: 2px; font-size: .85rem; opacity: .85; }
.acao:disabled { opacity: .6; cursor: not-allowed; }
.linha-isbn { display: flex; gap: 8px; }
.linha-isbn input { flex: 1; min-width: 0; }

/* campos e botões */
input:not([type=file]), select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; background: #fff;
  border: 1px solid #B9C1BB; border-radius: 8px;
}
textarea { min-height: 84px; resize: vertical; }
.primario, .secundario, .perigo { min-height: 50px; padding: 0 18px; border-radius: 10px; font-weight: 600; }
.primario { width: 100%; background: var(--pano); color: #fff; border: 0; }
.secundario { background: var(--folha); color: var(--pano-2); border: 2px solid var(--pano); }
.perigo { background: none; border: 0; color: var(--vinho); }
.campo { display: grid; gap: 4px; margin-bottom: 12px; }
.campo > span { font-size: .85rem; color: var(--suave); }
.duas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ajuda { color: var(--suave); margin: -4px 0 14px; max-width: 60ch; }

/* lista: a cor da lombada indica a situação do livro */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.livro {
  --st: var(--cinza); position: relative; display: grid; grid-template-columns: 48px 1fr auto; gap: 12px;
  align-items: center; width: 100%; min-height: 76px; padding: 10px 12px 10px 24px; text-align: left;
  background: var(--folha); border: 1px solid var(--risca); border-radius: 6px 12px 12px 6px;
}
.livro::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; border-radius: 6px 0 0 6px;
  background:
    linear-gradient(rgba(255,255,255,.55), rgba(255,255,255,.55)) 0 14% / 100% 2px no-repeat,
    linear-gradient(rgba(255,255,255,.55), rgba(255,255,255,.55)) 0 86% / 100% 2px no-repeat,
    var(--st);
}
[data-status="pendente"] { --st: var(--cinza); }
[data-status="processando"] { --st: var(--azul); }
[data-status="revisar"] { --st: var(--mostarda); }
[data-status="ok"] { --st: var(--verde); }
[data-status="erro"] { --st: var(--vinho); }
.capa { width: 48px; height: 66px; border-radius: 3px; overflow: hidden; background: var(--risca); }
.capa img { width: 100%; height: 100%; object-fit: cover; display: block; }
.info { display: grid; gap: 1px; min-width: 0; }
.info strong {
  font: 600 1rem/1.25 var(--serif); display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.info span { font-size: .88rem; color: var(--suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.estado { font-size: .8rem; color: var(--suave); }
.vazio { padding: 18px; color: var(--suave); background: var(--folha); border: 1px dashed #B9C1BB; border-radius: 10px; }
.rodape-lista { margin: 18px 0 0; text-align: center; }
.rodape-lista a { color: var(--pano); }
@media (prefers-reduced-motion: no-preference) {
  .livro[data-status="processando"]::before { animation: pulso 1.4s ease-in-out infinite; }
  @keyframes pulso { 50% { opacity: .4; } }
}

/* barra de abas */
.abas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--folha); border-top: 1px solid var(--risca); padding-bottom: env(safe-area-inset-bottom);
}
.abas button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; background: none; border: 0; border-top: 3px solid transparent; color: var(--suave); font-size: .8rem;
}
.abas button[aria-selected="true"] { color: var(--pano); border-top-color: var(--pano); font-weight: 600; }
.abas svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.selo {
  position: absolute; top: 6px; left: calc(50% + 8px); min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--mostarda); color: var(--tinta); font-size: .75rem; font-weight: 700; line-height: 20px;
}

/* ficha do livro (folha que sobe da base) */
dialog { border: 0; padding: 0; color: var(--tinta); background: var(--folha); }
dialog::backdrop { background: rgba(10, 20, 17, .55); }
#ficha { width: 100%; max-width: 640px; max-height: 92dvh; margin: auto auto 0; border-radius: 18px 18px 0 0; }
#acesso { width: min(92vw, 380px); border-radius: 14px; }
.acesso { padding: 20px; }
.acesso h2 { margin-top: 0; }
.folha-ficha { padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); }
.ficha-topo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.fechar { min-height: 44px; padding: 0 4px; background: none; border: 0; color: var(--pano); font-weight: 600; }
.selo-estado { --st: var(--cinza); padding: 3px 10px; border-radius: 10px; font-size: .8rem; background: var(--st); color: #fff; }
.selo-estado[data-status="revisar"] { color: var(--tinta); }
.foto-livro { display: block; width: 100%; max-height: 38dvh; object-fit: contain; background: #1b2421; border-radius: 10px; margin-bottom: 12px; }
.aviso-ficha { margin: 0 0 12px; padding: 10px 12px; background: #F5E7E9; border-left: 4px solid var(--vinho); border-radius: 4px; }
.folha-ficha h3 { font: 600 1.05rem var(--serif); margin: 8px 0; }
.cand { display: grid; gap: 1px; width: 100%; padding: 10px 12px; text-align: left; background: #fff; border: 1px solid #B9C1BB; border-radius: 8px; min-height: 60px; }
.cand strong { font: 600 1rem var(--serif); }
.cand span { font-size: .88rem; color: var(--suave); }
.folha-ficha form { margin-top: 14px; }
.folha-ficha details { margin: 16px 0; color: var(--suave); }
.folha-ficha pre { white-space: pre-wrap; font: .82rem/1.4 var(--sans); background: #fff; padding: 10px; border-radius: 8px; max-height: 180px; overflow: auto; }
.ficha-rodape { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }

/* leitor de código de barras */
#leitor { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; }
#leitor video { width: 100%; height: 100%; object-fit: cover; }
.mira { position: absolute; left: 8%; right: 8%; top: 38%; height: 20%; border: 3px solid var(--mostarda); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
.leitor-topo { position: absolute; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 10px) 14px; }
.leitor-topo button { min-height: 44px; padding: 0 18px; border-radius: 22px; border: 0; background: rgba(0,0,0,.6); color: #fff; font-weight: 600; }
.leitor-base { position: absolute; left: 0; right: 0; bottom: 0; display: grid; gap: 2px; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.85)); }
.leitor-base strong { font: 600 1.15rem var(--serif); }
.leitor-base span { font-size: .88rem; opacity: .9; }

/* aviso */
#aviso {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30; max-width: min(92vw, 480px);
  transform: translateX(-50%); padding: 11px 16px; border-radius: 10px; background: var(--tinta); color: #fff;
  opacity: 0; pointer-events: none; transition: opacity .2s; font-size: .92rem;
}
#aviso.visivel { opacity: 1; }
#aviso.erro { background: var(--vinho); }

.botao-foto { display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer; }
.fotos-ficha { margin-bottom: 12px; }
.versao { margin-top: 28px; text-align: center; }
.botao-foto:focus-within { outline: 3px solid var(--azul); outline-offset: 2px; }
