/* ==========================================================
   FutstatsBR — Estatísticas Avançadas
   Versão refatorada – cores consistentes, sem !importants abusivos
   Fundo principal: #171717 (cinza escuro)
========================================================== */

/* ----------------------------------------------
   1. RESET E BASE
---------------------------------------------- */
html,
body {
  background: #171717 !important; /* necessário para sobrescrever Bootstrap */
  overflow-x: hidden;
}

main,
main.py-4,
#app > main {
  background: #171717 !important;
  padding-top: 0 !important;
  margin-top: 0 !important;
}

main > .container,
main > .container-fluid {
  background: transparent !important;
  padding-top: 0 !important;
}

/* ----------------------------------------------
   2. LAYOUT PRINCIPAL
---------------------------------------------- */
.stats-page {
  position: relative;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  min-height: 100vh;
  padding-bottom: 42px;
  background: #171717;
  color: rgba(255, 255, 255, 0.92);
}

.stats-page * {
  border-radius: 0 !important;
}

@media (max-width: 1100px) {
  .stats-page {
    padding-bottom: calc(78px + 26px);
  }
}

.stats-container {
  width: min(calc(100% - (clamp(10px, 2.2vw, 30px) * 2)), 1820px);
  margin: 16px auto 42px;
}

.stats-layout {
  display: grid;
  grid-template-columns: minmax(280px, 460px) minmax(0, 1fr);
  gap: clamp(12px, 2vw, 20px);
  align-items: start;
}

@media (max-width: 1100px) {
  .stats-layout {
    grid-template-columns: 1fr;
  }
}

.stats-left {
  display: grid;
  gap: 14px;
}

.stats-right {
  min-width: 0;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

@media (min-width: 1101px) {
  .stats-left {
    position: sticky;
    top: 92px;
    align-self: start;
  }
}

/* ----------------------------------------------
   3. HEADER E TIER
---------------------------------------------- */
.stats-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.stats-tier {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.stats-tier__badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  font-weight: 800;
}

.stats-tier__text {
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
}

.tier-free {
  background: rgba(92, 184, 92, 0.18);
  border-color: rgba(92, 184, 92, 0.35);
  color: rgba(255, 255, 255, 0.92);
}

.tier-premium {
  background: rgba(251, 191, 36, 0.95);
  border-color: #fbbf24;
  color: #111;
}

.stats-header__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ----------------------------------------------
   4. CARDS GERAIS
---------------------------------------------- */
.stats-page .card {
  overflow: hidden;
  border: none;
  box-shadow: none;
  background: #171717;
}

.stats-page .card-header {
  background: #171717;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 800;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 14px;
}

.stats-page .card-body {
  color: rgba(255, 255, 255, 0.9);
  padding: 14px;
}

/* ----------------------------------------------
   5. FORMULÁRIOS E INPUTS (sem !important)
---------------------------------------------- */
.stats-page .form-label {
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  font-weight: 700;
}

.stats-page .form-select,
.stats-page .form-control {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background-color: #171717;
  color: rgba(255, 255, 255, 0.92);
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

/* Seta personalizada para selects (branca) */
.stats-page select.form-select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
}

/* Estados de foco */
.stats-page .form-select:focus,
.stats-page .form-control:focus {
  outline: none;
  border-color: rgba(59, 130, 246, 0.65);
  background-color: #171717;
  color: rgba(255, 255, 255, 0.92);
  box-shadow: none;
}

/* Desabilitados */
.stats-page .form-select:disabled,
.stats-page .form-control:disabled,
.stats-page .btn:disabled,
.stats-page button:disabled {
  background-color: #202020 !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.55) !important;
  opacity: 0.8;
  cursor: not-allowed;
}

/* Placeholder */
.stats-page .form-control::placeholder {
  color: rgba(255, 255, 255, 0.5);
  opacity: 1;
}

/* ----------------------------------------------
   6. BOTÕES E CTAs
---------------------------------------------- */
.stats-page .btn {
  font-weight: 800;
  border-radius: 0;
}

.stats-page .btn-primary {
  background-color: #0a58ca;
  border-color: #0a58ca;
  color: #fff;
}

.stats-page .btn-primary:hover {
  background-color: #0846a3;
  border-color: #0846a3;
}

.stats-page .btn-outline-light {
  border-color: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.92);
}

.stats-page .btn-outline-light:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
  color: #fff;
}

.stats-page .btn-outline-secondary {
  border-color: rgba(34, 211, 238, 0.55);
  color: #22d3ee;
}

.stats-page .btn-outline-secondary:hover {
  border-color: rgba(34, 211, 238, 0.75);
  background: rgba(34, 211, 238, 0.1);
  color: #fff;
}

/* CTAs de alerta (login, premium) */
.stats-cta-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 4px solid transparent;
}

.stats-cta-alert-login {
  border-left-color: #0a58ca;
}

.stats-cta-alert-free {
  border-left-color: #5cb85c;
}

.stats-cta-copy {
  min-width: 0;
}

.stats-cta-title {
  font-weight: 900;
  letter-spacing: 0.2px;
}

.stats-cta-text {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.64);
  font-size: 13px;
}

.stats-cta-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

/* Botões de acesso (login, register, premium) */
.stats-access-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font-weight: 900;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.stats-access-btn-login {
  background-color: #0a58ca;
  color: #fff;
}
.stats-access-btn-login:hover {
  background-color: #0846a3;
  color: #fff;
}

.stats-access-btn-register {
  background-color: #198754;
  color: #fff;
}
.stats-access-btn-register:hover {
  background-color: #146c43;
  color: #fff;
}

.stats-access-btn-premium {
  background-color: #ff8800;
  color: #fff;
}
.stats-access-btn-premium:hover {
  background-color: #e67800;
  color: #fff;
}

.stats-access-btn-sm {
  padding: 8px 12px;
  font-size: 12px;
}

@media (max-width: 576px) {
  .stats-cta-alert {
    flex-direction: column;
    align-items: flex-start;
  }
  .stats-cta-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* ----------------------------------------------
   7. FILTROS – SUMÁRIO E MENSAGENS
---------------------------------------------- */
.stats-filter-hint,
.stats-advanced__hint,
.stats-filters-modal__subtitle {
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  font-weight: 700;
}

.stats-message-container {
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.88);
  font-weight: 800;
}

.stats-message-container.initial-hidden {
  display: none;
}

.filters-summary {
  margin-bottom: 10px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 800;
}

.stats-current-filters {
  min-height: 92px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  line-height: 1.5;
  font-weight: 800;
}

.stats-filter-summary-card .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stats-filter-summary-actions .btn {
  min-height: 46px;
}

.stats-generate-mini {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

/* ----------------------------------------------
   8. PAINEL DE FILTROS (DENTRO DO MODAL)
---------------------------------------------- */
.filters-panel {
  overflow: visible;
  padding-right: 6px;
}

.stats-filters-grid {
  margin-bottom: 16px;
}

.stats-advanced {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
}

.stats-advanced > summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  list-style: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.86);
  font-weight: 900;
}

.stats-advanced > summary::-webkit-details-marker {
  display: none;
}

.stats-advanced[open] {
  background: rgba(255, 255, 255, 0.045);
}

/* ----------------------------------------------
   9. TABELA DE RANKING E GRÁFICO
---------------------------------------------- */
.stats-summary {
  background: #171717;
  margin-bottom: 16px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.stat-card .value {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.2px;
}

.stat-card .label {
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  font-weight: 800;
}

.stats-table {
  border-color: rgba(255, 255, 255, 0.1) !important;
}

.stats-table thead th {
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.86) !important;
  font-weight: 900;
}

.stats-table tbody td {
  color: rgba(255, 255, 255, 0.86) !important;
  vertical-align: middle;
}

.highlight-row {
  background: rgba(34, 197, 94, 0.1) !important;
}

.team-logo {
  width: 24px;
  height: 24px;
  margin-right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  object-fit: contain;
}

.variacao-positiva {
  color: #22c55e;
  font-weight: 900;
}

.variacao-negativa {
  color: #ef4444;
  font-weight: 900;
}

.variacao-neutra {
  color: rgba(255, 255, 255, 0.6);
  font-weight: 800;
}

.stats-chart-card .chart-container {
  min-height: clamp(260px, 32vh, 420px);
}

.chart-canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ----------------------------------------------
   10. MODAIS (com fundo #171717, sem azul)
---------------------------------------------- */
.modal-content {
  background-color: #171717;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header,
.modal-footer {
  border-color: rgba(255, 255, 255, 0.1);
  background: transparent;
}

.modal-header .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* Modal de filtros (específico) */
.stats-filters-modal {
  background: #171717;
  color: rgba(255, 255, 255, 0.94);
}

.stats-filters-modal .modal-title {
  font-weight: 1000;
}

.stats-filters-modal .modal-footer {
  justify-content: space-between;
}

/* Modal de acesso */
.stats-access-modal {
  background: #171717;
  color: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.stats-access-modal .modal-title {
  font-weight: 1000;
}

#statsAccessModalFooter {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#statsAccessModalFooter .btn {
  min-width: 120px;
  padding: 10px 16px;
  font-weight: 900;
}

#statsAccessModalFooter .btn:first-child {
  background-color: #0a58ca;
  border-color: #0a58ca;
  color: #fff;
}
#statsAccessModalFooter .btn:first-child:hover {
  background-color: #0846a3;
}

#statsAccessModalFooter .btn:last-child {
  background-color: #198754;
  border-color: #198754;
  color: #fff;
}
#statsAccessModalFooter .btn:last-child:hover {
  background-color: #146c43;
}

/* ----------------------------------------------
   11. AUTOCOMPLETE (dropdowns)
---------------------------------------------- */
.stats-autocomplete-box {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0f172a;
}

.stats-autocomplete-item {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.stats-autocomplete-item:last-child {
  border-bottom: 0;
}

.stats-autocomplete-item:hover,
.stats-autocomplete-item.active {
  background: rgba(59, 130, 246, 0.18);
}

.stats-autocomplete-title {
  display: block;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
}

.stats-autocomplete-subtitle {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.8rem;
}

.stats-input-help,
.stats-autocomplete-empty {
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.78rem;
}

.stats-autocomplete-empty {
  padding: 10px 12px;
}

/* ----------------------------------------------
   12. CLASSES UTILITÁRIAS PARA CONTROLE DE EXIBIÇÃO
---------------------------------------------- */
.stats-jogadores-only.d-none,
.stats-equipes-only.d-none {
  display: none !important;
}

.disabled-filter {
  pointer-events: none;
  opacity: 0.6;
}

/* ----------------------------------------------
   13. IMPRESSÃO
---------------------------------------------- */
@media print {
  .no-print {
    display: none !important;
  }
  .stats-page {
    width: 100% !important;
    margin-left: 0 !important;
    background: #000 !important;
    color: #fff !important;
  }
  .stats-container {
    width: 100% !important;
    margin: 0 !important;
  }
}

/* ----------------------------------------------
   14. CORREÇÕES ESPECÍFICAS PARA AUTOCOMPLETE (cores)
---------------------------------------------- */
#resultadoTimesEquipe.stats-autocomplete-box,
#resultadoTimesJogador.stats-autocomplete-box,
#resultadoJogadores.stats-autocomplete-box {
  background: #2b2b2b;
  border: 1px solid #4a4a4a;
  color: #e5e5e5;
}

#resultadoTimesEquipe .stats-autocomplete-item,
#resultadoTimesJogador .stats-autocomplete-item,
#resultadoJogadores .stats-autocomplete-item {
  background: transparent;
  color: #e5e5e5;
  border-bottom: 1px solid #3a3a3a;
}

#resultadoTimesEquipe .stats-autocomplete-item:hover,
#resultadoTimesEquipe .stats-autocomplete-item.active,
#resultadoTimesJogador .stats-autocomplete-item:hover,
#resultadoTimesJogador .stats-autocomplete-item.active,
#resultadoJogadores .stats-autocomplete-item:hover,
#resultadoJogadores .stats-autocomplete-item.active {
  background: #4a4a4a !important;
  color: #ffffff !important;
}

#resultadoTimesEquipe .stats-autocomplete-item small,
#resultadoTimesJogador .stats-autocomplete-item small,
#resultadoJogadores .stats-autocomplete-item small {
  color: #bdbdbd;
}

#resultadoTimesEquipe .stats-autocomplete-clear,
#resultadoTimesJogador .stats-autocomplete-clear,
#resultadoJogadores .stats-autocomplete-clear {
  background: #3a3a3a;
  border: 1px solid #555;
  color: #e5e5e5;
}

#resultadoTimesEquipe .stats-autocomplete-clear:hover,
#resultadoTimesJogador .stats-autocomplete-clear:hover,
#resultadoJogadores .stats-autocomplete-clear:hover {
  background: #4a4a4a;
  color: #fff;
}

#tabelaRanking tbody,
#tabelaRanking tbody tr,
#tabelaRanking tbody td {
  background: transparent !important;
}

/* ==========================================================
   15. AJUSTES RESPONSIVOS: TRÊS BOTÕES LADO A LADO (<=1100px)
========================================================== */
@media (max-width: 1100px) {
  /* Esconde o botão original do cabeçalho */
  #btnExportHTML {
    display: none !important;
  }

  /* Exibe o botão duplicado dentro do card */
  .btn-export-card {
    display: inline-flex !important;
  }

  /* Transforma o container dos botões em flex horizontal */
  .stats-filter-summary-actions {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px;
  }

  /* Cada botão ocupa a mesma largura, com texto quebrado se necessário */
  .stats-filter-summary-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 4px !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
    white-space: normal !important;
    word-break: break-word;
    text-align: center;
  }

  /* Força a exibição do texto "Exportar HTML" em telas pequenas */
  .btn-export-card span,
  #btnExportHTMLCard span {
    display: inline !important;
  }
}

@media (min-width: 1101px) {
  .btn-export-card {
    display: none !important;
  }

  /* Garante que o container dos botões volte ao layout de grid (empilhado) */
  .stats-filter-summary-actions {
    display: grid !important;
    gap: 8px;
  }

  .stats-filter-summary-actions .btn {
    width: 100%;
  }
}

/* ==========================================================
   16. MELHORIAS NO MODAL DE FILTROS (<=1100px)
========================================================== */
@media (max-width: 1100px) {
  /* Reduz padding e altura dos campos de formulário dentro da modal */
  #statsFiltersModal .form-select,
  #statsFiltersModal .form-control {
    padding: 6px 12px !important;
    height: 38px !important;
    font-size: 13px !important;
  }

  /* Labels mais compactas */
  #statsFiltersModal .form-label {
    font-size: 12px !important;
    margin-bottom: 4px !important;
    font-weight: 600;
  }

  /* Força os campos a ficarem lado a lado (2 por linha) */
  #statsFiltersModal .row .col-12.col-sm-6 {
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }

  /* Ajusta o rodapé do modal */
  #statsFiltersModal .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* ==========================================================
   17. OCULTAR TEXTOS DE AJUDA NO MOBILE
========================================================== */
@media (max-width: 1100px) {
  .stats-input-help {
    display: none !important;
  }
}

/* Ajuste dos cards de resumo em telas menores */
@media (max-width: 768px) {
  .stat-card {
    padding: 8px 4px !important;  /* reduz o espaçamento interno */
  }
  .stat-card .value {
    font-size: 16px !important;    /* valor principal menor */
  }
  .stat-card .label {
    font-size: 10px !important;    /* label menor */
    line-height: 1.3;
  }
}

