/**
 * pdv.css — PDV usando o design system do painel administrativo CRA
 * Tokens, sidebar, topbar, botões, badges, toasts = idênticos ao admin
 * Componentes específicos do PDV (scanner, carrinho, estoque) = extras
 */

/* ── Tokens (idênticos ao admin) ─────────────────────────── */
:root {
  color-scheme: light;
  --bg: #fffdf8;
  --surface: #f5f1e9;
  --surface-strong: #ede7da;
  --fg: #191816;
  --muted: #6f6c65;
  --faint: #9a968c;
  --border: rgba(25, 24, 22, 0.14);
  --border-strong: rgba(25, 24, 22, 0.26);
  --accent: #9f2721;
  --accent-deep: #741b17;
  --accent-hover: #872019;
  --on-accent: #fffdf8;
  --olive: #596047;
  --olive-bg: #eef0e8;
  --green: #596047;
  --green-bg: #eef0e8;
  --red: #9f2721;
  --red-bg: #fae8e7;
  --amber: #a16207;
  --amber-bg: #fef9e7;
  --shadow-sm: 0 1px 2px rgba(25, 24, 22, 0.05);
  --shadow-lg: 0 24px 48px -12px rgba(25, 24, 22, 0.22);
  --topbar-bg: #fffdf8;
  --radius: 8px;
  --radius-lg: 12px;
  --font-display: 'Manrope', system-ui, -apple-system, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
svg { display: block; }
img { display: block; max-width: 100%; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.02em; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Scrollbars (como admin) */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 7px; height: 7px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 1.5px solid transparent; background-clip: content-box; }

/* ── App shell (grid como admin) ─────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}
.main {
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}
.content {
  padding: 28px 32px 56px;
  max-width: 1280px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  flex: 1;
}

/* ── Sidebar (idêntica ao admin) ─────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 20px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  overflow: hidden;
  display: block; flex: none;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-word {
  display: grid;
  line-height: 1;
}
.brand-word b {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-word span {
  margin-top: 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--muted);
  text-transform: uppercase;
}
.nav {
  display: grid;
  gap: 3px;
  margin: 8px -16px 0;
  padding: 0 16px;
  flex: 1;
  min-height: 0;
  align-content: start;
  align-self: stretch;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-label {
  padding: 0 10px;
  margin: 10px 0 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 11px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.16s, color 0.16s;
}
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--surface); color: var(--fg); }
.nav-link.active {
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  position: relative;
}
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.sidebar-foot {
  margin-top: auto;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: grid;
  gap: 10px;
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius);
}
.user-card:hover { background: var(--surface); }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 12px; font-weight: 600;
  flex: none;
}
.user-card .u-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.user-card .u-role { font-size: 11.5px; color: var(--muted); line-height: 1.2; }

/* ── Topbar (idêntica ao admin) ──────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .page-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.topbar .page-crumb { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius);
  display: grid; place-items: center;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--fg); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: none; }

/* ── Net badge ───────────────────────────────────────────── */
.net-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
}
.net-badge.online { background: oklch(0.92 0.06 145); color: oklch(0.42 0.14 145); }
.net-badge.offline { background: var(--red-bg); color: var(--red); }
.net-badge.local { background: oklch(0.93 0.04 250); color: oklch(0.45 0.12 250); }
.net-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ── Buttons (idênticos ao admin) ────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-soft {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-soft:hover { background: var(--surface-strong); }
.btn-ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 6px;
  display: grid; place-items: center;
  color: var(--muted);
}
.btn-icon:hover { background: var(--surface); color: var(--fg); }

/* ── Badge ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-danger { background: var(--red-bg); color: var(--red); }

/* ── Toast (idêntico ao admin) ───────────────────────────── */
.toast-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
}
.toast-error { background: var(--red); color: var(--on-accent); }
.toast-warn { background: var(--amber); color: #fff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   PDV — Layout principal (scanner + carrinho)
   ============================================================ */
.pdv-layout {
  display: grid;
  grid-template-columns: 1fr 440px;
  gap: 20px;
  min-height: calc(100vh - 120px);
}

/* ============================================================
   MODALS & BACKDROPS (estilo admin)
   ============================================================ */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(25, 24, 22, 0.44);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.backdrop.open {
  display: flex;
  animation: backdropIn 0.2s ease;
}
@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.backdrop.right {
  justify-content: flex-end;
  padding: 0;
}
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 0;
}
.modal-head h3 {
  font-size: 17px;
  font-weight: 600;
}
.modal-head .sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 3px;
}
.modal-body {
  padding: 20px 24px 24px;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 24px;
}

/* ── Form fields (estilo admin) ──────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.field {
  display: grid;
  gap: 6px;
}
.field.full {
  grid-column: 1 / -1;
}
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field .input,
.field .select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  background: var(--bg);
  color: var(--fg);
  transition: border-color 0.15s;
}
.field .input:focus,
.field .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(159, 39, 33, 0.1);
}
.field .input.invalid {
  border-color: var(--red);
}
.field-error {
  font-size: 11.5px;
  color: var(--red);
  display: none;
}
.field.has-error .field-error {
  display: block;
}

/* ── Pills (estilo admin) ────────────────────────────────── */
.pill-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.pill {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.pill:hover {
  background: var(--surface-strong);
  color: var(--fg);
}
.pill.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

/* ── Scanner bar ─────────────────────────────────────────── */
.scan-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.scan-wrap { position: relative; flex: 1; }
.scan-bar input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: .03em;
  background: var(--bg);
  color: var(--fg);
  transition: border-color .15s;
}
.scan-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(159, 39, 33, 0.1);
}
.scan-bar input::placeholder { color: var(--faint); font-weight: 400; letter-spacing: 0; font-family: var(--font-body); }

/* ── Search results dropdown ─────────────────────────────── */
#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}
#search-results.visible { display: block; }
.sr-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: none;
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--surface); }
.sr-name { flex: 1; font-size: 13.5px; font-weight: 600; }
.sr-price { font-family: var(--font-display); font-weight: 700; font-size: 14px; color: var(--accent); }
.sr-ean { font-size: 11px; color: var(--muted); }
.sr-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── Camera reader ───────────────────────────────────────── */
#camera-reader {
  display: none;
  margin-bottom: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--accent);
}
#camera-reader.active { display: block; }

/* ── Carrinho ────────────────────────────────────────────── */
.cart-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
}
.cart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.cart-head h2 { font-family: var(--font-display); font-size: 15px; font-weight: 700; }
.cart-head .cart-count { font-size: 12px; color: var(--muted); }
.cart-scroll { flex: 1; overflow-y: auto; }
.cart-scroll table { width: 100%; border-collapse: collapse; }
.cart-scroll th {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
}
.cart-scroll td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.cart-prod-name { font-weight: 600; font-size: 13px; }
.cart-prod-ean { font-size: 11px; color: var(--muted); margin-top: 2px; }
.cart-qty { white-space: nowrap; text-align: center; }
.qty-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--fg);
}
.qty-btn:hover { background: var(--surface-strong); }
.qty-val {
  display: inline-block;
  min-width: 28px;
  text-align: center;
  font-weight: 700;
  font-family: var(--font-display);
}
.qty-input {
  width: 48px;
  height: 28px;
  text-align: center;
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  padding: 0;
  -moz-appearance: textfield;
}
.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.qty-input:focus {
  outline: none;
  border-color: var(--accent);
}
.cart-price { font-family: var(--font-display); font-weight: 600; }
.cart-subtotal { font-family: var(--font-display); font-weight: 700; color: var(--accent); }
.cart-del { text-align: center; }
.del-btn {
  width: 32px; height: 32px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}
.del-btn:hover { background: var(--surface); color: var(--red); }
.del-btn svg { width: 16px; height: 16px; }
.cart-empty td { text-align: center; color: var(--muted); padding: 40px 12px; font-size: 13px; }

/* ── Cart footer ─────────────────────────────────────────── */
.cart-foot {
  border-top: 2px solid var(--fg);
  padding: 14px 18px;
}
.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.cart-total-label { font-size: 14px; font-weight: 600; }
.cart-total-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; }
.pag-group {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.pag-btn {
  flex: 1;
  height: 36px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  transition: all .15s;
}
.pag-btn:hover { background: var(--surface-strong); }
.pag-btn.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.cart-actions { display: flex; gap: 8px; }
.cart-actions .btn { flex: 1; justify-content: center; }

/* ── Success modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.success-card {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 380px;
  width: 90%;
  animation: popIn .3s ease;
}
@keyframes popIn {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.success-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--green-bg);
  color: var(--green);
  display: grid; place-items: center;
  margin: 0 auto 16px;
  font-size: 32px;
}
.success-card h3 { font-family: var(--font-display); font-size: 20px; margin-bottom: 4px; }
.success-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.success-kv {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.success-kv strong { font-family: var(--font-display); }

/* ── Dicas (área vazia do PDV) ───────────────────────────── */
.pdv-tips { color: var(--muted); font-size: 13px; }

/* ============================================================
   ESTOQUE — Layout
   ============================================================ */
.est-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.est-header .search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.est-header .search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--muted);
}
.est-header .search-box input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  background: var(--bg);
  color: var(--fg);
}
.est-header .search-box input:focus { outline: none; border-color: var(--accent); }
.est-header select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
}

.est-table-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.est-table-wrap table { width: 100%; border-collapse: collapse; }
.est-table-wrap th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.est-table-wrap td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.est-table-wrap tr:last-child td { border-bottom: none; }
.row-low { background: var(--red-bg); }
.td-ean { font-family: var(--font-display); font-size: 12px; letter-spacing: .03em; color: var(--muted); }
.td-nome { font-weight: 600; }
.td-cat { color: var(--muted); font-size: 12.5px; }
.td-price { font-family: var(--font-display); font-weight: 600; }
.td-est { font-family: var(--font-display); font-weight: 700; }
.est-low { color: var(--red); }
.td-min { color: var(--muted); font-size: 12px; }
.td-acao { display: flex; gap: 4px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 260px;
    z-index: 200;
    transition: left .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .menu-btn { display: grid; }
  .pdv-layout { grid-template-columns: 1fr; }
  .cart-panel { position: static; max-height: none; min-height: 400px; }
}
@media (max-width: 600px) {
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .scan-bar { flex-direction: column; }
  .scan-bar input { font-size: 16px; }
  .est-header { flex-direction: column; }
  .est-header .search-box { min-width: 100%; }
}
