:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #d9dee8;
  --accent: #1769aa;
  --accent-dark: #0f4f85;
  --ok: #15803d;
  --warn: #b45309;
  --shadow: 0 12px 28px rgba(30, 41, 59, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

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

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 34px;
}

h2 {
  font-size: 17px;
}

.settings,
.status-row,
.metrics,
.tabs,
.timeline-search,
.details-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings {
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

input,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
}

#apiKeyInput {
  width: min(360px, 52vw);
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.danger-button {
  background: #be123c;
}

.warning-button {
  background: #f59e0b;
}

.warning-button:hover {
  background: #d97706;
}

.danger-button:hover {
  background: #9f1239;
}

.status-row {
  justify-content: space-between;
  margin: 12px 0 18px;
}

#statusText {
  margin: 0;
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.retention-metrics {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 14px;
}

.tutorial-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 14px;
}

.progression-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 14px;
}

.retention-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 240px)) auto;
  gap: 12px;
  align-items: end;
  margin: 18px 0 14px;
}

.retention-filters input,
.retention-filters select {
  width: 100%;
}

.retention-filter-actions {
  display: flex;
  gap: 8px;
}

.retention-filter-actions button {
  min-width: 82px;
}

#retentionResetButton {
  border-color: var(--line);
  background: #eef3f8;
  color: var(--text);
}

#retentionResetButton:hover {
  background: #dde7f0;
}

.retention-metrics article,
.tutorial-metrics article,
.progression-metrics article,
.retention-chart-shell,
.tutorial-chart-shell,
.progression-chart-shell,
.benchmark-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.retention-metrics article {
  min-height: 104px;
  padding: 16px;
}

.tutorial-metrics article {
  min-height: 104px;
  padding: 16px;
}

.progression-metrics article {
  min-height: 104px;
  padding: 16px;
}

.retention-metrics span,
.tutorial-metrics span,
.progression-metrics span,
.chart-head span,
.muted-cell {
  color: var(--muted);
}

.retention-metrics span,
.tutorial-metrics span,
.progression-metrics span {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.retention-metrics strong,
.tutorial-metrics strong,
.progression-metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.retention-metrics small,
.tutorial-metrics small,
.progression-metrics small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.retention-chart-shell {
  margin-bottom: 0;
  overflow: hidden;
}

.tutorial-chart-shell {
  margin-bottom: 0;
  overflow: hidden;
}

.progression-chart-shell {
  margin-bottom: 18px;
  overflow: hidden;
}

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

.chart-head span {
  font-size: 13px;
}

.compact-filter {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.compact-filter span {
  font-size: 12px;
  font-weight: 700;
}

.compact-filter select {
  min-width: 92px;
}

.retention-chart {
  overflow: auto;
  padding: 12px 14px 16px;
}

.retention-chart svg {
  display: block;
  min-width: 760px;
  width: 100%;
  height: auto;
}

.chart-grid {
  stroke: #e6ebf2;
  stroke-width: 1;
}

.chart-label,
.chart-date {
  fill: var(--muted);
  font-size: 12px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 8px 36px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.empty-chart {
  margin: 0;
  color: var(--muted);
  padding: 18px 2px;
}

.tutorial-chart {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.stage-dropoff-chart {
  overflow: auto;
  padding: 12px 14px 16px;
}

.stage-dropoff-legend {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stage-dropoff-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stage-dropoff-legend i {
  width: 28px;
  height: 10px;
  border-radius: 999px;
}

.stage-dropoff-legend .low {
  background: rgba(190, 18, 60, 0.12);
}

.stage-dropoff-legend .high {
  background: rgba(190, 18, 60, 0.86);
}

.stage-dropoff-grid {
  display: grid;
  gap: 6px;
  min-width: max(680px, calc(92px + (var(--stage-column-count) * 74px)));
}

.stage-dropoff-row {
  display: grid;
  grid-template-columns: 86px repeat(var(--stage-column-count), minmax(58px, 1fr));
  gap: 6px;
  align-items: center;
}

.stage-dropoff-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stage-dropoff-head-cell,
.stage-dropoff-row-label,
.stage-dropoff-cell {
  min-height: 34px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.stage-dropoff-row-label {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stage-dropoff-cell {
  background: rgba(190, 18, 60, var(--dropoff-alpha));
  font-size: 12px;
  font-weight: 800;
  padding: 0 6px;
}

.stage-dropoff-cell.low {
  color: #881337;
}

.stage-dropoff-cell.medium,
.stage-dropoff-cell.high {
  color: #fff;
}

.stage-dropoff-cell.is-empty {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
}

.tutorial-step-row {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(260px, 1fr);
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.progression-bucket-row {
  display: grid;
  grid-template-columns: minmax(130px, 220px) minmax(260px, 1fr);
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

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

.progression-bucket-name strong,
.progression-bucket-name span {
  display: block;
}

.progression-bucket-name span,
.progression-bars span {
  color: var(--muted);
  font-size: 12px;
}

.progression-bars {
  display: grid;
  gap: 6px;
}

.progression-bars i {
  display: block;
  min-width: 2px;
  height: 12px;
  border-radius: 999px;
  background: #7c3aed;
}

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

.tutorial-step-name strong,
.tutorial-step-name span {
  display: block;
}

.tutorial-step-name strong {
  font-size: 14px;
}

.tutorial-step-name span,
.tutorial-bars span {
  color: var(--muted);
  font-size: 12px;
}

.tutorial-bars {
  display: grid;
  gap: 8px;
}

.tutorial-bars div {
  display: grid;
  gap: 5px;
}

.tutorial-bars i {
  display: block;
  min-width: 2px;
  height: 10px;
  border-radius: 999px;
}

.time-bar {
  background: var(--accent);
}

.dropoff-bar {
  background: #be123c;
}

.benchmark-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 16px;
}

.benchmark-card {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 190px;
  border-left-width: 4px;
  padding: 14px;
}

.benchmark-card span,
.benchmark-card small,
.benchmark-card p {
  color: var(--muted);
}

.benchmark-card span {
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.benchmark-card strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.benchmark-card small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.benchmark-card ul {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.benchmark-card li {
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
}

.benchmark-card .weak {
  background: #fff1f2;
  color: #be123c;
}

.benchmark-card .good {
  background: #ecfdf5;
  color: #047857;
}

.benchmark-card .strong {
  background: #eff6ff;
  color: #1d4ed8;
}

.benchmark-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
}

.benchmark-weak {
  border-left-color: #be123c;
}

.benchmark-good {
  border-left-color: #047857;
}

.benchmark-strong {
  border-left-color: #1d4ed8;
}

.timeline-search {
  justify-content: flex-start;
  margin: 0 0 18px;
}

.timeline-search label {
  width: min(560px, 100%);
}

.timeline-search input {
  width: 100%;
}

.metrics article {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: var(--shadow);
}

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

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.tabs {
  border-bottom: 1px solid var(--line);
  margin-top: 8px;
}

.tab {
  min-height: 44px;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
}

.tab:hover,
.tab.active {
  background: var(--panel);
  color: var(--accent);
  border-color: var(--line);
  border-bottom-color: var(--panel);
}

.table-wrap {
  overflow: auto;
  max-height: 48vh;
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--panel);
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f8;
  color: #344054;
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 13px;
}

tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #edf7ff;
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #edf7f0;
  color: var(--ok);
  padding: 0 8px;
  font-weight: 700;
}

.pill.warn {
  background: #fff7ed;
  color: var(--warn);
}

.details {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.details-head {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

#copyButton {
  min-height: 34px;
  background: #eef3f8;
  color: var(--text);
}

#copyButton:hover {
  background: #dde7f0;
}

pre {
  overflow: auto;
  max-height: 320px;
  margin: 0;
  padding: 16px;
  font-size: 13px;
  line-height: 1.55;
}

.public-page {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 42px 22px 56px;
}

.public-hero {
  margin-bottom: 22px;
}

.public-hero p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
}

.public-document {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}

.public-document h2 {
  margin-top: 28px;
}

.public-document h2:first-child {
  margin-top: 0;
}

.public-document p {
  color: #344054;
  line-height: 1.7;
}

.public-document p:first-child {
  margin-top: 0;
}

.public-document p:last-child {
  margin-bottom: 0;
}

.public-document a {
  color: var(--accent);
  font-weight: 700;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 18px;
  }

  .topbar,
  .status-row {
    align-items: stretch;
    flex-direction: column;
  }

  .settings {
    justify-content: stretch;
  }

  .settings label,
  .settings button,
  .timeline-search,
  .timeline-search button,
  #apiKeyInput {
    width: 100%;
  }

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

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

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

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

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

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

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

@media (max-width: 560px) {
  .metrics {
    grid-template-columns: 1fr;
  }

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

  .retention-filters {
    grid-template-columns: 1fr;
  }

  .retention-filter-actions button {
    flex: 1;
  }

  .chart-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .tutorial-step-row {
    grid-template-columns: 1fr;
  }

  .progression-bucket-row {
    grid-template-columns: 1fr;
  }

  .benchmark-grid {
    grid-template-columns: 1fr;
  }
}
