:root {
  --bg: #F7F6F1;
  --bg-alt: #FFFFFF;
  --surface: #FFFFFF;
  --ink: #16150F;
  --ink-soft: #58554A;
  --primary: #121110;
  --primary-dark: #000000;
  --accent: #F2B705;
  --accent-dark: #C99400;
  --accent-soft: #FBE29A;
  --line: #E4E1D6;
  --radius: 8px;
  --danger: #C0392B;
  --danger-bg: #FBEAE8;
  --success: #1E7A46;
  --success-bg: #E9F6EE;
  --warn: #9A6B00;
  --warn-bg: #FBE29A;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
  font-size: var(--fs, 15px);
  line-height: var(--lh, 1.5);
}

h1, h2, h3 { font-family: "Space Grotesk", sans-serif; font-weight: 600; color: var(--ink); margin: 0 0 6px; }
h1 { font-size: 22px; }
h2 { font-size: 17px; margin-top: 0; }
h3 { font-size: 14px; }

.hidden { display: none !important; }

.logo { display: flex; align-items: center; gap: 10px; font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 16px; color: var(--primary-dark); }
.logo-mark { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary-dark); color: var(--accent); font-size: 13px; font-weight: 700; }
.dot { color: var(--accent-dark); }

/* ---------- LOGIN ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-panel { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 32px; }
.login-panel .logo { margin-bottom: 20px; }
.lead-small { color: var(--ink-soft); font-size: 13.5px; margin: 0 0 20px; }
.hint { color: var(--ink-soft); font-size: 11.5px; margin-top: 16px; line-height: 1.5; }

.field { display: block; margin-bottom: 14px; }
.field-inline { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 13px; color: var(--ink-soft); }
.field-inline input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
input:not([type]), input[type="text"], input[type="search"], input[type="url"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-alt); color: var(--ink); font-family: "IBM Plex Sans", sans-serif; font-size: 14px;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-dark); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn { font-family: "IBM Plex Sans", sans-serif; font-weight: 600; font-size: 13.5px; padding: 10px 18px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; }
.btn-primary { background: var(--btn-bg, var(--accent)); color: var(--btn-ink, var(--primary-dark)); border-color: var(--btn-bg, var(--accent)); }
.btn-primary:hover { background: var(--btn-bg-hover, var(--accent-dark)); border-color: var(--btn-bg-hover, var(--accent-dark)); }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-outline:hover { border-color: var(--ink-soft); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #E8B4AC; }
.btn-success { background: var(--success-bg); color: var(--success); border-color: #A9D4BA; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.input-sm { width: auto; padding: 5px 8px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- APP LAYOUT (barra superior tipo ribbon) ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { background: var(--topbar-bg, var(--primary-dark)); color: var(--topbar-ink, #fff); box-shadow: var(--topbar-sombra, none); flex-shrink: 0; position: sticky; top: 0; z-index: 30; }
.topbar-row1 { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--topbar-linha, rgba(255,255,255,0.08)); }
.topbar-logo { color: var(--topbar-ink, #fff); }
.topbar-logo .logo-mark { background: var(--accent); color: var(--primary-dark); }
.topbar-user { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.user-info { text-align: right; }
.user-name { font-size: 13px; font-weight: 600; color: var(--topbar-ink, #fff); }
.user-role { font-size: 11px; color: var(--topbar-ink-soft, #A8A597); }
.topbar-user .btn-outline { color: var(--topbar-ink-soft, #D8D6CC); border-color: var(--topbar-borda, rgba(255,255,255,0.25)); }
.topbar-user .btn-outline:hover { border-color: var(--topbar-ink, #fff); color: var(--topbar-ink, #fff); }

#nav.ribbon-nav { display: flex; flex-direction: row; flex-wrap: wrap; gap: 3px; padding: 6px 18px; }
.nav-item { display: flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: var(--radius); color: var(--nav-ink, #D8D6CC); font-size: 13px; font-weight: 500; cursor: pointer; border: none; background: none; text-align: left; white-space: nowrap; transition: background .12s ease, color .12s ease; }
.nav-item .nav-icon { font-size: 15px; line-height: 1; }
.nav-item:hover { background: var(--nav-hover-bg, rgba(255,255,255,0.08)); color: var(--nav-hover-ink, #fff); }
.nav-item.active { background: var(--nav-ativo-bg, var(--accent)); color: var(--nav-ativo-ink, var(--primary-dark)); font-weight: 600; box-shadow: var(--nav-ativo-sombra, none); }

.content { flex: 1; padding: 28px 32px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------- tela inicial com icones grandes (home) ---------- */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.icon-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px 10px; cursor: pointer; text-align: center; transition: transform .08s ease, border-color .08s ease; }
.icon-tile:hover { border-color: var(--accent-dark); transform: translateY(-2px); }
.icon-tile .icon-tile-glyph { font-size: 30px; line-height: 1; width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-soft); }
.icon-tile .icon-tile-label { font-size: 12.5px; font-weight: 600; color: var(--ink); }

.toast { position: fixed; top: 18px; right: 18px; padding: 12px 18px; border-radius: var(--radius); font-size: 13.5px; font-weight: 600; z-index: 100; box-shadow: 0 4px 14px rgba(0,0,0,0.12); }
.toast.ok { background: var(--success-bg); color: var(--success); border: 1px solid #A9D4BA; }
.toast.err { background: var(--danger-bg); color: var(--danger); border: 1px solid #E8B4AC; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.section-sub { color: var(--ink-soft); font-size: 13px; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card, 10px); padding: 22px; margin-bottom: 20px; box-shadow: var(--sombra-card, none); }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: var(--fs-th, 11px); text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: var(--td-pad, 10px 10px); border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: var(--linha-hover, transparent); }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge-accent { background: var(--accent-soft); color: var(--accent-dark); }
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-err { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-muted { background: var(--bg); color: var(--ink-soft); border: 1px solid var(--line); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab-btn { white-space: nowrap; padding: 9px 14px; border: none; background: none; font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--aba-ativa, var(--accent)); }

.server-error { display: flex; gap: 8px; background: var(--danger-bg); border: 1px solid #E8B4AC; color: var(--danger); padding: 11px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.server-ok { display: flex; gap: 8px; background: var(--success-bg); border: 1px solid #A9D4BA; color: var(--success); padding: 11px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }

.muted { color: var(--ink-soft); }
.mono { font-family: "Courier New", monospace; font-size: 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-state { color: var(--ink-soft); font-size: 13px; padding: 18px 0; }


/* Campo de busca com sugestoes (autocomplete) - substitui <select> gigante quando a lista tem
   muitos itens (clientes, produtos). Filtra no navegador mesmo, sem ir ao servidor de novo. */
.search-picker { position: relative; }
.sp-input { width: 100%; }
.sp-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); max-height: 280px; overflow-y: auto; }
.sp-list.hidden { display: none; }
.sp-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.sp-item:last-child { border-bottom: none; }
.sp-item:hover { background: var(--bg); }
.sp-item-label { font-size: 13.5px; font-weight: 600; }
.sp-item-sub { font-size: 11.5px; color: var(--ink-soft); margin-top: 1px; }
.sp-empty { padding: 12px; font-size: 12.5px; color: var(--ink-soft); }

.cart-line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cart-line:last-child { border-bottom: none; }
.cart-line .name { flex: 1; font-size: 13.5px; }
.price-matrix td.num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .topbar-row1 { flex-wrap: wrap; padding: 10px 14px; }
  #nav.ribbon-nav { padding: 6px 10px; }
  .content { padding: 20px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .icon-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* ---------- celular: tabelas viram cartoes (2.8.6) ----------
   Cada linha vira um cartao e cada celula mostra o titulo da coluna antes do valor
   (o titulo e copiado do cabecalho por app.js > rotularTabelas). Tabelas com a classe
   "manter-tabela" ficam como estao. */
@media (max-width: 700px) {
  #view table:not(.manter-tabela), #view table:not(.manter-tabela) tbody, #view table:not(.manter-tabela) tr, #view table:not(.manter-tabela) td { display: block; width: 100%; }
  #view table:not(.manter-tabela) thead { display: none; }
  #view table:not(.manter-tabela) tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  #view table:not(.manter-tabela) tr.hidden { display: none; }
  #view table:not(.manter-tabela) td { border: none; padding: 4px 0; text-align: left !important; }
  #view table:not(.manter-tabela) td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin-bottom: 1px; }
  #view table:not(.manter-tabela) td:empty { display: none; }
  #view .row-actions { gap: 6px; }
  #view .row-actions .btn { flex: 1 1 auto; }
  .card { padding: 16px; }
  .section-head { flex-wrap: wrap; gap: 10px; }
}

/* 2.27.2 - novo pedido "tudo intuitivo": foto e preço na pesquisa, carrinho com − / +, total sempre à vista */
.sp-thumb { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 6px; background: #fff; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; overflow: hidden; }
.sp-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sp-right { text-align: right; white-space: nowrap; font-size: 12px; }
.np-preco { font-weight: 700; font-size: 13.5px; }
.np-est { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--bg); color: var(--ink-soft); }
.np-est.ok { background: #DCFCE7; color: #166534; }
.np-est.zero { background: #FEE2E2; color: #991B1B; }
.np-busca-linha { display: flex; gap: 10px; flex-wrap: nowrap; align-items: flex-start; }
@media (max-width: 700px) { .np-busca-linha { flex-wrap: wrap; } }
.np-busca-linha .sp-input { font-size: 15px; padding: 11px 12px; border-width: 2px; }
.np-busca-linha .sp-list { max-height: 420px; }
.np-mais { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 10px; }
.np-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 3px 10px 3px 3px; font-size: 12px; cursor: pointer; }
.np-chip:hover { border-color: var(--accent, #FACC15); }
.np-chip img { width: 24px; height: 24px; object-fit: contain; border-radius: 50%; background: #fff; }
.np-carrinho { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.np-linha { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; background: var(--surface); }
.np-linha.falta { border-color: #FCA5A5; background: #FEF2F2; }
.np-nome { flex: 1 1 auto; min-width: 0; font-size: 13px; }
.np-qtd { display: flex; align-items: center; gap: 4px; }
.np-qtd input { width: 64px; text-align: center; padding: 5px; }
.np-val { min-width: 110px; text-align: right; font-size: 13px; }
.np-total-fixo { display: none; }
.np-total-fixo.ativo { display: flex; position: sticky; bottom: 0; z-index: 30; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 12px 0; padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 2px solid var(--accent, #FACC15); box-shadow: 0 -6px 18px rgba(0,0,0,.08); font-size: 13.5px; }
.np-total-valor { margin-left: auto; text-align: right; }
.np-total-valor b { font-size: 18px; }
@media (max-width: 700px) { .np-linha { flex-wrap: wrap; } .np-val { min-width: 0; } .np-total-fixo.ativo { bottom: 56px; } }
