:root {
  --azul: #1d4ed8; --azul-escuro: #1e3a8a; --azul-claro: #dbeafe; --fundo: #f3f4f6; --card: #ffffff; --borda: #e5e7eb;
  --texto: #111827; --texto-2: #6b7280; --verde: #15803d; --verde-claro: #dcfce7; --vermelho: #b91c1c; --vermelho-claro: #fee2e2;
  --amarelo: #a16207; --amarelo-claro: #fef9c3; --laranja: #c2410c; --laranja-claro: #ffedd5; --raio: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--fundo); color: var(--texto); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 17px; margin: 0 0 10px; } h3 { font-size: 15px; margin: 0 0 8px; }
.carregando { padding: 40px; text-align: center; color: var(--texto-2); }

/* layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.nav { background: var(--azul-escuro); color: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav .marca { font-weight: 700; font-size: 16px; margin-bottom: 18px; line-height: 1.2; }
.nav .marca small { display: block; font-weight: 400; opacity: .75; font-size: 12px; }
.nav a { display: flex; gap: 10px; align-items: center; color: #dbeafe; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.ativo { background: var(--azul); color: #fff; }
.nav .grupo { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; margin: 14px 10px 6px; }
.nav .rodape { margin-top: 22px; font-size: 12px; opacity: .8; padding: 0 10px; }
.nav .rodape a { display: inline; padding: 0; color: #bfdbfe; }
.conteudo { padding: 22px 26px 60px; min-width: 0; }
.topo { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topo .sub { color: var(--texto-2); }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.acoes select { width: auto; }
.menu-btn { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; left: -260px; width: 240px; z-index: 30; transition: left .2s; }
  .nav.aberto { left: 0; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  .menu-btn { display: inline-block; }
  .conteudo { padding: 14px; }
}

/* cards e grids */
.card { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px; margin-bottom: 16px; }
/* cada pedido lido do PDF do cliente, dentro da tela de vendas */
.card-mini { border: 1px solid var(--borda); border-radius: var(--raio); padding: 12px; background: var(--card); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); padding: 14px 16px; }
.kpi .n { font-size: 26px; font-weight: 700; color: var(--azul-escuro); }
.kpi .l { color: var(--texto-2); font-size: 13px; }
.linha { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.campo { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.campo label { font-size: 12px; color: var(--texto-2); }
.campo.cresce { flex: 1; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], select, textarea {
  padding: 7px 9px; border: 1px solid #d1d5db; border-radius: 7px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul-claro); border-color: var(--azul); }
input.curto { width: 80px; } input.medio { width: 120px; }
textarea { min-height: 70px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 7px; border: 1px solid #d1d5db; background: #fff; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primario { background: var(--azul); color: #fff; border-color: var(--azul); }
.btn.primario:hover { background: #1e40af; }
.btn.perigo { color: var(--vermelho); border-color: #fca5a5; }
.btn.perigo:hover { background: var(--vermelho-claro); }
.btn.pequeno { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--azul-claro); color: var(--azul-escuro); white-space: nowrap; }
.tag.verde { background: var(--verde-claro); color: var(--verde); } .tag.vermelho { background: var(--vermelho-claro); color: var(--vermelho); }
.tag.amarelo { background: var(--amarelo-claro); color: var(--amarelo); } .tag.cinza { background: #e5e7eb; color: #374151; } .tag.laranja { background: var(--laranja-claro); color: var(--laranja); }
.muted { color: var(--texto-2); } .pequeno { font-size: 12px; }
.dir { text-align: right; } .centro { text-align: center; }
.pos { color: var(--verde); } .neg { color: var(--vermelho); }
.aviso { background: var(--amarelo-claro); border: 1px solid #fde68a; color: #713f12; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.erro-box { background: var(--vermelho-claro); border: 1px solid #fca5a5; color: #7f1d1d; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.ok-box { background: var(--verde-claro); border: 1px solid #86efac; color: #14532d; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }

/* tabelas */
.tabela-wrap { overflow-x: auto; border: 1px solid var(--borda); border-radius: var(--raio); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--borda); text-align: left; vertical-align: middle; }
th { background: #f9fafb; font-weight: 600; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tr:hover td { background: #fafafa; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td input[type=number], td select, td input[type=text] { padding: 4px 6px; min-width: 60px; }
td input.qt { width: 64px; text-align: right; }
td select.faixa { min-width: 150px; }
.tabela-wrap { --thumb-w: 38px; --thumb-h: 50px; }
/* Capa de livro não tem proporção fixa: por padrão aparece inteira, sem corte.
   Quem preferir o encaixe cheio liga "cortar para preencher". */
.thumb { width: var(--thumb-w); height: var(--thumb-h); object-fit: contain; border-radius: 4px; background: #fff; border: 1px solid var(--borda); flex: none; }
/* a foto guarda a proporção que veio: altura igual para todas, largura conforme a capa */
img.thumb { width: auto; max-width: calc(var(--thumb-h) * 1.3); }
div.thumb { background: #eee; }
.fotos-cortadas img.thumb { width: var(--thumb-w); object-fit: cover; }
.thumb.grande { width: 90px; height: 124px; }
.thumb.quebrada { background: var(--vermelho-claro); }
tr.destaque td { background: var(--amarelo-claro); }
tr.ok-row td { background: #f0fdf4; }
tr.bad-row td { background: #fff1f2; }
/* barra de busca/filtros que continua visível ao rolar a lista */
.filtros-fixos { position: sticky; top: 0; z-index: 9; background: var(--fundo); padding-top: 2px; }
.filtros-fixos .card { margin-bottom: 10px; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
/* total do pedido sempre à vista enquanto a lista rola */
.totais-fixos { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin: 10px -16px -16px; padding: 9px 16px; background: var(--azul-claro); color: var(--azul-escuro); border-top: 1px solid #bfdbfe; border-radius: 0 0 var(--raio) var(--raio); font-size: 13px; }
.totais-fixos b { font-size: 15px; }
/* Telas menores: a moldura (menu lateral e margens) cede espaço para a tabela. */
@media (max-width: 1500px) { .conteudo { padding: 16px 14px 50px; } }
@media (max-width: 1300px) {
  .shell { grid-template-columns: 190px 1fr; }
  .nav { padding: 14px 10px; } .nav a { padding: 7px 8px; gap: 8px; }
  .conteudo { padding: 14px 10px 50px; }
}
@media (max-width: 1180px) { .shell { grid-template-columns: 164px 1fr; } .nav { font-size: 13px; } .conteudo { padding: 12px 8px 50px; } }

/* A tabela do pedido tem muitas colunas: em telas menores ela encolhe (espaçamento,
   fonte e campos) em vez de esconder informação ou obrigar a rolar de lado. */
.tab-pedido { font-size: 12.5px; }
.tab-pedido th { font-weight: 600; line-height: 1.15; }
.tab-pedido td.col-livro { min-width: 170px; }
.tab-pedido td input.qt { width: 68px; }
.tab-pedido td input.qt.curto { width: 46px; padding-left: 4px; padding-right: 2px; }
.tab-pedido td select.faixa { min-width: 116px; max-width: 150px; }
.tab-pedido td .c-cx { line-height: 1.1; }
@media (max-width: 1600px) {
  .tab-pedido { font-size: 12px; }
  .tab-pedido th, .tab-pedido td { padding: 4px 5px; }
  .tab-pedido td.col-livro { min-width: 150px; }
  .tab-pedido td input.qt { width: 60px; }
  .tab-pedido td select.faixa { min-width: 104px; }
}
@media (max-width: 1300px) {
  .tab-pedido td select.faixa { min-width: 78px; max-width: 104px; }
  .tab-pedido .thumb { --thumb-w: 30px; --thumb-h: 40px; }
}
@media (max-width: 1380px) {
  .tab-pedido { font-size: 11.5px; }
  .tab-pedido th, .tab-pedido td { padding: 3px 4px; }
  .tab-pedido td.col-livro { min-width: 130px; }
  .tab-pedido td input.qt { width: 54px; }
  .tab-pedido td input.qt.curto { width: 40px; }
  .tab-pedido td select.faixa { min-width: 92px; max-width: 120px; }
  .tab-pedido .pequeno { font-size: 10.5px; }
}
@media (max-width: 1180px) {
  .tab-pedido { font-size: 11px; }
  .tab-pedido th, .tab-pedido td { padding: 2px 3px; }
  .tab-pedido td.col-livro { min-width: 110px; }
  .tab-pedido td input.qt { width: 44px; }
  .tab-pedido td input.qt.curto { width: 34px; }
  .tab-pedido td select.faixa { min-width: 74px; max-width: 92px; }
  .tab-pedido .thumb { --thumb-w: 28px; --thumb-h: 38px; }
}
.tab-pedido td.col-livro b { font-weight: 600; }
.tab-pedido td, .tab-pedido th { vertical-align: middle; }

/* Separação por loja: cabeçalho travado, faixa em destaque e cores por grupo de faixa. */
.tabela-wrap.rolagem { max-height: calc(100vh - 300px); overflow: auto; }
.tabela-wrap.rolagem thead th { position: sticky; top: 0; z-index: 3; box-shadow: 0 1px 0 var(--borda); }
.tabela-wrap.rolagem tfoot th { position: sticky; bottom: 0; background: #f9fafb; z-index: 3; box-shadow: 0 -1px 0 var(--borda); }
tr.destacar > td { animation: piscar 2.2s ease-out; }
@keyframes piscar { 0%, 40% { background: #fef08a !important; } 100% { background: transparent; } }
.tab-sep .composicao { grid-template-columns: 1fr 1.25fr; }
.faixa-etiqueta { display: inline-flex; flex-direction: column; gap: 1px; padding: 3px 8px; border-radius: 8px; background: var(--azul-claro); color: var(--azul-escuro); font-weight: 600; line-height: 1.15; white-space: normal; }
.faixa-etiqueta b { font-size: 13px; }
.tab-sep td.col-faixa { min-width: 96px; }
.tab-sep th.col-loja, .tab-sep td.col-loja { text-align: center; }
.tab-sep td.col-loja input.loja { width: 64px; text-align: right; }
.tab-sep tfoot th.col-loja { font-variant-numeric: tabular-nums; }
.sep-cores tbody tr.g0 td { background: #ffffff; }
.sep-cores tbody tr.g1 td { background: #eef4ff; }
.sep-cores tbody tr.ok-row td { background: #f0fdf4; }
.sep-cores tbody tr.bad-row td { background: #fff1f2; }
.sep-cores tbody tr.inicio-grupo td { border-top: 2px solid #c7d2fe; }

/* acordeão com a conta do livro */
tr.detalhe > td { background: #f8fafc; border-bottom: 2px solid var(--borda); padding: 0; }
/* o detalhe flutua sobre a linha: a altura é dada por JS e a largura não mexe nas colunas */
tr.detalhe > td:last-child { position: relative; }
.composicao { position: absolute; left: 0; top: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 12px 16px 16px; width: min(980px, calc(100vw - 300px)); }
.composicao > div { min-width: 0; }
@media (max-width: 900px) { .composicao { grid-template-columns: 1fr; width: calc(100vw - 40px); } }
table.conta { table-layout: fixed; }
table.conta td:first-child { word-break: break-word; }
table.conta td:last-child { width: 118px; }
@media (max-width: 900px) { .composicao { grid-template-columns: 1fr; } }
.composicao h4 { margin: 0 0 6px; font-size: 13px; color: var(--texto-2); text-transform: uppercase; letter-spacing: .04em; }
/* histórico de preço de tabela dentro do acordeão: quebra em colunas conforme couber */
.composicao > .hist-tab { grid-column: 1 / -1; margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--borda); }
.hist-tab .colunas { columns: 200px; column-gap: 22px; margin-bottom: 6px; }
.hist-tab .l { break-inside: avoid; display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 3px 6px; border-bottom: 1px dotted #e5e7eb; font-size: 13px; font-variant-numeric: tabular-nums; }
.hist-tab .l.atual { background: var(--azul-claro); border-radius: 6px; border-bottom-color: transparent; }
.hist-tab .l .v { white-space: nowrap; }
.hist-tab .l .marca { font-size: 11px; color: var(--azul-escuro); text-transform: uppercase; letter-spacing: .03em; }
table.conta { width: 100%; font-size: 13px; }
table.conta td { padding: 3px 6px; border-bottom: 1px dotted #e5e7eb; }
table.conta tr:last-child td { border-bottom: none; }
.btn.abrir { min-width: 26px; justify-content: center; padding: 2px 6px; }
.filtros-fixos.compacta .some-ao-rolar { display: none; }
.filtros-fixos.compacta .card { padding: 10px 16px 0; }
.totais-fixos .pos { color: var(--verde); }
input[type=range] { accent-color: var(--azul); padding: 0; }
.paginacao { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 0; flex-wrap: wrap; }

/* abas */
.abas { display: flex; gap: 4px; border-bottom: 1px solid var(--borda); margin-bottom: 16px; flex-wrap: wrap; }
.abas a { padding: 9px 14px; border-bottom: 2px solid transparent; color: var(--texto-2); margin-bottom: -1px; }
.abas a:hover { text-decoration: none; color: var(--texto); }
.abas a.ativo { color: var(--azul); border-bottom-color: var(--azul); font-weight: 600; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin-bottom: 18px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; }
.modal.larga { max-width: 1100px; }
.modal h2 { margin-bottom: 14px; }
.modal .rodape { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; animation: sobe .2s; }
.toast.erro { background: var(--vermelho); } .toast.ok { background: var(--verde); }
@keyframes sobe { from { transform: translateY(10px); opacity: 0; } }

/* drop zone */
.drop { border: 2px dashed #cbd5e1; border-radius: var(--raio); padding: 26px; text-align: center; color: var(--texto-2); cursor: pointer; background: #fff; }
.drop.sobre { border-color: var(--azul); background: var(--azul-claro); }
.drop input { display: none; }
.barra { height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; }
.barra > div { height: 100%; background: var(--azul); transition: width .3s; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }
.mapa-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.resumo-linha { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.resumo-linha .item { background: #f9fafb; border: 1px solid var(--borda); border-radius: 8px; padding: 8px 12px; }
.resumo-linha .item b { display: block; font-size: 18px; }
.resumo-linha .item.dica { display: flex; align-items: center; flex: 1; min-width: 240px; background: transparent; border-color: transparent; }
.resumo-linha .item.dica b { display: inline; font-size: inherit; }
.sit-ok { color: var(--verde); } .sit-faltou, .sit-nao_faturado { color: var(--vermelho); } .sit-sobrou, .sit-nao_pedido { color: var(--laranja); } .sit-preco_diferente { color: var(--amarelo); }
kbd { background: #eee; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
details summary { cursor: pointer; color: var(--azul); }

/* impressão (listas de separação) */
@media print {
  .nav, .topo .acoes, .abas, .nao-imprimir, #toasts { display: none !important; }
  .shell { display: block; } .conteudo { padding: 0; }
  .card { border: none; padding: 0; } body { background: #fff; }
  table { font-size: 11px; } th { position: static; }
  .quebra { page-break-before: always; }
}

/* aviso clicavel na barra de totais (ex.: "12 abaixo da margem pedida") */
.tag.como-link { border: 0; cursor: pointer; font: inherit; font-size: 12px; }
.tag.como-link:hover { filter: brightness(0.95); text-decoration: underline; }

/* loja que nao recebeu nada na separacao: aparece no resumo, mas sem destaque */
.resumo-linha .item.apagado { opacity: 0.55; }

/* endereco de retorno do OAuth: precisa ser copiado inteiro, sem quebrar */
.codigo-larga { flex: 1; padding: 8px 10px; background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 8px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; overflow-x: auto; white-space: nowrap; }

/* frase que explica, em portugues, o que a separacao vai fazer no Bling */
.explica { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: #eff6ff;
  border: 1px solid #bfdbfe; color: #1e3a8a; font-size: 13.5px; line-height: 1.5; }
.explica:empty { display: none; }

/* abrir a conta insere uma linha; sem isso o navegador empurra a rolagem sozinho */
.tabela-wrap.rolagem { overflow-anchor: none; }

/* resumo do que a ordem de transferencia faz em cada deposito */
.tab-depositos td { vertical-align: top; }
.tab-depositos td div { line-height: 1.45; }
h3.titulo-bloco { margin: 14px 0 6px; font-size: 14px; color: #334155; }

/* passo a passo da tela de notas recebidas */
ol.passos { list-style: none; margin: 6px 0 0; padding: 0; }
ol.passos li { padding: 9px 0 9px 2px; border-top: 1px solid var(--borda); line-height: 1.5; }
ol.passos li:first-child { border-top: 0; }
ol.passos li div { margin-top: 2px; }

/* recalibragem: linha que continua abaixo da margem pedida */
tr.aviso-row td { background: #fffbeb; }
.tab-recalibrar .col-faixa-nova { min-width: 260px; }
.tab-recalibrar .col-faixa-nova select { width: 100%; font-size: 12px; }
.tab-recalibrar td { vertical-align: top; }
.tab-recalibrar input.qt-nova { width: 70px; }
button.como-link { background: none; border: none; padding: 0; color: var(--azul); cursor: pointer; font: inherit; text-decoration: underline; }

.tab-recalibrar .col-marca { width: 62px; text-align: center; white-space: nowrap; }
.tab-recalibrar .col-marca .so-esta { display: block; margin: 4px auto 0; font-size: 11px; padding: 2px 6px; }

.nao-quebra { white-space: nowrap; }
