/* Estatísticas — versão com cores inteligentes, profundidade e hierarquia visual */
#statsView.stats-view{
  --ag-blue:#1a73e8;
  --ag-blue-soft:#e8f0fe;
  --ag-cyan:#00acc1;
  --ag-green:#188038;
  --ag-green-soft:#e6f4ea;
  --ag-amber:#f29900;
  --ag-amber-soft:#fff4dc;
  --ag-red:#d93025;
  --ag-red-soft:#fce8e6;
  --ag-purple:#7c3aed;
  --ag-purple-soft:#f1e9ff;
  --ag-ink:#202124;
  --ag-muted:#5f6368;
  --ag-line:#e4eaf3;
  background:
    radial-gradient(circle at 12% -8%, rgba(26,115,232,.10), transparent 30%),
    radial-gradient(circle at 86% 4%, rgba(124,58,237,.07), transparent 26%),
    linear-gradient(180deg,#f5f8fe 0%,#f8fafc 50%,#f6f8fb 100%) !important;
}

/* Header com destaque, mas sem virar bloco pesado */
#statsView .stats-hero{
  isolation:isolate;
  border-color:rgba(26,115,232,.18) !important;
  background:
    linear-gradient(135deg,rgba(26,115,232,.12),rgba(255,255,255,.90) 42%,rgba(255,255,255,.96)),
    radial-gradient(circle at 88% 18%,rgba(124,58,237,.12),transparent 32%) !important;
  box-shadow:
    0 1px 2px rgba(60,64,67,.04),
    0 20px 46px rgba(26,115,232,.075) !important;
}
#statsView .stats-hero::after{
  content:"";
  position:absolute;
  width:210px;
  height:210px;
  right:-70px;
  top:-95px;
  background:radial-gradient(circle,rgba(66,133,244,.20),transparent 62%);
  filter:blur(2px);
  z-index:-1;
}

/* Filtros com aparência de toolbelt */
#statsView .stats-filters{
  background:rgba(255,255,255,.72) !important;
  backdrop-filter:blur(16px) saturate(1.25);
  border-color:rgba(26,115,232,.14) !important;
}
#statsView .st-pill.active{
  background:linear-gradient(180deg,#e8f0fe,#f5f9ff) !important;
  color:var(--ag-blue) !important;
  border-color:rgba(26,115,232,.30) !important;
}

/* KPIs: paleta por função, sem vermelho/verde gritante */
#statsView .st-kpi{
  position:relative;
  overflow:hidden;
}
#statsView .st-kpi::before{
  height:0 !important;
}
#statsView .st-kpi::after{
  content:"";
  position:absolute;
  inset:0 auto 0 0;
  width:4px;
  background:var(--kpi-accent,var(--ag-blue));
  opacity:.92;
}
#statsView .st-kpi .st-kpi-label,
#statsView .st-kpi .st-kpi-sub{
  position:relative;
  z-index:1;
}
#statsView .st-kpi .st-kpi-value{
  position:relative;
  z-index:1;
  color:var(--kpi-accent,var(--ag-blue)) !important;
}
#statsView .st-kpi:nth-child(1){
  --kpi-accent:var(--ag-blue);
  background:linear-gradient(135deg,#fff,rgba(232,240,254,.72)) !important;
}
#statsView .st-kpi:nth-child(2){
  --kpi-accent:var(--ag-green);
  background:linear-gradient(135deg,#fff,rgba(230,244,234,.72)) !important;
}
#statsView .st-kpi:nth-child(3){
  --kpi-accent:var(--ag-amber);
  background:linear-gradient(135deg,#fff,rgba(255,244,220,.78)) !important;
}
#statsView .st-kpi:nth-child(4){
  --kpi-accent:#3c4043;
  background:linear-gradient(135deg,#fff,#f5f7fb) !important;
}
#statsView .st-kpi:nth-child(5){
  --kpi-accent:var(--ag-purple);
  background:linear-gradient(135deg,#fff,rgba(241,233,255,.70)) !important;
}
#statsView .st-kpi:nth-child(6){
  --kpi-accent:var(--ag-cyan);
  background:linear-gradient(135deg,#fff,rgba(224,247,250,.72)) !important;
}
#statsView .st-kpi:hover{
  transform:translateY(-3px) scale(1.008);
}

/* Destaque de tamanho: primeiro KPI ligeiramente mais nobre em telas largas */
@media(min-width:1180px){
  #statsView .stats-kpis{
    grid-template-columns:1.14fr 1fr 1fr .94fr 1fr 1fr !important;
  }
  #statsView .st-kpi:nth-child(1) .st-kpi-value{
    font-size:23px !important;
  }
}

/* Cards com hierarquia: gráficos principais mais destacados */
#statsView .stats-grid > .st-card:nth-child(1),
#statsView .stats-grid > .st-card:nth-child(2){
  border-color:rgba(26,115,232,.14) !important;
  box-shadow:
    0 1px 2px rgba(60,64,67,.035),
    0 18px 42px rgba(60,64,67,.055) !important;
}
#statsView .stats-grid > .st-card:nth-child(1) .st-card-head{
  background:
    linear-gradient(180deg,rgba(232,240,254,.55),#fff) !important;
}
#statsView .stats-grid > .st-card:nth-child(2) .st-card-head{
  background:
    linear-gradient(180deg,rgba(241,233,255,.45),#fff) !important;
}

/* Gráficos: cores por linha, suaves e legíveis */
#statsView .st-chart-bars .st-bar-row:nth-child(1) .st-bar-fill{
  background:linear-gradient(90deg,#1a73e8,#6ea8fe) !important;
}
#statsView .st-chart-bars .st-bar-row:nth-child(2) .st-bar-fill{
  background:linear-gradient(90deg,#188038,#58b368) !important;
}
#statsView .st-chart-bars .st-bar-row:nth-child(3) .st-bar-fill{
  background:linear-gradient(90deg,#7c3aed,#a78bfa) !important;
}
#statsView .st-chart-bars .st-bar-row:nth-child(4) .st-bar-fill{
  background:linear-gradient(90deg,#f29900,#fbbc04) !important;
}
#statsView .st-chart-bars .st-bar-row:nth-child(n+5) .st-bar-fill{
  background:linear-gradient(90deg,#00acc1,#67d7e2) !important;
}
#statsView .st-chart-bars .st-bar-row:nth-child(1) .st-bar-val{color:#1a73e8 !important}
#statsView .st-chart-bars .st-bar-row:nth-child(2) .st-bar-val{color:#188038 !important}
#statsView .st-chart-bars .st-bar-row:nth-child(3) .st-bar-val{color:#7c3aed !important}
#statsView .st-chart-bars .st-bar-row:nth-child(4) .st-bar-val{color:#b06000 !important}
#statsView .st-chart-bars .st-bar-row:nth-child(n+5) .st-bar-val{color:#00838f !important}
#statsView .st-bar-track,
#statsView .st-progress{
  background:#edf2f8 !important;
  overflow:hidden;
}
#statsView .st-bar-fill{
  position:relative;
}
#statsView .st-bar-fill::after{
  content:"";
  position:absolute;
  inset:0;
  background:linear-gradient(90deg,transparent,rgba(255,255,255,.38),transparent);
  transform:translateX(-100%);
  animation:statsBarSheen 2.8s ease-in-out infinite;
}
@keyframes statsBarSheen{
  0%,45%{transform:translateX(-100%)}
  75%,100%{transform:translateX(100%)}
}

/* Tabela: cor com inteligência, menos semáforo nos custos */
#statsView .st-table .blue{color:#1a73e8 !important}
#statsView .st-table .green{color:#188038 !important}
#statsView .st-table .red{
  color:#8a5a00 !important;
  background:rgba(255,244,220,.46);
  border-radius:8px;
}
#statsView .st-table td.red{
  font-weight:850;
}

/* Produtos: destaque tipo dashboard, com primeira coluna mais editorial */
#statsView .st-card.span-12{
  background:
    linear-gradient(180deg,#fff,#fbfdff) !important;
}
#statsView .st-card.span-12 .st-card-head{
  background:
    linear-gradient(90deg,rgba(232,240,254,.58),#fff 52%) !important;
}
#statsView .st-card.span-12 .st-table tbody tr:first-child td{
  background:linear-gradient(90deg,rgba(232,240,254,.48),transparent 70%) !important;
}
#statsView .st-card.span-12 .st-table tbody tr:first-child .st-name-main{
  color:#1a73e8 !important;
}

/* Mini cards abaixo: paleta diferenciada por cards */
#statsView .st-mini:nth-child(1){
  background:linear-gradient(135deg,#fff,var(--ag-blue-soft)) !important;
}
#statsView .st-mini:nth-child(2){
  background:linear-gradient(135deg,#fff,var(--ag-green-soft)) !important;
}
#statsView .st-mini:nth-child(3){
  background:linear-gradient(135deg,#fff,var(--ag-amber-soft)) !important;
}
#statsView .st-mini:nth-child(4){
  background:linear-gradient(135deg,#fff,var(--ag-purple-soft)) !important;
}
#statsView .st-mini:nth-child(1) .st-mini-value{color:#1a73e8 !important}
#statsView .st-mini:nth-child(2) .st-mini-value{color:#188038 !important}
#statsView .st-mini:nth-child(3) .st-mini-value{color:#b06000 !important}
#statsView .st-mini:nth-child(4) .st-mini-value{color:#7c3aed !important}

/* Badges diferentes por contexto, sem poluir */
#statsView .st-card:nth-child(1) .st-card-badge{background:#e8f0fe !important;color:#1a73e8 !important}
#statsView .st-card:nth-child(2) .st-card-badge{background:#f1e9ff !important;color:#7c3aed !important;border-color:rgba(124,58,237,.18) !important}
#statsView .st-card:nth-child(3) .st-card-badge{background:#e6f4ea !important;color:#188038 !important;border-color:rgba(24,128,56,.18) !important}
#statsView .st-card:nth-child(4) .st-card-badge{background:#fff4dc !important;color:#b06000 !important;border-color:rgba(242,153,0,.20) !important}

/* Blur/glow de fundo nos cards principais */
#statsView .st-card{
  position:relative;
}
#statsView .st-card::before{
  content:"";
  position:absolute;
  inset:auto -40px -70px auto;
  width:150px;
  height:150px;
  border-radius:999px;
  background:rgba(26,115,232,.045);
  filter:blur(18px);
  pointer-events:none;
}
#statsView .stats-grid > .st-card:nth-child(2)::before{
  background:rgba(124,58,237,.055);
}
#statsView .stats-grid > .st-card:nth-child(3)::before{
  background:rgba(24,128,56,.045);
}

/* Animação em tabela e cards ao entrar */
#statsView.active .st-table tbody tr{
  animation:statsRowFade .32s ease both;
}
#statsView.active .st-table tbody tr:nth-child(1){animation-delay:.04s}
#statsView.active .st-table tbody tr:nth-child(2){animation-delay:.07s}
#statsView.active .st-table tbody tr:nth-child(3){animation-delay:.10s}
#statsView.active .st-table tbody tr:nth-child(4){animation-delay:.13s}
@keyframes statsRowFade{
  from{opacity:0;transform:translateX(-5px)}
  to{opacity:1;transform:translateX(0)}
}

/* Escala geral: deixa a tela menos blocada */
#statsView .st-card-body{
  min-height:0;
}
#statsView .st-card.span-6 .st-card-body{
  padding-top:13px !important;
  padding-bottom:16px !important;
}

/* Dark mode com a mesma lógica, sem brancos */
body:not([data-theme="light"]) #statsView .st-kpi:nth-child(n),
body:not([data-theme="light"]) #statsView .st-card:nth-child(n),
body:not([data-theme="light"]) #statsView .stats-hero,
body:not([data-theme="light"]) #statsView .stats-filters{
  background:linear-gradient(180deg,color-mix(in srgb,var(--surface) 94%,var(--accent) 6%),var(--surface)) !important;
}
body:not([data-theme="light"]) #statsView .st-table .red{
  background:rgba(242,153,0,.10);
}
