:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary: var(--tg-theme-secondary-bg-color, #f2f2f7);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

button, select, input { font: inherit; color: inherit; }

button { cursor: pointer; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 12px 32px;
}

.screen {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px 8px;
}

.screen h1 { font-size: 22px; margin: 0; }

.muted { color: var(--hint); margin: 0; }

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.top h1 { font-size: 22px; margin: 0; }

.role { color: var(--hint); font-size: 13px; }

.tabs, .chips, .filters, .legend {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tabs, .chips { overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }

.chip, .tab, .back, .primary {
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--text);
  min-height: 40px;
  padding: 8px 14px;
  white-space: nowrap;
}

.chip.active, .tab.active, .primary {
  background: var(--button);
  color: var(--button-text);
}

.filters { flex-wrap: wrap; margin-bottom: 12px; }

.filters select, .dates input {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--secondary);
  padding: 8px 10px;
  max-width: 100%;
}

.dates { display: flex; gap: 8px; margin: -4px 0 12px; }

.dates label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--hint); flex: 1; }

.hint { color: var(--hint); font-size: 12px; margin: 0 0 12px; }

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

@media (min-width: 640px) {
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.card, .link-row, .partner-row {
  background: var(--secondary);
  border-radius: 14px;
  padding: 10px 12px;
}

.card .label, .meta { color: var(--hint); font-size: 12px; }

.card .value { font-size: 18px; font-weight: 600; margin-top: 2px; }

.link-row, .partner-row {
  width: 100%;
  text-align: left;
  border: 0;
  margin-top: 8px;
  display: block;
}

.link-row .url {
  display: block;
  margin-top: 4px;
  color: var(--link);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics-line { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 8px; font-size: 13px; }

.section-title { margin: 8px 0 0; font-size: 16px; }

.detail-link {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--secondary);
  border-radius: 12px;
  word-break: break-all;
  user-select: text;
}

.actions { display: flex; gap: 8px; margin: 8px 0 14px; }

canvas {
  width: 100%;
  height: 180px;
  display: block;
  background: var(--secondary);
  border-radius: 14px;
}

.legend { margin: 8px 0 12px; font-size: 12px; color: var(--hint); }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.swatch.subs { background: var(--button); }
.swatch.ftd { background: var(--text); }

.table-wrap { overflow-x: auto; margin-top: 8px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }

th, td {
  padding: 8px;
  border-bottom: 1px solid var(--hint);
  text-align: right;
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

th { color: var(--hint); font-weight: 600; }

.status { color: var(--hint); padding: 12px 0; }
