/* Funnels (src/routes/funnels.ts), cohorts (src/routes/cohorts.ts) and the
   funnel dashboard widget (public/static/app/analytics.js).
   Tokens come from site.css; nothing here sets a color of its own. Bars and
   cells mix the accent into the panel, so both themes keep their contrast:
   text sits on at most a 38% mix, which keeps --text above 7:1 in light and
   dark. */

/* ---------- funnels page ---------- */

.fn-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.fn-pick {
  min-width: 0;
}

.fn-pick .chip {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fn-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.fn-card {
  display: grid;
  gap: 16px;
}

.fn-card-head,
.ch-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: flex-start;
  justify-content: space-between;
}

.fn-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.fn-actions form {
  display: contents;
}

.fn-headline,
.ch-headline {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.015em;
  color: var(--text);
}

.ch-headline {
  margin-top: 4px;
  font-size: 18px;
}

.fn-kpis {
  background: var(--bg-raised);
}

.fn-change {
  font-variant-numeric: tabular-nums;
}

.fn-change.is-up {
  color: var(--found);
}

.fn-change.is-down {
  color: var(--lost);
}

/* The bars: one row a step, the drop-off line between rows. */
.fn-steps {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fn-step {
  display: grid;
  gap: 6px;
}

.fn-step-head {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto 56px;
  gap: 10px;
  align-items: baseline;
  font-size: var(--type-ui);
}

.fn-num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-family: var(--mono);
  font-size: var(--type-label);
  color: var(--text-dim);
  background: var(--bg-tint);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  align-self: center;
}

.fn-name {
  overflow: hidden;
  font-weight: var(--weight-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fn-count,
.fn-pct {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.fn-pct {
  color: var(--text-dim);
}

.fn-bar {
  position: relative;
  height: 28px;
  margin-left: 34px;
  overflow: hidden;
  background: var(--bg-tint);
  border-radius: var(--r-sm);
}

.fn-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--w);
  background: var(--accent);
  border-radius: var(--r-sm);
  transition: width var(--dur-4) ease;
}

/* The period before: a thin mark at its length, over the bar. */
.fn-bar b {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: calc(var(--w) - 2px);
  width: 2px;
  background: var(--text);
  border-radius: var(--r-xs);
  opacity: 0.55;
}

.fn-gap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 8px 0 12px 34px;
  padding-left: 12px;
  font-size: var(--type-small);
  color: var(--text-dim);
  border-left: 2px dotted var(--line-strong);
}

.fn-left a {
  color: var(--lost);
  font-weight: var(--weight-medium);
}

.fn-left {
  color: var(--lost);
}

.fn-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
}

.fn-legend i {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 3px;
}

.fn-legend-now {
  background: var(--accent);
}

.fn-legend-prev {
  width: 2px !important;
  background: var(--text);
  opacity: 0.55;
}

.fn-note {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.fn-split {
  display: grid;
  gap: 10px;
}

.fn-table {
  table-layout: auto;
}

.fn-table th:first-child {
  width: auto;
}

.fn-table th {
  white-space: nowrap;
}

.fn-split-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fn-rate {
  position: relative;
  display: inline-block;
  min-width: 64px;
  padding: 2px 6px;
  font-variant-numeric: tabular-nums;
  isolation: isolate;
}

.fn-rate i {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: -1;
  width: var(--w);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 4px;
}

.fn-empty-actions {
  justify-content: center;
}

.fn-people {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fn-people li + li {
  border-top: 1px solid var(--line);
}

.fn-people a {
  display: grid;
  gap: 2px;
  min-height: 44px;
  padding: 10px 0;
  color: var(--text);
  text-decoration: none;
}

.fn-people a:hover .fn-person {
  color: var(--accent);
}

.fn-person {
  font-weight: 600;
}

.fn-person-sub {
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- the builder ---------- */

.fn-build .card {
  display: grid;
  gap: 18px;
}

.fn-steps-field,
.fn-window {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.fn-rows {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: none;
}

.fn-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.fn-row[hidden] {
  display: none;
}

.fn-row-fields {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px;
}

.fn-row-fields [hidden] {
  display: none;
}

.fn-row-tools {
  display: flex;
  gap: 2px;
}

.fn-row-tools [data-up] svg {
  transform: rotate(180deg);
}

.fn-row:first-child [data-up] {
  visibility: hidden;
}

.fn-add {
  justify-self: start;
}

.fn-delete {
  justify-self: start;
}

/* ---------- cohorts ---------- */

.ch-card {
  display: grid;
  gap: 14px;
}

.ch-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 3px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.ch-grid th {
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

.ch-grid tbody th {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}

.ch-grid .num {
  text-align: right;
}

.ch-size {
  padding: 6px 8px;
  color: var(--text-dim);
}

.ch-cell {
  min-width: 52px;
  padding: 7px 8px;
  text-align: right;
  white-space: nowrap;
  background: color-mix(in srgb, var(--accent) calc(var(--v) * 38%), var(--bg-raised));
  border-radius: 5px;
}

.ch-cell.is-first {
  color: var(--text-dim);
  background: var(--bg-tint);
}

.ch-cell.is-future {
  background: transparent;
}

.ch-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-foot,
.ch-empty {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.ch-ltv th:first-child {
  width: 28%;
}

/* ---------- the funnel widget ---------- */

.dw-funnel {
  display: grid;
  align-content: start;
  gap: 10px;
}

.dw-funnel-line {
  align-self: start;
  margin: 0;
  font-size: var(--type-small);
  color: var(--text-dim);
}

.dw-funnel .fn-gap {
  margin: 4px 0 6px 34px;
  font-size: var(--type-caption);
}

.dw-funnel .fn-bar {
  height: 20px;
}

@media (max-width: 720px) {
  .fn-headline {
    font-size: var(--type-title);
  }
  .fn-step-head {
    grid-template-columns: 24px minmax(0, 1fr) auto 48px;
    gap: 8px;
  }
  .fn-bar,
  .fn-gap {
    margin-left: 0;
  }
  /* Each step is its own group on phones: number, fields stacked, tools, a line under it. */
  .fn-row {
    align-items: start;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }
  .fn-row > .fn-num {
    align-self: start;
    margin-top: 9px;
  }
  .fn-row-tools {
    flex-direction: column;
  }
  .fn-row-fields {
    grid-template-columns: minmax(0, 1fr);
  }
  .fn-top .fn-new {
    width: 100%;
  }
  /* Phones: name, started and conversion; finished is in the step bars above. */
  .fn-table th:nth-child(3),
  .fn-table td:nth-child(3) {
    display: none;
  }
  .fn-split-name {
    max-width: 130px;
  }
  .fn-rate {
    min-width: 0;
  }
}
