:root {
  --bg: #F7F8F6;
  --surface: #FFFFFF;
  --surface-alt: #EFF1ED;
  --border: #E2E6DF;
  --text: #181A17;
  --text-muted: #5F665C;
  --primary: #2D6A4F;
  --primary-hover: #22513C;
  --primary-soft: rgba(45, 106, 79, 0.12);
  --accent: #D97706;
  --accent-soft: rgba(217, 119, 6, 0.12);
  --danger: #C1121F;
  --danger-soft: rgba(193, 18, 31, 0.10);
  --shadow-sm: 0 1px 2px rgba(24, 26, 23, 0.04);
  --shadow-md: 0 8px 24px rgba(24, 26, 23, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111311;
    --surface: #191C19;
    --surface-alt: #222622;
    --border: #2D332D;
    --text: #F2F4F1;
    --text-muted: #98A095;
    --primary: #52B788;
    --primary-hover: #40916C;
    --primary-soft: rgba(82, 183, 136, 0.16);
    --accent: #F59E0B;
    --accent-soft: rgba(245, 158, 11, 0.16);
    --danger: #F87171;
    --danger-soft: rgba(248, 113, 113, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  --bg: #111311;
  --surface: #191C19;
  --surface-alt: #222622;
  --border: #2D332D;
  --text: #F2F4F1;
  --text-muted: #98A095;
  --primary: #52B788;
  --primary-hover: #40916C;
  --primary-soft: rgba(82, 183, 136, 0.16);
  --accent: #F59E0B;
  --accent-soft: rgba(245, 158, 11, 0.16);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Cabeçalho */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-slot {
  height: 28px;
  display: flex;
  align-items: center;
  color: var(--text);
}

.brand-slot svg {
  height: 28px;
  width: auto;
  display: block;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sync-pill:hover {
  border-color: var(--primary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.status-dot.online { background: var(--primary); }
.status-dot.syncing { background: #3B82F6; animation: pulse 1s infinite; }
.status-dot.offline { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Navegação Desktop */
.desktop-nav {
  display: none;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  gap: 8px;
}

@media (min-width: 768px) {
  .desktop-nav {
    display: flex;
  }
  .bottom-nav {
    display: none !important;
  }
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.nav-badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* Ícones SVG Inline */
.icon-inline, .icon-nav, .icon-input, .icon-sec {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-inline svg { width: 16px; height: 16px; }
.icon-nav svg { width: 20px; height: 20px; }
.icon-input svg { width: 17px; height: 17px; color: var(--text-muted); }
.icon-sec svg { width: 20px; height: 20px; }

/* Área Principal */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px calc(88px + var(--safe-bottom));
}

@media (min-width: 768px) {
  .app-main {
    padding-bottom: 40px;
  }
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* Cartões KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .kpi-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.kpi-card.kpi-highlight {
  background: var(--primary-soft);
  border-color: rgba(45, 106, 79, 0.25);
}

.kpi-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.kpi-value {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}

.kpi-highlight .kpi-value {
  color: var(--primary);
}

/* Barra de Pesquisa e Ações */
.toolbar-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.search-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 42px;
  transition: border-color 0.15s ease;
}

.search-box:focus-within {
  border-color: var(--primary);
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  padding-left: 8px;
  outline: none;
  width: 100%;
}

/* Botões */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.08s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn-primary:active, .btn-secondary:active, .btn-danger:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-alt);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-compact {
  padding: 0 13px;
}

/* Filtros Horizontais */
.filter-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 10px;
  scrollbar-width: none;
}

.filter-pills::-webkit-scrollbar {
  display: none;
}

.pill {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
}

.catalog-meta-bar {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 500;
}

/* Grupos de Secções / Categorias */
.groups-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.aisle-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.aisle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.aisle-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.aisle-icon-badge {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
}

.aisle-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.1px;
}

.aisle-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.items-list {
  display: flex;
  flex-direction: column;
}

/* Cartão de Item (Lista & Despensa) */
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.item-row:last-child {
  border-bottom: none;
}

.item-row:hover {
  background: rgba(128, 128, 128, 0.03);
}

.check-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: transparent;
  transition: all 0.15s ease;
}

.check-btn:hover {
  border-color: var(--primary);
}

.check-btn.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #FFFFFF;
}

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

.item-title-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

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

.item-row.is-bought .item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-qty-pill {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 1px 7px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

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

.obs-tag {
  background: var(--surface-alt);
  padding: 1px 7px;
  border-radius: 5px;
  color: var(--text);
  font-weight: 500;
}

.overdue-tag {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 5px;
}

.store-badge {
  display: inline-flex;
  align-items: center;
  height: 16px;
}

.store-badge svg {
  height: 15px;
  width: auto;
}

.item-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.price-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.price-main {
  display: block;
  font-weight: 700;
  font-size: 14px;
}

.price-sub {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

/* Stepper Quantidade Rápido */
.qty-stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.qty-stepper button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.qty-stepper button:hover {
  background: var(--border);
}

.qty-stepper span {
  min-width: 24px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Toggle Em Falta na Despensa */
.toggle-falta-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.toggle-falta-btn.in-list {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

/* Secção No Carrinho */
.carrinho-section {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.carrinho-section.hidden {
  display: none;
}

.carrinho-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.carrinho-header h3 {
  margin: 0;
  font-size: 14.5px;
}

/* Estado Vazio */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.empty-state-art svg {
  width: 96px;
  height: 96px;
  margin-bottom: 12px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.empty-state p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* Navegação Inferior Mobile */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.bottom-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.bottom-tab.active {
  color: var(--primary);
}

.bottom-tab .nav-badge {
  position: absolute;
  top: 5px;
  right: calc(50% - 24px);
  padding: 0 5px;
  font-size: 10px;
}

/* Modais */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding-bottom: var(--safe-bottom);
}

@media (min-width: 640px) {
  .modal-card {
    border-radius: var(--radius-lg);
    padding-bottom: 0;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 16.5px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input, .form-group select {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
}

.form-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.price-compare-box, .sync-info-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
}

.price-compare-box.hidden {
  display: none;
}

.store-links-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.store-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
}

.modal-footer-split {
  justify-content: space-between;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(74px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

@media (min-width: 768px) {
  .toast {
    bottom: 24px;
  }
}

.toast.hidden {
  display: none;
}
