/* Mercadinho Howli — Estilo único, mobile-first */

:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --border: #e8e6df;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --primary: #1a1a1a;
  --primary-fg: #ffffff;
  --accent: #ff7a45;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #ca8a04;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0e;
    --surface: #1a1a18;
    --border: #2b2b28;
    --text: #f3f3f0;
    --text-muted: #9a9a93;
    --primary: #f3f3f0;
    --primary-fg: #0f0f0e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 140px; /* espaço pro carrinho fixo */
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-top: 8px;
}
.header h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header .sub { color: var(--text-muted); font-size: 14px; }

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: transform .05s, opacity .15s;
  text-decoration: none;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}
.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; }
.btn-lg { padding: 16px 20px; font-size: 17px; }

/* Inputs */
.input, .select, textarea {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.input:focus, .select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field { margin-bottom: 14px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

/* Pessoa selector */
.person-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.person-picker .label { margin: 0; flex-shrink: 0; }
.person-picker select { flex: 1; border: none; background: transparent; font-weight: 600; font-size: 16px; padding: 4px 0; }

/* Grid de produtos */
.products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.product {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
  position: relative;
}
.product.out { opacity: 0.5; }
.product .emoji { font-size: 36px; line-height: 1; }
.product .name { font-weight: 600; font-size: 15px; line-height: 1.3; }
.product .price { color: var(--text-muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.product .stock-tag {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.product .stock-tag.low { color: var(--warning); border-color: var(--warning); }
.product .stock-tag.out { color: var(--danger); border-color: var(--danger); }

.qty-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  gap: 6px;
}
.qty-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.qty-btn:active { transform: scale(0.92); }
.qty-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.qty-value { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; min-width: 24px; text-align: center; }

/* Carrinho fixo */
.cart-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--primary);
  color: var(--primary-fg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 100;
  transform: translateY(100%);
  transition: transform .25s ease;
  box-shadow: 0 -4px 16px rgba(0,0,0,.1);
}
.cart-bar.visible { transform: translateY(0); }
.cart-info { display: flex; flex-direction: column; }
.cart-count { font-size: 12px; opacity: 0.7; }
.cart-total { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cart-bar .btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Vendas / histórico */
.sale {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.sale-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.sale-date { color: var(--text-muted); font-size: 13px; }
.sale-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.sale-items { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: rgba(22,163,74,.12); color: var(--success); }
.badge-warning { background: rgba(202,138,4,.12); color: var(--warning); }
.badge-danger { background: rgba(220,38,38,.12); color: var(--danger); }

/* Saldo grande */
.balance {
  text-align: center;
  padding: 28px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.balance-label { color: var(--text-muted); font-size: 14px; margin-bottom: 6px; }
.balance-value { font-size: 38px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.balance-value.zero { color: var(--success); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-backdrop.visible { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
}

/* QR Code */
.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 12px;
}
.qr-wrap canvas, .qr-wrap img {
  border-radius: var(--radius-sm);
  background: white;
  padding: 12px;
}
.pix-code {
  width: 100%;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  word-break: break-all;
  user-select: all;
}

/* Filtros / abas */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  flex: 1;
  padding: 8px 14px;
  border-radius: 99px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.tab.active {
  background: var(--primary);
  color: var(--primary-fg);
}

/* Admin tabela */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 14px;
}
.table th, .table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--bg);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.table tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty .emoji { font-size: 48px; margin-bottom: 10px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translate(-50%, 100px);
  background: var(--primary);
  color: var(--primary-fg);
  padding: 12px 20px;
  border-radius: 99px;
  box-shadow: var(--shadow);
  z-index: 300;
  transition: transform .25s ease;
  font-size: 14px;
  font-weight: 500;
}
.toast.visible { transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--success); color: white; }

/* Utilidades */
.row { display: flex; gap: 10px; align-items: center; }
.row.space { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Banner modo demo */
#demo-banner {
  background: #fef3c7;
  color: #78350f;
  padding: 10px 16px;
  text-align: center;
  font-size: 13px;
  border-bottom: 1px solid #fcd34d;
  position: sticky;
  top: 0;
  z-index: 50;
}
#demo-banner code {
  background: rgba(0,0,0,.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
}
#demo-banner .demo-reset {
  margin-left: 8px;
  background: rgba(0,0,0,.1);
  border: none;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}
#demo-banner .demo-reset:hover { background: rgba(0,0,0,.2); }
@media (prefers-color-scheme: dark) {
  #demo-banner { background: #422006; color: #fbbf24; border-bottom-color: #78350f; }
}

/* Banner de instalação PWA */
#install-banner {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 150;
  animation: slideUp .25s ease;
}
#install-banner span { flex: 1; font-size: 14px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

/* Busca */
.search-input {
  font-size: 15px;
}

/* Chips de categoria */
.cat-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 12px;
  margin: 0 -16px 4px;
  padding-left: 16px; padding-right: 16px;
  scrollbar-width: none;
}
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all .15s;
}
.cat-chip.active {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}

/* Foto do produto */
.product-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg);
}

/* Thumbnail (tabela admin) */
.thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

/* Nota no card de saldo */
.balance-note {
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 99px;
  display: inline-block;
}

/* Alerta */
.alert {
  background: #fef3c7;
  color: #78350f;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert a { color: inherit; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .alert { background: #422006; color: #fbbf24; border-color: #78350f; }
}

/* Dashboard cards */
.dash-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (min-width: 640px) {
  .dash-cards { grid-template-columns: repeat(4, 1fr); }
}
.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.dash-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.dash-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.chart-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}
.chart-box {
  position: relative;
  height: 260px;
  width: 100%;
}
