/* state.css — the state organ.
   Design intent: the funnel must make blockage impossible to misread. A stage
   that is empty should look empty. A stage that is starved should look starved.
   Totals get no visual prominence at all, because the whole failure this page
   exists to prevent was a large total reading as health. */

.state-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

/* ── Headline ─────────────────────────────────────────────────────────── */

.state-headline {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2.25rem 2.25rem 2rem;
  margin-bottom: 1.25rem;
}

.state-headline__eyebrow {
  font-size: .7rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .9rem;
}

.state-headline__statement {
  font-size: clamp(1.5rem, 3.4vw, 2.35rem);
  line-height: 1.22;
  font-weight: 600;
  letter-spacing: -.025em;
  margin: 0 0 1rem;
  color: var(--ink);
  text-wrap: balance;
}

.state-headline__statement em {
  font-style: normal;
  color: var(--red);
}

.state-headline__sub {
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0;
  max-width: 62ch;
}

.state-headline__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: .8rem;
  color: var(--muted);
}

.state-headline__meta code {
  background: var(--paper-soft);
  padding: .12rem .4rem;
  border-radius: 5px;
  font-size: .74rem;
}

/* ── The funnel ───────────────────────────────────────────────────────── */

.funnel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem 2.25rem 2.25rem;
  margin-bottom: 1.25rem;
}

.funnel__head {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: .5rem;
}

.funnel__head h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -.02em;
}

.funnel__note {
  color: var(--muted);
  font-size: .82rem;
  margin: 0 0 1.9rem;
  max-width: 70ch;
  line-height: 1.6;
}

.funnel__rows {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 8.5rem) minmax(0, 1fr) minmax(0, 7rem);
  align-items: center;
  gap: 1.1rem;
  padding: .62rem 0;
  position: relative;
}

.stage__label {
  font-size: .82rem;
  font-weight: 550;
  letter-spacing: -.01em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: .45rem;
  min-width: 0;
}

.stage__label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The bar. Width is set inline from live data as a percentage of the
   widest stage. Empty stages get the hatched treatment instead. */
.stage__track {
  position: relative;
  height: 30px;
  background: var(--paper-soft);
  border-radius: 6px;
  overflow: hidden;
  min-width: 0;
}

.stage__bar {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--am-purple), #b44dff);
  min-width: 2px;
  transition: width .5s cubic-bezier(.2, .7, .3, 1);
}

/* A stage nobody has ever reached is not a small bar. It is a hole. */
.stage--empty .stage__track {
  background: repeating-linear-gradient(
    -45deg,
    rgba(184, 68, 85, .1) 0 6px,
    transparent 6px 12px
  );
  border: 1px dashed rgba(184, 68, 85, .5);
}

.stage--empty .stage__bar { display: none; }

.stage--empty .stage__label { color: var(--red); }

.stage__zero {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding-left: .7rem;
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--red);
  font-weight: 600;
}

.stage__count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--ink);
}

.stage--empty .stage__count { color: var(--red); }

.stage__count small {
  display: block;
  font-size: .68rem;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
  margin-top: .1rem;
}

/* The drop between two stages — this is the actual content of the chart. */
.drop {
  display: grid;
  grid-template-columns: minmax(0, 8.5rem) minmax(0, 1fr) minmax(0, 7rem);
  gap: 1.1rem;
  align-items: center;
  min-height: 1.55rem;
}

.drop__rule {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .7rem;
  color: var(--muted);
  padding-left: .1rem;
}

.drop__rule::before {
  content: "";
  width: 1px;
  height: 1.1rem;
  background: var(--line-bright);
  flex: none;
  margin-left: .35rem;
}

.drop--worst .drop__rule {
  color: var(--red);
  font-weight: 600;
}

.drop--worst .drop__rule::before {
  background: var(--red);
  width: 2px;
}

.drop__pct {
  font-variant-numeric: tabular-nums;
}

/* ── Definition list under the funnel ─────────────────────────────────── */

.stage-defs {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: .85rem;
}

.stage-defs h3 {
  margin: 0 0 .3rem;
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage-def {
  display: grid;
  grid-template-columns: minmax(0, 8.5rem) minmax(0, 1fr);
  gap: 1.1rem;
  font-size: .82rem;
  line-height: 1.55;
}

.stage-def dt {
  font-weight: 600;
  color: var(--ink);
}

.stage-def dd {
  margin: 0;
  color: var(--ink-soft);
}

/* ── Freshness lanes ──────────────────────────────────────────────────── */

.lanes {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem 2.25rem 2.25rem;
  margin-bottom: 1.25rem;
}

.lanes h2 {
  margin: 0 0 .5rem;
  font-size: 1.15rem;
  letter-spacing: -.02em;
}

.lanes__note {
  color: var(--muted);
  font-size: .82rem;
  margin: 0 0 1.6rem;
  max-width: 74ch;
  line-height: 1.6;
}

.lane-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: .8rem;
}

.lane {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-width: 0;
}

.lane__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .6rem;
}

.lane__name {
  font-weight: 600;
  font-size: .9rem;
  letter-spacing: -.01em;
  min-width: 0;
}

.lane__owner {
  display: block;
  font-weight: 400;
  font-size: .72rem;
  color: var(--muted);
  margin-top: .15rem;
}

.pill {
  font-size: .63rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-weight: 700;
  padding: .24rem .5rem;
  border-radius: 999px;
  white-space: nowrap;
  flex: none;
}

.pill--fresh { background: rgba(62, 143, 119, .13); color: var(--green); }
.pill--overdue { background: rgba(166, 110, 8, .14); color: var(--yellow); }
.pill--unreachable { background: rgba(184, 68, 85, .13); color: var(--red); }
.pill--declared { background: var(--paper-soft); color: var(--muted); }

.lane__meta {
  font-size: .74rem;
  color: var(--muted);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}

.lane__budget {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .72rem;
  color: var(--muted);
}

.lane__budget-track {
  flex: 1;
  height: 3px;
  background: var(--paper-soft);
  border-radius: 2px;
  overflow: hidden;
  min-width: 0;
}

.lane__budget-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--green);
}

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

.lane__note {
  font-size: .74rem;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0;
}

.lane--external {
  border-style: dashed;
  background: linear-gradient(var(--paper-soft), var(--paper-soft)) padding-box;
}

/* ── Generic section shell ────────────────────────────────────────────── */

.state-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem 2.25rem 2.25rem;
  margin-bottom: 1.25rem;
}

.state-panel h2 {
  margin: 0 0 .5rem;
  font-size: 1.15rem;
  letter-spacing: -.02em;
}

.state-panel__note {
  color: var(--muted);
  font-size: .82rem;
  margin: 0 0 1.6rem;
  max-width: 74ch;
  line-height: 1.6;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

table.state-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  min-width: 34rem;
}

table.state-table th,
table.state-table td {
  text-align: left;
  padding: .68rem .85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.state-table th {
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  background: var(--paper-soft);
}

table.state-table tr:last-child td { border-bottom: none; }

table.state-table td code {
  font-size: .72rem;
  color: var(--ink-soft);
  word-break: break-word;
}

.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ── Blocks ───────────────────────────────────────────────────────────── */

.block-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
  display: grid;
  gap: .6rem;
}

.block-card + .block-card { margin-top: .8rem; }

.block-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
}

.block-card__name { font-weight: 600; font-size: .95rem; }

.block-card__id {
  font-size: .72rem;
  color: var(--muted);
  display: block;
  margin-top: .15rem;
  word-break: break-all;
}

.block-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
  gap: .7rem;
  font-size: .76rem;
}

.block-facts div span {
  display: block;
  color: var(--muted);
  font-size: .66rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: .2rem;
}

.block-facts div strong { font-weight: 550; word-break: break-word; }

.qual-bar {
  display: flex;
  gap: 3px;
  margin-top: .2rem;
}

.qual-bar i {
  height: 6px;
  flex: 1;
  border-radius: 2px;
  background: var(--paper-soft);
}

.qual-bar i.pass { background: var(--green); }
.qual-bar i.blocked { background: var(--red); opacity: .55; }

@media (max-width: 720px) {
  .stage,
  .drop,
  .stage-def { grid-template-columns: minmax(0, 6rem) minmax(0, 1fr) minmax(0, 4.5rem); }
  .stage-def { grid-template-columns: minmax(0, 6rem) minmax(0, 1fr); }
  .state-headline,
  .funnel,
  .lanes,
  .state-panel { padding-left: 1.25rem; padding-right: 1.25rem; }
}

/* Known structural defects — derived, not hand-maintained. */
.defect {
  border: 1px solid var(--line);
  border-left: 3px solid var(--yellow);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
  display: grid;
  gap: .65rem;
}
.defect + .defect { margin-top: .8rem; }
.defect__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .6rem;
}
.defect__name {
  font-weight: 600;
  font-size: .92rem;
  letter-spacing: -.015em;
  max-width: 72ch;
  line-height: 1.45;
}

/* Upstream discovery surface — reservoirs above the funnel, not stages in it. */
.upstream { margin: 0 0 2rem; padding: 1.25rem; border: 1px solid var(--paper-line); border-radius: var(--radius); background: var(--paper-soft); }
.upstream__head h3 { margin: 0 0 .4rem; font-size: 1rem; letter-spacing: .01em; }
.upstream__head p { margin: 0 0 1rem; font-size: .85rem; line-height: 1.55; color: var(--ink-soft); max-width: 68ch; }
.upstream__cards { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); }
.upstream__card { padding: .85rem 1rem; border: 1px solid var(--paper-line); border-left: 3px solid var(--am-lilac); border-radius: calc(var(--radius) / 2); background: var(--paper); }
.upstream__card--unreachable { border-left-color: var(--orange); }
.upstream__card h4 { margin: 0 0 .35rem; font-size: .9rem; }
.upstream__obs { margin: 0 0 .5rem; font-size: .82rem; line-height: 1.5; color: var(--ink); }
.upstream__meta { margin: 0; font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.upstream__state { font-weight: 600; }
.upstream__card--unreachable .upstream__state { color: var(--orange); }
