:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1c2430;
  --text-2: #5b6574;
  --text-3: #8a93a1;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e6f4f2;
  --danger: #c2410c;
  --danger-soft: #fdf0e9;
  --ok: #15803d;
  --ok-soft: #e8f5ec;
  --warn: #a16207;
  --warn-soft: #fdf6e3;
  --info: #1d4ed8;
  --info-soft: #eaf0fd;
  --sidebar: #12201f;
  --sidebar-text: #b9c6c4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; color: #fff; font-weight: 650; font-size: 15px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand small { display: block; color: var(--sidebar-text); font-weight: 400; font-size: 11px; }
.nav-sec { padding: 14px 18px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6f8482; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 18px; margin: 1px 8px; border-radius: 7px; color: var(--sidebar-text); text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.ativo { background: rgba(20, 184, 166, .16); color: #fff; }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; background: #f59e0b; color: #111; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 22px; position: sticky; top: 0; z-index: 20; }
.topbar .titulo { font-weight: 600; font-size: 15px; }
.topbar .espaco { flex: 1; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface); cursor: pointer; position: relative; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 650; font-size: 12px; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow-lg); min-width: 190px; padding: 6px; z-index: 30; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.dropdown button:hover { background: var(--surface-2); }
.content { padding: 22px; max-width: 1360px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .acoes { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head .escolha { flex: none; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #f1c5ae; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { width: 32px; padding: 0; }
.btn svg { width: 16px; height: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field .ajuda { font-size: 11.5px; color: var(--text-3); }
.input, select.input, textarea.input { height: 36px; border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 10px; background: var(--surface); width: 100%; min-width: 0; }
textarea.input { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
.input:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--accent); }
.input-group { display: flex; gap: 6px; }
.input-group .input { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar .field { min-width: 140px; }
.toolbar .busca { flex: 1; min-width: 200px; }

.tabela-wrap { overflow-x: auto; }
table.tabela { width: 100%; border-collapse: collapse; }
.tabela th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tabela td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tabela tr:last-child td { border-bottom: 0; }
.tabela tbody tr.clicavel { cursor: pointer; }
.tabela tbody tr.clicavel:hover td { background: #fafbfc; }
.tabela tr.selecionado td { background: var(--accent-soft) !important; }
.tabela tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
.tabela .acoes-linha { display: flex; gap: 4px; justify-content: flex-end; }
.vazio { padding: 40px 16px; text-align: center; color: var(--text-3); }

.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 12px 10px; cursor: pointer; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.ativo { color: var(--accent); border-bottom-color: var(--accent); }

.thumb { width: 40px; height: 40px; border-radius: 7px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: block; }
.thumb-vazio { width: 40px; height: 40px; border-radius: 7px; background: var(--surface-2); border: 1px dashed var(--border-strong); display: grid; place-items: center; color: var(--text-3); }
.fotos-edit { display: flex; gap: 8px; flex-wrap: wrap; }
.foto-item { position: relative; }
.foto-item img { width: 78px; height: 78px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.foto-item button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #1c2430; color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.foto-add { width: 78px; height: 78px; border-radius: 8px; border: 1px dashed var(--border-strong); display: grid; place-items: center; cursor: pointer; color: var(--text-2); background: var(--surface-2); font-size: 12px; text-align: center; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.kpi { padding: 14px 16px; }
.kpi .rot { font-size: 12px; color: var(--text-2); font-weight: 550; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.barras { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding: 16px 16px 0; }
.barras .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.barras .b span.col { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.barras .b.hoje span.col { background: #14b8a6; }
.barras .b small { font-size: 10.5px; color: var(--text-3); }
.barras-rot { display: flex; gap: 6px; padding: 4px 16px 14px; }
.barras-rot span { flex: 1; text-align: center; font-size: 10.5px; color: var(--text-3); }

/* ---------- venda ---------- */
.venda-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.resumo-venda { position: sticky; top: 72px; }
.linha-total { display: flex; justify-content: space-between; padding: 6px 0; }
.linha-total.grande { font-size: 20px; font-weight: 750; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }
.resultados-busca { border: 1px solid var(--border); border-radius: 8px; max-height: 280px; overflow-y: auto; margin-top: 8px; }
.resultados-busca .res { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.resultados-busca .res:last-child { border-bottom: 0; }
.resultados-busca .res:hover { background: var(--surface-2); }
.escolha { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.escolha button { border: 0; background: var(--surface); padding: 0 14px; height: 34px; cursor: pointer; font-weight: 550; }
.escolha button + button { border-left: 1px solid var(--border-strong); }
.escolha button.ativo { background: var(--accent); color: #fff; }
.bloco { border: 1px solid var(--border); border-radius: 9px; padding: 12px; background: var(--surface-2); }
.combo { position: relative; }
.combo-lista { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; z-index: 40; }
.combo-lista div { padding: 8px 10px; cursor: pointer; }
.combo-lista div:hover, .combo-lista div.foco { background: var(--surface-2); }

/* ---------- modais ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; }
.modal.largo { max-width: 860px; }
.modal.xlargo { max-width: 1180px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.fechar { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-3); }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1c2430; color: #fff; padding: 11px 14px; border-radius: 9px; box-shadow: var(--shadow-lg); max-width: 380px; animation: entra .18s ease-out; }
.toast.erro { background: #9a3412; }
.toast.ok { background: #166534; }
@keyframes entra { from { transform: translateY(8px); opacity: 0; } }

/* ---------- login ---------- */
.login-pag { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 0%, #d7efec 0, transparent 45%), var(--bg); }
.login-box { width: 100%; max-width: 380px; }
.login-box .brand { color: var(--text); padding: 0 0 18px; justify-content: center; }
.login-box .card { padding: 24px; }
.alerta { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alerta.info { background: var(--info-soft); color: var(--info); }
.alerta.erro { background: var(--danger-soft); color: var(--danger); }
.alerta.ok { background: var(--ok-soft); color: var(--ok); }
.alerta.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- catálogo ---------- */
.cat-layout { display: grid; grid-template-columns: 270px 1fr; gap: 16px; }
.cat-preview { background: #dfe3e8; border-radius: 10px; padding: 18px; max-height: 70vh; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.folha { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); position: relative; flex: none; overflow: hidden; }
.folha-in { position: absolute; inset: 0; display: flex; flex-direction: column; }
.folha-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--cat-cor, #0f766e); }
.folha-grid { flex: 1; display: grid; }
.cat-cel { border: 1px solid #e3e6eb; border-radius: 6px; display: flex; flex-direction: column; overflow: hidden; }
.cat-img { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; background: #f6f7f9; }
.cat-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cat-txt { line-height: 1.25; }
.cat-preco { font-weight: 800; color: var(--cat-cor, #0f766e); }
.folha-rodape { color: #8a93a1; display: flex; justify-content: space-between; }

/* ---------- recibo / impressão ---------- */
.recibo { font-family: system-ui, sans-serif; color: #111; max-width: 760px; margin: 0 auto; background: #fff; padding: 28px; }
.recibo h2 { font-size: 18px; }
.recibo table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.recibo th, .recibo td { padding: 6px 4px; border-bottom: 1px solid #ddd; text-align: left; font-size: 12.5px; }
.recibo .tot { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.recibo .tot.big { font-size: 16px; font-weight: 800; border-top: 2px solid #111; margin-top: 4px; padding-top: 8px; }
.recibo .ass { margin-top: 48px; display: grid; grid-template-columns: 1fr 1fr; gap: 40px; text-align: center; font-size: 12px; }
.recibo .ass div { border-top: 1px solid #111; padding-top: 6px; }
#area-impressao { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body > *:not(#area-impressao) { display: none !important; }
  #area-impressao { display: block !important; }
  .recibo { padding: 0; max-width: none; }
}

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .venda-grid { grid-template-columns: 1fr; }
  .resumo-venda { position: static; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.aberta { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px; }
  .topbar { padding: 0 14px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .cat-layout { grid-template-columns: 1fr; }
  .user-chip .nome-user { display: none; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .modal-fundo { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
}
