/* ============================================================
   TOKENS — estrutura extraida do padrao salao/oficina
   (docs/auditoria-2026-08/DESIGN_SYSTEM_REFERENCE.md), valores de
   cor mantidos na marca verde do Master Caixa.
   ============================================================ */
:root {
  /* Marca */
  --brand: #0f5c4d;
  --brand-dark: #0a3f35;
  --brand-light: #e6f2ef;
  --brand-ultra: #f3f9f7;
  --primary: var(--brand);
  --primary-dark: var(--brand-dark);
  --primary-light: var(--brand-light);
  --accent: #178a6f;

  /* Superficies */
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #f7f9f8;

  /* Bordas */
  --border: #dde5e2;
  --border-focus: var(--accent);

  /* Texto */
  --text: #1c2b28;
  --text-2: #4b5a56;
  --text-3: #8a9a95;

  /* Status — par cor forte + fundo claro, contraste AA garantido pelo texto fixo mais escuro */
  --success: #059669; --success-bg: #ecfdf5; --success-light: #d1fae5; --success-text: #065f46;
  --danger: #dc2626;  --danger-bg: #fef2f2;  --danger-light: #fee2e2;  --danger-text: #991b1b;
  --warning: #d97706; --warning-bg: #fffbeb; --warning-light: #fef3c7; --warning-text: #92400e;
  --info: #2563eb;    --info-bg: #eff6ff;    --info-light: #dbeafe;    --info-text: #1e40af;

  /* Dominio financeiro (entrada/saida) — alias semantico sobre success/danger */
  --entrada: var(--success);
  --saida: var(--danger);

  /* Espacamento */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-7: 32px; --space-8: 40px; --space-9: 48px; --space-10: 64px;

  /* Raio, sombra, transicao */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --touch: 44px;
  --shadow-sm: 0 1px 2px rgba(15, 92, 77, .05);
  --shadow: 0 1px 3px rgba(15, 92, 77, .08), 0 1px 2px rgba(15, 92, 77, .04);
  --shadow-lg: 0 8px 24px rgba(15, 92, 77, .12);
  --shadow-xl: 0 20px 60px rgba(15, 92, 77, .16);
  --transition: .15s ease;
  --ring-focus: 0 0 0 4px rgba(15, 92, 77, .18);

  /* Tipografia — corpo sans-serif, titulos serif (mesma hierarquia do salao) */
  --font: 'Outfit', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  /* Campos monetarios — fonte com numeros tabulares reais, padrao ERP financeiro */
  --font-money: 'Inter', var(--font);
  /* Largura fixa de campo monetario: cobe "-R$ 99.999.999.999,99" (21 col) sem cortar */
  --money-w: 236px;

  --sidebar-w: 260px;
  --topbar-h: 64px;
  --z-sidebar: 100;
  --z-modal-backdrop: 900;
  --z-modal: 950;
  --z-toast: 9999;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: .9rem;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0 0 8px; color: var(--primary-dark); }
a { color: var(--accent); text-decoration: none; }
p { margin: 0 0 8px; line-height: 1.6; }

:focus-visible { outline: none; box-shadow: var(--ring-focus); border-radius: var(--radius-sm); }

/* --- Layout --- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark) 0%, #06251f 100%);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: var(--z-sidebar);
}
.sidebar-logo { padding: 20px; font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: .2px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo small { display: block; font-family: var(--font); font-weight: 400; font-size: 11px; opacity: .6; margin-top: 2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-grupo { padding: 14px 20px 6px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; opacity: .35; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: rgba(255,255,255,.7); cursor: pointer;
  font-size: .85rem; font-weight: 600; border-left: 3px solid transparent;
  transition: var(--transition);
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; border-left-color: rgba(255,255,255,.3); }
.nav-item.active { background: rgba(255,255,255,.12); border-left-color: var(--accent); color: #fff; }
.nav-icon { width: 18px; text-align: center; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar-titulo { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; color: var(--primary-dark); }
.topbar-titulo small { display: block; font-family: var(--font); font-weight: 400; font-size: 11px; color: var(--text-3); }
.topbar-user { display: flex; align-items: center; gap: var(--space-3); font-size: .8rem; }
.topbar-user .empresa { color: var(--text-3); font-size: 11px; }
.topbar-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }

.menu-toggle {
  display: none; background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--primary-dark); padding: 4px 6px; flex-shrink: 0; border-radius: var(--radius-sm);
}
.sidebar-backdrop { display: none; }

.content { padding: var(--space-6); flex: 1; min-width: 0; }

/* --- Cards / paineis --- */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow); }
.card + .card { margin-top: var(--space-4); }
.card-titulo { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; color: var(--text); margin-bottom: var(--space-3); }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media screen and (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } }
@media screen and (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
.stat-tile .rotulo { font-size: 11.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.stat-tile .valor {
  font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; color: var(--primary-dark);
  margin-top: 4px; font-variant-numeric: tabular-nums; text-align: right; line-height: 1.25;
}
.stat-tile .valor.entrada { color: var(--entrada); }
.stat-tile .valor.saida { color: var(--saida); }

/* --- Upload de arquivo (Importacao) --- */
.upload-box {
  border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: var(--space-5);
  text-align: center; cursor: pointer; transition: var(--transition); color: var(--text-2);
}
.upload-box:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-box-icone { font-size: 2rem; margin-bottom: 6px; }

.progress-bar { width: 100%; height: 10px; background: var(--surface-2); border-radius: 50px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 50px; transition: width .3s ease; }

/* --- Botoes --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: .65rem 1.3rem; border-radius: var(--radius-sm); border: 1.5px solid transparent;
  font-family: var(--font); font-size: .85rem; font-weight: 700; cursor: pointer;
  background: var(--surface); color: var(--text); border-color: var(--border);
  transition: var(--transition); position: relative; overflow: hidden; white-space: nowrap;
}
.btn::after { content: ''; position: absolute; inset: 0; background: rgba(255,255,255,0); transition: var(--transition); pointer-events: none; }
.btn:hover::after { background: rgba(255,255,255,.1); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: .35rem .85rem; font-size: .75rem; }
.btn-lg { padding: .85rem 1.8rem; font-size: .95rem; border-radius: var(--radius); }
.btn-block { width: 100%; }

.btn-loading { pointer-events: none; color: transparent !important; }
.btn-loading::before {
  content: ''; position: absolute; width: 16px; height: 16px; left: calc(50% - 8px); top: calc(50% - 8px);
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%;
  animation: girar .6s linear infinite;
}
.btn-outline.btn-loading::before, .btn-ghost.btn-loading::before { border-color: rgba(15,92,77,.25); border-top-color: var(--primary); }

/* Acao de linha de tabela — familia compacta, cor por fundo claro */
.btn-row { padding: .28rem .65rem; font-size: .72rem; font-weight: 700; border: none; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; transition: var(--transition); }
.btn-row-edit { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.btn-row-edit:hover { background: var(--border); }
.btn-row-delete { background: var(--danger-bg); color: var(--danger); }
.btn-row-delete:hover { filter: brightness(.96); }
.btn-row-view { background: var(--info-bg); color: var(--info); }
.btn-row-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success); }
.btn-row-success:hover { filter: brightness(.97); }
.row-actions { display: flex; gap: .3rem; justify-content: flex-end; flex-wrap: wrap; }

/* --- Formularios --- */
label { display: block; font-size: .72rem; font-weight: 700; color: var(--text-3); margin-bottom: .3rem; letter-spacing: .01em; }
.form-control {
  width: 100%; min-height: 40px; padding: .5rem .8rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: .875rem; background: var(--surface); color: var(--text); font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.form-control:hover:not(:focus):not([disabled]):not([readonly]) { border-color: var(--border-focus); }
.form-control:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: var(--ring-focus); }
.form-control[readonly], .form-control[disabled] { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.form-control::placeholder { color: var(--text-3); opacity: .7; }
textarea.form-control { min-height: 84px; resize: vertical; line-height: 1.55; }

.form-control.inp-error { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(220,38,38,.15); }
.form-control.inp-shake { animation: shake .3s ease; }
@keyframes shake { 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
.form-error { font-size: .72rem; color: var(--danger); font-weight: 600; margin-top: 4px; display: none; }
.form-error.show { display: block; }

/* Lembrete discreto (nao bloqueia nem exige acao) — ver .form-error acima p/ o caso que bloqueia */
.campo-aviso {
  font-size: .78rem; color: var(--warning-text); background: var(--warning-light);
  border: 1px solid var(--warning); border-radius: var(--radius-sm); padding: .5rem .75rem; margin: 8px 0;
}

.campo { margin-bottom: 14px; }
.campo-linha { display: flex; gap: 12px; }
.campo-linha > .campo { flex: 1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.card-secao { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--primary); margin: 22px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.card-secao:first-of-type { margin-top: 0; }
.lbl-req, label .req, label.required::after { color: var(--danger); margin-left: 2px; font-weight: 700; }
.campo-hint { font-size: 11px; color: var(--text-3); margin-top: 4px; min-height: 14px; }
.campo-hint.ok { color: var(--success); }
.campo-hint.erro { color: var(--danger); }

/* --- Busca --- */
.busca-campo { position: relative; max-width: 320px; width: 100%; }
.busca-campo input { padding-left: 2.1rem; border-radius: 999px; background: var(--surface-2); }
.busca-campo input:focus { background: var(--surface); }
.busca-campo::before { content: '🔍'; position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); font-size: .8rem; opacity: .55; pointer-events: none; }

/* --- Tabelas --- */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.tbl th { text-align: left; padding: .65rem 1rem; background: var(--surface-2); color: var(--text-3); font-weight: 700; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; border-bottom: 2px solid var(--border); white-space: nowrap; }
table.tbl td { padding: .7rem 1rem; border-bottom: 1px solid var(--surface-2); vertical-align: middle; }
table.tbl tbody tr { transition: background var(--transition); }
table.tbl tbody tr:hover { background: var(--brand-ultra); }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-money); font-weight: 600; }
.valor-entrada { color: var(--entrada); font-weight: 700; }
.valor-saida { color: var(--saida); font-weight: 700; }

/* Mobile: tabela vira "mini-ficha" via data-label */
@media screen and (max-width: 768px) {
  .tbl-wrap.tbl-mobile-cards table.tbl thead { display: none; }
  .tbl-wrap.tbl-mobile-cards table.tbl tr { display: block; border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .tbl-wrap.tbl-mobile-cards table.tbl td { display: flex; justify-content: space-between; gap: 10px; padding: .3rem 0; border: none; }
  .tbl-wrap.tbl-mobile-cards table.tbl td::before { content: attr(data-label); font-weight: 700; color: var(--text-3); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
}

/* Perfis e permissoes: lista de perfis + matriz. Modelo espelha o sistema salao
   (rbac-grid) — lista destacada com borda/fundo no perfil ativo, categorias
   agrupadas na matriz, colapsando para 1 coluna no mobile. */
.perfis-grid { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: flex-start; }
.perfil-item {
  display: flex; align-items: center; padding: .55rem .7rem; margin-bottom: .35rem;
  border-radius: 9px; cursor: pointer; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .85rem; font-weight: 600;
  transition: background var(--transition), border-color var(--transition);
}
.perfil-item:hover { background: var(--surface-2); }
.perfil-item.active { border-color: var(--brand); background: var(--brand-ultra); color: var(--brand); }
.perfil-grupo-linha {
  padding: .5rem .85rem .2rem; font-size: .65rem; font-weight: 800; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .1em; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
@media screen and (max-width: 768px) {
  .perfis-grid { grid-template-columns: 1fr; }
}

/* Mobile: lista de fechamentos de caixa em cards (1a linha Data+Status, 2a linha
   Dinheiro/Despesa+Posicao, 3a linha Fichas+Acumulado, 4a linha acoes) */
.caixa-cards-mobile { display: none; }
@media screen and (max-width: 768px) {
  .tbl-desktop-only { display: none; }
  .caixa-cards-mobile { display: block; }
  .caixa-card-mobile { padding: .7rem 1rem; border-bottom: 1px solid var(--border); text-align: left; }
  .caixa-card-mobile > div { margin-bottom: 4px; }
  .caixa-card-mobile-linha { display: flex; justify-content: space-between; gap: 10px; }
  .caixa-card-mobile .row-actions { margin-top: 6px; }
}

/* Boletim de caixa (abas 1-4) — campos monetarios em largura fixa (--money-w cobre
   "-R$ 99.999.999.999,99" sem cortar). Flexbox + wrap encaixa o maximo de campos por
   linha conforme espaco disponivel (Full HD/2K/4K, notebook) e empilha sozinho quando
   um campo de --money-w deixa de caber ao lado de outro — sem precisar de breakpoints
   manuais para a densidade. */
.cx-campos { display: flex; flex-wrap: wrap; gap: var(--space-4); }
.cx-campos > .campo:not(.campo-money) { flex: 1 1 var(--money-w); }
.campo-money, .campo-linha > .campo.campo-money { flex: 0 0 var(--money-w); margin-bottom: 14px; }

.campo-money .form-control,
.form-control[data-mask="moeda"] {
  font-family: var(--font-money);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 16px;
  text-align: right;
  letter-spacing: -.01em;
}

/* Linha dinamica (despesas/estornos): descricao ocupa o espaco restante, valor fica
   com a mesma largura fixa dos demais campos monetarios do boletim. */
.campo-linha { align-items: flex-end; }
.campo-linha > .campo.campo-desc { flex: 1 1 auto; min-width: 160px; }

/* Cards de totais (Sub total / Resultado a transportar / A transportar / Total a
   transportar): espacamento vertical padronizado entre o stat-tile e os campos ao redor. */
.cx-stat { margin: var(--space-3) 0; }

/* Mobile: lista de usuarios em cards compactos (rotulo:valor lado a lado, alinhado a esquerda) */
.usuario-cards-mobile { display: none; }
@media screen and (max-width: 768px) {
  .usuario-cards-mobile { display: block; }
  .usuario-card-mobile { padding: .7rem 1rem; border-bottom: 1px solid var(--border); text-align: left; }
  .usuario-card-mobile > div { margin-bottom: 4px; }
  .usuario-card-mobile-rodape { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
  .usuario-card-mobile-rodape .row-actions { justify-content: flex-end; }
}

/* --- Badges --- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .65rem; border-radius: 50px; font-size: .7rem; font-weight: 700; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success, .badge-entrada { background: var(--success-light); color: var(--success-text); }
.badge-danger, .badge-saida { background: var(--danger-light); color: var(--danger-text); }
.badge-warning, .badge-alerta { background: var(--warning-light); color: var(--warning-text); }
.badge-info { background: var(--info-light); color: var(--info-text); }
.badge-neutro, .badge-neutral { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* --- Abas --- */
.tab-bar { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: var(--space-5); flex-wrap: wrap; }
.tab-btn { padding: .6rem 1.1rem; background: none; border: none; border-bottom: 3px solid transparent; margin-bottom: -2px; font-size: .82rem; font-weight: 700; color: var(--text-3); cursor: pointer; border-radius: var(--radius-sm) var(--radius-sm) 0 0; transition: var(--transition); }
.tab-btn:hover { color: var(--primary); background: var(--primary-light); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- Filtros / paginacao --- */
.filter-bar { display: flex; gap: 10px; align-items: flex-end; margin-bottom: var(--space-4); flex-wrap: wrap; }
.filter-bar .campo { margin-bottom: 0; min-width: 160px; }

.pag-bar { padding: .65rem 1rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; align-items: center; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.pag-bar:first-child { border-top: none; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; margin-bottom: var(--space-3); }
.pag-bar .tm { font-size: .75rem; color: var(--text-3); flex: 1; text-align: center; }
.pag-bar .btn { padding: .3rem .75rem; font-size: .75rem; }
@media screen and (max-width: 480px) {
  .pag-bar { gap: .35rem; flex-wrap: wrap; }
  .pag-bar .tm { order: -1; width: 100%; }
}

/* --- Modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,20,18,.5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: var(--z-modal-backdrop); }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-xl); animation: slideUp .22s ease; z-index: var(--z-modal); }
.modal.modal-lg { max-width: 900px; }
.modal.modal-shake { animation: shake .3s ease; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: var(--space-5) var(--space-5) 0; }
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: var(--space-5); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-3); border-radius: var(--radius-sm); padding: 2px 6px; transition: var(--transition); }
.modal-close:hover { background: var(--danger-bg); color: var(--danger); }

.hidden { display: none !important; }

/* --- CepSearch (public/js/cep-search-modal.js) — modal "Buscar CEP" Estado > Cidade > Logradouro --- */
body.csm-lock { overflow: hidden; }
.cep-input-wrap { position: relative; }
.cep-input-wrap .form-control { padding-right: 42px; }
.csm-trigger {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: none; border-radius: var(--radius-sm);
  background: var(--primary-light); cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center;
}

.csm-overlay { position: fixed; inset: 0; background: rgba(10,20,18,.5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: var(--z-modal-backdrop); }
.csm-box { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-xl); animation: slideUp .22s ease; z-index: var(--z-modal); display: flex; flex-direction: column; }
.csm-header { display: flex; justify-content: space-between; align-items: center; padding: var(--space-5) var(--space-5) 0; }
.csm-title { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--primary-dark); }
.csm-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-3); border-radius: var(--radius-sm); padding: 4px 8px; transition: var(--transition); }
.csm-close:hover { background: var(--danger-bg); color: var(--danger); }

.csm-steps { display: flex; gap: 6px; margin: var(--space-4) var(--space-5) 0; border-bottom: 1px solid var(--border); padding-bottom: var(--space-4); }
.csm-step { flex: 1; text-align: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: .78rem; font-weight: 700; }
.csm-step.active { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.csm-step.done { background: var(--primary-light); border-color: var(--primary-light); color: var(--primary-dark); }

.csm-body { padding: var(--space-5); flex: 1; overflow-y: auto; }
.csm-panel.hidden { display: none; }
.csm-input { width: 100%; box-sizing: border-box; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: .9rem; font-family: inherit; color: var(--text); background: var(--surface); }
.csm-input:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(23,138,111,.15); }

.csm-breadcrumb { font-size: .8rem; color: var(--text-3); margin-bottom: var(--space-3); }

.csm-grid-uf { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; max-height: 360px; overflow-y: auto; margin-top: var(--space-4); padding-right: 4px; }
.csm-uf-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; text-align: left; transition: var(--transition); font-family: inherit; }
.csm-uf-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.csm-uf-sigla { font-weight: 800; color: var(--primary-dark); font-size: .9rem; display: block; }
.csm-uf-nome { font-size: .76rem; color: var(--text-3); display: block; }

.csm-lista { max-height: 360px; overflow-y: auto; margin-top: var(--space-4); display: flex; flex-direction: column; gap: 6px; }
.csm-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; text-align: left; font-family: inherit; font-size: .85rem; color: var(--text); transition: var(--transition); }
.csm-item:hover, .csm-item-hl { border-color: var(--primary); background: var(--primary-light); }
.csm-item mark { background: var(--warning-light); color: var(--text); border-radius: 3px; padding: 0 2px; }
.csm-item-badge { font-size: .7rem; font-weight: 700; color: var(--text-3); flex-shrink: 0; }
.csm-log-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.csm-log-rua { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csm-log-bairro { font-size: .76rem; color: var(--text-3); }
.csm-log-cep { font-weight: 700; color: var(--primary-dark); flex-shrink: 0; }

.csm-msg { text-align: center; padding: 1.5rem 1rem; color: var(--text-3); font-size: .85rem; }
.csm-spin { display: inline-block; animation: girar .9s linear infinite; }

.csm-footer { display: flex; justify-content: flex-end; gap: 10px; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
.csm-btn-voltar, .csm-btn-cancelar { padding: 9px 16px; border-radius: var(--radius-sm); font-size: .84rem; font-weight: 700; cursor: pointer; border: 1px solid transparent; background: transparent; color: var(--text-2); transition: var(--transition); }
.csm-btn-voltar:hover, .csm-btn-cancelar:hover { background: var(--surface-2); }

@media (max-width: 640px) {
  .csm-box { max-width: 100%; max-height: 92vh; }
  .csm-grid-uf { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- Confirm (substitui confirm()/prompt() nativo) --- */
.confirm-overlay { position: fixed; inset: 0; background: rgba(10,20,18,.5); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 99999; }
.confirm-box { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 420px; box-shadow: var(--shadow-xl); padding: var(--space-6); text-align: center; animation: slideUp .22s ease; }
.confirm-icone { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; margin: 0 auto var(--space-3); }
.confirm-icone.danger { background: var(--danger-bg); color: var(--danger); }
.confirm-icone.warning { background: var(--warning-bg); color: var(--warning); }
.confirm-icone.info { background: var(--info-bg); color: var(--info); }
.confirm-titulo { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; color: var(--text); }
.confirm-msg { font-size: .85rem; color: var(--text-2); margin-top: 6px; }
.confirm-campo { margin-top: var(--space-4); text-align: left; }
.confirm-acoes { display: flex; gap: 10px; justify-content: center; margin-top: var(--space-5); }
.confirm-acoes .btn { flex: 1; }

/* --- Toast --- */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: flex-start; gap: .65rem; min-width: 260px; max-width: 380px;
  padding: .8rem .9rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--info);
  box-shadow: var(--shadow-lg); font-size: .82rem; font-weight: 600; color: var(--text);
  opacity: 0; transform: translateX(24px); transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-icon { width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 800; flex-shrink: 0; }
.toast-close { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 14px; padding: 0 0 0 6px; margin-left: auto; flex-shrink: 0; }
.toast.sucesso { border-left-color: var(--success); } .toast.sucesso .toast-icon { background: var(--success-light); color: var(--success-text); }
.toast.erro { border-left-color: var(--danger); } .toast.erro .toast-icon { background: var(--danger-light); color: var(--danger-text); }
.toast.info { border-left-color: var(--info); } .toast.info .toast-icon { background: var(--info-light); color: var(--info-text); }

/* --- Spinner / skeleton / empty state --- */
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: girar .7s linear infinite; margin: 30px auto; }
@keyframes girar { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: skeletonWave 1.5s infinite; border-radius: 6px; }
.skeleton-row { height: 40px; margin-bottom: 8px; }
.skeleton-text { height: 14px; margin-bottom: 6px; }
.skeleton-text.w-60 { width: 60%; }
.skeleton-text.w-80 { width: 80%; }
@keyframes skeletonWave { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.vazio { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty-state { text-align: center; padding: 2.5rem 1.5rem; }
.empty-state .icone { font-size: 2.4rem; }
.empty-state .titulo { font-size: 1rem; font-weight: 700; color: var(--text); margin-top: .5rem; }
.empty-state .msg { font-size: .85rem; color: var(--text-3); max-width: 420px; margin: .35rem auto 0; }
.empty-state .btn { margin-top: 1rem; }

/* --- Auth (login/cadastro) --- */
#auth-root { display: block; width: 100%; flex: 1 1 auto; }
.auth-wrap {
  min-height: 100vh; width: 100%; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--primary-dark), var(--primary));
  padding: 24px;
}
.auth-card {
  background: var(--surface); border-radius: 24px; width: 100%; max-width: 420px;
  padding: 34px 30px; box-shadow: var(--shadow-xl); margin: 0 auto;
}
.auth-card.auth-cadastro { max-width: 720px; }

.auth-icone {
  width: 56px; height: 56px; border-radius: 50%; background: var(--primary-light);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  margin: 0 auto 14px;
}
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .nome { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--primary-dark); }
.auth-logo .sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }

.auth-card .campo label { text-align: left; }
.auth-senha-wrap { position: relative; }
.auth-senha-wrap .form-control { padding-right: 42px; }
.auth-senha-toggle, .pwd-eye {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 15px; padding: 0;
}

.auth-pill-form .form-control { border-radius: 999px; padding: 12px 18px; }
.auth-pill-form .btn-primary { border-radius: 999px; padding: 12px; font-size: 14px; }
.auth-pill-form .btn-outline { border-radius: 999px; padding: 11px; font-size: 13.5px; width: 100%; margin-top: 10px; }

.auth-divisor { display: flex; align-items: center; gap: 10px; margin: 18px 0 4px; color: var(--text-3); font-size: 12px; }
.auth-divisor::before, .auth-divisor::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.auth-erro { background: var(--danger-bg); color: var(--danger-text); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 14px; text-align: center; }
.auth-footer { text-align: center; margin-top: 16px; font-size: 12.5px; color: var(--text-3); }

/* --- Wizard de cadastro de empresa --- */
.wizard-titulo { font-family: var(--font-display); font-size: 20px; font-weight: 800; color: var(--primary-dark); text-align: center; margin: 0; }
.wizard-sub { font-size: 12.5px; color: var(--text-3); text-align: center; margin: 2px 0 20px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }

.wizard-steps { display: flex; align-items: flex-start; justify-content: center; margin-bottom: 24px; }
.wizard-step { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 86px; flex-shrink: 0; }
.wizard-step-num {
  width: 32px; height: 32px; border-radius: 50%; background: var(--bg); color: var(--text-3);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.wizard-step.active .wizard-step-num { background: var(--primary-dark); color: #fff; }
.wizard-step.done .wizard-step-num { background: var(--success); color: #fff; }
.wizard-step-label { font-size: 11px; color: var(--text-3); text-align: center; }
.wizard-step.active .wizard-step-label { color: var(--primary-dark); font-weight: 700; }
.wizard-line { flex: 1 1 auto; height: 2px; background: var(--border); margin-top: 16px; max-width: 50px; }
.wizard-line.done { background: var(--success); }

.wizard-form-titulo { font-family: var(--font-display); font-size: 21px; font-weight: 800; color: var(--primary-dark); margin: 0 0 18px; }

.wizard-secao {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); margin: 22px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.wizard-secao:first-child { margin-top: 0; }

.campo-feedback { font-size: 12px; font-weight: 700; margin-top: 6px; }
.campo-feedback.ok { color: var(--success); }
.campo-feedback.erro { color: var(--danger); }

.campo-cep-wrap { position: relative; }
.campo-cep-wrap .form-control { padding-right: 42px; }
.campo-cep-busca {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: none; border-radius: var(--radius-sm);
  background: var(--primary-light); cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center;
}

.wizard-intro { text-align: center; padding: 10px 6px 4px; }
.wizard-intro .icone { font-size: 40px; margin-bottom: 10px; }
.wizard-intro p { color: var(--text-2); font-size: 13.5px; line-height: 1.6; margin-bottom: 18px; }
.wizard-intro ul { text-align: left; list-style: none; padding: 0; margin: 0 0 22px; font-size: 13px; color: var(--text-2); }
.wizard-intro li { padding: 6px 0; }
.wizard-intro li::before { content: '✓ '; color: var(--success); font-weight: 700; }

/* --- Boletim de caixa (impressao) --- */
.boletim-print { font-family: 'Courier New', monospace; font-size: 11.5px; color: #000; background: #fff; padding: 12px; }
.boletim-print h1 { font-family: 'Courier New', monospace; font-size: 15px; margin: 0; }
.boletim-print .cabecalho { border-bottom: 1px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
.boletim-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.boletim-col { border-top: 1px solid #000; padding-top: 4px; }
.boletim-col h3 { font-family: 'Courier New', monospace; font-size: 12px; margin: 0 0 6px; }
.boletim-linha { display: flex; justify-content: space-between; padding: 1px 0; border-bottom: 1px dotted #ccc; }
.boletim-linha .rotulo { text-transform: uppercase; }
.boletim-linha .valor { font-variant-numeric: tabular-nums; }
.boletim-discriminado { margin-top: 8px; font-size: 11px; }

#print-area { display: none; }

@media print {
  body * { visibility: hidden; }
  #print-area { display: block; visibility: visible; position: absolute; top: 0; left: 0; width: 100%; }
  #print-area * { visibility: visible; }
  .no-print { display: none !important; }
}

/* --- Utilitarios --- */
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; } .flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.texto-3 { color: var(--text-3); }
.small { font-size: 12px; }

/* ============================================================
   RESPONSIVIDADE — breakpoints canonicos: 768 / 640 / 480
   ============================================================ */

@media screen and (max-width: 900px) {
  .menu-toggle { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    width: min(var(--sidebar-w), 80vw);
  }
  .sidebar.aberta { transform: translateX(0); box-shadow: var(--shadow-lg); }

  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(10, 20, 18, .45); z-index: calc(var(--z-sidebar) - 1);
  }
  .sidebar-backdrop.aberta { display: block; }

  .main { margin-left: 0; }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; }
  .topbar-user > div:first-child { display: none; }

  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media screen and (max-width: 768px) {
  .form-control { min-height: 48px; font-size: 16px; border-radius: 10px; }
  .card { border-radius: 12px; padding: .85rem; }
}

@media screen and (max-width: 640px) {
  .content { padding: 12px; }
  .card { padding: 14px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .campo-linha { flex-direction: column; gap: 0; align-items: stretch; }
  .campo-linha > .campo { flex-basis: auto !important; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .campo { min-width: 0; }

  table.tbl { font-size: 12px; }
  table.tbl th, table.tbl td { padding: 8px; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-body { padding: 16px; }

  .auth-wrap { padding: 12px; align-items: flex-start; }
  .auth-card, .auth-card.auth-cadastro { padding: 24px 18px; border-radius: 16px; max-width: 100%; }
  .wizard-steps { gap: 0; }
  .wizard-step { width: 64px; }
  .wizard-step-label { font-size: 9.5px; }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }

  .boletim-cols { grid-template-columns: 1fr; }

  .stat-tile .valor { font-size: 20px; }
}

@media screen and (max-width: 480px) {
  .pag-bar { padding: .5rem .75rem; }
  .btn-row { padding: .24rem .55rem; }
}
