/* Design system — Gestão de Estoque. No build, no CDN. */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --border: #e3e6ee;
  --text: #1c2233;
  --muted: #667085;
  --primary: #4338ca;
  --primary-600: #3730a3;
  --primary-50: #eef0ff;
  --success: #15803d; --success-bg: #e7f6ec;
  --warning: #b45309; --warning-bg: #fef3dc;
  --danger: #b91c1c; --danger-bg: #fdeaea;
  --info: #0369a1; --info-bg: #e3f2fb;
  --sidebar: #1b1f3b;
  --sidebar-text: #c9cdea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; } h2 { font-size: 1.15rem; margin: 0 0 .5rem; } h3 { font-size: 1rem; margin: 0 0 .5rem; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.1rem 1rem; color: #fff; text-decoration: none !important; }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: #fff; font-weight: 700; letter-spacing: .5px; }
.brand-text { display: flex; flex-direction: column; font-weight: 600; line-height: 1.2; }
.brand-text small { font-weight: 400; color: var(--sidebar-text); font-size: .75rem; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: .5rem .75rem; flex: 1; overflow-y: auto; }
.nav-link { display: flex; align-items: center; gap: .75rem; padding: .7rem .8rem; border-radius: 8px; color: var(--sidebar-text); font-size: .95rem; min-height: 44px; }
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-ico { width: 1.2rem; text-align: center; font-size: .9rem; opacity: .9; }
.sidebar-foot { padding: 1rem 1.1rem; border-top: 1px solid rgba(255, 255, 255, .1); }
.user-box { display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .9rem; color: #fff; }
.user-box form { margin: 0; }
.user-actions { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.user-actions .link-btn { font-size: .85rem; }
.link-btn { background: none; border: 0; color: var(--sidebar-text); cursor: pointer; font: inherit; text-decoration: underline; padding: .25rem; }
.link-btn:hover { color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-title { font-weight: 600; flex: 1; }
.topbar-actions { display: flex; gap: .5rem; }
.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; font-size: 1.3rem; width: 44px; height: 44px; cursor: pointer; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }
.scrim { display: none; }

/* Page */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumbs { font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
.breadcrumbs .sep { margin: 0 .4rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.center-card { max-width: 560px; margin: 3rem auto; text-align: center; }

/* Messages */
.messages { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.alert { padding: .75rem 1rem; border-radius: 8px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bfe3cb; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f2d9a3; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #f3c0c0; }
.alert-info, .alert-debug { background: var(--info-bg); color: var(--info); border-color: #b9dcf0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1.1rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none !important; transition: background .15s, border-color .15s; }
.btn:hover { background: #f0f2f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; } .btn-danger:hover { background: #991b1b; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: .25rem .7rem; font-size: .875rem; }
.btn-block { width: 100%; }
.btn.disabled, .btn:disabled { opacity: .5; pointer-events: none; }
:focus-visible { outline: 3px solid rgba(67, 56, 202, .35); outline-offset: 1px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.form-grid .field { margin-bottom: 0; }
.field label { font-weight: 500; font-size: .9rem; }
.req { color: var(--danger); }
.input, .select { width: 100%; min-height: 44px; padding: .5rem .75rem; border: 1px solid #c9ceda; border-radius: 8px; background: #fff; font: inherit; color: var(--text); }
.input:focus, .select:focus { border-color: var(--primary); outline: 3px solid rgba(67, 56, 202, .2); }
.textarea { min-height: 90px; resize: vertical; }
.help { color: var(--muted); font-size: .8rem; }
.error { color: var(--danger); font-size: .85rem; }
.has-error .input, .has-error .select { border-color: var(--danger); }
.check-label { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; }
.check-label input { width: 20px; height: 20px; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 180px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  /* sombras laterais que só aparecem quando há conteúdo escondido para rolar (dica de rolagem horizontal) */
  background: linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) left center / 40px 100% no-repeat local,
              linear-gradient(to left, var(--surface) 30%, rgba(255,255,255,0)) right center / 40px 100% no-repeat local,
              radial-gradient(farthest-side at 0 50%, rgba(16,24,40,.22), rgba(16,24,40,0)) left center / 12px 100% no-repeat scroll,
              radial-gradient(farthest-side at 100% 50%, rgba(16,24,40,.22), rgba(16,24,40,0)) right center / 12px 100% no-repeat scroll,
              var(--surface); }
.table code { white-space: nowrap; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfd; padding: .75rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8f9fd; }
.table th.num, .table td.num { text-align: right; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* Badges */
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eceef4; color: #475467; white-space: nowrap; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { display: flex; flex-direction: column; gap: .2rem; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); color: var(--text); text-decoration: none !important; }
a.stat-card:hover { background: #f8f9fd; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-hint { color: var(--muted); font-size: .8rem; }
.stat-card.tone-success { border-left-color: var(--success); } .stat-card.tone-warning { border-left-color: var(--warning); }
.stat-card.tone-danger { border-left-color: var(--danger); } .stat-card.tone-info { border-left-color: var(--info); }

/* Pagination */
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1rem 0; flex-wrap: wrap; }
.pagination-info { color: var(--muted); font-size: .9rem; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: linear-gradient(160deg, #1b1f3b, #4338ca); }
.login-card { background: var(--surface); border-radius: 14px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.login-brand { color: var(--text); padding: 0 0 1rem; } .login-brand .brand-text small { color: var(--muted); }

/* Tablet / mobile */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; }
  .app.menu-open ~ .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 10; }
  .menu-toggle { display: inline-grid; place-items: center; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}
@media (max-width: 1180px) {
  .table th, .table td { padding: .6rem .65rem; }
  .table .col-secondary { display: none; }  /* colunas secundárias saem no tablet para a tabela caber */
}
@media (max-width: 1440px) { .pdv-table th, .pdv-table td { padding: .6rem .6rem; } }
@media print { .sidebar, .topbar, .scrim, .no-print { display: none !important; } .app { display: block; } body { background: #fff; } .card { box-shadow: none; } }

/* Tabs (parceiros) e lista de detalhes */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tab { padding: .6rem 1rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.detail-grid dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.detail-grid dd { margin: .15rem 0 0; }

/* PDV (sales) */
.pdv { display: grid; grid-template-columns: minmax(280px, 2fr) minmax(320px, 3fr); gap: 1.25rem; align-items: start; }
/* com a barra lateral aberta (tablet paisagem, 961-1180px) duas colunas deixam o campo do leitor minúsculo */
@media (max-width: 1180px) { .pdv { grid-template-columns: 1fr; } }
.pdv-scan-row { display: flex; gap: .5rem; margin-top: .3rem; flex-wrap: wrap; }
.pdv-scan-row #scan-code { flex: 1 1 14rem; min-width: 12rem; }
.pdv-big { font-size: 1.25rem; min-height: 56px; }
.pdv-qty { width: 5.5rem; flex: none; text-align: right; }
.pdv-price { width: 7.5rem; text-align: right; display: inline-block; }
.pdv-results { margin-top: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.pdv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.pdv-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 8px; }
.pdv-quick { margin-top: .75rem; } .pdv-quick summary { cursor: pointer; font-weight: 500; padding: .4rem 0; }
.pdv-customer { margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.pdv-short td { background: var(--danger-bg); }
.text-danger { color: var(--danger); } .text-warning { color: var(--warning); }
.pdv-summary { margin: 1rem 0; display: flex; flex-direction: column; gap: .6rem; }
.pdv-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.pdv-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: .75rem; border-top: 2px solid var(--border); font-size: 1.1rem; }
.pdv-total strong { font-size: 2.5rem; line-height: 1.1; color: var(--primary); font-variant-numeric: tabular-nums; }
.pdv-finalize { display: flex; flex-direction: column; gap: .5rem; }
.pdv-finish { min-height: 60px; font-size: 1.2rem; }

/* ---- T07: usuário/perfil no menu, painel */
.user-id { display: flex; flex-direction: column; min-width: 0; }
.user-role { font-size: .75rem; opacity: .75; }
.pdv-cta { display: flex; flex-direction: column; gap: .25rem; margin-bottom: 1.25rem; padding: 1.4rem 1.6rem; border-radius: var(--radius); background: var(--primary); color: #fff; text-decoration: none !important; box-shadow: var(--shadow); }
.pdv-cta { width: 100%; border: 0; font: inherit; text-align: left; cursor: pointer; }
.pdv-cta:hover { filter: brightness(1.08); }
.pdv-cta-title { font-size: 1.6rem; font-weight: 700; }
.pdv-cta-sub { opacity: .9; }
.dash-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; align-items: start; }

/* R2: painel em uma coluna em telas médias; SKU nunca quebra no meio. */
@media (max-width: 1100px) { .dash-cols { grid-template-columns: 1fr; } }
.table code { white-space: nowrap; word-break: keep-all; }
