/* Reset e Configurações Gerais */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: #f8f9fa;
  color: #202124;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Barra Superior do Aplicativo */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background-color: #ffffff;
  border-bottom: 1px solid #dadce0;
  box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sheet-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: rgba(15, 157, 88, 0.1);
  border-radius: 8px;
}

.title-container h1 {
  font-size: 18px;
  font-weight: 600;
  color: #202124;
  line-height: 1.2;
}

.cloud-status {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  cursor: pointer;
}

/* Botoes e Status OAuth */
.auth-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge {
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-badge.loading { background-color: #e8f0fe; color: #1a73e8; }
.status-badge.connected { background-color: #e6f4ea; color: #137333; }
.status-badge.disconnected { background-color: #fce8e6; color: #c5221f; }

.btn-bling {
  background-color: #1a73e8;
  color: white;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3);
}

.btn-bling:hover {
  background-color: #1557b0;
  box-shadow: 0 1px 3px 1px rgba(60,64,67,0.15);
}

.btn-logout {
  background-color: #ffffff;
  color: #5f6368;
  border: 1px solid #dadce0;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  background-color: #f1f3f4;
  color: #202124;
}

.hidden { display: none !important; }

/* Container do Alerta */
.alert-banner {
  padding: 12px 24px;
  background-color: #fce8e6;
  color: #c5221f;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  border-bottom: 1px solid #f8d0cb;
}

/* ================= NAVEGAÇÃO EM ABAS (TABS) ================= */
.app-tab-navigation {
  background: #ffffff;
  border-bottom: 1px solid #dadce0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  position: sticky;
  top: 65px;
  z-index: 90;
  overflow-x: auto;
}

.tabs-scroll-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  max-width: 1350px;
  margin: 0 auto;
}

.app-tab-btn {
  background: #f1f3f4;
  border: 1px solid #dadce0;
  color: #5f6368;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 18px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.app-tab-btn:hover {
  background: #e8eaed;
  color: #202124;
}

.app-tab-btn.active {
  background: #e8f0fe;
  color: #1a73e8;
  border-color: #1a73e8;
  box-shadow: 0 1px 2px rgba(26,115,232,0.2);
}

.tab-separator {
  width: 2px;
  height: 24px;
  background-color: #dadce0;
  margin: 0 8px;
  flex-shrink: 0;
}

.dynamic-tabs-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Planilha Principal */
.sheet-container {
  max-width: 1350px;
  width: 100%;
  margin: 24px auto;
  padding: 0 24px;
  flex: 1;
}

.sheet-subnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid #dadce0;
}

.sheet-tab-active {
  font-size: 16px;
  font-weight: 700;
  color: #1a73e8;
  border-bottom: 3px solid #1a73e8;
  padding-bottom: 11px;
  margin-bottom: -14px;
  text-transform: uppercase;
}

.summary-stats {
  display: flex;
  gap: 24px;
  font-size: 14px;
  color: #5f6368;
}

.summary-stats strong { color: #202124; font-weight: 600; }

/* Grid de KPIs (Top Box) */
.kpi-grid {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin-bottom: 24px;
  max-width: 500px;
  overflow: hidden;
}

.kpi-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e0e0e0;
  min-height: 44px;
}

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

.kpi-label {
  width: 230px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  color: #202124;
  background-color: #f8f9fa;
  border-right: 1px solid #e0e0e0;
}

.kpi-value {
  flex: 1;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  text-align: right;
  color: #202124;
}

/* Linha da Meta com Destaque Amarelo */
.meta-row { background-color: #ffe599; }
.meta-row .kpi-label { background-color: #ffe599; border-right-color: #ecd287; }

.kpi-value-input {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 16px;
  background-color: #ffe599;
}

.currency-symbol { font-size: 15px; font-weight: 700; color: #202124; margin-right: 4px; }

.kpi-value-input input {
  width: 140px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid #dcb952;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 15px;
  font-weight: 700;
  text-align: right;
  color: #202124;
  outline: none;
  transition: background 0.2s, box-shadow 0.2s;
}

.kpi-value-input input:focus {
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.4);
  border-color: #1a73e8;
}

.highlight-red { color: #cc0000 !important; font-size: 16px; }

/* ================= CARDS DOS VENDEDORES ================= */
.salesmen-summary-section {
  margin-bottom: 24px;
}

.salesmen-cards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}

.salesman-card {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  min-width: 160px;
  flex: 0 1 200px; /* don't grow to fill the line; allow shrinking for smaller viewports */
  max-width: 260px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.salesman-card-title {
  font-size: 12px;
  font-weight: 700;
  color: #202124;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.salesman-card-val {
  font-size: 16px;
  font-weight: 700;
  color: #202124;
}

/* ================= TABELAS (DIÁRIA & RESUMO) ================= */
.daily-table-section {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow-x: auto;
}

.daily-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.daily-table th {
  background-color: #434343;
  color: #ffffff;
  font-weight: 700;
  padding: 12px 16px;
  border: 1px solid #555555;
  text-align: center;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.daily-table td {
  padding: 10px 16px;
  border: 1px solid #e0e0e0;
  color: #202124;
  white-space: nowrap;
}

.col-dia { width: 70px; text-align: center; }
.col-data { width: 110px; text-align: center; }
.col-semana { width: 160px; }
.col-faturamento { text-align: right; width: 180px; font-weight: 700; }
.col-perc { text-align: right; width: 180px; }

.daily-table tbody tr { transition: background-color 0.15s; }
.daily-table tbody tr:hover { background-color: #f1f3f4; }

.row-weekend { background-color: #fff2cc !important; }

.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

.table-total-row td {
  background-color: #f8f9fa;
  font-size: 15px;
  border-top: 2px solid #5f6368;
  color: #202124;
  font-weight: 700;
}

/* ================= RESUMO GERAL ================= */
.resumo-tables-container {
  display: flex;
  flex-direction: column;
  gap: 36px;
  margin-top: 16px;
}

.resumo-title {
  font-size: 18px;
  font-weight: 700;
  color: #202124;
  margin-bottom: 16px;
  border-left: 4px solid #1a73e8;
  padding-left: 12px;
  display: flex;
  align-items: center;
}

.resumo-separator {
  height: 2px;
  background-color: #dadce0;
  margin: 12px 0;
}

/* ================= TOP CLIENTES ================= */
.top-clientes-section {
  margin-top: 16px;
}

.top-clientes-card {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow-x: auto;
}

.top-clientes-table td {
  padding: 14px 16px;
  vertical-align: middle;
}

.col-rank { font-weight: 700; font-size: 15px; color: #5f6368; }
.col-cliente { font-weight: 600; font-size: 15px; }
.col-valor { font-weight: 700; font-size: 15px; color: #137333; }

.bar-container {
  width: 100%;
  height: 22px;
  background: #e8eaed;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.bar-fill {
  height: 100%;
  background: #38761d;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Responsividade */
@media (max-width: 768px) {
  .app-header { padding: 12px 16px; }
  .tabs-scroll-container { padding: 8px 16px; }
  .sheet-container { padding: 0 16px; margin: 16px auto; }
  .kpi-grid { max-width: 100%; }
  .kpi-label { width: 180px; font-size: 13px; }
  .daily-table td, .daily-table th { padding: 8px 10px; font-size: 13px; }
}

/* Painel de Filtros de Vendedores */
.seller-filter-panel {
  background: #ffffff;
  border: 1px solid #dadce0;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.filter-label {
  font-size: 11px;
  font-weight: 700;
  color: #5f6368;
  margin-bottom: 12px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.filter-badges-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #dadce0;
  background: #f8f9fa;
  color: #3c4043;
  user-select: none;
}
.filter-badge:hover {
  background: #f1f3f4;
  border-color: #bdc1c6;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.filter-badge.inactive {
  background: #f1f3f4 !important;
  color: #9aa0a6 !important;
  border-color: #dadce0 !important;
  text-decoration: line-through;
  opacity: 0.6;
}
.filter-badge .badge-icon {
  margin-right: 6px;
  display: inline-flex;
  align-items: center;
}

/* Loading Overlay Estilo Premium */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  display: none !important;
  opacity: 0;
}

.loading-card {
  background: #ffffff;
  border: 1px solid #dadce0;
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  text-align: center;
  max-width: 440px;
  width: 90%;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

.spinner-container {
  margin-bottom: 24px;
  position: relative;
  display: inline-flex;
}

.premium-spinner {
  width: 56px;
  height: 56px;
  border: 5px solid #e8f0fe;
  border-top: 5px solid #1a73e8;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-card h3 {
  font-size: 18px;
  font-weight: 600;
  color: #202124;
  margin-bottom: 10px;
  line-height: 1.4;
}

.loading-timer {
  font-size: 15px;
  font-weight: 700;
  color: #1a73e8;
  background-color: #e8f0fe;
  padding: 6px 16px;
  border-radius: 20px;
  margin-bottom: 20px;
  display: inline-block;
  letter-spacing: 0.5px;
}

.loading-subtext {
  font-size: 12px;
  color: #5f6368;
  line-height: 1.5;
  border-top: 1px solid #dadce0;
  padding-top: 16px;
  width: 100%;
}

/* ================= REGRAS DE IMPRESSÃO A4 PAISAGEM ================= */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm 10mm 8mm 10mm;
  }
  
  /* Oculta tudo que não faz parte do relatório */
  .app-header, 
  .app-tab-navigation, 
  .seller-filter-panel, 
  .loading-overlay, 
  .alert-banner,
  #btn-print-a4,
  .kpi-row.meta-row,
  .btn-bling,
  .btn-logout {
    display: none !important;
  }

  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    font-size: 11px !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .sheet-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .view-section {
    display: block !important;
    page-break-after: avoid;
    page-break-inside: avoid;
  }

  /* Ajustes nas tabelas para caberem em A4 */
  .daily-table-section {
    margin: 0 !important;
    overflow: visible !important;
  }

  table.daily-table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 10px !important;
  }

  table.daily-table th, 
  table.daily-table td {
    padding: 4px 6px !important;
    border: 1px solid #999999 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Ajustes nos KPIs */
  .kpi-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }

  .kpi-row {
    padding: 8px !important;
    border: 1px solid #cccccc !important;
    border-radius: 4px !important;
    background-color: #f8f9fa !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .kpi-value {
    font-size: 16px !important;
  }

  /* Cards de vendedores */
  .salesmen-cards-grid {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 6px !important;
    margin-bottom: 12px !important;
  }

  .salesman-card {
    padding: 6px !important;
    border: 1px solid #dddddd !important;
    background-color: #fdfdfd !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Forçar quebra de página se necessário apenas para abas específicas */
  .resumo-tables-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 20px !important;
  }

  .resumo-block {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}
