:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #697586;
  --line: #dde3ea;
  --green: #16815f;
  --blue: #2764d8;
  --red: #c2413a;
  --yellow: #b7791f;
  --teal: #0f766e;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(31, 41, 51, 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;
}

.app-header {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 84px;
  padding: 16px 28px;
  position: sticky;
  top: 0;
  z-index: 4;
}

.eyebrow {
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.header-actions {
  align-items: center;
  display: flex;
  gap: 12px;
}

.refresh-meta {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 2px;
  justify-items: end;
}

.refresh-meta strong {
  color: var(--ink);
  font-size: 13px;
}

.token-field {
  display: grid;
  gap: 4px;
}

.token-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.token-field input {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  height: 40px;
  max-width: 180px;
  padding: 0 10px;
}

.token-field input:focus {
  border-color: var(--green);
  outline: 2px solid rgba(22, 129, 95, 0.16);
}

.primary-button {
  align-items: center;
  background: var(--green);
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.button-icon {
  font-size: 18px;
  line-height: 1;
}

main {
  margin: 0 auto;
  max-width: 1440px;
  padding: 18px 28px 36px;
}

.tabs {
  align-items: center;
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  min-height: 36px;
  padding: 0 14px;
  white-space: nowrap;
}

.tab.active {
  background: #1f2933;
  border-color: #1f2933;
  color: #ffffff;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.warnings {
  background: #fff8eb;
  border: 1px solid #f0d39a;
  border-radius: var(--radius);
  color: #7a4a08;
  font-size: 14px;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.scope-strip {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.2fr);
  margin-bottom: 16px;
  padding: 14px 16px;
}

.scope-strip div:first-child {
  display: grid;
  gap: 4px;
}

.scope-label {
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.scope-strip small,
.block-note,
.kpi small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.scope-channels {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.scope-channels span {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 2px;
  min-height: 58px;
  padding: 8px 10px;
}

.scope-channels strong {
  color: var(--ink);
}

.hidden {
  display: none;
}

.kpi-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

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

.kpi {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 16px;
}

.kpi span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi strong {
  font-size: clamp(22px, 2vw, 32px);
  line-height: 1.1;
}

.dashboard-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.channel-card-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.channel-card {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 6px;
  min-height: 92px;
  padding: 12px;
}

.channel-card strong {
  color: var(--muted);
  font-size: 13px;
}

.channel-card span {
  font-size: 24px;
  font-weight: 800;
}

.channel-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.two-col {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.block {
  min-width: 0;
  padding: 16px;
}

.block-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
}

.block-note {
  margin: -6px 0 12px;
}

.block-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.bar-chart,
.stack-list,
.rank-list,
.donut-list {
  display: grid;
  gap: 10px;
}

.bar-row,
.stack-row,
.rank-row {
  display: grid;
  gap: 6px;
}

.bar-top,
.stack-top,
.rank-top {
  align-items: center;
  display: flex;
  font-size: 13px;
  gap: 10px;
  justify-content: space-between;
}

.bar-top strong,
.stack-top strong,
.rank-top strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track,
.stack-track {
  background: #edf1f5;
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
}

.bar-fill,
.stack-fill {
  background: var(--blue);
  border-radius: inherit;
  height: 100%;
  min-width: 2px;
}

.stack-fill.green {
  background: var(--green);
}

.stack-fill.yellow {
  background: var(--yellow);
}

.stack-fill.red {
  background: var(--red);
}

.rank-row {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.rank-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.rank-row small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donut-item {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 90px 1fr auto;
}

.dot {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  margin-right: 8px;
  width: 10px;
}

.table-wrap {
  max-height: 430px;
  overflow: auto;
}

.table-wrap.tall {
  max-height: 620px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  padding: 10px 8px;
  text-align: right;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

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

.pair-label {
  display: block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pair-label.wide {
  max-width: 420px;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
}

.status.ok {
  background: #e8f7ef;
  color: #11734d;
}

.status.check {
  background: #fff4db;
  color: #8a5200;
}

.status.muted {
  background: #edf1f5;
  color: #526070;
}

@media (max-width: 980px) {
  .app-header {
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
  }

  main {
    padding: 14px 16px 28px;
  }

  .kpi-grid,
  .two-col,
  .scope-strip,
  .channel-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .scope-strip {
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .app-header,
  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .refresh-meta {
    justify-items: start;
  }

  .token-field input {
    max-width: none;
    width: 100%;
  }

  .kpi-grid,
  .two-col,
  .scope-strip,
  .scope-channels,
  .channel-card-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }
}
