:root {
  --marrom: #4a3b32;
  --marrom-escuro: #2C1B10;
  --marrom-mais-escuro: #1a0f08;
  --areia: #C4B1A2;
  --areia-clara: #e8e4d9;
  --fundo: #f4f1ea;
  --verde: #2d5a27;
  --verde-escuro: #1e3d1a;
  --vermelho: #8b0000;
  --borda: #d9d2c3;
  --texto: #3a2f27;
  --texto-suave: #7d7366;
  --toque: 44px;
  --sombra: 0 2px 8px rgba(44, 27, 16, .08);
  --sombra-forte: 0 8px 24px rgba(44, 27, 16, .14);
  --raio: 14px;
  --sidebar: 264px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--fundo); color: var(--texto); font-size: 16px; }
.hidden { display: none !important; }

/* ============================================================
   LOGIN
   ============================================================ */
#tela-login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #3d2a1a 0%, #2C1B10 50%, #1a0f08 100%); padding: 20px; }
.card-login { width: 100%; max-width: 400px; background: var(--fundo); border-radius: 22px; padding: 32px 28px 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.40); border: 1px solid rgba(255,255,255,.25); }
form.card-login { margin: 0; }
#logo-login { width: 180px; max-width: 70%; margin: 0 auto; display: block; }
.card-login .subtitulo { text-align: center; color: var(--marrom); font-size: 12px; font-weight: 600; margin-bottom: 10px; }
.card-login input { height: var(--toque); border: 1.5px solid var(--borda); border-radius: 10px; padding: 0 14px; font-size: 16px; background: #fff; }
.card-login input:focus { outline: none; border-color: var(--marrom); box-shadow: 0 0 0 3px rgba(74,59,50,.18); }
.feedback { min-height: 18px; font-size: 13px; text-align: center; color: var(--vermelho); font-weight: 600; }
.lembrar-linha { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--marrom); font-weight: 600; cursor: pointer; }
.lembrar-linha input { width: 16px; height: 16px; accent-color: var(--marrom); }

/* ============================================================
   BOTOES
   ============================================================ */
.btn { height: var(--toque); border: none; border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer; width: 100%; font-family: inherit; }
.btn:active { transform: scale(.98); }
.btn.primario { background: var(--marrom); color: #fff; }
.btn.verde { background: var(--verde); color: #fff; }
.btn.laranja { background: #d97706; color: #fff; }
.btn.perigo { background: var(--vermelho); color: #fff; }
.btn.secundario { background: transparent; color: var(--marrom); border: 2px solid var(--marrom); }
.btn.pequeno { height: 34px; font-size: 13px; border-radius: 8px; padding: 0 12px; width: auto; white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
#app { min-height: 100dvh; display: flex; }
#menu-lateral { position: fixed; top: 0; bottom: 0; left: 0; z-index: 80; width: var(--sidebar); background: linear-gradient(180deg, var(--marrom) 0%, var(--marrom-escuro) 70%, var(--marrom-mais-escuro) 100%); color: #fff; transform: translateX(-100%); transition: transform .24s; display: flex; flex-direction: column; box-shadow: 4px 0 24px rgba(0,0,0,.25); }
#menu-lateral.aberto { transform: translateX(0); }
#logo-menu { padding: 22px 22px 14px; text-align: center; }
#logo-menu img { width: 72px; height: 72px; object-fit: contain; margin: 0 auto 8px; background: rgba(255,255,255,.92); border-radius: 16px; padding: 6px; }
#logo-nome { display: block; font-size: 15px; font-weight: 800; }
.menu-separador { height: 1px; background: rgba(255,255,255,.18); margin: 8px 18px; }
.menu-secao { padding: 18px 22px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 1.4px; color: rgba(255,255,255,.45); }
#menu-lateral a { display: flex; align-items: center; gap: 12px; padding: 13px 22px; font-size: 15px; font-weight: 600; color: #eaf3e8; text-decoration: none; cursor: pointer; border-left: 3px solid transparent; }
#menu-lateral a:hover { background: rgba(255,255,255,.08); }
#menu-lateral a.ativo { background: rgba(255,255,255,.12); border-left-color: var(--areia); color: #fff; }
#menu-lateral a .mi { font-size: 18px; width: 26px; text-align: center; }
.menu-rodape { margin-top: auto; padding: 14px 22px 18px; font-size: 12px; opacity: .75; border-top: 1px solid rgba(255,255,255,.14); word-break: break-all; }
#overlay { position: fixed; inset: 0; z-index: 75; background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .22s; }
#overlay.visivel { opacity: 1; pointer-events: auto; }
#area-principal { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar { position: sticky; top: 0; z-index: 60; height: 56px; background: rgba(244,241,234,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--borda); display: flex; align-items: center; justify-content: space-between; padding: 0 12px; }
#topbar .icone { background: none; border: none; color: var(--marrom); font-size: 22px; width: var(--toque); height: var(--toque); cursor: pointer; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
#titulo-topbar { font-size: 17px; font-weight: 800; color: var(--marrom); }
#conteudo { flex: 1; padding: 12px 10px calc(76px + env(safe-area-inset-bottom)); width: 100%; max-width: 100%; }

/* ============================================================
   BOTTOM NAV (mobile)
   ============================================================ */
#bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 65; height: calc(60px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.97); backdrop-filter: blur(8px); border-top: 1px solid var(--borda); display: flex; padding-bottom: env(safe-area-inset-bottom); }
.bn-item { flex: 1; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--texto-suave); font-size: 20px; cursor: pointer; padding: 2px; }
.bn-item small { font-size: 10px; font-weight: 700; }
.bn-item.ativo { color: var(--marrom); }

/* ============================================================
   CARDS
   ============================================================ */
.cartao { background: #fff; border-radius: var(--raio); padding: 14px 12px; margin-bottom: 12px; box-shadow: var(--sombra); border: 1px solid rgba(217,210,195,.7); }
.cartao h3 { color: var(--marrom); font-size: 15px; margin-bottom: 8px; }
.cartao p { font-size: 14px; line-height: 1.5; }
.muted { color: var(--texto-suave); font-size: 13px; }
.cartao-acoes { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.cartao-acoes .btn { flex: 1; min-width: 110px; }

/* ============================================================
   DASHBOARD GRID
   ============================================================ */
.grid-resumo { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.resumo-item { background: #fff; border-radius: var(--raio); padding: 14px 10px; border: 1px solid rgba(217,210,195,.7); text-align: center; box-shadow: var(--sombra); }
.resumo-item.clicavel { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.resumo-item.clicavel:active { transform: scale(.97); }
.resumo-item .num { font-size: 22px; font-weight: 800; color: var(--marrom); }
.resumo-item .rot { font-size: 11px; color: var(--texto-suave); margin-top: 2px; font-weight: 600; }

/* ============================================================
   LINHAS DE LISTA (NFS-e, Boletos, Orcamentos, Fechamentos)
   ============================================================ */
.linha-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 2px; border-bottom: 1px solid var(--borda); }
.linha-item:last-child { border-bottom: none; }
.linha-item .titulo { font-weight: 700; font-size: 14px; line-height: 1.3; }
.linha-item .sub { font-size: 12px; color: var(--texto-suave); margin-top: 2px; }
.linha-item .acoes { display: flex; gap: 4px; flex-shrink: 0; align-items: center; }

/* ============================================================
   FORMULARIOS
   ============================================================ */
.form-grupo { margin-bottom: 12px; }
.form-grupo label { display: block; font-size: 12px; font-weight: 700; color: var(--marrom); margin-bottom: 4px; }
.form-grupo label .req { color: var(--vermelho); font-weight: 400; font-size: 10px; vertical-align: super; }
.form-grupo input, .form-grupo select, .form-grupo textarea { width: 100%; height: var(--toque); border: 1.5px solid var(--borda); border-radius: 10px; padding: 0 12px; font-size: 16px; background: #fff; font-family: inherit; }
.form-grupo textarea { height: auto; min-height: 80px; padding: 12px; resize: vertical; }
.form-grupo input:focus, .form-grupo select:focus, .form-grupo textarea:focus { outline: none; border-color: var(--marrom); box-shadow: 0 0 0 3px rgba(74,59,50,.15); }
.form-grupo input[readonly] { background: #f5f3ee; color: var(--texto); cursor: default; }
.input { height: var(--toque); border: 1.5px solid var(--borda); border-radius: 10px; padding: 0 12px; font-size: 15px; background: #fff; font-family: inherit; color: var(--texto); }
.input:focus { outline: none; border-color: var(--marrom); box-shadow: 0 0 0 3px rgba(74,59,50,.15); }
.form-secao { font-size: 11px; font-weight: 800; color: var(--marrom-escuro); letter-spacing: .6px; border-bottom: 1px solid var(--borda); padding-bottom: 5px; margin: 16px 0 10px; display: flex; align-items: center; gap: 8px; }
.form-duplo { display: grid; grid-template-columns: 1fr; gap: 0; }
.form-triplo { display: grid; grid-template-columns: 1fr; gap: 0; }
.form-botoes { display: flex; gap: 10px; margin-top: 16px; justify-content: stretch; }
.form-botoes .btn { flex: 1; padding: 0 16px; }
.btn-voltar { background: none; border: none; color: var(--marrom); font-size: 14px; font-weight: 700; cursor: pointer; padding: 8px 4px; margin-bottom: 8px; }
.form-ajuda { font-size: 11px; color: var(--texto-suave); margin-top: 4px; line-height: 1.4; }
.form-novo-cliente { background: #f9f7f2; border: 2px dashed var(--borda); border-radius: 12px; padding: 12px; margin-bottom: 10px; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   TABELAS
   ============================================================ */
.tabela-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -10px; padding: 0 10px; }
.tabela-dados { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela-dados th { text-align: center; padding: 8px 6px; font-size: 11px; font-weight: 700; color: var(--texto-suave); border-bottom: 2px solid var(--borda); white-space: nowrap; }
.tabela-dados td { padding: 8px 6px; border-bottom: 1px solid var(--borda); font-size: 13px; text-align: center; }
.tabela-dados tr.clicavel { cursor: pointer; }
.tabela-itens { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela-itens th { text-align: center; font-size: 11px; font-weight: 700; color: var(--texto-suave); padding: 5px 3px; }
.tabela-itens td { padding: 3px; text-align: center; }
.tabela-itens input { width: 100%; height: 34px; border: 1px solid var(--borda); border-radius: 6px; padding: 0 6px; font-size: 14px; min-width: 60px; }
.tabela-itens input:focus { outline: none; border-color: var(--marrom); }
.tabela-itens .btn-remover { background: none; border: none; color: var(--vermelho); font-size: 18px; cursor: pointer; padding: 4px 6px; }

/* ============================================================
   MODAL / PAINEL
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: flex; align-items: flex-start; justify-content: center; padding: 12px; overflow-y: auto; }
.painel { background: var(--fundo); border-radius: 16px; width: 100%; max-width: 96vw; max-height: 92dvh; overflow-y: auto; padding: 16px 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); margin: auto 0; }
.painel h2 { color: var(--marrom); font-size: 17px; margin-bottom: 14px; }
.painel-full { max-width: 98vw; }

/* ============================================================
   TOAST & SPINNER
   ============================================================ */
#toast { position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--marrom-escuro); color: #fff; padding: 12px 20px; border-radius: 999px; font-size: 13px; font-weight: 600; z-index: 200; box-shadow: var(--sombra-forte); max-width: 90vw; text-align: center; white-space: nowrap; }
.spinner { border: 3px solid var(--areia-clara); border-top-color: var(--marrom); border-radius: 50%; width: 26px; height: 26px; margin: 24px auto; animation: girar .7s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ============================================================
   BADGES
   ============================================================ */
.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.badge.verde { background: #e4efe2; color: var(--verde); }
.badge.marrom { background: #efe7de; color: var(--marrom); }
.badge.vermelho { background: #fce4e4; color: var(--vermelho); }

/* ============================================================
   DESPESAS DASHBOARD
   ============================================================ */
.desp-dash-grid { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.desp-dash-grid > div { flex: 1; min-width: 0; }
.desp-dash-total { background: #dc3545; color: #fff; padding: 10px 14px; border-radius: 10px; margin: 10px 0; font-size: 16px; font-weight: 700; }
.desp-painel { background: #fff; border: 1px solid var(--borda); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.desp-painel-titulo { font-size: 12px; font-weight: 800; letter-spacing: .6px; padding: 10px 14px; border-bottom: 1px solid var(--borda); }
.desp-painel-corpo { padding: 12px 14px; font-size: 14px; font-family: "SF Mono", "Cascadia Code", Consolas, monospace; flex: 1; }
.desp-painel-corpo p { margin: 4px 0; line-height: 1.6; }

/* ============================================================
   CONTROLE DE PERMISSAO (view mode)
   ============================================================ */
body.somente-leitura .acoes .btn:not(.pequeno):not(.btn.pequeno.primario),
body.somente-leitura .btn-acao { display: none !important; }

/* ============================================================
   UTILITARIOS
   ============================================================ */
.text-right { text-align: right; }
.text-center { text-align: center; }

/* Centraliza todas as tabelas (sobrescreve classes inline) */
.tabela-dados td, .tabela-dados th,
.tabela-itens td, .tabela-itens th { text-align: center !important; vertical-align: middle; }

/* ============================================================
   MOBILE EXTRA (telas muito pequenas)
   ============================================================ */
@media (max-width: 600px) {
  .linha-item { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 4px; }
  .linha-item > div:first-child { width: 100%; }
  .linha-item .acoes { flex-wrap: wrap; gap: 6px; justify-content: flex-start; padding-top: 4px; }
  .linha-item .acoes .btn.pequeno { height: 34px; padding: 0 10px; font-size: 12px; }
  .linha-item .titulo { font-size: 14px; }
  .linha-item .sub { font-size: 12px; }
  .badge { font-size: 10px; padding: 3px 8px; }
  .cartao { padding: 14px 12px; }
}
@media (max-width: 380px) {
  .linha-item .acoes .btn.pequeno { height: 30px; padding: 0 6px; font-size: 11px; min-width: auto; }
  .linha-item .titulo { font-size: 13px; }
  .linha-item .sub { font-size: 11px; }
  .badge { font-size: 9px; padding: 2px 6px; }
  .cartao { padding: 12px 10px; }
  .btn { font-size: 15px; }
  .bn-item { font-size: 18px; }
  .bn-item small { font-size: 9px; }
  .tabela-itens th { font-size: 10px; }
  .tabela-itens td { font-size: 12px; }
  .tabela-itens input { font-size: 13px; height: 32px; min-width: 50px; }
  #topbar { height: 50px; padding: 0 10px; }
  #titulo-topbar { font-size: 15px; }
  #conteudo { padding: 10px 6px calc(72px + env(safe-area-inset-bottom)); }
  .painel { max-width: 100vw; padding: 12px 10px; }
  .painel-full { max-width: 100vw; }
}

/* ============================================================
   TABLET / DESKTOP
   ============================================================ */
@media (min-width: 768px) {
  #menu-lateral { transform: translateX(0); }
  #btn-menu { display: none; }
  #overlay { display: none; }
  #bottom-nav { display: none; }
  #area-principal { margin-left: var(--sidebar); }
  .form-duplo { grid-template-columns: 1fr; gap: 0; }
  .form-triplo { grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
  .grid-resumo { grid-template-columns: repeat(3, 1fr); }
  .painel { max-width: 600px; padding: 28px; }
  .painel-full { max-width: 700px; }
  #conteudo { padding: 16px 20px calc(76px + env(safe-area-inset-bottom)); }
  .linha-item .titulo { font-size: 15px; }
  .linha-item .sub { font-size: 12.5px; }
  .desp-dash-grid { flex-direction: row; }
}

@media (min-width: 1024px) {
  #topbar { height: 62px; padding: 0 28px; background: rgba(255,255,255,.88); }
  #conteudo { padding: 24px 32px 40px; max-width: 1240px; margin: 0 auto; }
  .cartao { padding: 20px 22px; border-radius: 16px; margin-bottom: 18px; }
  .grid-resumo { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .resumo-item { padding: 20px 16px; border-radius: 14px; }
  .resumo-item .num { font-size: 28px; }
  .linha-item:hover { background: #faf8f3; }
  .cartao form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; }
  .cartao form > .form-grupo, .cartao form > .form-duplo, .cartao form > .form-triplo { grid-column: span 1; }
  .cartao form > .form-secao, .cartao form > .form-botoes { grid-column: 1 / -1; }
  .form-grupo label { font-size: 12px; letter-spacing: .5px; }
  #toast { bottom: 24px; left: auto; right: 24px; transform: none; }
  .painel { max-width: 800px; }
  .desp-dash-grid { flex-direction: row; }
}

/* Remove as setas dos campos numericos (padrao de uso: digitacao manual) */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
