:root {
  --fundo: #f3f5f8;
  --painel: #ffffff;
  --texto: #1f2933;
  --suave: #66788a;
  --borda: #d9e0e7;
  --primaria: #1d5fbf;
  --perigo: #c0392b;
  --sucesso: #1e8449;
  --aviso: #b9770e;
  --menu: #1c2834;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 15px; }
body { margin: 0; font-family: "Segoe UI", Roboto, Arial, sans-serif; color: var(--texto); background: var(--fundo); }
a { color: var(--primaria); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
.cartao h2:first-child { margin-top: 0; }

/* Layout com menu lateral */
.layout { display: flex; min-height: 100vh; }
.menu { width: 230px; flex-shrink: 0; background: var(--menu); color: #cfd8e3; padding: 1rem 0; display: flex; flex-direction: column; }
.menu a, .menu .link { color: #cfd8e3; text-decoration: none; padding: .45rem 1.25rem; display: block; text-align: left; }
.menu a:hover, .menu .link:hover { background: rgba(255,255,255,.08); color: #fff; }
.menu .marca { color: #fff; font-weight: 700; font-size: 1.1rem; padding-bottom: 1rem; }
.menu .destaque { background: var(--primaria); color: #fff; margin: .25rem 1rem; border-radius: 6px; text-align: center; font-weight: 600; }
.menu .secao { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: #7f93a8; padding: 1rem 1.25rem .25rem; }
.menu .sair { margin-top: auto; }
.link { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }
.conteudo { flex: 1; padding: 1.5rem 2rem; min-width: 0; }

/* Celular: veja "Celular e telas estreitas" no fim do arquivo. */
.barra-celular { display: none; }

/* Orçamento de energia solar */
.sugestao-solar { margin: .75rem 0 0; padding: .6rem .8rem; border-radius: 6px; background: #fff7e0; border: 1px solid #f0d27a; color: #6b4e00; }
.sugestao-solar .botao { margin-left: .5rem; padding: .25rem .7rem; }
.resultado-solar hr { border: 0; border-top: 1px solid var(--borda); margin: .5rem 0; }
.resultado-solar .destaque-verde strong { color: var(--sucesso); font-size: 1.1rem; }
body.tema-escuro .sugestao-solar { background: #3a3110; border-color: #6b5a1e; color: #f3dc8e; }

/* Botão Voltar, no alto de todas as telas (menos o Início) */
.botao-voltar { display: inline-flex; align-items: center; gap: .3rem; margin: -.6rem 0 .8rem; padding: .3rem .8rem; font: inherit; font-size: .9rem;
  border: 1px solid var(--borda); border-radius: 999px; background: var(--painel); color: var(--texto); cursor: pointer; }
.botao-voltar:hover { border-color: var(--primaria); color: var(--primaria); }

/* Componentes */
.cartao { background: var(--painel); border: 1px solid var(--borda); border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem; }
.estreito { max-width: 520px; }
.cabecalho { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.cabecalho h1 { margin: 0; }
.suave { color: var(--suave); }
.duas-colunas { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }

.botao { display: inline-block; padding: .5rem 1rem; border: 1px solid var(--borda); border-radius: 6px; background: var(--painel); color: var(--texto); text-decoration: none; cursor: pointer; font: inherit; }
.botao:hover { border-color: var(--primaria); }
.botao.primario { background: var(--primaria); border-color: var(--primaria); color: #fff; }
.botao.primario:hover { filter: brightness(.9); }
.botao.perigo { background: var(--perigo); border-color: var(--perigo); color: #fff; }
.botao.grande { padding: .75rem 1.5rem; font-size: 1.1rem; }
.botao:disabled { opacity: .5; cursor: not-allowed; }
.botoes { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* Formulários */
input, select, textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--borda); border-radius: 6px; background: #fff; color: var(--texto); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaria); outline-offset: -1px; }
.campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem 1.25rem; }
.campo { display: flex; flex-direction: column; gap: .25rem; }
.campo label { font-weight: 600; font-size: .9rem; }
.campo.check label { font-weight: normal; display: flex; align-items: center; gap: .5rem; margin-top: 1.4rem; }
.campo.largo { grid-column: 1 / -1; }
.campo input:not([type=checkbox]), .campo select, .campo textarea { width: 100%; }
.campo.com-erro input, .campo.com-erro select { border-color: var(--perigo); }
.erro-texto { color: var(--perigo); }
.busca { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.busca input[type=search] { min-width: 260px; flex: 1; max-width: 480px; }

/* Tabelas */
.tabela-rolagem { overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; background: var(--painel); }
.tabela th, .tabela td { padding: .5rem .65rem; border-bottom: 1px solid var(--borda); text-align: left; }
.tabela thead th { background: #e9eef4; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: #44566a; }
.tabela tbody tr:hover { background: #f7f9fc; }
.tabela .num { text-align: right; white-space: nowrap; }
.tabela .acoes { white-space: nowrap; text-align: right; }
.tabela .acoes a { margin-left: .75rem; }
.tabela .vazio { text-align: center; color: var(--suave); padding: 2rem; }
.tabela tr.cancelada td { color: var(--suave); text-decoration: line-through; }
a.perigo { color: var(--perigo); }
.positivo { color: var(--sucesso); }
.negativo { color: var(--perigo); }

.paginacao { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

.indicadores { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.indicador { background: var(--painel); border: 1px solid var(--borda); border-radius: 8px; padding: 1rem 1.25rem; min-width: 180px; display: flex; flex-direction: column; }
a.indicador { text-decoration: none; color: inherit; }
a.indicador:hover { border-color: var(--primaria); }
.indicador .rotulo { color: var(--suave); font-size: .85rem; }
.indicador .valor { font-size: 1.6rem; font-weight: 700; }

.etiqueta { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.etiqueta.verde { background: #d5f5e3; color: var(--sucesso); }
.etiqueta.vermelha { background: #fadbd8; color: var(--perigo); }

/* Mensagens */
.mensagens { margin-bottom: 1rem; }
.msg { padding: .7rem 1rem; border-radius: 6px; margin-bottom: .5rem; background: #eaf2fd; border: 1px solid #c6dbf7; }
.msg.sucesso { background: #e9f7ef; border-color: #b7e4c7; }
.msg.erro { background: #fdecea; border-color: #f5c6c0; }
.msg.aviso { background: #fef5e7; border-color: #f8d9a0; }

/* Login */
.tela-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: .9rem; }
.login h1 { margin: 0; }
.login label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; }

/* Documentos (OS e orçamento) */
.documento { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.documento > .msg { grid-column: 1 / -1; }
.documento-lateral { position: sticky; top: 1rem; }
.campos.uma-coluna { grid-template-columns: 1fr; }
.largura-total { width: 100%; text-align: center; margin-top: .5rem; }
.acoes-documento form { display: inline; margin: 0; }
.acoes-documento { margin-top: 0; }
.linha-total { display: flex; justify-content: space-between; padding: .3rem 0; border-bottom: 1px dashed var(--borda); }
.total-documento { display: flex; justify-content: space-between; align-items: baseline; margin-top: .75rem; padding: .6rem .8rem; border-radius: 6px; background: var(--menu); color: #fff; }
.total-documento strong { font-size: 1.5rem; }
.info:not(.msg) { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 1rem 0 0; font-size: .9rem; }
.info dt { color: var(--suave); }
.info dd { margin: 0; }
.check { display: flex; align-items: center; gap: .5rem; }
.nowrap { white-space: nowrap; }
.tabela tr.clicavel { cursor: pointer; }
.seletor-situacao { padding: .25rem .4rem; max-width: 190px; }
.etiqueta.azul { background: #dbe8fb; color: #1d4f9c; }
.etiqueta.laranja { background: #fdebd0; color: #9c5a0e; }
body.tema-escuro .etiqueta.azul { background: #1d2c40; color: #9cc2f5; }
body.tema-escuro .etiqueta.laranja { background: #3a2e15; color: #f5c27a; }

.busca-com-lista { position: relative; flex: 1; min-width: 220px; }
.busca-com-lista input { width: 100%; }
.resultados { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 2px); max-height: 320px; overflow-y: auto; background: var(--painel); border: 1px solid var(--borda); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.resultados > div { padding: .6rem .75rem; }
.resultado { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--borda); background: none; color: var(--texto); font: inherit; padding: .5rem .75rem; cursor: pointer; }
.resultado.ativo, .resultado:hover { background: #dbe8fb; }
body.tema-escuro .resultado.ativo, body.tema-escuro .resultado:hover { background: #1d3557; }
.resultado .preco { float: right; color: var(--suave); }
.busca-cliente { margin-bottom: .75rem; display: flex; flex-direction: column; gap: .35rem; }
.cliente-escolhido { display: flex; align-items: center; gap: .75rem; font-size: 1.1rem; }
.busca-itens { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.tabela-itens input { width: 100%; padding: .3rem .4rem; }
.tabela-itens input.curto { width: 6.5rem; text-align: right; }
.tabela-itens .remover { background: none; border: 0; color: var(--perigo); font-size: 1.3rem; cursor: pointer; }

@media (max-width: 1000px) {
  .documento { grid-template-columns: 1fr; }
  .documento-lateral { position: static; }
}

/* Logotipo */
.menu .marca { display: flex; align-items: center; gap: .6rem; }
.menu .marca img { max-height: 40px; max-width: 70px; object-fit: contain; background: #fff; border-radius: 4px; padding: 2px; }
.logo-login { max-height: 90px; max-width: 220px; object-fit: contain; align-self: center; }
.logo-previa { max-height: 80px; max-width: 240px; border: 1px solid var(--borda); border-radius: 6px; padding: 4px; background: #fff; }
.barra-salvar { position: sticky; bottom: 0; background: var(--fundo); padding: .75rem 0; }

/* Menu no topo (configurável) */
body.menu-topo .layout { flex-direction: column; }
body.menu-topo .menu { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .4rem .75rem; }
body.menu-topo .menu .secao { display: none; }
body.menu-topo .menu a, body.menu-topo .menu .link { padding: .45rem .7rem; }
body.menu-topo .menu .marca { padding: .25rem 1rem .25rem .25rem; }
body.menu-topo .menu .sair { margin: 0 0 0 auto; }
body.menu-topo .menu .link { width: auto; }

/* Tema escuro (configurável) */
body.tema-escuro {
  --fundo: #151b22;
  --painel: #1f2731;
  --texto: #e3e9ef;
  --suave: #93a4b5;
  --borda: #34404d;
  color-scheme: dark;
}
body.tema-escuro input, body.tema-escuro select, body.tema-escuro textarea { background: #151b22; color: var(--texto); }
body.tema-escuro .tabela thead th { background: #283341; color: #c2cfdc; }
body.tema-escuro .tabela tbody tr:hover { background: #26303b; }
body.tema-escuro .msg { background: #1d2c40; border-color: #2e4a6e; }
body.tema-escuro .msg.sucesso { background: #18301f; border-color: #2a5a39; }
body.tema-escuro .msg.erro { background: #3a1d1a; border-color: #6b2f28; }
body.tema-escuro .msg.aviso { background: #3a2e15; border-color: #6b5422; }
body.tema-escuro .etiqueta.verde { background: #18301f; }
body.tema-escuro .etiqueta.vermelha { background: #3a1d1a; }

/* Abas do menu (Cadastros, Financeiro, Comercial...) */
.aba-menu > summary { list-style: none; cursor: pointer; color: #fff; font-weight: 600; padding: .55rem 1.25rem; user-select: none; }
.aba-menu > summary::-webkit-details-marker { display: none; }
.aba-menu > summary::after { content: "▸"; float: right; opacity: .6; }
.aba-menu[open] > summary::after { content: "▾"; }
.aba-menu > summary:hover, .menu .aba-link:hover { background: rgba(255,255,255,.08); }
.menu .aba-link { color: #fff; font-weight: 600; }
.aba-menu[open] { background: rgba(0,0,0,.15); padding-bottom: .35rem; }
.aba-menu a { padding: .35rem 1.25rem .35rem 1.75rem; font-size: .95rem; }
.aba-menu a.sub { padding-left: 2.6rem; font-size: .88rem; }
/* Menu no topo: cada aba abre uma lista suspensa. */
body.menu-topo .aba-menu { position: relative; }
body.menu-topo .aba-menu > summary { padding: .45rem .8rem; }
body.menu-topo .aba-menu > summary::after { float: none; margin-left: .35rem; }
body.menu-topo .aba-menu[open] { background: rgba(255,255,255,.08); border-radius: 6px 6px 0 0; padding-bottom: 0; }
body.menu-topo .aba-itens { position: absolute; top: 100%; left: 0; z-index: 30; min-width: 260px; background: var(--menu);
  padding: .4rem 0; border-radius: 0 6px 6px 6px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }

/* Abas dos cadastros (1. Dados principais, 2. Outros dados...) */
.abas-titulos { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 2px solid var(--borda); margin-bottom: 1rem; }
.aba-titulo { font: inherit; padding: .5rem 1rem; border: 1px solid var(--borda); border-bottom: 0; border-radius: 6px 6px 0 0; background: var(--fundo); color: var(--texto); cursor: pointer; margin-bottom: -2px; }
.aba-titulo.ativa { background: var(--painel); border-color: var(--primaria); border-bottom: 2px solid var(--painel); font-weight: 600; }
.aba-titulo.com-erro { color: var(--perigo); }

/* Consultas no cadastro (CNPJ, CEP, código de barras) */
.ok-texto { color: var(--sucesso); }
.com-botao { display: flex; gap: .4rem; }
.com-botao input { flex: 1; min-width: 0; }
.com-botao .botao { padding: .4rem .8rem; white-space: nowrap; }
.campo:has([data-ncm]) { grid-column: span 2; }
.lista-ncm { list-style: none; margin: .4rem 0 0; padding: 0; max-height: 260px; overflow-y: auto; border: 1px solid var(--borda); border-radius: 6px; }
.lista-ncm button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--borda); background: none; color: var(--texto); font: inherit; font-size: .9rem; padding: .45rem .7rem; cursor: pointer; }
.lista-ncm button:hover { background: #dbe8fb; }
body.tema-escuro .lista-ncm button:hover { background: #1d3557; }

/* Listas de marcar (materiais na retirada e devolução, áreas de acesso do usuário) */
.estreito-medio { max-width: 860px; }
.lista-marcar { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .35rem 1rem; max-height: 340px; overflow-y: auto;
  border: 1px solid var(--borda); border-radius: 6px; padding: .6rem .8rem; margin-bottom: 1rem; }
.lista-marcar label { padding: .2rem 0; cursor: pointer; }
.filtro-lista { width: 100%; max-width: 360px; margin-bottom: .5rem; }

/* Atalhos da tela inicial */
.atalhos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.atalho { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; min-height: 105px; padding: .8rem .6rem;
  background: var(--painel); border: 1px solid var(--borda); border-radius: 10px; text-decoration: none; color: var(--texto); text-align: center; font-weight: 600; }
.atalho:hover, .atalho:focus { border-color: var(--primaria); box-shadow: 0 4px 14px rgba(0,0,0,.08); outline: 0; }
.atalho .icone { font-size: 2rem; line-height: 1; }
.lista-atalhos .icone { font-size: 1.2rem; }

/* Usuários: perfis e áreas */
.form-usuario { max-width: 1000px; }
.perfis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.perfil-opcao, .area-opcao { display: flex; gap: .6rem; align-items: flex-start; border: 1px solid var(--borda); border-radius: 8px; padding: .65rem .8rem; cursor: pointer; }
.perfil-opcao:has(input:checked) { border-color: var(--primaria); background: #eaf2fd; }
.perfil-opcao span, .area-opcao span { display: flex; flex-direction: column; gap: .15rem; }
.perfil-opcao input, .area-opcao input { margin-top: .2rem; }
.lista-areas { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .5rem; }
.area-opcao:has(input:checked) { border-color: var(--sucesso); }
.area-opcao .do-perfil { display: none; font-style: normal; color: var(--suave); font-size: .85rem; }
.area-opcao.incluida { background: var(--fundo); cursor: default; }
.area-opcao.incluida .do-perfil { display: inline; }
body.tema-escuro .perfil-opcao:has(input:checked) { background: #1d2c40; }

/* Menu do item avulso (OS e orçamento) */
.menu-avulso { position: relative; }
.menu-avulso-opcoes { position: absolute; z-index: 25; right: 0; top: calc(100% + 2px); min-width: 200px; background: var(--painel);
  border: 1px solid var(--borda); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: .25rem 0; }
.menu-avulso-opcoes button { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--texto);
  font: inherit; padding: .55rem .9rem; cursor: pointer; }
.menu-avulso-opcoes button:hover, .menu-avulso-opcoes button:focus { background: #dbe8fb; outline: 0; }
body.tema-escuro .menu-avulso-opcoes button:hover, body.tema-escuro .menu-avulso-opcoes button:focus { background: #1d3557; }

/* Editor do layout de impressão */
.layout-editor { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.layout-previa { position: sticky; top: 1rem; }
.layout-previa iframe { width: 100%; height: 80vh; border: 1px solid var(--borda); border-radius: 6px; background: #e9edf2; }
.lista-blocos { list-style: none; margin: 0; padding: 0; border: 1px solid var(--borda); border-radius: 6px; }
.lista-blocos li { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; border-bottom: 1px solid var(--borda); }
.lista-blocos li:last-child { border-bottom: 0; }
.lista-blocos li label { flex: 1; display: flex; align-items: center; gap: .5rem; }
.lista-blocos li.oculto label { color: var(--suave); text-decoration: line-through; }
.lista-blocos button { border: 1px solid var(--borda); background: var(--painel); color: var(--texto); border-radius: 4px; cursor: pointer; width: 2rem; }
textarea.codigo { font-family: Consolas, "Courier New", monospace; font-size: .85rem; }
@media (max-width: 1000px) { .layout-editor { grid-template-columns: 1fr; } .layout-previa { position: static; } }

@media print {
  .menu, .nao-imprimir, .mensagens { display: none !important; }
  .conteudo { padding: 0; }
  .cartao { border: 0; padding: 0; }
}

/* Celular e telas estreitas (vale também com o menu no topo). O menu vira uma gaveta aberta pelo botão ☰. */
@media (max-width: 800px) {
  body .barra-celular { display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 40;
    background: var(--menu); color: #fff; padding: calc(.5rem + env(safe-area-inset-top, 0px)) .75rem .5rem; }
  .botao-menu { font: inherit; font-weight: 600; color: #fff; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.35);
    border-radius: 8px; padding: .45rem .8rem; cursor: pointer; }
  .marca-celular { color: #fff; text-decoration: none; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body .layout, body.menu-topo .layout { display: block; }
  body .menu, body.menu-topo .menu { display: none; position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(85vw, 320px);
    flex-direction: column; flex-wrap: nowrap; align-items: stretch; overflow-y: auto; padding: calc(1rem + env(safe-area-inset-top, 0px)) 0 1rem;
    box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
  body.menu-aberto .menu { display: flex; }
  body.menu-aberto { overflow: hidden; }
  body .menu a, body .menu .link, body.menu-topo .menu a, body.menu-topo .menu .link { padding: .7rem 1.25rem; }
  body.menu-topo .menu .sair { margin: auto 0 0; }
  body.menu-topo .menu .link { width: 100%; }
  body.menu-topo .aba-itens { position: static; box-shadow: none; min-width: 0; }
  .conteudo { padding: 1rem .8rem 2rem; }
  h1 { font-size: 1.35rem; }
  .cabecalho { align-items: flex-start; }
  .cartao { padding: 1rem .85rem; }
  .campos { grid-template-columns: 1fr; }
  /* 16px nos campos: o iPhone não dá zoom sozinho ao tocar */
  input, select, textarea { font-size: 16px; }
  .botao, .botao-voltar { padding-top: .6rem; padding-bottom: .6rem; }
  .acoes-documento { display: flex; flex-wrap: wrap; gap: .4rem; }
  .tabela th, .tabela td { padding: .45rem .5rem; }
  form.busca > input { flex: 1 1 100%; width: 100%; }
}
/* No celular as teclas F4, F6... não existem: esconde as dicas [F6] do menu. */
body.disp-celular .menu .tecla-dica { display: none; }
.link-cliente { text-align: center; }
.separador-login { display: flex; align-items: center; gap: .75rem; color: var(--suave); font-size: .9rem; }
.separador-login::before, .separador-login::after { content: ""; flex: 1; border-top: 1px solid var(--borda); }
.login-area { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: stretch; }