/* Estilos Globais e Sistema de Design — Economy Cart PWA */
/* economy-cart/css/app.css */

:root {
  /* Paleta de Cores Premium (Escala Verde Floresta/Esmeralda) */
  --color-primary-dark: #1b4332;
  --color-primary: #2d6a4f;
  --color-primary-medium: #40916c;
  --color-primary-light: #52b788;
  --color-primary-pale: #d8f3dc;
  
  --color-bg-main: #f4f7f5;
  --color-card-bg: #ffffff;
  
  /* Estados de Alerta de Limite */
  --color-alert-safe: #2d6a4f;
  --color-alert-warning: #ffb703;
  --color-alert-danger: #f4511e;
  
  /* Cores de Texto e Neutros */
  --color-text-main: #212529;
  --color-text-muted: #6c757d;
  --color-border: #dee2e6;
  
  /* Efeitos e Sombras */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(27,67,50,0.15);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-round: 50px;
  
  /* Toque Padrão Material Design */
  --touch-target-size: 48px;
}

/* Reset e Configurações de Tela Inteira */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--color-bg-main);
  color: var(--color-text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Shell do SPA */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 90px; /* Espaço para o footer fixo */
}

/* Container Principal */
.container {
  width: 100%;
  max-width: 480px; /* Largura padrão mobile-first centralizada */
  margin: 0 auto;
  padding: 16px;
}

/* ==========================================
   TIPOGRAFIA E TÍTULOS
   ========================================== */
h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 12px;
}

/* ==========================================
   COMPONENTES DE FORMULÁRIO (Toque Mínimo 48px)
   ========================================== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  height: var(--touch-target-size);
  padding: 12px 16px;
  font-size: 1rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: var(--touch-target-size);
  padding: 0 24px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn-outline {
  background-color: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
}

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

.btn-danger {
  background-color: var(--color-alert-danger);
  color: #ffffff;
}

.btn-sm {
  height: 38px;
  padding: 0 12px;
  font-size: 0.875rem;
}

/* ==========================================
   TELA DE LOGIN (Premium Glassmorphic Card)
   ========================================== */
.login-bg {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-header img {
  width: 72px;
  height: 72px;
  margin-bottom: 12px;
  border-radius: var(--radius-md);
}

/* ==========================================
   SHELL E CORPO DO APLICATIVO
   ========================================== */
.app-header {
  background-color: var(--color-primary-dark);
  color: #ffffff;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 600;
}

.logout-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.logout-btn:active {
  background-color: rgba(255, 255, 255, 0.1);
}

/* ==========================================
   CARDS DE COMPRAS E HISTÓRICO
   ========================================== */
.card {
  background-color: var(--color-card-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  transition: transform 0.2s, box-shadow 0.2s;
}

.card-clickable {
  cursor: pointer;
}

.card-clickable:active {
  transform: translateY(1px);
  box-shadow: none;
}

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-primary-dark);
}

.card-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.badge {
  display: inline-flex;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.badge-sync {
  background-color: var(--color-primary-pale);
  color: var(--color-primary-dark);
}

.badge-offline {
  background-color: #ffe6e6;
  color: var(--color-alert-danger);
}

/* ==========================================
   TELA DE COMPRA (INTERATIVA)
   ========================================== */
.add-item-form {
  background-color: var(--color-primary-pale);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px dashed var(--color-primary);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-row .form-group-flex-2 {
  flex: 2;
}

/* Lista de Itens Adicionados */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ffffff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--color-primary-medium);
  animation: slideIn 0.2s ease-out;
}

.item-info {
  flex: 1;
}

.item-name {
  font-weight: 600;
  font-size: 1rem;
}

.item-qty-price {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.item-total {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-primary-dark);
  margin-right: 16px;
}

.delete-item-btn {
  background: none;
  border: none;
  color: var(--color-alert-danger);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target-size);
  height: var(--touch-target-size);
}

/* ==========================================
   RESUMO DE GASTOS (Footer Fixo com Status Reativo)
   ========================================== */
.footer-budget {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
  color: #ffffff;
  z-index: 100;
  transition: background-color 0.4s ease, transform 0.3s ease;
}

/* Cores Dinâmicas do Orçamento */
.bg-budget-safe {
  background-color: var(--color-alert-safe);
}

.bg-budget-warning {
  background-color: var(--color-alert-warning);
  color: #212529 !important; /* Melhora contraste com fundo amarelo */
}

.bg-budget-warning .budget-total,
.bg-budget-warning .budget-limit {
  color: #212529 !important;
}

.bg-budget-danger {
  background-color: var(--color-alert-danger);
  animation: shake 0.5s ease-in-out;
}

.budget-info {
  display: flex;
  flex-direction: column;
}

.budget-label {
  font-size: 0.85rem;
  opacity: 0.9;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.budget-total {
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1.1;
}

.budget-limit {
  font-size: 0.85rem;
  opacity: 0.85;
}

/* Botão de Finalizar no Footer */
.btn-finalizar {
  background-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border: 1.5px solid #ffffff;
  border-radius: var(--radius-round);
  font-weight: 600;
  padding: 0 16px;
  height: 40px;
}

.bg-budget-warning .btn-finalizar {
  border-color: #212529;
  color: #212529;
  background-color: rgba(0,0,0,0.05);
}

.btn-finalizar:active {
  background-color: rgba(255, 255, 255, 0.4);
}

/* ==========================================
   TOAST NOTIFICATIONS (Elegantes e Flutuantes)
   ========================================== */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: 90%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: rgba(33, 37, 41, 0.95);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: toastFadeIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  pointer-events: auto;
  border-left: 5px solid var(--color-primary-light);
}

.toast-success {
  border-left-color: var(--color-primary-light);
}

.toast-error {
  border-left-color: var(--color-alert-danger);
}

.toast-info {
  border-left-color: #0dcaf0;
}

.toast-close {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 1.1rem;
  opacity: 0.7;
  cursor: pointer;
  margin-left: 12px;
  line-height: 1;
}

/* ==========================================
   BOTÃO DE AÇÃO FLUTUANTE (FAB)
   ========================================== */
.fab {
  position: fixed;
  bottom: 100px; /* Posicionado acima do footer fixo */
  right: 20px;
  width: 56px;
  height: 56px;
  background-color: var(--color-primary);
  color: #ffffff;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  border: none;
  cursor: pointer;
  font-size: 1.75rem;
  z-index: 90;
  transition: background-color 0.2s, transform 0.2s;
}

.fab:active {
  transform: scale(0.95);
  background-color: var(--color-primary-dark);
}

/* ==========================================
   ANIMAÇÕES E TRANSIÇÕES
   ========================================== */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Estado de Transição das Páginas */
.fade-in-page {
  animation: slideIn 0.3s ease-out;
}

/* ==========================================
   BARRA DE NAVEGAÇÃO INFERIOR (BOTTOM-NAV)
   ========================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px; /* Alinhado ao container principal SPA */
  height: 64px;
  background-color: var(--color-card-bg);
  border-top: 1.5px solid var(--color-border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 999;
  padding: 0 8px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  transition: color 0.2s, transform 0.1s;
}

.nav-item:active {
  transform: scale(0.95);
}

.nav-item.active {
  color: var(--color-primary);
  font-weight: 700;
}

.nav-icon {
  font-size: 1.35rem;
  margin-bottom: 2px;
  transition: transform 0.2s ease-out;
}

.nav-item.active .nav-icon {
  transform: translateY(-2px) scale(1.15);
}

/* ==========================================
   PAINEL DE ESTATÍSTICAS E DASHBOARD
   ========================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stats-card-full {
  grid-column: span 2;
}

.stat-widget {
  background: var(--color-card-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-widget-gradient {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #ffffff;
  border: none;
}

.stat-widget-gradient .stat-label,
.stat-widget-gradient .stat-sub {
  color: rgba(255, 255, 255, 0.85);
}

.stat-widget-gradient .stat-value {
  color: #ffffff;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--color-primary-dark);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Consultor de Economia */
.advisor-card {
  background-color: var(--color-card-bg);
  border: 1.5px solid var(--color-primary-pale);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.product-select-container {
  margin-bottom: 16px;
}

.advisor-result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

.advisor-badge-box {
  background-color: var(--color-bg-main);
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--color-primary);
  display: flex;
  flex-direction: column;
}

.advisor-badge-box.expensive {
  border-left-color: var(--color-alert-danger);
}

.advisor-badge-box.saving {
  border-left-color: var(--color-alert-warning);
  background-color: #fffde7;
}

.advisor-box-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--color-text-muted);
}

.advisor-box-price {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--color-text-main);
  margin: 2px 0;
}

.advisor-box-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* Gráficos Contêiner */
.chart-card {
  background-color: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.chart-container {
  position: relative;
  width: 100%;
  height: 200px;
  margin-top: 12px;
}

/* Estilo para relatórios / Impressão e PDF */
@media print {
  body {
    background-color: #ffffff;
  }
  
  .bottom-nav, 
  .fab, 
  .logout-btn, 
  #btn-export-pdf,
  .product-select-container {
    display: none !important;
  }
  
  .container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .card, .stat-widget, .advisor-card, .chart-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
  }
}

/* ==========================================
   BANNER DE STATUS DE CONEXÃO
   ========================================== */
.banner-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 14px;
  animation: fadeInBanner 0.3s ease;
}

.banner-status.banner-online {
  background-color: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.banner-status.banner-offline {
  background-color: #fff3e0;
  color: #e65100;
  border: 1px solid #ffcc80;
}

.banner-status.banner-syncing {
  background-color: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}

.banner-status-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.banner-status-text {
  flex: 1;
  line-height: 1.4;
}

.banner-status-time {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.8;
  display: block;
  margin-top: 2px;
}

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

/* Spinner de Sincronização */
.sync-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-primary-pale);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spinSync 0.8s linear infinite;
  margin: 0 auto;
}

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

