:root {
  --stats-bg: #f6f7f9;
  --stats-card: #ffffff;
  --stats-text: #1f2430;
  --stats-soft: #667085;
  --stats-line: #e4e7ec;
  --stats-money: #0f766e;
  --stats-chip: #f8fafc;
  --stats-chip-active: #1f2430;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--stats-bg);
  color: var(--stats-text);
  font-family: Arial, Helvetica, sans-serif;
}

.stats-page {
  padding: 12px 14px 26px;
}

.stats-wrap {
  max-width: 1240px;
  margin: 0 auto;
}

.stats-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.stats-back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid var(--stats-line);
  border-radius: 999px;
  background: var(--stats-card);
  color: var(--stats-text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.stats-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.stats-top h1,
.stats-table-head h2 {
  margin: 0;
}

.stats-top h1 {
  font-size: 24px;
  line-height: 1.1;
}

.stats-updated,
.summary-label,
.stats-empty,
.stats-table th {
  color: var(--stats-soft);
}

.stats-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--stats-soft);
  font-weight: 400;
}

.stats-data-note {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--stats-soft);
  font-weight: 500;
}

.stats-updated,
.summary-inline-meta {
  font-size: 12px;
}

.stats-overview-card,
.stats-table-card {
  background: var(--stats-card);
  border: 1px solid var(--stats-line);
  border-radius: 12px;
}

.stats-overview-card {
  padding: 10px 12px;
  margin-bottom: 10px;
}

.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 12px;
  align-items: start;
}

.overview-item {
  min-width: 0;
}

.overview-item-money {
  min-width: 120px;
}

.summary-label {
  display: block;
  margin-bottom: 1px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-value {
  display: block;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 700;
}

.summary-value.money {
  color: var(--stats-money);
  font-size: 17px;
  white-space: nowrap;
}

.stats-table-card {
  overflow: hidden;
}

.stats-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--stats-line);
}

.stats-table-head h2 {
  font-size: 16px;
}

.stats-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.stats-filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stats-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid var(--stats-line);
  border-radius: 999px;
  background: var(--stats-chip);
  color: var(--stats-text);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

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

.stats-toolbar {
  padding: 8px 14px 0;
}

.stats-search {
  display: block;
  max-width: 220px;
}

.stats-search input {
  width: 100%;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--stats-line);
  border-radius: 10px;
  background: #fff;
  color: var(--stats-text);
  font-size: 13px;
}

.stats-table-scroll {
  max-height: min(48vh, 430px);
  overflow: auto;
  overscroll-behavior: contain;
}

.stats-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
}

.stats-table th,
.stats-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--stats-line);
  text-align: center;
  font-size: 13px;
}

.stats-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafafa;
  font-size: 11px;
  font-weight: 700;
}

.stats-table tbody tr:hover {
  background: #fafafa;
}

.stats-table tbody tr[hidden] {
  display: none;
}

.stats-table th:first-child,
.stats-table td.city {
  text-align: left;
}

.stats-table td.city {
  font-weight: 700;
}

.stats-table td.money {
  color: var(--stats-money);
  font-weight: 700;
  white-space: nowrap;
}

.stats-table td.potential-money {
  color: #0f4c81;
  font-weight: 700;
  white-space: nowrap;
}

.stats-table td.net-negative {
  color: #dc2626;
  font-weight: 700;
  white-space: nowrap;
}

.summary-value.net-negative {
  color: #dc2626;
}

.stats-total-row td {
  position: sticky;
  bottom: 0;
  z-index: 3;
  font-weight: 700;
  background: #fafafa;
  box-shadow: 0 -1px 0 var(--stats-line);
}

.stats-empty {
  padding: 16px 14px;
  font-size: 13px;
}

.stats-detail-card {
  margin-top: 10px;
  overflow: hidden;
}

.stats-detail-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 58px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--stats-line);
  cursor: pointer;
  list-style: none;
  background: #fff;
}

.stats-detail-summary::-webkit-details-marker {
  display: none;
}

.stats-detail-heading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 176px;
  font-size: 16px;
  font-weight: 700;
}

.stats-detail-heading strong {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--stats-chip);
  color: var(--stats-soft);
  font-size: 12px;
  text-align: center;
}

.stats-detail-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.stats-detail-metrics div {
  min-width: 0;
}

.stats-detail-metrics span {
  display: block;
  margin-bottom: 2px;
  color: var(--stats-soft);
  font-size: 11px;
  font-weight: 700;
}

.stats-detail-metrics strong {
  display: block;
  color: #0f4c81;
  font-size: 15px;
  white-space: nowrap;
}

.stats-detail-toggle {
  width: 30px;
  height: 30px;
  border: 1px solid var(--stats-line);
  border-radius: 999px;
  background: var(--stats-chip);
  position: relative;
  flex: 0 0 auto;
}

.stats-detail-toggle::before,
.stats-detail-toggle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 2px;
  border-radius: 999px;
  background: var(--stats-text);
  transform: translate(-50%, -50%);
}

.stats-detail-toggle::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.stats-detail-card[open] .stats-detail-toggle::after {
  opacity: 0;
}

.stats-detail-scroll {
  max-height: min(42vh, 360px);
}

.stats-detail-table {
  min-width: 980px;
}

.stats-detail-text {
  max-width: 260px;
  text-align: left !important;
  white-space: normal;
  line-height: 1.35;
}

.stats-detail-meta {
  display: block;
  margin-top: 3px;
  color: var(--stats-soft);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
}

.page-version-bar {
  padding: 8px 14px 18px;
  color: var(--stats-soft);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 860px) {
  .stats-top,
  .stats-table-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats-overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-controls {
    justify-content: flex-start;
  }
}

@media (max-width: 600px) {
  .stats-page {
    padding: 10px 8px 20px;
  }

  .stats-actions {
    justify-content: stretch;
  }

  .stats-back-link {
    width: 100%;
  }

  .stats-top {
    gap: 4px;
    margin-bottom: 6px;
  }

  .stats-top h1 {
    font-size: 20px;
  }

  .stats-updated {
    font-size: 11px;
  }

  .stats-overview-card {
    padding: 8px 10px;
    margin-bottom: 8px;
  }

  .stats-overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 10px;
  }

  .summary-value {
    font-size: 16px;
  }

  .summary-value.money {
    font-size: 16px;
  }

  .stats-table-head {
    padding: 8px 10px;
    gap: 8px;
  }

  .stats-table-head h2 {
    font-size: 15px;
  }

  .stats-controls,
  .stats-filter-chips,
  .stats-search {
    width: 100%;
  }

  .stats-filter-chips {
    gap: 5px;
  }

  .stats-chip {
    flex: 1 1 auto;
    min-height: 28px;
    padding: 5px 8px;
    font-size: 11px;
  }

  .stats-toolbar {
    padding: 8px 10px 0;
  }

  .stats-detail-metrics {
    grid-template-columns: 1fr;
  }

  .stats-detail-summary {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .stats-detail-heading,
  .stats-detail-metrics {
    grid-column: 1 / 2;
  }

  .stats-detail-toggle {
    grid-column: 2 / 3;
    grid-row: 1 / span 2;
  }

  .stats-table-scroll {
    max-height: 46vh;
  }

  .stats-search {
    max-width: none;
  }

  .page-version-bar {
    padding: 8px 10px 16px;
    font-size: 10px;
  }
}
