/* Statistics route enhancements. Kept separate so the core stylesheet does not grow. */

#indicators {
  --stats-favorable: #138808;
  --stats-adverse: #b3261e;
  --stats-mixed: #87939d;
}

/* Keep every indicator card on the same three-state visual language. */
#indicators .indicator.tone-better {
  --card-accent: var(--stats-favorable) !important;
  border-top-color: var(--stats-favorable);
}

#indicators .indicator.tone-worse {
  --card-accent: var(--stats-adverse) !important;
  border-top-color: var(--stats-adverse);
}

#indicators .indicator.tone-flat {
  --card-accent: var(--stats-mixed) !important;
  border-top-color: var(--stats-mixed);
}

#indicators .stats-overview article,
#indicators .tracker-card {
  border-top-color: var(--stats-mixed);
}

#indicators .stats-overview .overview-adverse,
#indicators .tracker-card.tracker-presser {
  border-top-color: var(--stats-adverse);
}

#indicators .stats-overview .overview-favorable {
  border-top-color: var(--stats-favorable);
}

.stats-signal-meter {
  display: grid;
  grid-template-columns: minmax(180px, 0.65fr) minmax(300px, 1.35fr);
  align-items: center;
  gap: 22px;
  margin: 14px 0 22px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.stats-signal-copy {
  display: grid;
  gap: 3px;
}

.stats-signal-copy > span,
.stats-topic-heading > span,
.stats-controls-title > span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.stats-signal-copy small,
.stats-topic-heading small,
.stats-controls-title small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.stats-signal-visual {
  display: grid;
  gap: 8px;
}

.stats-signal-track {
  display: flex;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ecef;
}

.stats-signal-track i {
  display: block;
  height: 100%;
  transform-origin: left center;
  animation: stats-meter-grow 0.7s cubic-bezier(.2, .75, .2, 1) both;
}

.stats-signal-track .is-favorable,
.stats-signal-values i.is-favorable { background: var(--stats-favorable); }
.stats-signal-track .is-adverse,
.stats-signal-values i.is-adverse { background: var(--stats-adverse); }
.stats-signal-track .is-mixed,
.stats-signal-values i.is-mixed { background: var(--stats-mixed); }

.stats-signal-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 15px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.stats-signal-values span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.stats-signal-values i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.stats-topic-explorer {
  margin: 0 0 17px;
}

.stats-topic-heading,
.stats-controls-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 9px;
}

.stats-topic-heading {
  padding: 0 2px;
}

.stats-topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px;
}

.stats-topic-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 9px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  scroll-snap-align: start;
  transition: transform .16s ease, border-color .16s ease, background-color .16s ease, box-shadow .16s ease;
}

.stats-topic-chip strong {
  display: grid;
  min-width: 23px;
  height: 23px;
  margin: 0;
  place-items: center;
  border-radius: 999px;
  background: #eef2f4;
  color: var(--muted);
  font-size: 10px;
}

.stats-topic-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 103, 31, 0.55);
  box-shadow: 0 5px 13px rgba(21, 29, 38, 0.08);
}

.stats-topic-chip.is-active {
  border-color: var(--bjp);
  background: rgba(255, 103, 31, 0.09);
  color: #8b3600;
}

.stats-topic-chip.is-active strong {
  background: var(--bjp);
  color: #fff;
}

.stats-controls-panel {
  position: sticky;
  top: 58px;
  z-index: 18;
  margin: 0 0 24px;
  padding: 13px;
  border: 1px solid rgba(205, 211, 216, 0.9);
  border-radius: 11px;
  background: rgba(251, 250, 245, 0.94);
  box-shadow: 0 8px 24px rgba(21, 29, 38, 0.08);
  backdrop-filter: blur(13px);
}

.stats-controls-title {
  display: grid;
  gap: 2px;
}

#indicators .stats-search > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#indicators .stats-search kbd {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  place-items: center;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .82);
  color: var(--muted);
  font: 800 10px/1 Inter, sans-serif;
}

.stats-density-toggle {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.stats-density-toggle button {
  min-height: 32px;
  padding: 5px 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}

.stats-density-toggle button.is-active {
  background: var(--ink);
  color: #fff;
}

#indicators .stats-toolbar {
  grid-template-columns: minmax(210px, 1.25fr) minmax(150px, .8fr) minmax(135px, .7fr) minmax(150px, .7fr) auto auto;
  margin: 0;
}

.stats-active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid rgba(205, 211, 216, 0.72);
}

.stats-active-filters[hidden] { display: none; }

.stats-active-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.stats-active-filters button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 4px 7px 4px 10px;
  border: 1px solid rgba(255, 103, 31, .36);
  border-radius: 999px;
  background: rgba(255, 103, 31, .08);
  color: #843600;
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.stats-active-filters button span {
  font-size: 16px;
  line-height: 1;
}

#indicators .indicator-grid {
  align-items: stretch;
}

#indicators .indicator {
  position: relative;
  content-visibility: auto;
  contain-intrinsic-size: 520px;
  animation: stats-card-enter .38s cubic-bezier(.2, .75, .2, 1) both;
  animation-delay: var(--stats-delay, 0ms);
}

#indicators .indicator:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 34px rgba(21, 29, 38, .12);
}

.indicator-taxonomy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-right: 74px;
}

.stats-copy-link {
  position: absolute;
  top: 13px;
  right: 13px;
  min-height: 29px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, .86);
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  font-weight: 850;
  cursor: pointer;
}

.stats-copy-link:hover,
.stats-copy-link.is-copied {
  border-color: var(--bjp);
  background: var(--bjp);
  color: #fff;
}

.stats-empty {
  grid-column: 1 / -1;
  display: grid;
  justify-items: start;
  gap: 8px;
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .55);
}

.stats-empty strong { margin: 0; font-size: 18px; }
.stats-empty p { margin: 0; color: var(--muted); }

.stats-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 24px auto 4px;
}

.stats-pagination[hidden] { display: none; }

.stats-pagination span {
  margin-right: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats-pagination button {
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.stats-pagination button:first-of-type {
  border-color: var(--bjp);
  background: var(--bjp);
  color: #fff;
}

#indicators[data-stats-density="compact"] .indicator-grid {
  gap: 10px;
}

#indicators[data-stats-density="compact"] .indicator {
  padding: 13px;
}

#indicators[data-stats-density="compact"] .indicator h3 {
  font-size: 16px;
}

#indicators[data-stats-density="compact"] .indicator strong {
  font-size: clamp(20px, 2vw, 25px);
}

#indicators[data-stats-density="compact"] .indicator > p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

#indicators[data-stats-density="compact"] .indicator-chart-container {
  margin: 12px 0;
}

@keyframes stats-card-enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes stats-meter-grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@media (max-width: 1100px) {
  #indicators .stats-toolbar {
    grid-template-columns: minmax(200px, 1fr) repeat(3, minmax(130px, .6fr));
  }

  #indicators .stats-toolbar .clear-filters-button,
  #indicators .stats-result {
    align-self: center !important;
    margin: 0 !important;
    padding: 0 !important;
  }
}

@media (max-width: 760px) {
  .stats-signal-meter {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 17px;
  }

  .stats-topic-heading small,
  .stats-controls-title small {
    display: none;
  }

  .stats-topic-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .stats-topic-chips::-webkit-scrollbar {
    display: none;
  }

  .stats-controls-panel {
    position: relative;
    top: auto;
    padding: 11px;
  }

  #indicators .stats-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  #indicators .stats-toolbar .stats-search {
    grid-column: 1 / -1;
  }

  #indicators .stats-toolbar .clear-filters-button,
  #indicators .stats-result {
    align-self: center !important;
  }

  #indicators .stats-toolbar .clear-filters-button {
    grid-column: 2;
    align-self: end !important;
    width: 100%;
  }

  #indicators .stats-toolbar .stats-result {
    grid-column: 1 / -1;
  }

  .stats-pagination {
    flex-wrap: wrap;
  }

  .stats-pagination span {
    flex-basis: 100%;
    margin: 0;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .stats-controls-heading {
    align-items: center;
  }

  .stats-density-toggle button {
    padding-inline: 7px;
  }

  .indicator-taxonomy {
    padding-right: 0;
  }

  .stats-copy-link {
    position: static;
    margin: 0 0 9px auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  #indicators .indicator,
  .stats-signal-track i,
  .stats-topic-chip {
    animation: none !important;
    transition: none !important;
  }
}
