:root {
  --color-green: #2e7d32;
  --color-green-bg: #e8f5e9;
  --color-orange: #e65100;
  --color-orange-bg: #fff3e0;
  --color-red: #c62828;
  --color-red-bg: #ffebee;
  --color-text: #212121;
  --color-muted: #6b6b6b;
  --color-border: #e0e0e0;
  --tabbar-height: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--color-text);
  background: #fafafa;
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
}

.app-header {
  padding: 16px;
  background: var(--color-green);
  color: white;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
}

main {
  padding: 16px;
}

.tab {
  display: none;
}

.tab--active {
  display: block;
}

h2 {
  margin-top: 0;
}

.hint {
  color: var(--color-muted);
  font-size: 14px;
}

/* --- Barra de sessão de compra --- */
.session-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: #1b5e20;
  color: white;
  font-size: 14px;
}

.session-actions {
  display: flex;
  gap: 8px;
}

.btn-chip {
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  background: white;
  color: var(--color-green);
  cursor: pointer;
}

.btn-chip--ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: white;
}

/* --- Resumo da compra (overlay) --- */
.summary-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.summary-panel {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: white;
  border-radius: 16px 16px 0 0;
  padding: 20px;
}

.summary-panel h2 {
  margin-top: 0;
}

.summary-average {
  text-align: center;
  font-size: 40px;
  font-weight: bold;
  padding: 12px;
  border-radius: 12px;
  background: #f0f0f0;
  color: var(--color-muted);
}

.summary-average.green {
  background: var(--color-green-bg);
  color: var(--color-green);
}

.summary-average.orange {
  background: var(--color-orange-bg);
  color: var(--color-orange);
}

.summary-average.red {
  background: var(--color-red-bg);
  color: var(--color-red);
}

.summary-counts {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 12px 0;
}

.summary-counts .badge {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 14px;
}

.summary-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}

.summary-item {
  border-left: 4px solid var(--color-border);
  padding: 6px 10px;
  font-size: 14px;
  background: #fafafa;
  border-radius: 6px;
}

.summary-item.green {
  border-left-color: var(--color-green);
}

.summary-item.orange {
  border-left-color: var(--color-orange);
}

.summary-item.red {
  border-left-color: var(--color-red);
}

.summary-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.summary-buttons .btn {
  margin: 0;
}

/* --- Scanner --- */
.reader {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.scan-status {
  text-align: center;
  color: var(--color-muted);
  margin: 12px 0;
}

.scan-card {
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
  border: 2px solid var(--color-border);
}

.scan-card.green {
  background: var(--color-green-bg);
  border-color: var(--color-green);
}

.scan-card.orange {
  background: var(--color-orange-bg);
  border-color: var(--color-orange);
}

.scan-card.red {
  background: var(--color-red-bg);
  border-color: var(--color-red);
}

.scan-card h3 {
  margin: 0 0 4px;
}

.scan-card .brand {
  color: var(--color-muted);
  margin: 0 0 8px;
}

.scan-card .score {
  font-size: 32px;
  font-weight: bold;
}

.scan-card .badges {
  display: flex;
  gap: 8px;
  margin: 8px 0;
  flex-wrap: wrap;
}

.scan-card .badge {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
}

.scan-card .ingredients {
  font-size: 13px;
  color: var(--color-muted);
  margin-top: 8px;
}

.badge-list {
  background: rgba(46, 125, 50, 0.15) !important;
  color: var(--color-green);
  font-weight: 600;
}

.badge-outside {
  background: rgba(0, 0, 0, 0.1) !important;
  color: var(--color-muted);
}

/* --- Botões --- */
.btn {
  display: block;
  width: 100%;
  max-width: 480px;
  margin: 12px auto 0;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.btn--primary {
  background: var(--color-green);
  color: white;
}

.btn--secondary {
  background: white;
  border: 2px solid var(--color-border);
  color: var(--color-text);
}

.btn--danger {
  background: white;
  border: 2px solid var(--color-red);
  color: var(--color-red);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.hidden {
  display: none !important;
}

/* --- Dispensa (fonte grande, alvo de toque grande - acessibilidade) --- */
.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dispensa-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 16px;
}

.dispensa-item .nome {
  flex: 1;
  font-size: 20px;
  font-weight: 600;
}

.dispensa-item .qtd {
  width: 56px;
  text-align: center;
  font-size: 28px;
  font-weight: bold;
}

.dispensa-item button {
  width: 56px;
  height: 56px;
  font-size: 28px;
  font-weight: bold;
  border: none;
  border-radius: 50%;
  background: var(--color-green);
  color: white;
  cursor: pointer;
}

.dispensa-item button.minus {
  background: var(--color-red);
}

/* --- Lista de compras --- */
.compra-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 17px;
}

.compra-item-linha {
  display: flex;
  align-items: center;
  gap: 10px;
}

.compra-item .check-icon {
  font-size: 18px;
  border: none;
  background: none;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.compra-item .compra-nome {
  flex: 1;
}

.compra-item strong {
  color: var(--color-green);
}

.compra-item--checked {
  background: var(--color-green-bg);
  border-color: var(--color-green);
}

.compra-item--checked .compra-nome {
  text-decoration: line-through;
  color: var(--color-muted);
}

.compra-item .badge {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.compra-item .badge.green {
  background: var(--color-green-bg);
  color: var(--color-green);
}

.compra-item .badge.orange {
  background: var(--color-orange-bg);
  color: var(--color-orange);
}

.compra-item .badge.red {
  background: var(--color-red-bg);
  color: var(--color-red);
}

.compra-scan-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--color-green-bg);
  font-size: 18px;
  cursor: pointer;
}

/* Seletor de quantidade pequeno: pra marcar "só achei 2 de 3" antes de confirmar. */
.compra-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 46px; /* alinha com o nome do produto, depois do checkbox */
}

.stepper-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  background: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.stepper-valor {
  min-width: 18px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.stepper-add {
  margin-left: 6px;
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  background: var(--color-green);
  color: white;
  cursor: pointer;
}

.empty-msg {
  text-align: center;
  color: var(--color-muted);
  padding: 32px 0;
}

/* --- Lista Padrão (cadastro de produtos) --- */
.produto-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.produto-form input {
  flex: 1 1 140px;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.produto-form input#input-produto-meta {
  flex: 0 1 90px;
}

.produto-form .btn {
  flex: 1 1 100%;
  margin: 0;
}

.produto-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 14px 16px;
}

.produto-item .produto-nome {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}

.produto-item .produto-meta {
  color: var(--color-muted);
  font-size: 14px;
}

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

.produto-item .produto-actions button {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.reset-section {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}

/* --- Tab bar --- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tabbar-height);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: white;
  border-top: 1px solid var(--color-border);
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  color: var(--color-muted);
  cursor: pointer;
}

.tab-btn--active {
  color: var(--color-green);
  font-weight: 600;
}

.tab-icon {
  font-size: 20px;
}
