/* ============================================================
   MERCADO — design tokens (light, neutro, soft)
   ============================================================ */
:root {
  /* Paleta neutra quente */
  --bg: #faf8f4;
  --bg-elev-1: #ffffff;
  --bg-elev-2: #f4f1ec;
  --bg-elev-3: #efeae3;
  --bg-input: #ffffff;
  --border: #e7e2d8;
  --border-strong: #d4cdc0;
  --text: #1c1a17;
  --text-muted: #6b6862;
  --text-dim: #9b968d;

  /* Acento slate sóbrio */
  --accent: #3a5570;
  --accent-hover: #2d4358;
  --accent-soft: rgba(58, 85, 112, 0.08);
  --accent-text: #ffffff;

  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.1);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.1);
  --success: #15803d;
  --success-soft: rgba(21, 128, 61, 0.1);
  --info: #1e40af;
  --info-soft: rgba(30, 64, 175, 0.1);

  /* Categorias com cores sóbrias */
  --cat-mercado: #1e40af;
  --cat-acougue: #991b1b;
  --cat-feira: #15803d;
  --cat-aleatorio: #52525b;

  /* Tipografia */
  --font-display: 'Fraunces', Georgia, serif;
  --font-ui: 'Bricolage Grotesque', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Espaçamento */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-pill: 999px;

  /* Sombras suaves */
  --shadow-sm: 0 1px 2px rgba(28, 26, 23, 0.04);
  --shadow-md: 0 2px 8px rgba(28, 26, 23, 0.06), 0 1px 2px rgba(28, 26, 23, 0.04);
  --shadow-lg: 0 8px 24px rgba(28, 26, 23, 0.1), 0 2px 6px rgba(28, 26, 23, 0.05);

  --nav-height-mobile: 64px;
  --header-height: 56px;
}

/* ============================================================
   Reset + base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

input, select, textarea { -webkit-appearance: none; appearance: none; }
input[type='number'] { -moz-appearance: textfield; }
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============================================================
   Layout
   ============================================================ */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.auth-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--space-6);
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
}

.app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  background: rgba(250, 248, 244, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.app-header h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 144, 'SOFT' 50;
}

.page {
  flex: 1;
  padding: var(--space-5);
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  animation: pageIn 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Bottom nav (mobile) / Side rail (desktop)
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
}

.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: var(--space-2);
  position: relative;
  transition: color 150ms;
}

.bottom-nav button .icon { font-size: 22px; line-height: 1; }

.bottom-nav button.active { color: var(--accent); }

.bottom-nav button.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

/* Bolinha de notificação no nav */
.nav-badge {
  position: absolute;
  top: 6px;
  right: 50%;
  margin-right: -22px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  letter-spacing: 0;
}

/* ============================================================
   Typography
   ============================================================ */
.brand {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 42px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variation-settings: 'opsz' 144, 'SOFT' 50;
  color: var(--text);
}

/* Marca da auth: card simples, sem etiqueta colorida */
.brand-mark {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.brand-mark::after {
  content: '';
  width: 32px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}

h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 100;
  margin-bottom: var(--space-2);
  color: var(--text);
}

h3 {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: var(--space-5);
}

/* ============================================================
   Forms
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-row {
  display: flex;
  gap: var(--space-3);
}
.form-row > * { flex: 1; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='date'],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  transition: border-color 150ms, box-shadow 150ms;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder { color: var(--text-dim); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%236b6862' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.field-help { font-size: 12px; color: var(--text-dim); margin-top: -2px; }
.field-error { font-size: 13px; color: var(--danger); margin-top: -2px; }

.input-prefix { position: relative; }
.input-prefix .prefix {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}
.input-prefix input {
  padding-left: 34px;
  font-family: var(--font-mono);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 11px 18px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
  transition: transform 100ms, background-color 150ms, border-color 150ms, box-shadow 150ms;
  border: 1px solid transparent;
  min-height: 44px;
  font-family: var(--font-ui);
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elev-1);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-elev-2); border-color: var(--border-strong); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-elev-2); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; min-height: 36px; }
.btn-icon { padding: 8px; min-height: 36px; min-width: 36px; }

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: var(--space-3); }

.card-flush { padding: 0; overflow: hidden; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

/* ============================================================
   Hero — agora pra estimativa da lista
   ============================================================ */
.hero {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.hero-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2);
}

.hero-amount {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 42px;
  line-height: 1.05;
  letter-spacing: -0.025em;
  font-variation-settings: 'opsz' 144;
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--text);
}

.hero-amount .currency {
  font-size: 18px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 500;
}

.hero-amount .cents {
  font-size: 20px;
  color: var(--text-muted);
}

.hero-meta {
  margin-top: var(--space-3);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.hero-sub {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

/* ============================================================
   Tabs (categorias) — com badge de contagem
   ============================================================ */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 4px;
  margin-bottom: var(--space-5);
}

.tabs button {
  flex: 1;
  padding: 9px 12px;
  border-radius: var(--r-pill);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tabs button.active {
  background: var(--bg-elev-1);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.tabs button .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bg-elev-3);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.tabs button.active .tab-count {
  background: var(--accent);
  color: var(--accent-text);
}

/* ============================================================
   Item rows (lista de compras, produtos)
   ============================================================ */
.item-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--space-2);
  transition: border-color 150ms, box-shadow 150ms;
  box-shadow: var(--shadow-sm);
}

.item-row:hover { border-color: var(--border-strong); }

.item-row.clickable { cursor: pointer; }

.item-row.checked {
  opacity: 0.55;
  background: var(--bg-elev-2);
  box-shadow: none;
}

.item-row.checked .item-name { text-decoration: line-through; }

.checkbox {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-elev-1);
  transition: all 150ms;
}

.checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox.checked::after {
  content: '';
  width: 6px;
  height: 11px;
  border: solid var(--accent-text);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.item-body {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 500;
  font-size: 15px;
  color: var(--text);
}

.item-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* Bloco destacado de preço/estimativa dentro do item da lista */
.item-pricing {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  flex-shrink: 0;
  min-width: 90px;
}

.item-pricing .estimativa {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.item-pricing .media-info {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  font-family: var(--font-mono);
}

.item-pricing .sem-historico {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
}

.item-price {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.item-actions {
  display: flex;
  gap: 4px;
}

/* ============================================================
   Badges (categorias e status)
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-mercado { background: rgba(30, 64, 175, 0.1); color: var(--cat-mercado); }
.badge-acougue { background: rgba(153, 27, 27, 0.1); color: var(--cat-acougue); }
.badge-feira { background: rgba(21, 128, 61, 0.1); color: var(--cat-feira); }
.badge-aleatorio { background: rgba(82, 82, 91, 0.1); color: var(--cat-aleatorio); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--bg-elev-3); color: var(--text-muted); }

/* ============================================================
   Modal / Sheet
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 26, 23, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  animation: backdropIn 200ms;
}

@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 600px;
  padding: var(--space-6) var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
  animation: sheetIn 280ms cubic-bezier(0.2, 0.9, 0.2, 1);
  box-shadow: var(--shadow-lg);
}

@keyframes sheetIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-handle {
  width: 38px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 999px;
  margin: -8px auto var(--space-5);
}

.modal h2 { margin-bottom: var(--space-4); }

.modal-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.modal-actions .btn { flex: 1; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal {
    border-radius: var(--r-xl);
    border-bottom: 1px solid var(--border);
    padding: var(--space-6);
  }
  .modal-handle { display: none; }
}

/* ============================================================
   Empty states
   ============================================================ */
.empty {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--text-muted);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: var(--space-3);
  opacity: 0.4;
}

.empty p { font-size: 14px; margin-bottom: var(--space-4); }

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 480px;
}

.toast {
  background: var(--bg-elev-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 250ms ease-out;
  pointer-events: auto;
  color: var(--text);
}

.toast.success { border-color: var(--success); background: var(--success-soft); color: var(--success); }
.toast.error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.toast.info { border-color: var(--info); background: var(--info-soft); color: var(--info); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   FAB (botão flutuante mobile)
   ============================================================ */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom) + 12px);
  right: 16px;
  z-index: 40;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 400;
  box-shadow: var(--shadow-lg);
  transition: transform 150ms;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

/* ============================================================
   Stats grid
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.stat {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.stat.highlight .stat-value { color: var(--accent); }

/* ============================================================
   Chart container
   ============================================================ */
.chart-wrap {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  height: 280px;
  position: relative;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   Auth pages
   ============================================================ */
.auth-card {
  width: 100%;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--space-8) var(--space-6);
  box-shadow: var(--shadow-md);
}

.auth-brand {
  text-align: center;
  margin-bottom: var(--space-8);
}

.auth-footer {
  text-align: center;
  margin-top: var(--space-5);
  font-size: 14px;
  color: var(--text-muted);
}

.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--space-5) 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ============================================================
   Spinner
   ============================================================ */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-full {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-12);
  color: var(--text-muted);
}

/* ============================================================
   Utilities
   ============================================================ */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }

.price-cheap { color: var(--success); }
.price-expensive { color: var(--danger); }
.price-fair { color: var(--text); }

/* Linha utilitária pra header de página com botão de ação */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.page-header .titles { flex: 1; min-width: 0; }
.page-header h2 { margin-bottom: 4px; }

/* ============================================================
   Setor (grupos na lista de compras)
   ============================================================ */
.setor-grupo + .setor-grupo {
  margin-top: var(--space-5);
}

.setor-header {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.setor-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--bg-elev-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: none;
  letter-spacing: 0;
}

/* ============================================================
   Item no carrinho (selecionado durante a compra)
   ============================================================ */
.item-row.in-cart {
  background: var(--accent-soft);
  border-color: var(--accent);
  border-left-width: 3px;
}

.item-row.in-cart .item-name {
  color: var(--text);
}

/* ============================================================
   Barra flutuante do carrinho
   ============================================================ */
.cart-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom) + 12px);
  z-index: 45;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--r-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  animation: cartBarIn 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes cartBarIn {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.cart-bar-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.cart-bar-count {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
  letter-spacing: 0.02em;
}

.cart-bar-total {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
}

.cart-bar .btn-primary {
  background: rgba(255, 255, 255, 0.18);
  color: var(--accent-text);
  border: 1px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
}

.cart-bar .btn-primary:hover {
  background: rgba(255, 255, 255, 0.28);
}

@media (min-width: 768px) {
  .cart-bar {
    left: 264px;
    right: 24px;
    bottom: 24px;
    max-width: 720px;
  }
}

/* Quando carrinho está visível, dá folga pra não esconder conteúdo nem botão "+" */
body:has(.cart-bar) .app-shell {
  padding-bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom) + 80px);
}
body:has(.cart-bar) .fab {
  bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom) + 88px);
}

@media (min-width: 768px) {
  body:has(.cart-bar) .app-shell { padding-bottom: 100px; }
  body:has(.cart-bar) .fab { bottom: 100px; }
}

/* ============================================================
   Responsive: desktop vira side rail
   ============================================================ */
@media (min-width: 768px) {
  .page { padding: var(--space-8) var(--space-6); }
  .app-shell { padding-bottom: 0; padding-left: 240px; }
  .app-header { padding-left: 264px; }
  .bottom-nav {
    top: 0;
    bottom: 0;
    right: auto;
    width: 240px;
    height: 100vh;
    flex-direction: column;
    padding: var(--space-5) var(--space-3);
    border-top: none;
    border-right: 1px solid var(--border);
    align-items: stretch;
    background: var(--bg-elev-1);
  }
  .bottom-nav::before {
    content: 'Mercado';
    display: block;
    padding: 0 12px;
    margin-bottom: var(--space-5);
    font-family: var(--font-display);
    font-size: 26px;
    color: var(--text);
    font-weight: 500;
    letter-spacing: -0.02em;
  }
  .bottom-nav button {
    flex: 0;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-3);
    padding: 12px var(--space-3);
    font-size: 14px;
    border-radius: var(--r-md);
  }
  .bottom-nav button.active {
    background: var(--accent-soft);
  }
  .bottom-nav button.active::before { display: none; }
  .bottom-nav button .icon { font-size: 18px; }
  .bottom-nav button .nav-badge {
    position: static;
    margin: 0 0 0 auto;
  }
  /* FAB visível no desktop também — fica no canto inferior direito */
  .fab {
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    font-size: 24px;
  }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

.fade-in { animation: fadeIn 200ms ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
