/* ==========================================================================
   COMPONENTS — the construction grammar.
   --------------------------------------------------------------------------
   These encode what the SITE needs (a panel, a tag, a stepped process, a human
   decision marker), not how a particular brand looks. Every visual property
   resolves to a token, so a direction with soft cards and round corners is the
   same markup with --radius and --shadow-* changed.
   ========================================================================== */


/* ---- Band: a bordered container whose cells share edges, no gaps ---- */
.band {
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  display: grid;
  overflow: hidden;
}
.band > * { padding: var(--space-4) var(--space-5); border-left: var(--border-w) solid var(--line); }
.band--2 { grid-template-columns: repeat(2, 1fr); }
.band--3 { grid-template-columns: repeat(3, 1fr); }
.band--4 { grid-template-columns: repeat(4, 1fr); }
.band--2 > :nth-child(2n+1),
.band--3 > :nth-child(3n+1),
.band--4 > :nth-child(4n+1) { border-left: 0; }
.band--2 > :nth-child(n+3),
.band--3 > :nth-child(n+4),
.band--4 > :nth-child(n+5) { border-top: var(--border-w) solid var(--line); }

@media (max-width: 860px) {
  .band--2, .band--3, .band--4 { grid-template-columns: 1fr; }
  .band > * { border-left: 0; border-top: var(--border-w) solid var(--line); }
  .band > :first-child { border-top: 0; }
}


/* ---- Ledger: label/value rows. The dense-page workhorse. ---- */
.ledger { border-top: var(--border-w) solid var(--line); }
.ledger > div {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-5);
  padding-block: var(--space-4);
  border-bottom: var(--border-w) solid var(--line);
  align-items: start;
}
@media (max-width: 720px) {
  .ledger > div { grid-template-columns: 1fr; gap: var(--space-2); }
}


/* ---- Panel: a full-bleed inverse surface ---- */
.panel {
  background: var(--ground-inverse);
  color: var(--ink-inverse);
  border: var(--border-w) solid var(--line-inverse);
  border-radius: var(--radius);
}
.panel--raised { background: var(--ground-raised); }
.panel--shadow { box-shadow: var(--shadow-panel); }

/* Card panel: a lifted surface of the section it sits in, rather than an
   inverse block. Used by the work-record illustration on the homepages. */
.panel--card {
  background: color-mix(in srgb, var(--heading) 5%, var(--ground));
  color: var(--ink);
  border-color: var(--line);
}
.panel--card .topline { border-color: var(--line); color: var(--ink-muted); }
.panel--card .topline > :first-child { color: var(--heading); }
.panel--card .topline .is-accent,
.panel--card .gate { color: var(--accent-text); border-color: var(--accent-text); }
.panel--card .ledger > div { border-color: var(--line); }

/* Every panel opens with a metadata row: title left, state right. */
.topline {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-w) solid var(--line-inverse);
  font-family: var(--font-label);
  font-size: var(--size-label);
  font-weight: var(--label-weight);
  letter-spacing: var(--label-tracking);
  text-transform: var(--label-transform);
  color: var(--ink-inverse-muted);
}
.topline > :first-child { color: var(--ink-inverse); }
.topline .is-accent { color: var(--accent-dark); }


/* ---- Chip: an outlined tag for sources and agents. Never filled. ---- */
.chip {
  display: inline-block;
  border: var(--border-w) solid var(--line);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-family: var(--font-label);
  font-size: var(--size-label);
  font-weight: var(--label-weight);
  letter-spacing: var(--label-tracking);
  text-transform: var(--label-transform);
  color: var(--ink);
}
.panel .chip, .section--inverse .chip { border-color: var(--line-inverse); color: var(--ink-inverse); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }


/* ---- Stepped rule: the process primitive. A continuous line with nodes
        sitting on it, each masking the line with the ground colour. ---- */
.steps { position: relative; padding-block: var(--space-5) var(--space-7); }
.steps::before {
  content: ""; position: absolute; left: 0; right: 0; top: calc(var(--space-5) + 10px);
  height: var(--border-w); background: var(--line);
}
.panel .steps::before, .section--inverse .steps::before { background: var(--line-inverse); }
.steps ol { list-style: none; margin: 0; padding: 0; display: grid; position: relative; }
.steps li { text-align: center; }
.steps b {
  display: inline-grid; place-items: center;
  width: 21px; height: 21px; border-radius: 50%;
  border: var(--border-w) solid var(--line);
  background: var(--ground);
  font-family: var(--font-label); font-size: 9px; font-weight: 600;
  color: var(--ink);
}
.panel .steps b, .section--inverse .steps b { background: var(--ground-inverse); border-color: var(--line); color: var(--ink-inverse); }
.steps li.is-active b { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.panel .steps li.is-active b,
.section--inverse .steps li.is-active b {
  background: var(--accent-dark); border-color: var(--accent-dark); color: var(--ground-inverse);
}
.steps span { display: block; margin-top: var(--space-2); }


/* ---- Gate: marks a named human decision. The only place H is a symbol. ---- */
.gate {
  display: inline-grid; place-items: center;
  width: 17px; height: 17px; border-radius: 50%;
  border: var(--border-w) solid var(--accent);
  color: var(--accent-text);
  font-family: var(--font-label); font-size: 9px; font-weight: 600;
  vertical-align: middle;
}
.panel .gate, .section--inverse .gate { color: var(--accent-dark); border-color: var(--accent-dark); }


/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-5);
  min-height: 46px; padding-inline: var(--space-4);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-control);
  font-family: var(--font-button, var(--font-control));
  font-size: var(--btn-size, 13px); font-weight: var(--btn-weight, 600);
  letter-spacing: -0.01em;
  color: var(--ink); text-decoration: none;
  box-shadow: var(--shadow-control);
  transition: background var(--motion-base) var(--motion-ease),
              color var(--motion-base) var(--motion-ease),
              box-shadow var(--motion-fast) var(--motion-ease),
              transform var(--motion-fast) var(--motion-ease);
}
.btn:hover { background: var(--ground-2); }

/* 2D shadow behaviour. Hover steps the offset down by one and moves the button
   into the gap; press lands it exactly where the shadow was. Both states are
   derived from --control-offset, so retuning the depth retunes the motion —
   and a flat theme (offset 0, e.g. ember) gets no motion at all: the min/max
   guards keep the hover from inventing a negative shadow. */
.btn:hover {
  transform: translate(min(1px, var(--control-offset)), min(1px, var(--control-offset)));
  box-shadow: max(calc(var(--control-offset) - 1px), 0px) max(calc(var(--control-offset) - 1px), 0px) 0 var(--shadow-control-color);
}
.btn:active {
  transform: translate(var(--control-offset), var(--control-offset));
  box-shadow: 0 0 0 var(--shadow-control-color);
}
.btn--primary {
  background: var(--ink); color: var(--ink-inverse); border-color: var(--ink);
}
.btn--primary:hover { background: var(--ink); }
.btn--accent {
  background: var(--accent); color: var(--accent-on); border-color: var(--accent);
}
.btn--accent:hover { background: var(--accent); }

/* Brand fill. --brand-on is often only large-text legible, so this stays a
   button or label surface and never carries prose. */
.btn--brand {
  background: var(--brand); color: var(--brand-on); border-color: var(--brand);
  font-weight: 600;
}
/* Flat themes (offset 0) lose the shadow-step hover, so the fill shifts
   instead. Offset themes keep a flat fill and move as before. */
.btn--brand:hover { background: color-mix(in srgb, var(--brand) 86%, var(--ground)); }

.btns { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }


/* ---- Status ---- */
.status { display: inline-flex; align-items: center; gap: var(--space-2); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status--ok      { color: var(--ok); }
.status--pending { color: var(--pending); }
.status--risk    { color: var(--risk); }


/* ---- Table: the dense-page workhorse. Hairline, no zebra, no fills. -------
   Wrapped in .table-wrap so it scrolls horizontally on narrow screens instead
   of forcing the whole page to scroll sideways. */
.table-wrap { overflow-x: auto; border: var(--border-w) solid var(--line); }

.table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: var(--size-small);
}
.table th, .table td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-4);
  border-bottom: var(--border-w) solid var(--line);
  border-left: var(--border-w) solid var(--line);
}
.table th:first-child, .table td:first-child { border-left: 0; }
.table tbody tr:last-child th,
.table tbody tr:last-child td { border-bottom: 0; }

.table thead th {
  position: sticky; top: 0;
  background: var(--ground-2);
  color: var(--heading);
  font-family: var(--font-label);
  font-size: var(--size-label);
  font-weight: var(--label-weight);
  letter-spacing: var(--label-tracking);
  text-transform: var(--label-transform);
  white-space: nowrap;
}
/* Row headers carry the module name, so they get the heading colour. */
.table tbody th {
  color: var(--heading);
  font-weight: 600;
  font-size: var(--size-body);
  white-space: nowrap;
}
.table td { color: var(--ink); }
.table .is-gate { color: var(--accent-text); white-space: nowrap; }

/* ---- Chip with a mark: a vendor logo (assets/img/logos, the -on-dark or
        -on-light file to suit the section) or the AdPilot mark, which is a mask
        so it takes the chip's text colour. ---- */
.chip--logo { display: inline-flex; align-items: center; gap: 8px; }
.chip__logo { flex: none; display: block; width: auto; height: 14px; }
.chip__mark {
  flex: none;
  width: 14px; height: 14px;
  background: currentColor;
  -webkit-mask: url(../img/brand/mark.svg) center / contain no-repeat;
          mask: url(../img/brand/mark.svg) center / contain no-repeat;
}

/* ---- Surface mark: the icon or logo that heads an interface card. ---- */
.surface-mark {
  display: flex;
  align-items: center;
  height: 28px;
  margin-bottom: var(--space-4);
  color: var(--heading);
  --icon-size: 24px;
  --icon-stroke: 1.5;
}
.surface-mark img { display: block; width: auto; height: 22px; }

/* ---- Ledger, paired: two facts side by side (Input | Output), each label
        directly above its value, one hairline above the pair and a thin
        rule between the cells. Replaces the 200px label column where the
        ledger sits in a card. ---- */
.ledger--pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border-top: var(--border-w) solid var(--line);
}
.ledger--pair > div {
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 6px;
  padding: 16px 20px 4px 0;
  border-bottom: 0;
}
.ledger--pair > div + div { padding-left: 20px; padding-right: 0; border-left: var(--border-w) solid var(--line); }
.ledger--pair p { margin: 0; color: var(--heading); }
@media (max-width: 640px) {
  .ledger--pair > div { grid-template-columns: 1fr; }
}

/* ---- Loops (Agents and models): the copy's own picture — AdPilot runs the
        outer loop AROUND the coding agents' inner loop — drawn as two
        tracks. Each track is a dashed line that flows slowly round the
        frame: the outer clockwise in the accent, the inner the other way in
        sage. Spec / Review / On-call sit as stations on the outer track's
        top edge; the model chips sit on its bottom edge, the base the loop
        runs on; the inner loop holds the agent chips. ---- */
.loops { padding-block: 22px 26px; }             /* room for what straddles the edges */
.loop {
  position: relative;
  isolation: isolate;
  --dash: 14px;
  --track: color-mix(in srgb, var(--accent) 75%, transparent);
}
.loop::before {                                   /* the flowing track */
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, var(--track) 50%, transparent 0) 0 0 / var(--dash) 1.5px repeat-x,
    linear-gradient(90deg, var(--track) 50%, transparent 0) 0 100% / var(--dash) 1.5px repeat-x,
    linear-gradient(0deg, var(--track) 50%, transparent 0) 0 0 / 1.5px var(--dash) repeat-y,
    linear-gradient(0deg, var(--track) 50%, transparent 0) 100% 0 / 1.5px var(--dash) repeat-y;
  animation: loop-flow 1.6s linear infinite;
}
@keyframes loop-flow {
  to { background-position: var(--dash) 0, calc(-1 * var(--dash)) 100%, 0 calc(-1 * var(--dash)), 100% var(--dash); }
}
@media (prefers-reduced-motion: reduce) { .loop::before { animation: none; } }

.loop--outer {
  display: grid;
  justify-items: center;
  gap: var(--space-6);
  padding: 64px var(--space-7) 64px;
}
.loop--inner {
  --track: color-mix(in srgb, var(--ill-sage) 80%, transparent);
  display: grid;
  justify-items: center;
  gap: var(--space-5);
  width: min(100%, 720px);
  padding: var(--space-6) var(--space-7);
  background: color-mix(in srgb, var(--ill-sage) 7%, transparent);
}
.loop--inner::before { animation-direction: reverse; }

.loop__tag { display: flex; align-items: center; gap: 10px; }
.loop__tag .label { color: var(--ink); }
.loop__tag::before {
  content: '';
  width: 7px; height: 7px;
  border: 1.5px solid var(--accent);
}
.loop--inner .loop__tag::before { border-color: var(--ill-sage); background: var(--ill-sage); }
.loop--outer > .loop__tag { justify-self: start; }

/* Stations: nodes sitting on the outer track's top edge. */
.loop__stations {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-evenly;
  translate: 0 -50%;
  pointer-events: none;
}
.loop__stations span {
  padding: 5px 12px;
  border: var(--border-w) solid var(--accent);
  background: var(--ground);
  font-family: var(--font-label);
  font-size: var(--size-label);
  letter-spacing: var(--label-tracking);
  text-transform: uppercase;
  color: var(--heading);
}

/* Models: the base, straddling the outer track's bottom edge. */
.loop__base {
  position: absolute;
  left: 50%; bottom: 0;
  translate: -50% 50%;
  display: flex;
  gap: var(--space-3);
  white-space: nowrap;
}
.loops .chip { padding: 7px 11px; background: var(--ground); }
.loops .chips { gap: var(--space-3); justify-content: center; }

@media (max-width: 760px) {
  .loops { padding-block: 16px 0; }
  .loop--outer { padding: 48px var(--space-5) var(--space-6); }
  .loop--inner { padding: var(--space-5); }
  .loop__stations { justify-content: space-around; }
  .loop__base { position: static; translate: none; flex-wrap: wrap; justify-content: center; white-space: normal; }
}
