/* ==========================================================================
   Rules Studio · 3 — How it fits
   "Side-car lanes": each system is a lane carrying the decision it asks
   for; Studio is docked beside the lanes, outside every one of them.
       Your systems        Decisions                        asks →        │
       ─────────────────────────────────────────────────── ← answers ── ┐│ Decision Rules
       Finflow             Which product to offer   [Group loan] ══●══ ○┤│ Studio
       Your core system    How risky an application is         ────── ○┤│ Rules written…
       A mobile or web app How much to lend                    ────── ○┤│ Draft·Tested·●Live
       Anything else…      Which loans need attention          ────── ○┘│
   Each lane's wire has two tracks: the question runs right on the upper
   one (blue), the answer runs back on the lower one (green) and lands in
   the lane. States (js/rules/fits.js): a row .is-asking / .is-answered;
   the dock .is-hit. One grid; lanes and the head use subgrid so every
   column lines up. On narrow screens the dock sits above the lanes.
   Prefixed .rf- and scoped to .rf.
   ========================================================================== */

.rf {
  --rf-frame: #FFFFFF;
  --rf-row: 68px;
  position: relative;
  padding: clamp(72px, 9vw, 120px) var(--page-px);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
:root[data-theme="dark"] .rf { --rf-frame: #0B1F42; }

.rf-inner { max-width: var(--container); margin: 0 auto; }
.rf-head { display: flex; flex-direction: column; gap: 14px; margin-bottom: clamp(36px, 4.5vw, 56px); }
.rf-title { font-size: var(--fs-section-title); font-weight: 600; line-height: 1.12; letter-spacing: -0.03em; }
.rf-title em { font-style: normal; color: var(--accent); }
.rf-sub { max-width: 680px; font-size: var(--fs-section-sub); line-height: 1.6; color: var(--text-secondary); }

.rf-fig { margin: 0; }

/* ─── The stage: lanes + the dock beside them ─────────────────────────── */
.rf-stage {
  display: grid;
  /* systems and answers share the spare width equally, so the Decisions
     column sits in the middle of the lanes, equally far from both */
  grid-template-columns: minmax(0, 1fr) max-content minmax(136px, 1fr) 172px minmax(240px, 280px);
  grid-template-rows: auto auto;
}
.rf-row--head,
.rf-lanes,
.rf-row { display: grid; grid-template-columns: subgrid; grid-column: 1 / 5; }
.rf-lanes { grid-row: 2; }
.rf-row { grid-column: 1 / -1; }

/* column heads */
.rf-row--head { align-items: end; padding-bottom: 12px; border-bottom: 1px solid var(--border-strong); }
.rf-row--head > span { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.rf-row--head > span:nth-child(2) { padding-left: 24px; }
.rf-dir { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
/* both labels start at the wire, arrow first, so arrows and words line up
   in two clean columns, like the two tracks below them */
.rf-dir em { display: flex; align-items: center; gap: 6px; font-style: normal; font-size: 12px; line-height: 1.25; white-space: nowrap; }
.rf-dir em:first-child { color: var(--accent-text); }
.rf-dir em + em { color: var(--good); }
.rf-dir b { font-weight: 600; }
.rf-dir .ti { flex: none; width: 14px; font-size: 14px; }

/* a lane */
.rf-row:not(.rf-row--head) {
  position: relative;
  align-items: center;
  min-height: var(--rf-row);
  border-bottom: 1px solid var(--border);
}
.rf-row:not(.rf-row--head)::before {
  content: '';
  position: absolute;
  inset: 0 0 -1px;
  z-index: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 7%, transparent), transparent 85%);
  box-shadow: inset 2px 0 0 var(--accent);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}
.rf-row.is-asking::before, .rf-row.is-answering::before, .rf-row.is-answered::before { opacity: 1; }
.rf-row > * { position: relative; z-index: 1; }

.rf-sys { display: flex; align-items: center; gap: 10px; padding: 0 16px 0 14px; font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--text-primary); }
.rf-sys .ti { flex: none; font-size: 18px; color: var(--text-muted); transition: color 0.3s ease; }
.rf-row.is-asking .rf-sys .ti, .rf-row.is-answering .rf-sys .ti, .rf-row.is-answered .rf-sys .ti { color: var(--accent); }
.rf-q { padding: 0 24px; font-size: 15px; line-height: 1.4; color: var(--text-secondary); transition: color 0.3s ease; }
.rf-row.is-asking .rf-q { color: var(--accent-text); }

/* the answer lands here */
.rf-ans { display: flex; justify-content: flex-end; padding-right: 12px; }
.rf-ans b {
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--good);
  background: var(--good-soft);
  border-radius: 8px;
  opacity: 0;
  transform: translateX(10px) scale(0.92);
  transition: opacity 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rf-row.is-answered .rf-ans b { opacity: 1; transform: none; }

/* the wire: upper track out, lower track back, a port at the dock */
.rf-wire { align-self: stretch; position: relative; }
.rf-wire::before,
.rf-wire::after {
  content: '';
  position: absolute;
  left: 0; right: 6px;
  border-top: 1.5px dashed var(--border-strong);
  transition: border-color 0.3s ease;
}
.rf-wire::before { top: calc(50% - 7px); }
.rf-wire::after  { top: calc(50% + 6px); }
.rf-row.is-asking .rf-wire::before { border-top-color: var(--accent-line); }
.rf-row.is-answering .rf-wire::after, .rf-row.is-answered .rf-wire::after { border-top-color: color-mix(in srgb, var(--good) 45%, transparent); }
.rf-port {
  position: absolute;
  right: -5px; top: 50%;
  width: 10px; height: 10px;
  margin-top: -5px;
  background: var(--rf-frame);
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  z-index: 2;
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.rf-row.is-asking .rf-port, .rf-row.is-answering .rf-port, .rf-row.is-answered .rf-port { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.rf-tok {
  position: absolute;
  left: 0;
  width: 9px; height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  opacity: 0;
}
.rf-tok--ask { top: calc(50% - 6.25px); background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rf-tok--ans { top: calc(50% + 6.75px); background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.rf-row.is-asking .rf-tok--ask { animation: rf-out 0.55s cubic-bezier(0.45, 0, 0.25, 1) forwards; }
.rf-row.is-answering .rf-tok--ans { animation: rf-back 0.4s cubic-bezier(0.45, 0, 0.25, 1) forwards; }
@keyframes rf-out  { 0% { left: 0; opacity: 0; } 20% { opacity: 1; } 90% { opacity: 1; } 100% { left: 100%; opacity: 0; } }
@keyframes rf-back { 0% { left: 100%; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { left: 0; opacity: 0; } }

/* ─── The dock: Studio, beside every lane ─────────────────────────────── */
.rf-dock {
  grid-column: 5;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 24px 24px 26px;
  background: color-mix(in srgb, var(--accent) 5%, var(--rf-frame));
  border: 1px solid var(--accent-line);
  border-radius: 14px;
  transition: box-shadow 0.3s ease;
}
.rf-dock.is-hit { box-shadow: 0 0 0 4px var(--accent-soft); }
.rf-dock-k { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 10px; color: var(--accent-text); background: var(--rf-frame); border: 1px solid var(--accent-line); border-radius: 10px; }
.rf-dock-k .ti { font-size: 19px; }
.rf-dock-t { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.25; color: var(--text-primary); }
.rf-dock small { font-size: 14px; line-height: 1.5; color: var(--text-secondary); }
.rf-mini { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
.rf-mini li { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.rf-mini li + li::before { content: ''; width: 12px; height: 1px; background: var(--border-strong); }
.rf-live { color: var(--good) !important; }
.rf-live::after { content: ''; order: -1; width: 7px; height: 7px; background: var(--good); border-radius: 50%; }
.rf-dock.is-hit .rf-live::after { animation: rf-tick 0.6s ease-out; }
@keyframes rf-tick { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); } 100% { box-shadow: 0 0 0 7px transparent; } }

.rf-cap { display: flex; align-items: center; gap: 6px; margin-top: 14px; font-size: 12.5px; color: var(--text-muted); }
.rf-cap .ti { flex: none; font-size: 14px; }
.rf-note { margin-top: 28px; font-size: 15px; line-height: 1.6; color: var(--text-secondary); }

/* ─── Narrow: the dock sits above, lanes stack ────────────────────────── */
@media (max-width: 960px) {
  .rf-stage { display: flex; flex-direction: column; }
  .rf-dock { order: -1; margin-bottom: 20px; }
  .rf-row--head { display: flex; flex-wrap: wrap; gap: 6px 16px; }
  .rf-row--head > span:nth-child(3) { display: none; }
  .rf-row--head > span:nth-child(2) { padding-left: 0; }
  .rf-row--head > span:nth-child(2)::before { content: '·'; margin-right: 16px; }
  .rf-dir { flex-basis: 100%; flex-direction: row; gap: 14px; padding: 0; }
  .rf-lanes, .rf-row { display: block; }
  .rf-row:not(.rf-row--head) { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 14px 0; }
  .rf-sys { grid-column: 1; padding: 0 0 0 12px; }
  .rf-q { grid-column: 1; padding: 0 0 0 40px; font-size: 14px; }
  .rf-ans { grid-column: 2; grid-row: 1 / 3; align-self: center; padding: 0; }
  .rf-wire { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rf-row::before, .rf-sys .ti, .rf-q, .rf-ans b, .rf-wire::before, .rf-wire::after, .rf-port, .rf-dock { transition: none; }
  .rf-tok { display: none; }
  .rf-dock.is-hit .rf-live::after { animation: none; }
}
