/* Envelopando Online Controle — estilos (celular primeiro) */
:root {
  --roxo: #5B1A9E; --roxo-esc: #3A0D6B; --roxo-claro: #F1E9FB; --roxo-med: #7B2CBF;
  --ouro: #F6B92B; --ouro-bg: #FFF6DC; --teal: #19C3B1;
  --grad: linear-gradient(135deg, #5B1A9E 0%, #7B2CBF 100%);
  --grad-ouro: linear-gradient(90deg, #F6B92B 0%, #F6B92B 35%, #19C3B1 70%, #6D5BF2 100%);
  --venda: #0E9F7E; --venda-bg: #E3F7F1;
  --gasto: #D9480F; --gasto-bg: #FDEDE5;
  --texto: #24123D; --suave: #6B5C80; --fundo: #F6F2FB; --card: #fff; --borda: #E7DDF3;
  --raio: 18px; --raio-sm: 12px;
  --sombra: 0 2px 12px rgba(58, 13, 107, .08), 0 1px 2px rgba(58, 13, 107, .05);
  --nav-h: 68px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--texto); background: var(--fundo); font-size: 17px; line-height: 1.45; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; color: var(--roxo-esc); }
h1 { font-size: 1.55rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--suave); } .small { font-size: .88rem; } .center { text-align: center; }
.container { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px; }
.cor-venda { color: var(--venda); } .cor-gasto { color: var(--gasto); }

/* botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px; padding: 12px 18px; font: inherit; font-weight: 700; cursor: pointer; min-height: 50px; text-decoration: none; transition: transform .08s, box-shadow .15s; color: var(--texto); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(91, 26, 158, .3); }
.btn-outline { background: #fff; border: 2px solid var(--borda); color: var(--roxo-esc); }
.btn-ghost { background: none; color: var(--roxo); }
.btn-danger { background: var(--gasto-bg); color: var(--gasto); }
.btn-block { width: 100%; } .btn-grande { min-height: 58px; font-size: 1.08rem; }
.btn[disabled] { opacity: .6; cursor: wait; }
.btn-link { background: none; border: 0; color: var(--roxo); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; padding: 6px 0; }
.btn-x { width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--roxo-claro); color: var(--roxo-esc); font-size: 1.15rem; cursor: pointer; flex: none; }

/* cartões e formulários */
.card { background: var(--card); border: 1px solid var(--borda); border-radius: var(--raio); box-shadow: var(--sombra); padding: 18px; margin-bottom: 14px; }
.card-cab { display: flex; justify-content: space-between; align-items: center; }
.card-cab h3 { margin: 0; }
label, .label { display: block; font-weight: 700; font-size: .95rem; margin-bottom: 6px; color: var(--roxo-esc); }
summary.label { cursor: pointer; }
.field { margin-bottom: 16px; }
input, select, textarea { width: 100%; font: inherit; font-size: 1.05rem; color: var(--texto); padding: 12px 14px; border: 2px solid var(--borda); border-radius: var(--raio-sm); background: #fff; min-height: 52px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--roxo-med); box-shadow: 0 0 0 4px rgba(123, 44, 191, .15); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-2 > div { min-width: 0; }
.hint { font-size: .85rem; color: var(--suave); margin-top: 8px; }
.alert { padding: 12px 14px; border-radius: var(--raio-sm); font-size: .95rem; margin-bottom: 14px; }
.alert-erro { background: var(--gasto-bg); color: #9a3009; }
.alert-ok { background: var(--venda-bg); color: #075e4b; }
.alert-aviso { background: var(--ouro-bg); color: #7a5300; }

/* carregando / login */
.carregando { min-height: 100vh; display: grid; place-content: center; justify-items: center; background: var(--grad); color: #fff; }
.carregando img { border-radius: 50%; animation: pulso 1.4s ease-in-out infinite; }
@keyframes pulso { 50% { transform: scale(1.06); } }
.login { min-height: 100vh; background: radial-gradient(circle at 50% 0%, #7B2CBF 0%, #5B1A9E 38%, #3A0D6B 100%); padding: 28px 16px 40px; }
.login-box { max-width: 420px; margin: 0 auto; text-align: center; }
.login-box > h1 { color: #fff; margin-top: 10px; }
.login-box > p.muted { color: #E6D8F7; }
.login-logo { width: 150px; height: 150px; border-radius: 50%; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.login .card { text-align: left; }
.login .btn-outline { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .45); }
.login-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.login-links .btn-link { font-size: .92rem; }

/* topo e menu */
.topo { position: sticky; top: 0; z-index: 20; background: var(--grad); color: #fff; padding-top: env(safe-area-inset-top); box-shadow: 0 2px 12px rgba(58, 13, 107, .25); }
.topo::after { content: ""; display: block; height: 4px; background: var(--grad-ouro); }
.topo-in { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.marca { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 800; font-size: 1.05rem; min-width: 0; }
.marca img { border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(246, 185, 43, .7); }
.marca span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.faixa { background: var(--ouro-bg); color: #7a5300; padding: 10px 16px; font-size: .9rem; text-align: center; }
.conteudo { padding-top: 16px; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: #fff; border-top: 1px solid var(--borda); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(58, 13, 107, .08); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--nav-h); color: var(--suave); text-decoration: none; font-size: .78rem; font-weight: 700; }
.nav svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav svg circle { fill: currentColor; stroke: none; }
.nav a.ativo { color: var(--roxo); }
.nav a.ativo svg { stroke-width: 2.4; }

/* ações grandes */
.acoes-grandes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.acao { display: flex; align-items: center; gap: 10px; border: 0; border-radius: var(--raio); padding: 18px 14px; min-height: 88px; font: inherit; color: #fff; cursor: pointer; text-align: left; box-shadow: var(--sombra); }
.acao:active { transform: scale(.98); }
.acao b { display: block; font-size: 1.3rem; } .acao small { display: block; opacity: .9; font-size: .85rem; }
.acao-ico { width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .22); display: grid; place-items: center; font-size: 1.6rem; font-weight: 800; flex: none; }
.acao-venda { background: linear-gradient(135deg, #0E9F7E, #19C3B1); }
.acao-gasto { background: linear-gradient(135deg, #D9480F, #F08C2B); }

/* resumos */
.resumo-titulo { font-weight: 800; color: var(--roxo); text-transform: uppercase; font-size: .82rem; letter-spacing: .06em; margin-bottom: 10px; }
.resumo-linhas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.resumo-linhas div { background: var(--fundo); border-radius: var(--raio-sm); padding: 10px 12px; min-width: 0; }
.resumo-linhas span { display: block; font-size: .82rem; color: var(--suave); }
.resumo-linhas b { font-size: 1.15rem; white-space: nowrap; }
.lucro { margin-top: 10px; display: flex; justify-content: space-between; align-items: baseline; background: var(--roxo-claro); border-radius: var(--raio-sm); padding: 12px 14px; border-left: 5px solid var(--ouro); }
.lucro span { font-weight: 700; color: var(--roxo-esc); }
.lucro strong { font-size: 1.6rem; color: var(--roxo); white-space: nowrap; }
.lucro-neg { background: var(--gasto-bg); border-left-color: var(--gasto); }
.lucro-neg strong { color: var(--gasto); }
.limite { margin-top: 14px; }
.limite-top { display: flex; justify-content: space-between; font-weight: 700; font-size: .92rem; margin-bottom: 6px; }
.limite p { margin: 8px 0 0; color: var(--suave); }
.barra { height: 12px; background: #EEE7F7; border-radius: 99px; overflow: hidden; }
.barra i { display: block; height: 100%; background: var(--grad-ouro); border-radius: 99px; }
.limite-atencao .barra i { background: var(--ouro); }
.limite-estourou .barra i, .limite-estourou20 .barra i { background: var(--gasto); }
.limite-estourou p, .limite-estourou20 p { color: var(--gasto); font-weight: 600; }
.nudge { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; font: inherit; cursor: pointer; background: var(--ouro-bg); border-color: #F3D98C; }
.nudge b { display: block; color: #7a5300; } .nudge small { display: block; color: #8a6a1c; margin-top: 2px; }
.nudge-ico { font-size: 1.6rem; }
.nudge-ok { background: var(--venda-bg); border-color: #BFE9DC; cursor: default; }
.nudge-ok b { color: #075e4b; } .nudge-ok small { color: #2f7a66; }
.barras { list-style: none; margin: 0; padding: 0; }
.barras li { display: grid; grid-template-columns: 7.5em 1fr auto; gap: 8px; align-items: center; margin: 8px 0; font-size: .9rem; }
.barra-fina { height: 9px; }
.barras b { white-space: nowrap; }

/* lista */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li + li { margin-top: 8px; }
.lista-compacta li + li { margin-top: 4px; }
.item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; background: #fff; border: 1px solid var(--borda); border-radius: var(--raio-sm); font: inherit; color: inherit; text-align: left; cursor: pointer; }
.lista-compacta .item { border: 0; padding: 10px 2px; border-bottom: 1px solid var(--borda); border-radius: 0; }
.item-ico { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; flex: none; }
.ico-venda { background: var(--venda-bg); color: var(--venda); } .ico-gasto { background: var(--gasto-bg); color: var(--gasto); }
.item-meio { flex: 1; min-width: 0; }
.item-meio b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meio small { color: var(--suave); font-size: .82rem; }
.item-valor { font-weight: 800; white-space: nowrap; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--roxo-claro); color: var(--roxo); vertical-align: middle; }
.tag-alerta { background: var(--ouro-bg); color: #8a5a00; }
.vazio { text-align: center; padding: 18px 8px; color: var(--suave); }
.filtros .abas { margin-bottom: 12px; }
.abas { display: flex; background: var(--fundo); border-radius: 14px; padding: 4px; }
.abas button { flex: 1; border: 0; background: none; padding: 10px; font: inherit; font-weight: 700; color: var(--suave); border-radius: 11px; cursor: pointer; min-height: 46px; }
.abas button.ativo { background: #fff; color: var(--roxo); box-shadow: var(--sombra); }
.filtros .row-2 + .row-2 { margin-top: 10px; }
.mini-resumo { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline; padding: 4px 4px 12px; font-size: .95rem; }
.mini-resumo span:first-child { font-weight: 800; color: var(--roxo-esc); margin-right: auto; }

/* diálogos */
.dlg { border: 0; padding: 0; border-radius: 20px; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); color: var(--texto); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dlg::backdrop { background: rgba(36, 18, 61, .55); }
.dlg[open] { display: flex; flex-direction: column; }
.dlg > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dlg-topo { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--borda); }
.dlg-topo h2 { margin: 0; font-size: 1.2rem; }
.dlg-corpo { padding: 16px; overflow: auto; flex: 1; }
.dlg-rodape { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--borda); background: #fff; }
.dlg-peq { width: min(420px, calc(100% - 24px)); }
@media (max-width: 600px) {
  .dlg-cheio { width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; margin: 0; }
  .dlg-cheio .dlg-topo { padding-top: calc(14px + env(safe-area-inset-top)); }
}
.modo-venda .dlg-topo { border-bottom: 4px solid var(--venda); }
.modo-gasto .dlg-topo { border-bottom: 4px solid var(--gasto); }
.valor-wrap { display: flex; align-items: center; border: 2px solid var(--borda); border-radius: var(--raio-sm); padding-left: 14px; background: #fff; }
.valor-wrap:focus-within { border-color: var(--roxo-med); box-shadow: 0 0 0 4px rgba(123, 44, 191, .15); }
.valor-wrap span { font-weight: 800; color: var(--suave); font-size: 1.2rem; }
.valor-wrap input { border: 0; box-shadow: none !important; font-size: 1.6rem; font-weight: 800; }
.dica-bruto { margin-top: 8px; background: var(--ouro-bg); border-radius: var(--raio-sm); padding: 8px 12px; font-size: .9rem; }
.dica-bruto summary { cursor: pointer; font-weight: 700; color: #7a5300; }
.dica-bruto p { margin: 8px 0 4px; color: #5e4300; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { margin: 0; font-weight: 600; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; min-height: 46px; padding: 8px 14px; border: 2px solid var(--borda); border-radius: 99px; background: #fff; cursor: pointer; font-size: .95rem; color: var(--texto); }
.chip input:checked + span { background: var(--roxo); border-color: var(--roxo); color: #fff; }
.chip input:focus-visible + span { box-shadow: 0 0 0 4px rgba(123, 44, 191, .25); }
.anexo-botoes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.anexo-btn { margin: 0; font-size: .98rem; padding: 10px; }
.anexos, .anexos-ver { list-style: none; margin: 10px 0 0; padding: 0; }
.anexo { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--borda); border-radius: var(--raio-sm); margin-top: 8px; }
.anexo img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; }
.anexo-ico { width: 52px; height: 52px; display: grid; place-items: center; font-size: 1.6rem; background: var(--fundo); border-radius: 8px; }
.anexo-nome { flex: 1; min-width: 0; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.anexo-nome small { display: block; color: var(--suave); }
.anexos-ver li + li { margin-top: 8px; }
.anexo-abrir { justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detalhe { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 16px; }
.detalhe dt { color: var(--suave); font-size: .9rem; } .detalhe dd { margin: 0; font-weight: 600; word-break: break-word; }
.grande { font-size: 1.35rem; }
.dlg-foto { background: #000; width: 100%; height: 100%; max-width: 100%; max-height: 100%; margin: 0; border-radius: 0; align-items: center; justify-content: center; }
.dlg-foto img { max-width: 100%; max-height: 100%; object-fit: contain; }
.btn-x-claro { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; background: rgba(255, 255, 255, .9); }

/* relatório */
.botoes-rel { display: grid; gap: 10px; margin-top: 14px; }
.rel-cab { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.rel-cab img { border-radius: 50%; }
.rel-cab h2 { margin: 0 0 2px; font-size: 1.15rem; }
.rel-cab p { margin: 0; }
.rel-totais { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.rel-totais div { background: var(--fundo); border-radius: var(--raio-sm); padding: 10px; min-width: 0; }
.rel-totais span { display: block; font-size: .75rem; color: var(--suave); }
.rel-totais b { font-size: 1.1rem; white-space: nowrap; }
.relatorio h3 { margin-top: 18px; }
.tab { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tab th, .tab td { padding: 7px 6px; border-bottom: 1px solid var(--borda); text-align: left; }
.tab thead th { color: var(--suave); font-size: .78rem; }
.tab tfoot th { border-top: 2px solid var(--roxo); }
.tab td:not(:first-child), .tab th:not(:first-child) { text-align: right; }
.tab-lista td, .tab-lista th { text-align: left !important; }
.tab-lista td.num { text-align: right !important; white-space: nowrap; }
.rel-folha { overflow-x: auto; }
.dicas { padding-left: 18px; margin: 0; } .dicas li { margin: 8px 0; }
.versao { margin-top: 18px; }

/* avisos rápidos */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 10000; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--roxo-esc); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 520px; animation: sobe .2s ease-out; }
.toast-erro { background: #9a3009; }
@keyframes sobe { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 480px) {
  .rel-folha { padding: 14px 10px; }
  .tab { font-size: .74rem; }
  .tab th, .tab td { padding: 6px 2px; }
  /* lista do relatório vira "cartõezinhos" no celular */
  .tab-lista thead { display: none; }
  .tab-lista tr { display: grid; grid-template-columns: 5.4em 1fr auto; column-gap: 6px; padding: 7px 0; border-bottom: 1px solid var(--borda); }
  .tab-lista td { border: 0; padding: 0 !important; }
  .tab-lista td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .tab-lista td:nth-child(3) { grid-column: 2; grid-row: 1; font-weight: 600; }
  .tab-lista td:nth-child(7) { grid-column: 3; grid-row: 1; }
  .tab-lista td:nth-child(2) { grid-column: 1; grid-row: 2; color: var(--suave); }
  .tab-lista td:nth-child(4) { grid-column: 2 / 4; grid-row: 2; color: var(--suave); }
  .tab-lista td:nth-child(6) { grid-column: 2 / 4; grid-row: 3; color: var(--suave); }
  .tab-lista td:nth-child(5) { display: none; }
}
@media (min-width: 700px) {
  .botoes-rel { grid-template-columns: repeat(3, 1fr); }
  .acao { min-height: 100px; }
}
/* botão flutuante "Instalar app" (pwa.js) acima do menu */
.fed-instalar { bottom: calc(var(--nav-h) + 18px) !important; }

/* impressão: só a folha do relatório */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 11pt; }
  .topo, .nav, .no-print, #toasts, .faixa, .fed-instalar, dialog, #r-painel, #r-lancamentos, #r-mais { display: none !important; }
  #r-relatorio { display: block !important; }
  .conteudo { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .rel-folha { overflow: visible; }
  .tab { font-size: 9pt; } .tab tr { break-inside: avoid; }
  .rel-totais { grid-template-columns: repeat(3, 1fr); }
  .rel-totais div { border: 1px solid #ccc; }
  .tab-lista thead { display: table-header-group !important; }
  .tab-lista tr { display: table-row !important; }
  .tab-lista td, .tab-lista th { display: table-cell !important; padding: 7px 6px !important; border-bottom: 1px solid #ddd !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
