:root {
  --azul-950: #081b36;
  --azul-900: #0f2d56;
  --azul-800: #173f72;
  --azul-700: #20518d;
  --azul-100: #e9f0f8;
  --fundo: #f3f6fa;
  --cartao: #ffffff;
  --texto: #132238;
  --texto-suave: #64748b;
  --borda: #dce4ee;
  --perigo: #b42318;
  --perigo-fundo: #fff0ee;
  --sombra: 0 12px 30px rgba(15, 45, 86, 0.08);
  --sombra-card: 0 8px 24px rgba(15, 45, 86, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--fundo);
  color: var(--texto);
}

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

button {
  cursor: pointer;
}

.topo {
  background: linear-gradient(135deg, var(--azul-950), var(--azul-900) 58%, var(--azul-800));
  border-bottom: 3px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 22px rgba(8, 27, 54, 0.16);
}

.topo-conteudo {
  width: min(1240px, calc(100% - 36px));
  min-height: 112px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}

.marca {
  display: flex;
  align-items: center;
  gap: 18px;
}

.logo {
  width: 76px;
  height: 76px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 5px 9px rgba(0, 0, 0, 0.16));
}

.marca-texto {
  min-width: 0;
}

.marca-sigla {
  display: block;
  margin-bottom: 3px;
  color: #cbd8e8;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #fff;
  font-size: clamp(1.65rem, 3vw, 2.25rem);
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.container {
  width: min(1240px, calc(100% - 36px));
  margin: 30px auto 64px;
}

.painel-controles {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(190px, 270px);
  gap: 12px;
  padding: 16px;
  background: var(--cartao);
  border: 1px solid var(--borda);
  border-radius: 16px;
  box-shadow: var(--sombra);
}

.campo-busca {
  position: relative;
}

.campo-busca svg {
  position: absolute;
  left: 15px;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translateY(-50%);
  fill: none;
  stroke: #718096;
  stroke-width: 2;
  stroke-linecap: round;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
  background: #fff;
  color: var(--texto);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

input,
select {
  height: 48px;
  padding: 0 14px;
}

.campo-busca input {
  padding-left: 45px;
}

textarea {
  padding: 12px 14px;
  resize: vertical;
  min-height: 94px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--azul-700);
  box-shadow: 0 0 0 3px rgba(32, 81, 141, 0.12);
}

.barra-catalogo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 22px 2px 18px;
}

.contador {
  margin: 0;
  color: var(--texto-suave);
  font-size: 0.98rem;
}

.contador strong {
  color: var(--texto);
  font-size: 1.08rem;
}

.status-conexao {
  min-height: 0;
  margin: -6px 2px 16px;
  color: var(--perigo);
  font-size: 0.9rem;
  font-weight: 650;
}

.status-conexao:empty {
  display: none;
}

.grade-livros {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.livro-card {
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--cartao);
  border: 1px solid var(--borda);
  border-radius: 16px;
  box-shadow: var(--sombra-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.livro-card:hover {
  transform: translateY(-3px);
  border-color: #c6d2df;
  box-shadow: 0 14px 34px rgba(15, 45, 86, 0.13);
}

.capa-livro {
  position: relative;
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(145deg, #e8eef6, #f6f8fb);
  border-bottom: 1px solid var(--borda);
}

.capa-livro img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 14px;
  background: #eef3f8;
}

.capa-placeholder {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: #8290a3;
  font-size: 0.82rem;
  font-weight: 700;
}

.capa-placeholder svg {
  width: 48px;
  height: 48px;
  fill: none;
  stroke: #9ba8b8;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.conteudo-card {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 16px;
}

.livro-card h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  line-height: 1.32;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.autor {
  min-height: 2.55em;
  margin: 0 0 12px;
  color: var(--texto-suave);
  font-size: 0.9rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.metadados {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 11px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--azul-100);
  color: var(--azul-800);
  font-size: 0.76rem;
  font-weight: 750;
  line-height: 1.2;
}

.tag.quantidade {
  background: #eef1f4;
  color: #4b5b6e;
}

.observacao {
  margin: 0 0 14px;
  color: var(--texto-suave);
  font-size: 0.84rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.acoes-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid #edf1f5;
}

.btn {
  min-height: 42px;
  padding: 9px 15px;
  border: 0;
  border-radius: 9px;
  font-weight: 750;
  transition: transform 0.15s, background 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.btn:not(:disabled):active {
  transform: translateY(1px);
}

.btn-principal {
  background: var(--azul-900);
  color: #fff;
  box-shadow: 0 5px 12px rgba(15, 45, 86, 0.14);
}

.btn-principal:not(:disabled):hover {
  background: var(--azul-800);
}

.btn-secundario {
  background: #edf2f7;
  color: #334155;
}

.btn-secundario:not(:disabled):hover {
  background: #e3e9f0;
}

.btn-perigo {
  background: var(--perigo);
  color: #fff;
}

.btn-perigo:not(:disabled):hover {
  background: #912018;
}

.btn-card {
  min-width: 0;
  min-height: 37px;
  padding: 7px 8px;
  border: 1px solid #d5dee8;
  border-radius: 8px;
  background: #fff;
  color: #34475d;
  font-size: 0.83rem;
  font-weight: 750;
}

.btn-card:hover {
  background: #f7f9fb;
  border-color: #c5d0dc;
}

.btn-card.remover {
  color: var(--perigo);
  background: #fff;
  border-color: #efcbc7;
}

.btn-card.remover:hover {
  background: var(--perigo-fundo);
}

.estado-vazio {
  margin-top: 12px;
  padding: 64px 20px;
  text-align: center;
  color: var(--texto-suave);
  background: rgba(255, 255, 255, 0.62);
  border: 1px dashed #cbd5e1;
  border-radius: 16px;
}

.icone-vazio {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--azul-100);
}

.icone-vazio svg {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: var(--azul-700);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.estado-vazio h2 {
  margin-bottom: 7px;
  color: var(--texto);
  font-size: 1.25rem;
}

.estado-vazio p {
  margin-bottom: 0;
}

.modal {
  width: min(680px, calc(100% - 28px));
  max-height: min(88vh, 820px);
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 18px;
  color: var(--texto);
  box-shadow: 0 30px 80px rgba(8, 27, 54, 0.28);
}

.modal::backdrop {
  background: rgba(8, 27, 54, 0.58);
  backdrop-filter: blur(3px);
}

.modal form,
.modal-pequeno {
  padding: 25px;
}

.modal-pequeno {
  max-width: 440px;
}

.modal-cabecalho {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.modal-cabecalho h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

.subtitulo {
  display: block;
  margin-bottom: 3px;
  color: var(--azul-700);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.btn-icone {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: #edf2f7;
  color: #475569;
  font-size: 1.55rem;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

.campo {
  display: block;
  margin-bottom: 15px;
  color: #334155;
  font-weight: 700;
}

.campo-largo {
  grid-column: 1 / -1;
}

.campo input,
.campo textarea {
  margin-top: 7px;
  font-weight: 400;
}

.opcional {
  color: #8290a3;
  font-weight: 500;
}

.rotulo-campo {
  display: block;
  margin-bottom: 8px;
}

.seletor-capa {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px dashed #c5d0dc;
  border-radius: 12px;
  background: #f8fafc;
}

.preview-capa {
  width: 92px;
  height: 122px;
  flex: 0 0 auto;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #eef3f8;
  border: 1px solid #d5dee8;
}

.preview-capa img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.placeholder-capa {
  display: grid;
  justify-items: center;
  gap: 5px;
  color: #8290a3;
  font-size: 0.72rem;
}

.placeholder-capa svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: #8d9bad;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.controles-capa {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.controles-capa small {
  flex-basis: 100%;
  color: #7b8798;
  font-weight: 500;
}

.input-arquivo {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.btn-arquivo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  cursor: pointer;
}

.btn-texto-perigo {
  min-height: 42px;
  background: transparent;
  color: var(--perigo);
  box-shadow: none;
}

.btn-texto-perigo:hover {
  background: var(--perigo-fundo);
}

.erro-formulario {
  margin: 2px 0 14px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--perigo-fundo);
  color: var(--perigo);
  font-size: 0.9rem;
  font-weight: 650;
}

.acoes-modal {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1000;
  max-width: min(380px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 10px;
  background: #132238;
  color: #fff;
  box-shadow: 0 16px 40px rgba(8, 27, 54, 0.25);
  font-weight: 650;
}

@media (max-width: 980px) {
  .grade-livros {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topo-conteudo,
  .container {
    width: min(100% - 26px, 1240px);
  }

  .topo-conteudo {
    min-height: 94px;
  }

  .logo {
    width: 62px;
    height: 62px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .container {
    margin-top: 20px;
  }

  .painel-controles {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
  }

  .barra-catalogo {
    margin-top: 17px;
  }

  .grade-livros {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px;
  }

  .livro-card {
    border-radius: 13px;
  }

  .capa-livro {
    aspect-ratio: 3 / 4;
  }

  .capa-livro img {
    padding: 9px;
  }

  .conteudo-card {
    padding: 12px;
  }

  .livro-card h3 {
    font-size: 0.94rem;
  }

  .autor {
    min-height: 2.45em;
    margin-bottom: 9px;
    font-size: 0.8rem;
  }

  .tag {
    min-height: 24px;
    padding: 3px 7px;
    font-size: 0.68rem;
  }

  .observacao {
    font-size: 0.76rem;
  }

  .acoes-card {
    gap: 6px;
    padding-top: 10px;
  }

  .btn-card {
    min-height: 34px;
    padding: 6px 5px;
    font-size: 0.74rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .campo,
  .campo-largo {
    grid-column: 1;
  }
}

@media (max-width: 500px) {
  .marca {
    gap: 12px;
  }

  .marca-sigla {
    font-size: 0.68rem;
  }

  h1 {
    font-size: 1.38rem;
  }

  .barra-catalogo {
    align-items: center;
  }

  .contador {
    font-size: 0.85rem;
  }

  .contador strong {
    font-size: 0.95rem;
  }

  .barra-catalogo .btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 0.84rem;
    white-space: nowrap;
  }

  .modal form,
  .modal-pequeno {
    padding: 20px 17px;
  }

  .seletor-capa {
    align-items: flex-start;
  }

  .preview-capa {
    width: 78px;
    height: 104px;
  }

  .controles-capa {
    flex-direction: column;
    align-items: flex-start;
  }

  .controles-capa small {
    flex-basis: auto;
  }

  .acoes-modal .btn {
    flex: 1;
  }
}

@media (max-width: 340px) {
  .grade-livros {
    grid-template-columns: 1fr;
  }

  .barra-catalogo {
    align-items: stretch;
    flex-direction: column;
  }

  .barra-catalogo .btn {
    width: 100%;
  }
}
