:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #1d2528;
  --muted: #627074;
  --line: #dfe6e1;
  --green: #176f57;
  --red: #b23b3b;
  --blue: #245f9f;
  --gold: #a66a16;
  --shadow: 0 10px 30px rgba(25, 38, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px) 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 20px;
}

p {
  color: var(--muted);
}

main {
  display: grid;
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 48px) 40px;
}

.toolbar,
.tableTools,
.panelHead,
.chartControls,
.segmented,
.metrics,
.split {
  display: flex;
  gap: 12px;
}

.toolbar {
  align-items: end;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font: inherit;
}

select {
  min-width: 190px;
  padding: 0 34px 0 12px;
}

input {
  min-width: 220px;
  padding: 0 12px;
}

.compactSelect {
  min-width: 112px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 118px;
  padding: 18px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric span {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin: 10px 0 8px;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.panel {
  padding: 18px;
  overflow: hidden;
}

.panelHead {
  align-items: start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panelHead p {
  margin-bottom: 0;
  font-size: 14px;
}

.chartControls {
  align-items: end;
  flex-wrap: wrap;
  justify-content: end;
}

.segmented {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
}

.segmented button {
  min-width: 48px;
  height: 32px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.segmented button.active {
  background: var(--ink);
  color: white;
}

.chartWrap {
  width: 100%;
  min-height: 300px;
}

#trendChart {
  display: block;
  width: 100%;
  height: 300px;
}

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

.rankList {
  display: grid;
  gap: 10px;
}

.rankItem {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.rankItem:first-child {
  border-top: 0;
}

.rankIndex {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: #edf2ef;
  color: var(--muted);
  font-weight: 800;
}

.rankName strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rankName span,
.rankValue span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.rankValue {
  text-align: right;
}

.rankValue strong {
  display: block;
  font-size: 16px;
}

.tableTools {
  align-items: center;
  flex-wrap: wrap;
}

.tableWrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 10px;
  border-top: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

th:first-child,
th:nth-child(2),
td:first-child,
td:nth-child(2) {
  text-align: left;
}

td:nth-child(2) {
  max-width: 360px;
}

.categoryRow {
  cursor: pointer;
}

.categoryRow:hover,
.categoryRow:focus {
  background: #f2f6f4;
  outline: none;
}

.categoryRow.selected {
  background: #eef4f8;
  box-shadow: inset 4px 0 0 var(--blue);
}

.empty {
  padding: 24px 0;
  color: var(--muted);
}

@media (max-width: 880px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .toolbar label,
  .toolbar select {
    width: 100%;
  }

  .metrics,
  .split {
    grid-template-columns: 1fr;
  }

  .panelHead {
    align-items: stretch;
    flex-direction: column;
  }

  .chartControls,
  .chartControls label,
  .chartControls select {
    width: 100%;
  }
}
