:root {
  --mp-primary: #2F6FED;
  --mp-primary-dark: #2557BE;
  --mp-primary-light: #EAF1FE;
  --mp-success: #1FA97A;
  --mp-success-light: #E6F6EF;
  --mp-danger: #E5484D;
  --mp-danger-light: #FDEAEA;
  --mp-warning: #F2A93B;
  --mp-warning-light: #FEF3E2;
  --mp-surface: #FFFFFF;
  --mp-bg: #F5F7FA;
  --mp-border: #E3E7EC;
  --mp-text: #1B2330;
  --mp-text-muted: #6B7280;
  --mp-radius: 0.6rem;
  --mp-radius-sm: 0.4rem;
  --mp-radius-lg: 1rem;
  --mp-shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --mp-shadow-md: 0 4px 16px rgba(16, 24, 40, .08);
  --mp-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mp-sidebar-width: 248px;
}

* { box-sizing: border-box; }

html, body {
  font-family: var(--mp-font);
  background-color: var(--mp-bg);
  color: var(--mp-text);
  font-size: 15px;
}

a { text-decoration: none; }

h1, h2, h3, h4, h5, h6 { font-weight: 600; color: var(--mp-text); letter-spacing: -.01em; }

/* ---- Botões ---- */
.btn { border-radius: var(--mp-radius-sm); font-weight: 500; padding: .5rem 1rem; transition: background-color .15s ease, border-color .15s ease, transform .05s ease; }
.btn:active { transform: scale(0.98); }
.btn-primary { background-color: var(--mp-primary); border-color: var(--mp-primary); }
.btn-primary:hover, .btn-primary:focus { background-color: var(--mp-primary-dark); border-color: var(--mp-primary-dark); }
.btn-outline-primary { color: var(--mp-primary); border-color: var(--mp-primary); }
.btn-outline-primary:hover { background-color: var(--mp-primary); border-color: var(--mp-primary); }
.btn-success { background-color: var(--mp-success); border-color: var(--mp-success); }
.btn-danger { background-color: var(--mp-danger); border-color: var(--mp-danger); }
.btn:focus, .btn:active:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.2rem var(--mp-primary-light);
  border-color: var(--mp-primary);
}

/* ---- Cards / superfícies ----
   Hierarquia por cor de superfície + borda fina, sem sombra por padrão: a sombra
   é reservada para elementos que realmente flutuam (modais, dropdowns, hover). */
.card {
  border: 1px solid var(--mp-border);
  border-radius: var(--mp-radius);
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.card-header { background-color: var(--mp-surface); border-bottom: 1px solid var(--mp-border); font-weight: 600; padding: .85rem 1.25rem; }
.card-body { padding: 1.25rem; }

a.card:hover { box-shadow: var(--mp-shadow-md); transform: translateY(-2px); border-color: transparent; }

/* ---- Tabelas (mais densas que cards de formulário - é uma ferramenta de trabalho) ---- */
.table { background-color: var(--mp-surface); border-radius: var(--mp-radius); overflow: hidden; margin-bottom: 0; }
.table thead th {
  background-color: var(--mp-bg);
  color: var(--mp-text-muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 700;
  border-bottom: 1px solid var(--mp-border);
  white-space: nowrap;
  padding: .65rem 1rem;
}
.table td { vertical-align: middle; border-color: var(--mp-border); padding: .65rem 1rem; }
.table-hover tbody tr { transition: background-color .1s ease; }
.table-hover tbody tr:hover { background-color: var(--mp-primary-light); }
.sortable-header { color: var(--mp-text-muted); }
.sortable-header.active { color: var(--mp-primary); font-weight: 700; }

/* ---- Form ---- */
.form-control, .form-select { border-radius: var(--mp-radius-sm); border-color: var(--mp-border); }
.form-label { font-weight: 500; font-size: .9rem; }

/* ---- Badges de status ---- */
.badge-ativo { background-color: var(--mp-success-light); color: var(--mp-success); font-weight: 600; }
.badge-inativo { background-color: var(--mp-border); color: var(--mp-text-muted); font-weight: 600; }
.badge-atraso { background-color: var(--mp-danger-light); color: var(--mp-danger); font-weight: 600; }
.badge-alerta { background-color: var(--mp-warning-light); color: var(--mp-warning); font-weight: 600; }

/* ---- Layout autenticado: sidebar fixa + conteúdo ---- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: var(--mp-sidebar-width);
  background-color: var(--mp-surface);
  border-right: 1px solid var(--mp-border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 1030;
}
.app-sidebar-brand { font-size: 1.15rem; font-weight: 700; color: var(--mp-primary); padding: 1.25rem 1.25rem .5rem; }
.app-sidebar .nav-link {
  color: var(--mp-text-muted);
  font-weight: 500;
  border-radius: var(--mp-radius-sm);
  margin: .15rem .75rem;
  padding: .55rem .75rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.app-sidebar .nav-link:hover { background-color: var(--mp-bg); color: var(--mp-text); }
.app-sidebar .nav-link.active { background-color: var(--mp-primary-light); color: var(--mp-primary); }
.app-sidebar .nav-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--mp-text-muted); padding: 1rem 1.25rem .25rem; }
.app-content { margin-left: var(--mp-sidebar-width); flex: 1; min-width: 0; }
.app-topbar {
  background-color: var(--mp-surface);
  border-bottom: 1px solid var(--mp-border);
  padding: .85rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 1020;
}
.app-main { padding: 1.5rem; }

.app-sidebar-overlay { display: none; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .app-sidebar.show { transform: translateX(0); }
  .app-content { margin-left: 0; }
  .app-sidebar-overlay {
    display: block; position: fixed; inset: 0; z-index: 1029;
    background: rgba(16, 24, 40, .45);
    opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
  }
  .app-sidebar-overlay.show { opacity: 1; visibility: visible; }
}

/* ---- Select com busca (combobox) ---- */
.ss-wrapper { position: relative; }
.ss-native { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; margin: 0; padding: 0; border: 0; }
.ss-control { cursor: pointer; display: flex; align-items: center; min-height: calc(1.5em + .75rem + 2px); background-color: var(--mp-surface); }
.ss-control.form-select-sm { min-height: calc(1.5em + .5rem + 2px); }
.ss-control:focus { outline: none; border-color: var(--mp-primary); box-shadow: 0 0 0 0.2rem var(--mp-primary-light); }
.ss-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-label.ss-placeholder { color: var(--mp-text-muted); }
.ss-panel {
  display: none; position: absolute; z-index: 1060; left: 0; right: 0; top: calc(100% + 2px);
  background: var(--mp-surface); border: 1px solid var(--mp-border); border-radius: var(--mp-radius-sm);
  box-shadow: var(--mp-shadow-md); overflow: hidden;
}
.ss-wrapper.open .ss-panel { display: block; }
.ss-search { display: flex; align-items: center; gap: .4rem; padding: .4rem .6rem; border-bottom: 1px solid var(--mp-border); color: var(--mp-text-muted); }
.ss-search .ss-input { border: none; outline: none; flex: 1; background: transparent; color: var(--mp-text); font-size: .9rem; }
.ss-list { max-height: 240px; overflow-y: auto; }
.ss-item { padding: .45rem .75rem; cursor: pointer; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-item:hover { background: var(--mp-bg); }
.ss-item.selected { background: var(--mp-primary-light); color: var(--mp-primary); font-weight: 500; }
.ss-item.disabled { color: var(--mp-text-muted); cursor: not-allowed; text-decoration: line-through; }
.ss-empty { padding: .6rem .75rem; color: var(--mp-text-muted); font-size: .85rem; text-align: center; }

/* ---- Página de autenticação (login/registro) ---- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--mp-primary) 0%, var(--mp-primary-dark) 100%);
  padding: 1.5rem;
}
.auth-card {
  background-color: var(--mp-surface);
  border-radius: var(--mp-radius-lg);
  box-shadow: var(--mp-shadow-md);
  padding: 2.25rem;
  width: 100%;
  max-width: 420px;
}
.auth-brand { font-weight: 700; font-size: 1.4rem; color: var(--mp-primary); margin-bottom: .25rem; }

/* ---- Page header padrão ---- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: .2rem; }
.page-header .text-muted { font-size: .88rem; }

/* ---- Stat cards ----
   .stat-card é a unidade padrão (densidade de painel); .stat-card-hero é usado para
   UM único número que deve dominar a tela (ex.: saldo no dashboard) - tamanho e peso
   bem maiores, não apenas mais um tile igual aos outros. */
.stat-card { background-color: var(--mp-surface); border: 1px solid var(--mp-border); border-radius: var(--mp-radius); padding: 1rem 1.1rem; }
.stat-icon { width: 38px; height: 38px; border-radius: var(--mp-radius-sm); display: flex; align-items: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0; }
.stat-card .stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-label { color: var(--mp-text-muted); font-size: .8rem; font-weight: 500; }

.stat-card-hero {
  background: linear-gradient(135deg, var(--mp-primary) 0%, var(--mp-primary-dark) 100%);
  color: #fff;
  border-radius: var(--mp-radius-lg);
  padding: 1.75rem 2rem;
  box-shadow: var(--mp-shadow-md);
}
.stat-card-hero .stat-label { color: rgba(255,255,255,.85); font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card-hero .stat-value { font-size: 2.5rem; font-weight: 700; letter-spacing: -.02em; }
.stat-card-hero .stat-icon { background-color: rgba(255,255,255,.18); color: #fff; width: 48px; height: 48px; font-size: 1.3rem; }

.stat-icon-primary { background-color: var(--mp-primary-light); color: var(--mp-primary); }
.stat-icon-success { background-color: var(--mp-success-light); color: var(--mp-success); }
.stat-icon-warning { background-color: var(--mp-warning-light); color: var(--mp-warning); }
.stat-icon-danger { background-color: var(--mp-danger-light); color: var(--mp-danger); }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--mp-text-muted); }
.empty-state i { font-size: 2.4rem; opacity: .4; margin-bottom: .75rem; display: block; }

/* ---- Animações leves ---- */
.fade-in { animation: mp-fade-in .18s ease; }
@keyframes mp-fade-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 768px) {
  html { font-size: 16px; }
}

/* ---- Temas por empresa (Configurações) ---- */
body[data-tema="verde"] {
  --mp-primary: #1FA97A; --mp-primary-dark: #178A63; --mp-primary-light: #E6F6EF;
}
body[data-tema="roxo"] {
  --mp-primary: #7C3AED; --mp-primary-dark: #6427CC; --mp-primary-light: #F1E9FE;
}
body[data-tema="laranja"] {
  --mp-primary: #F2780C; --mp-primary-dark: #CC630A; --mp-primary-light: #FEF1E6;
}

/* ---- PDV (Nova venda) ---- */
.pdv { display: grid; grid-template-columns: 1fr 360px; gap: 1rem; align-items: start; }
@media (max-width: 991px) { .pdv { grid-template-columns: 1fr; } }

.pdv-chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
.pdv-chips::-webkit-scrollbar { display: none; }
.pdv-chip { flex: 0 0 auto; white-space: nowrap; border: 1px solid var(--mp-border); background: var(--mp-surface); color: var(--mp-text); border-radius: 999px; padding: .35rem .85rem; font-size: .85rem; cursor: pointer; transition: all .15s ease; }
.pdv-chip:hover { border-color: var(--mp-primary); }
.pdv-chip.ativo { background: var(--mp-primary); border-color: var(--mp-primary); color: #fff; font-weight: 500; }

.pdv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.pdv-produto { border: 1px solid var(--mp-border); border-radius: var(--mp-radius); background: var(--mp-surface); overflow: hidden; cursor: pointer; text-align: left; padding: 0; transition: box-shadow .15s ease, transform .05s ease, border-color .15s ease; display: flex; flex-direction: column; }
.pdv-produto:hover { box-shadow: var(--mp-shadow-md); border-color: var(--mp-primary); }
.pdv-produto:active { transform: scale(.98); }
.pdv-produto:disabled { opacity: .5; cursor: not-allowed; }
.pdv-produto-foto { height: 96px; width: 100%; object-fit: contain; background: var(--mp-bg); padding: 4px; }
.pdv-produto-sem-foto { height: 96px; display: flex; align-items: center; justify-content: center; background: var(--mp-bg); color: var(--mp-text-muted); font-size: 1.6rem; }
.pdv-produto-info { padding: .5rem .6rem; display: flex; flex-direction: column; gap: .15rem; flex-grow: 1; }
.pdv-produto-nome { font-size: .82rem; font-weight: 500; line-height: 1.2; }
.pdv-produto-preco { font-weight: 600; color: var(--mp-primary); font-size: .9rem; }
.pdv-produto-estoque { font-size: .72rem; color: var(--mp-text-muted); }
.pdv-produto-pix { font-size: .74rem; font-weight: 600; color: var(--mp-success); }
.pdv-pix-tag { display: inline-block; margin-left: .35rem; font-size: .6rem; font-weight: 700; text-transform: uppercase; color: #fff; background: var(--mp-success); border-radius: 4px; padding: 0 .3rem; vertical-align: middle; }

.pdv-ticket { position: sticky; top: 1rem; display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.pdv-ticket-itens { flex-grow: 1; overflow-y: auto; padding: .5rem .75rem; min-height: 120px; }
.pdv-ticket-item { display: flex; flex-direction: column; gap: .35rem; padding: .5rem 0; border-bottom: 1px solid var(--mp-border); }
.pdv-ticket-item:last-child { border-bottom: none; }
.pdv-ti-topo { display: flex; align-items: center; gap: .5rem; }
.pdv-ti-nome { flex: 1 1 auto; min-width: 0; font-size: .85rem; font-weight: 500; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdv-ti-total { flex: 0 0 auto; font-weight: 600; white-space: nowrap; }
.pdv-ti-linha2 { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.pdv-qtd { display: inline-flex; align-items: center; border: 1px solid var(--mp-border); border-radius: var(--mp-radius-sm); overflow: hidden; flex: 0 0 auto; }
.pdv-qtd button { width: 26px; height: 28px; border: none; background: var(--mp-bg); color: var(--mp-text); font-weight: 600; line-height: 1; cursor: pointer; }
.pdv-qtd button:hover { background: var(--mp-primary-light); color: var(--mp-primary); }
.pdv-qtd input { width: 34px; height: 28px; border: none; text-align: center; font-size: .82rem; }
/* Impede que os campos encolham (o valor era cortado, ex.: "239.90" virava "239"). */
.pdv-preco-input { width: 112px; flex: 0 0 auto; }
.pdv-preco-input .input-group-text { padding: 0 .4rem; }
.pdv-preco-input input { padding-left: .4rem; padding-right: .4rem; min-width: 0; }
.pdv-desc-input { width: 92px; flex: 0 0 auto; }
.pdv-desc-input .pdv-desc-tipo { padding: 0 .35rem; min-width: 34px; font-size: .78rem; }
.pdv-desc-input input { padding-left: .35rem; padding-right: .35rem; min-width: 0; }
.pdv-ti-remover { border: none; background: none; color: var(--mp-danger); cursor: pointer; padding: 0 .2rem; }
.pdv-ticket-rodape { border-top: 1px solid var(--mp-border); padding: .85rem; background: var(--mp-surface); border-radius: 0 0 var(--mp-radius) var(--mp-radius); }
.pdv-total { font-size: 1.35rem; font-weight: 700; color: var(--mp-primary); line-height: 1.1; }

/* ---- PDV: tela cheia + leitor de código de barras ---- */
#pdvContainer:fullscreen { background: var(--mp-bg); padding: 1rem; overflow: auto; }
#pdvContainer.pdv-cheio .pdv-ticket { max-height: calc(100vh - 2rem); }
#pdvContainer.pdv-cheio #pdvBusca { font-size: 1.05rem; height: calc(2.4rem + 2px); }
.pdv-ticket-item.flash { animation: pdv-flash .7s ease; }
@keyframes pdv-flash {
  0% { background: var(--mp-success-light); }
  100% { background: transparent; }
}
.pdv-toast {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%);
  z-index: 1080; padding: .6rem 1.1rem; border-radius: 999px;
  font-weight: 600; font-size: .95rem; box-shadow: var(--mp-shadow-md);
  pointer-events: none;
}
.pdv-toast-ok { background: var(--mp-success); color: #fff; }
.pdv-toast-erro { background: var(--mp-danger); color: #fff; }

/* ---- Calendário de despesas ---- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cabecalho { margin-bottom: 4px; }
.cal-dow { text-align: center; font-size: .75rem; font-weight: 600; color: var(--mp-text-muted); padding: .25rem 0; }
.cal-celula { min-height: 96px; border: 1px solid var(--mp-border); border-radius: var(--mp-radius-sm); padding: .3rem; background: var(--mp-surface); display: flex; flex-direction: column; gap: .25rem; }
.cal-celula.cal-fora { background: var(--mp-bg); border-style: dashed; opacity: .5; }
.cal-celula.cal-hoje { border-color: var(--mp-primary); box-shadow: 0 0 0 1px var(--mp-primary) inset; }
.cal-celula-topo { display: flex; align-items: center; justify-content: space-between; }
.cal-dia { font-size: .8rem; font-weight: 600; }
.cal-total { font-size: .68rem; color: var(--mp-text-muted); font-weight: 600; }
.cal-itens { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-item { display: block; font-size: .72rem; line-height: 1.25; padding: 1px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; border-left: 3px solid transparent; }
a.cal-item:hover { filter: brightness(.96); }
.cal-pendente { background: var(--mp-warning-light); color: #8a5a00; border-left-color: var(--mp-warning); }
.cal-vencida { background: var(--mp-danger-light); color: #a11; border-left-color: var(--mp-danger); }
.cal-paga { background: var(--mp-success-light); color: #14603f; border-left-color: var(--mp-success); }
.cal-legenda { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.cal-legenda.cal-pendente { background: var(--mp-warning); }
.cal-legenda.cal-vencida { background: var(--mp-danger); }
.cal-legenda.cal-paga { background: var(--mp-success); }
@media (max-width: 575px) {
  .cal-celula { min-height: 68px; }
  .cal-item { font-size: .6rem; }
}
