/* ==========================================================================
   Rules Studio · 2 — Your credit policy, in your team's hands
   "Your team, live": the policy in a no-code rule builder, drawn to the
   conventions of decision-engine products (structured conditions as
   field · operator · value chips, versions, a test result), in a light
   tile captioned as an illustration (it is not the product screen):
       ┌ ▲ Decisions › Product eligibility policy  v4·Draft  v3 live   (AM)(RK) [Test the draft] ┐
       │ Rules        │ Which products should this client be offered?                           │
       │ 1 Individual │ ┌ Rule 2  Group loan  Changed ──────────────────────┐                   │
       │ 2 Group   •  │ │ If   [Monthly cash flow] [is above] [~~12,000~~ 10,000] │             │
       │ 3 Top-up     │ │ And  [Completed loans] [at least] [1]              │                   │
       │ + Add rule   │ │ Then [Offer product] [Group loan]                  │                   │
       │              │ └───────────────────────────────────────────────────┘                   │
       │              │ ┌ Test result ─ v3 ▇▇▇▇▇▇ 412 · v4 ▇▇▇▇▇▇▇ 498 · +86 ┐                  │
       │ ● Draft ─ ○ Tested ─ ○ Live   message                                                   │
       └──────────────────────────────────────────────────────────────────────────────────────────┘
   The window runs margin to margin; the five points follow as a 3 + 2
   grid. The team's cursors (Abhinav, Ritik, Vineet) act
   it out on a loop while in view (js/rules/policy.js); data-stage 0–2 and the
   edit's phase classes drive the rest. Stage colours: Draft grey, Tested
   blue, Live green. Prefixed .rp- and scoped to .rp.
   ========================================================================== */

.rp {
  --rp-frame:  #FFFFFF;
  --rp-shadow: 0 1px 2px rgba(10,47,107,0.04), 0 24px 48px -32px rgba(10,47,107,0.32);
  --rp-a: var(--accent);          /* Abhinav · Risk */
  --rp-r: var(--good);            /* Ritik · Compliance */
  --rp-v: #6A4BD6;                /* Vineet · Risk */
  --rp-red: #C2410C;
  --rp-chip: color-mix(in srgb, var(--surface-raised) 70%, var(--rp-frame));

  position: relative;
  padding: clamp(72px, 9vw, 120px) var(--page-px);
  background: var(--surface-raised);
  border-top: 1px solid var(--border);
}
/* the demo window stays light in dark mode, so it reads as a product
   screen on the dark page instead of blending into it: the light theme's
   tokens are pinned on the window (everything inside resolves from them) */
:root[data-theme="dark"] .rp-doc {
  color-scheme: light;
  --text-primary:   #0D1B2A;
  --text-secondary: #4A5568;
  --text-muted:     #8A95A3;
  --surface:        #FFFFFF;
  --surface-raised: #F7F9FC;
  --border:         rgba(0,0,0,0.08);
  --border-strong:  rgba(0,0,0,0.14);
  --accent:      var(--blue-600);
  --accent-text: var(--blue-700);
  --accent-soft: var(--blue-50);
  --accent-line: var(--blue-200);
  --good:      #12806A;
  --good-soft: #DDF3EC;
  --rp-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 28px 56px -28px rgba(0,0,0,0.75);
  --rp-chip: color-mix(in srgb, var(--surface-raised) 70%, var(--rp-frame));
  border-color: transparent;
}

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

/* ─── Layout: the illustration margin to margin, the five points below ── */
.rp-body { display: grid; gap: clamp(40px, 5vw, 60px); }
.rp-fig { position: relative; margin: 0; }

/* ─── The app window ──────────────────────────────────────────────────── */
.rp-doc {
  --rp-c: var(--text-muted);
  --rp-soft: color-mix(in srgb, var(--text-muted) 16%, transparent);
  position: relative;
  background: var(--rp-frame);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--rp-shadow);
  overflow: clip;
}
.rp-doc[data-stage="1"] { --rp-c: var(--accent-text); --rp-soft: var(--accent-soft); }
.rp-doc[data-stage="2"] { --rp-c: var(--good); --rp-soft: var(--good-soft); }

/* app bar: breadcrumb, version, presence, the action */
.rp-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 18px 16px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.rp-bar-l { display: flex; align-items: center; gap: 8px; min-width: 0; }
.rp-crumb { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 13px; color: var(--text-muted); }
.rp-crumb .ti { font-size: 15px; }
.rp-crumb .ti-chevron-right { font-size: 13px; opacity: 0.7; }
.rp-doc-name { font-size: 13.5px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rp-ver {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  margin-left: 4px;
  padding: 2px 8px 2px 7px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--rp-c);
  background: var(--rp-soft);
  border-radius: 6px;
  transition: color 0.3s ease, background-color 0.3s ease;
}
.rp-ver b { font-family: var(--font-mono); font-weight: 500; }
.rp-ver-dot { width: 5px; height: 5px; background: currentColor; border-radius: 50%; }
.rp-doc[data-stage="2"] .rp-ver-dot { animation: rp-live 1.6s ease-out infinite; }
@keyframes rp-live { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); } 100% { box-shadow: 0 0 0 6px transparent; } }
.rp-was { flex: none; font-size: 11.5px; color: var(--text-muted); white-space: nowrap; transition: opacity 0.3s ease; }
.rp-was b { font-family: var(--font-mono); font-weight: 500; }
.rp-doc[data-stage="2"] .rp-was { opacity: 0; }

.rp-bar-r { display: flex; align-items: center; gap: 14px; flex: none; }
.rp-people { display: flex; }
.rp-av {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  font-size: 11px;
  font-weight: 700;
  color: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--rp-frame);
  transition: box-shadow 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rp-people .rp-av + .rp-av { margin-left: -6px; }
.rp-av--a { --c: var(--rp-a); background: var(--rp-a); }
.rp-av--r { --c: var(--rp-r); background: var(--rp-r); }
.rp-av--v { --c: var(--rp-v); background: var(--rp-v); }
.rp-people .rp-av.is-active { position: relative; z-index: 1; transform: translateY(-2px); box-shadow: 0 0 0 2px var(--rp-frame), 0 0 0 4px var(--c); }

/* the action (display-only; the team presses it): Test the draft →
   Publish → Start over */
.rp-next {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: #FFFFFF;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: default;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.rp-next .ti { font-size: 15px; transition: transform 0.25s var(--ease-out); }
.rp-next.is-pressed { transform: scale(0.96); }
.rp-doc[data-stage="2"] .rp-next { color: var(--text-primary); background: transparent; border-color: var(--border-strong); }

/* ─── Body: rule list + editor ────────────────────────────────────────── */
.rp-app { display: grid; grid-template-columns: 156px minmax(0, 1fr); }

.rp-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 10px;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-raised) 45%, var(--rp-frame));
}
.rp-side small { padding: 0 8px 8px; font-size: 11px; font-weight: 600; color: var(--text-muted); }
.rp-side-i {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: 7px;
}
.rp-side-i em { width: 16px; font-style: normal; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.rp-side-i.is-on { font-weight: 600; color: var(--text-primary); background: var(--rp-frame); box-shadow: 0 0 0 1px var(--border); }
.rp-side-dot { width: 6px; height: 6px; margin-left: auto; background: var(--rp-a); border-radius: 50%; transition: opacity 0.3s ease; }
.rp-side-add { display: flex; align-items: center; gap: 6px; margin-top: 6px; padding: 7px 8px; font-size: 12.5px; color: var(--text-muted); }
.rp-side-add .ti { font-size: 14px; }

.rp-main { display: flex; flex-direction: column; gap: 14px; padding: 18px clamp(16px, 2.2vw, 24px) 20px; min-width: 0; }
.rp-q { font-family: var(--font-display); font-size: clamp(16px, 1.4vw, 18px); font-weight: 600; letter-spacing: -0.01em; color: var(--text-primary); }

/* the rule card */
.rp-rule { padding: 6px 0 10px; border: 1px solid var(--border); border-radius: 10px; }
.rp-rule-h { display: flex; align-items: center; gap: 8px; padding: 8px 14px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.rp-rule-h span:first-child { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); }
.rp-rule-h b { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.rp-tag { margin-left: auto; padding: 1px 7px; font-size: 11px; font-weight: 600; color: var(--accent-text); background: var(--accent-soft); border-radius: 5px; transition: opacity 0.3s ease; }

.rp-cond { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 5px 14px; }
.rp-cond--then { margin-top: 4px; padding-top: 9px; border-top: 1px dashed var(--border); }
.rp-kw { width: 34px; flex: none; font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; color: var(--text-muted); }
.rp-cond--then .rp-kw { color: var(--accent-text); }
.rp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 9px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--text-primary);
  background: var(--rp-chip);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.rp-chip .ti { font-size: 14px; color: var(--text-muted); }
.rp-chip--o { color: var(--text-secondary); background: transparent; border-style: dashed; }
.rp-chip--v { font-family: var(--font-mono); font-size: 12.5px; background: var(--rp-frame); border-color: var(--border-strong); }
.rp-chip--p { font-weight: 600; color: var(--accent-text); background: var(--accent-soft); border-color: transparent; }
.rp-add { display: inline-flex; align-items: center; gap: 6px; margin: 6px 14px 0 54px; font-size: 12.5px; color: var(--text-muted); }
.rp-add .ti { font-size: 14px; }

/* the edit: pristine → selected → edited (struck old, new in green) */
.rp-edit { transition: box-shadow 0.2s ease, border-color 0.2s ease; }
.rp-old { margin-right: 6px; color: var(--rp-red); text-decoration: line-through; text-decoration-thickness: 1.5px; border-radius: 3px; transition: background-color 0.2s ease, color 0.2s ease; }
.rp-new { color: var(--good); font-weight: 600; }
.rp-edit.is-pristine .rp-old,
.rp-edit.is-selected .rp-old { margin-right: 0; color: inherit; text-decoration: none; }
.rp-edit.is-selected { border-color: var(--rp-a); box-shadow: 0 0 0 3px color-mix(in srgb, var(--rp-a) 18%, transparent); }
.rp-edit.is-selected .rp-old { background: color-mix(in srgb, var(--rp-a) 24%, transparent); }
.rp-edit.is-pristine .rp-new,
.rp-edit.is-selected .rp-new { display: none; }
.rp-new.is-typing::after {
  content: '';
  display: inline-block;
  width: 1.5px; height: 1em;
  margin-left: 1px;
  vertical-align: -0.12em;
  background: var(--rp-a);
  animation: rp-caret 0.8s steps(1) infinite;
}
@keyframes rp-caret { 50% { opacity: 0; } }
/* before the edit: nothing marked as changed */
.rp-doc.is-fresh .rp-tag, .rp-doc.is-fresh .rp-side-dot { opacity: 0; }

/* the test: an empty state, then the result in the same place */
.rp-test { display: grid; border: 1px solid var(--border); border-radius: 10px; }
.rp-test > * { grid-area: 1 / 1; transition: opacity 0.3s ease; }
.rp-test-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; font-size: 13px; color: var(--text-muted); border: 1px dashed var(--border-strong); border-radius: 9px; margin: -1px; }
.rp-test-empty .ti { font-size: 18px; }
.rp-test-empty small { font-size: 12px; opacity: 0.85; }
.rp-test-res { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px 14px 14px; opacity: 0; }
.rp-doc:not([data-stage="0"]) .rp-test-empty { opacity: 0; }
.rp-doc:not([data-stage="0"]) .rp-test-res { opacity: 1; }
.rp-doc:not([data-stage="0"]) .rp-test { border-color: var(--border); }
.rp-test-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin-bottom: 2px; }
.rp-test-h span { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-primary); }
.rp-test-h .ti { font-size: 16px; color: var(--rp-r); }
.rp-test-h small { font-size: 11.5px; color: var(--text-muted); }
.rp-qb { display: grid; grid-template-columns: 26px minmax(0, 1fr) 36px; align-items: center; gap: 10px; }
.rp-qb span { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); }
.rp-qb b { font-family: var(--font-mono); font-size: 12px; font-weight: 500; text-align: right; color: var(--text-secondary); }
.rp-qb i { height: 8px; background: var(--border-strong); border-radius: 4px; transform-origin: left center; transform: scaleX(0); transition: transform 0.7s var(--ease-out); }
.rp-qb--new i { background: var(--good); }
.rp-qb--new b { font-weight: 600; color: var(--text-primary); }
.rp-doc:not([data-stage="0"]) .rp-qb i { transform: scaleX(var(--w)); }
.rp-doc:not([data-stage="0"]) .rp-qb--new i { transition-delay: 0.15s; }
.rp-effect { justify-self: start; display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; padding: 3px 9px; font-size: 12.5px; font-weight: 600; color: var(--good); background: var(--good-soft); border-radius: 6px; }
.rp-effect .ti { font-size: 14px; }

/* ─── Status bar: stage and message ───────────────────────────────────── */
.rp-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-raised) 45%, var(--rp-frame));
}
/* the stepper: numbered steps; a done step fills and turns to a check, the
   connector into the current step fills left to right, then the current
   step pops. Live is the end, so it completes in green. */
.rp-stages { display: flex; align-items: center; gap: 6px; flex: none; }
.rp-st { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-muted); transition: color 0.3s ease; }
.rp-st + .rp-st::before {
  content: '';
  width: 26px; height: 2px;
  margin-right: 1px;
  border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent)) left / 0% 100% no-repeat, var(--border-strong);
  transition: background-size 0.35s var(--ease-out);
}
.rp-st-dot {
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  color: var(--text-muted);
  box-shadow: inset 0 0 0 1.5px var(--border-strong);
  transition: background-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
}
.rp-st-dot > * { grid-area: 1 / 1; transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease; }
.rp-st-dot em { font-style: normal; font-family: var(--font-mono); font-size: 10px; font-weight: 500; }
.rp-st-dot .ti { font-size: 12px; opacity: 0; transform: scale(0.4); }

/* connectors into reached steps fill */
.rp-doc[data-stage="1"] .rp-st[data-i="1"]::before,
.rp-doc[data-stage="2"] .rp-st[data-i="1"]::before,
.rp-doc[data-stage="2"] .rp-st[data-i="2"]::before { background-size: 100% 100%; }
/* current step: blue ring, pops once the connector has filled */
.rp-doc[data-stage="0"] .rp-st[data-i="0"],
.rp-doc[data-stage="1"] .rp-st[data-i="1"],
.rp-doc[data-stage="2"] .rp-st[data-i="2"] { color: var(--text-primary); }
.rp-doc[data-stage="0"] .rp-st[data-i="0"] .rp-st-dot,
.rp-doc[data-stage="1"] .rp-st[data-i="1"] .rp-st-dot { color: var(--accent-text); box-shadow: inset 0 0 0 1.5px var(--accent), 0 0 0 3px var(--accent-soft); animation: rp-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s both; }
@keyframes rp-pop { 0% { transform: scale(0.7); } 100% { transform: scale(1); } }
/* done steps (and Live, the last): filled, the number turns into a check */
.rp-doc[data-stage="1"] .rp-st[data-i="0"] .rp-st-dot,
.rp-doc[data-stage="2"] .rp-st[data-i="0"] .rp-st-dot,
.rp-doc[data-stage="2"] .rp-st[data-i="1"] .rp-st-dot { color: #FFFFFF; background: var(--accent); box-shadow: none; }
.rp-doc[data-stage="2"] .rp-st[data-i="2"] .rp-st-dot { color: #FFFFFF; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); animation: rp-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s both; }
.rp-doc[data-stage="1"] .rp-st[data-i="0"] .rp-st-dot em,
.rp-doc[data-stage="2"] .rp-st .rp-st-dot em { opacity: 0; transform: scale(0.4); }
.rp-doc[data-stage="1"] .rp-st[data-i="0"] .rp-st-dot .ti,
.rp-doc[data-stage="2"] .rp-st .rp-st-dot .ti { opacity: 1; transform: none; }
.rp-doc[data-stage="2"] .rp-st[data-i="2"] .rp-st-dot .ti { transition-delay: 0.3s; }

.rp-msg { flex: 1 1 260px; font-size: 13px; line-height: 1.5; color: var(--text-secondary); transition: opacity 0.18s ease; }
.rp-msg.is-swap { opacity: 0; }

/* ─── The team's cursors (placed by JS, relative to the window) ───────── */
.rp-cur {
  --c: var(--rp-a);
  position: absolute;
  left: 0; top: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  gap: 2px;
  opacity: 0;
  transform: translate(var(--x, 0px), var(--y, 0px));
  transition: transform 0.85s cubic-bezier(0.45, 0, 0.2, 1), opacity 0.3s ease;
  pointer-events: none;
}
.rp-cur--r { --c: var(--rp-r); }
.rp-cur--v { --c: var(--rp-v); }
.rp-cur svg { width: 15px; height: 19px; fill: var(--c); stroke: var(--rp-frame); stroke-width: 1.2; filter: drop-shadow(0 2px 3px rgba(10,30,60,0.25)); }
.rp-cur em {
  position: absolute;
  top: 13px; left: 15px;
  padding: 2px 8px;
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  color: #FFFFFF;
  background: var(--c);
  border-radius: 6px 6px 6px 2px;
}
/* near the window's right edge the name flag flips to the left of the pointer */
.rp-cur.is-flip em { left: auto; right: 13px; border-radius: 6px 6px 2px 6px; }
.rp-cur.is-on { opacity: 1; }
.rp-cur.is-click svg { animation: rp-click 0.3s ease-out; }
@keyframes rp-click { 50% { transform: scale(0.8); } }

/* first run only: a ripple where a click lands */
.rp-ripple {
  position: absolute;
  z-index: 5;
  width: 36px; height: 36px;
  margin: -18px 0 0 -18px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 22%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 55%, transparent);
  pointer-events: none;
  animation: rp-ripple 0.6s var(--ease-out) forwards;
}
@keyframes rp-ripple { 0% { opacity: 1; transform: scale(0.2); } 100% { opacity: 0; transform: scale(1.3); } }

.rp-note { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }
.rp-note .ti { flex: none; font-size: 14px; }

/* ─── The five points: a 3 + 2 grid under hairlines ───────────────────── */
.rp-pts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px clamp(28px, 3.5vw, 48px); margin: 0; }
.rp-pt { padding-top: 18px; border-top: 1px solid var(--border-strong); }
.rp-pt dt { font-family: var(--font-display); font-size: 16.5px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.35; color: var(--text-primary); }
.rp-pt dd { margin: 8px 0 0; max-width: 36ch; font-size: 14.5px; line-height: 1.6; color: var(--text-secondary); }

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .rp-crumb { display: none; }
}
@media (max-width: 1000px) {
  .rp-pts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rp-crumb { display: inline-flex; }
}
@media (max-width: 720px) {
  .rp-app { grid-template-columns: minmax(0, 1fr); }
  .rp-side { display: none; }
  .rp-crumb { display: none; }
  .rp-bar { flex-wrap: wrap; }
  .rp-bar-r { width: 100%; justify-content: space-between; }
}
@media (max-width: 560px) {
  .rp-pts { grid-template-columns: minmax(0, 1fr); }
  .rp-doc-name { display: none; }
  .rp-kw { width: 100%; }
  .rp-add { margin-left: 14px; }
  .rp-test-empty { min-height: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  .rp-cur, .rp-msg, .rp-ver, .rp-was, .rp-av, .rp-test > *, .rp-qb i, .rp-tag, .rp-side-dot, .rp-st, .rp-st::before, .rp-st-dot, .rp-st-dot > * { transition: none !important; }
  .rp-st-dot { animation: none !important; }
  .rp-doc[data-stage="2"] .rp-ver-dot, .rp-new.is-typing::after { animation: none; }
}
