:root {
  --ink: #183330;
  --muted: #687c77;
  --line: #d9e3df;
  --paper: #f4f7f5;
  --white: #ffffff;
  --deep: #153d39;
  --green: #147d6f;
  --green-soft: #e4f2ed;
  --orange: #c55a2d;
  --orange-soft: #f9e9df;
  --red: #b74d47;
  --yellow: #ddaa42;
  --shadow: 0 7px 21px rgba(21, 61, 57, 0.065);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, select { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin-top: 0; }

.topbar {
  min-height: 88px;
  padding: 16px clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--deep);
  color: var(--white);
}

.brand-lockup, .topbar-meta, .filter-band, .section-heading { display: flex; }
.brand-lockup { align-items: center; gap: 13px; }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid #8bc0b4;
  border-radius: 6px;
  color: #f4d184;
  font-size: 13px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: #5c8780;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.8px;
}
.topbar .eyebrow { color: #a8cec5; }
h1 { margin-bottom: 0; font-size: 21px; font-weight: 700; }
h1 span { color: #f4d184; font-weight: 600; }
h2 { margin-bottom: 0; font-size: 17px; font-weight: 700; }

.topbar-meta { align-items: center; justify-content: flex-end; gap: 11px; color: #d6e8e3; font-size: 12px; }
.source-badge {
  padding: 5px 8px;
  border-radius: 4px;
  background: #245950;
  color: #d8f3eb;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.source-badge.is-loading { background: #466249; color: #fbefbf; }
.source-badge.is-warning { background: #755331; color: #ffe3a2; }
.updated-at { white-space: nowrap; }
.icon-button {
  width: 33px;
  height: 33px;
  border: 1px solid #5c968b;
  border-radius: 4px;
  background: transparent;
  color: var(--white);
  font-size: 20px;
  line-height: 1;
}
.icon-button:hover { background: #245950; }
.icon-button:disabled { cursor: wait; opacity: 0.6; }

main { width: min(1500px, 100%); margin: 0 auto; padding: 24px clamp(20px, 4vw, 64px) 52px; }
.filter-band {
  align-items: end;
  flex-wrap: wrap;
  gap: 10px 15px;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--line);
}
.filter-group {
  display: flex;
  height: 36px;
  overflow: hidden;
  border: 1px solid #bdcdc7;
  border-radius: 4px;
  background: var(--white);
}
.filter-group button {
  min-width: 77px;
  padding: 0 11px;
  border: 0;
  border-right: 1px solid #d9e2df;
  background: var(--white);
  color: #4c625d;
  font-size: 13px;
}
.filter-group button:last-child { border-right: 0; }
.filter-group button.is-active { background: var(--deep); color: var(--white); font-weight: 700; }
.select-field { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 650; }
.select-field select {
  height: 36px;
  min-width: 118px;
  padding: 0 31px 0 10px;
  border: 1px solid #bdcdc7;
  border-radius: 4px;
  background: var(--white);
  color: var(--ink);
  font-size: 13px;
}
.data-window { margin: 0 0 9px auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
button:focus, select:focus { outline: 2px solid #80c6b7; outline-offset: 2px; }

.notice {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  padding: 11px 13px;
  border-left: 4px solid var(--yellow);
  background: #fff8e8;
  color: #72572c;
  line-height: 1.5;
}
.notice[hidden] { display: none; }
.notice strong { color: #573c13; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 22px 0;
}
.metric {
  min-width: 0;
  min-height: 125px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  box-shadow: var(--shadow);
}
.metric p { margin-bottom: 13px; color: var(--muted); font-size: 12px; }
.metric strong { display: block; overflow: hidden; color: var(--deep); font-size: 25px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.metric span { display: block; margin-top: 10px; color: #899792; font-size: 11px; line-height: 1.35; }
.metric-spend { border-top: 3px solid var(--orange); }
.metric-spend strong { color: var(--orange); }

.section-block {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  box-shadow: var(--shadow);
}
.market-section, .leaderboard-section { padding: 20px 21px 9px; }
.section-heading { align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-note, .chart-caption { margin: 2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; text-align: right; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 0 10px 11px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-align: left;
  white-space: nowrap;
}
th:not(:first-child), td:not(:first-child) { text-align: right; }
td { padding: 13px 10px; border-top: 1px solid #e5ece9; vertical-align: middle; }
.money-cell { color: var(--deep); font-size: 13px; font-weight: 650; white-space: nowrap; }
.strong { font-weight: 800; }
.sub-line { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; line-height: 1.3; white-space: nowrap; }
.market-tag {
  display: inline-block;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}
.market-id { background: var(--green-soft); color: #17675c; }
.market-my { background: var(--orange-soft); color: #9d4929; }
.empty-cell { padding: 31px; color: var(--muted); text-align: center !important; }

.trend-grid, .bottom-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.chart-panel, .campaign-section, .health-panel { padding: 20px 21px; }
.chart-wrap { height: 238px; position: relative; }
canvas { display: block; width: 100%; height: 100%; }
.axis-labels { display: flex; justify-content: space-between; min-height: 14px; padding-left: 48px; color: #8c9b96; font-size: 10px; }

.leaderboard-section { margin-top: 16px; }
.leaderboard-table { min-width: 950px; }
.campaign-table { min-width: 680px; }
.name-cell { max-width: 240px; overflow: hidden; text-align: left !important; text-overflow: ellipsis; white-space: nowrap; }
.name-cell strong, .name-cell > span:not(.market-tag) { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-table .market-tag { display: block; width: max-content; margin-bottom: 4px; }

.bottom-grid { grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.7fr); }
.source-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.source-list li {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid #edf1ef;
}
.source-list li:last-child { border-bottom: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--yellow); }
.status-dot.is-ok { background: var(--green); }
.status-dot.is-error { background: var(--red); }
.source-name { display: block; font-size: 12px; font-weight: 700; }
.source-meta { display: block; margin-top: 2px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.source-state { color: #778781; font-size: 10px; white-space: nowrap; }
.health-footnote { margin: 15px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

@media (max-width: 1220px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 880px) {
  .trend-grid, .bottom-grid { grid-template-columns: 1fr; }
  .bottom-grid { margin-top: 16px; }
}

@media (max-width: 680px) {
  .topbar { min-height: 0; align-items: flex-start; flex-direction: column; padding: 16px 20px; }
  .topbar-meta { width: 100%; justify-content: flex-start; }
  .updated-at { overflow: hidden; text-overflow: ellipsis; }
  main { padding: 18px 16px 40px; }
  .filter-band { align-items: stretch; }
  .filter-group { width: 100%; }
  .filter-group button { flex: 1; min-width: 0; padding: 0 5px; font-size: 12px; }
  .select-field { flex: 1 1 calc(50% - 8px); }
  .select-field select { width: 100%; min-width: 0; }
  .data-window { width: 100%; margin: 0; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .metric { min-height: 109px; padding: 13px; }
  .metric strong { font-size: 22px; }
  .market-section, .leaderboard-section, .chart-panel, .campaign-section, .health-panel { padding: 16px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .section-note, .chart-caption { text-align: left; }
}
