/* Propeller Design System — component layer
 * Reusable primitives built on tokens.css. Namespace: .pr-* (matches --pr-* tokens).
 * Every component here is exercised by patterns/dashboard.html — no speculative
 * primitives. Consume after tokens.css.
 */

/* ---- App shell ---- */
.pr-app { min-height: 100vh; background: var(--pr-bg); color: var(--pr-text);
  font-family: var(--pr-font-sans); }
/* Skip link (WCAG 2.4.1 bypass-blocks) — visible only on keyboard focus. */
.pr-skip-link { position: absolute; left: var(--pr-space-2); top: -3rem; z-index: 100;
  background: var(--pr-primary-600); color: var(--pr-text-on-primary);
  padding: var(--pr-space-2) var(--pr-space-4); border-radius: var(--pr-radius-md);
  transition: top var(--pr-duration-fast) var(--pr-ease); }
.pr-skip-link:focus { top: var(--pr-space-2); }
.pr-appbar { display: flex; align-items: center; gap: var(--pr-space-4);
  padding: var(--pr-space-3) var(--pr-space-4); background: var(--pr-surface);
  border-bottom: 1px solid var(--pr-border); }
.pr-wordmark { font-weight: var(--pr-weight-semibold); font-size: var(--pr-text-lg);
  display: inline-flex; align-items: center; gap: var(--pr-space-2); }
.pr-wordmark .mark { width: 1.1rem; height: 1.1rem; border-radius: var(--pr-radius-sm);
  background: var(--pr-primary-600); display: inline-block; }
.pr-appbar .spacer { margin-left: auto; }

/* ---- Layout ---- */
.pr-main { max-width: var(--pr-container); margin: 0 auto;
  padding: var(--pr-space-6) var(--pr-space-4); }
.pr-section-title { font-size: var(--pr-text-xl); margin: 0 0 var(--pr-space-3); }
.pr-cols { display: grid; gap: var(--pr-space-6); }
@media (min-width: 56rem) { .pr-cols { grid-template-columns: 1fr 20rem; align-items: start; } }

/* ---- Card / panel ---- */
.pr-card { background: var(--pr-surface); border: 1px solid var(--pr-border);
  border-radius: var(--pr-radius-lg); box-shadow: var(--pr-shadow-sm); }
.pr-card-pad { padding: var(--pr-space-5); }
.pr-panel-head { padding: var(--pr-space-4) var(--pr-space-5);
  border-bottom: 1px solid var(--pr-border); display: flex; align-items: center;
  gap: var(--pr-space-3); }
.pr-panel-head h3 { margin: 0; font-size: var(--pr-text-lg); }

/* ---- Stat tile ---- */
.pr-stats { display: grid; gap: var(--pr-space-4); margin-bottom: var(--pr-space-8);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); }
.pr-stat { background: var(--pr-surface); border: 1px solid var(--pr-border);
  border-radius: var(--pr-radius-lg); padding: var(--pr-space-4); box-shadow: var(--pr-shadow-sm); }
.pr-stat .label { color: var(--pr-text-muted); font-size: var(--pr-text-sm);
  font-weight: var(--pr-weight-medium); }
.pr-stat .value { font-size: var(--pr-text-2xl); font-weight: var(--pr-weight-semibold);
  line-height: var(--pr-leading-tight); margin-top: var(--pr-space-1); }
.pr-stat .delta { font-size: var(--pr-text-sm); margin-top: var(--pr-space-1); }
.pr-stat .delta.good { color: var(--pr-success-700); }
.pr-stat .delta.bad  { color: var(--pr-danger-700); }

/* ---- Badge (status) — meaning carries a label, never color alone ---- */
.pr-badge { display: inline-flex; align-items: center; gap: var(--pr-space-2);
  padding: var(--pr-space-1) var(--pr-space-3); border-radius: var(--pr-radius-full);
  font-size: var(--pr-text-sm); font-weight: var(--pr-weight-medium); white-space: nowrap; }
.pr-badge .dot { width: .5rem; height: .5rem; border-radius: var(--pr-radius-full);
  background: currentColor; flex: none; }
/* InvoiceStatus (core schema) -> badge variant:
 *   paid, promised      -> is-paid      | overdue            -> is-due
 *   disputed            -> is-escalate  | in_negotiation     -> is-pending
 *   open, written_off   -> is-neutral
 * Always pair with a text label — meaning never rides on color alone. */
.pr-badge.is-paid     { background: var(--pr-status-paid-bg);     color: var(--pr-status-paid-fg); }
.pr-badge.is-due      { background: var(--pr-status-due-bg);      color: var(--pr-status-due-fg); }
.pr-badge.is-escalate { background: var(--pr-status-escalate-bg); color: var(--pr-status-escalate-fg); }
.pr-badge.is-pending  { background: var(--pr-status-pending-bg);  color: var(--pr-status-pending-fg); }
.pr-badge.is-neutral  { background: var(--pr-surface-alt);        color: var(--pr-text-secondary); }
.pr-badge:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; } /* when rendered as a button */

/* ---- Button ---- */
.pr-btn { font: inherit; font-weight: var(--pr-weight-semibold); cursor: pointer;
  min-height: var(--pr-tap-target); padding: 0 var(--pr-space-4);
  border-radius: var(--pr-radius-md); border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--pr-space-2);
  transition: background var(--pr-duration-fast) var(--pr-ease); }
.pr-btn:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; }
.pr-btn-primary { background: var(--pr-primary-600); color: var(--pr-text-on-primary); }
.pr-btn-primary:hover { background: var(--pr-primary-700); }
.pr-btn-secondary { background: var(--pr-surface); color: var(--pr-text);
  border-color: var(--pr-border-strong); }
.pr-btn-secondary:hover { background: var(--pr-surface-alt); }
.pr-btn-sm { min-height: 2.25rem; padding: 0 var(--pr-space-3); font-size: var(--pr-text-sm); }

/* ---- Account row (work queue item) ---- */
.pr-rows { list-style: none; margin: 0; padding: 0; }
.pr-row { display: grid; gap: var(--pr-space-3); padding: var(--pr-space-4) var(--pr-space-5);
  border-bottom: 1px solid var(--pr-border); }
.pr-row:last-child { border-bottom: 0; }
.pr-row-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--pr-space-2) var(--pr-space-3); }
.pr-row-top .who { font-weight: var(--pr-weight-semibold); }
.pr-row-top .inv { color: var(--pr-text-muted); font-family: var(--pr-font-mono);
  font-size: var(--pr-text-sm); }
.pr-row-top .amt { margin-left: auto; font-weight: var(--pr-weight-semibold);
  font-variant-numeric: tabular-nums; }
.pr-draft { background: var(--pr-surface-alt); border: 1px solid var(--pr-border);
  border-radius: var(--pr-radius-md); padding: var(--pr-space-3) var(--pr-space-4);
  color: var(--pr-text-secondary); font-size: var(--pr-text-sm); line-height: var(--pr-leading-relaxed); }
.pr-draft .draft-label { display: block; color: var(--pr-text-muted);
  font-size: var(--pr-text-xs); text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: var(--pr-space-1); }
.pr-row-actions { display: flex; flex-wrap: wrap; gap: var(--pr-space-2); }
/* Account name rendered as a nav control (opens the record). */
.pr-rowlink { background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--pr-link); text-align: left; }
.pr-rowlink:hover { text-decoration: underline; }
.pr-rowlink:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; border-radius: var(--pr-radius-sm); }

/* ---- Definition list (policy envelope) ---- */
.pr-dl { margin: 0; padding: var(--pr-space-4) var(--pr-space-5); }
.pr-dl div { display: flex; justify-content: space-between; gap: var(--pr-space-3);
  padding: var(--pr-space-2) 0; border-bottom: 1px solid var(--pr-border); }
.pr-dl div:last-child { border-bottom: 0; }
.pr-dl dt { color: var(--pr-text-muted); font-size: var(--pr-text-sm); margin: 0; }
.pr-dl dd { margin: 0; font-weight: var(--pr-weight-medium); text-align: right; }

/* ---- Back link ---- */
.pr-back { display: inline-flex; align-items: center; gap: var(--pr-space-2);
  color: var(--pr-link); text-decoration: none; font-size: var(--pr-text-sm);
  font-weight: var(--pr-weight-medium); margin-bottom: var(--pr-space-3); }
.pr-back:hover { text-decoration: underline; }
.pr-back:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; border-radius: var(--pr-radius-sm); }

/* ---- Meta grid (record header facts) ---- */
.pr-meta-grid { display: grid; gap: var(--pr-space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
  padding: var(--pr-space-4) var(--pr-space-5); }
.pr-meta-grid .k { color: var(--pr-text-muted); font-size: var(--pr-text-sm); }
.pr-meta-grid .v { font-weight: var(--pr-weight-semibold); margin-top: var(--pr-space-1);
  font-variant-numeric: tabular-nums; }

/* ---- Actor chip (who took an action) ----
 * Maps Interaction.actor (core schema): agent=Propeller · human=operator · debtor=customer. */
.pr-actor { display: inline-flex; align-items: center; gap: var(--pr-space-1);
  font-size: var(--pr-text-xs); font-weight: var(--pr-weight-semibold);
  text-transform: uppercase; letter-spacing: .05em; padding: 2px var(--pr-space-2);
  border-radius: var(--pr-radius-sm); }
.pr-actor.agent  { background: var(--pr-primary-100); color: var(--pr-primary-700); }   /* Propeller */
.pr-actor.human  { background: var(--pr-surface-alt); color: var(--pr-text-secondary); } /* operator */
.pr-actor.debtor { background: transparent; border: 1px solid var(--pr-border-strong); color: var(--pr-text-secondary); } /* customer */

/* ---- Timeline (documented record / audit trail) ---- */
.pr-timeline { list-style: none; margin: 0; padding: var(--pr-space-2) var(--pr-space-5) var(--pr-space-5); }
.pr-event { position: relative; padding: var(--pr-space-4) 0 var(--pr-space-4) var(--pr-space-6);
  border-left: 2px solid var(--pr-border); }
.pr-event:last-child { border-left-color: transparent; }
.pr-event::before { content: ""; position: absolute; left: -7px; top: var(--pr-space-5);
  width: 12px; height: 12px; border-radius: var(--pr-radius-full);
  background: var(--pr-surface); border: 2px solid var(--pr-border-strong); }
.pr-event.is-escalate::before { border-color: var(--pr-danger-700); background: var(--pr-status-escalate-bg); }
.pr-event.is-inbound::before  { border-color: var(--pr-info-700); background: var(--pr-status-pending-bg); }
.pr-event.is-resolved::before { border-color: var(--pr-success-700); background: var(--pr-status-paid-bg); }
.pr-event-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--pr-space-2) var(--pr-space-3); }
.pr-event-head .title { font-weight: var(--pr-weight-semibold); }
.pr-event-head .when { color: var(--pr-text-muted); font-size: var(--pr-text-sm);
  margin-left: auto; font-variant-numeric: tabular-nums; }
.pr-event-body { margin-top: var(--pr-space-2); color: var(--pr-text-secondary);
  font-size: var(--pr-text-sm); line-height: var(--pr-leading-relaxed); }
.pr-event-note { margin-top: var(--pr-space-2); font-size: var(--pr-text-sm);
  color: var(--pr-text-muted); }
.pr-event-note .ok  { color: var(--pr-success-700); font-weight: var(--pr-weight-medium); }
.pr-event-note .out { color: var(--pr-danger-700);  font-weight: var(--pr-weight-medium); }

/* ---- Callout (why this surfaced) ---- */
.pr-callout { display: flex; gap: var(--pr-space-3); padding: var(--pr-space-4) var(--pr-space-5);
  border-radius: var(--pr-radius-md); border: 1px solid; line-height: var(--pr-leading-relaxed); }
.pr-callout .ic { flex: none; width: 1.5rem; height: 1.5rem; border-radius: var(--pr-radius-full);
  display: grid; place-items: center; font-weight: var(--pr-weight-semibold); }
.pr-callout .ct { font-size: var(--pr-text-sm); }
.pr-callout .ct strong { display: block; margin-bottom: var(--pr-space-1); font-size: var(--pr-text-base); }
.pr-callout.danger { background: var(--pr-status-escalate-bg); border-color: var(--pr-danger-700);
  color: var(--pr-status-escalate-fg); }
.pr-callout.info { background: var(--pr-status-pending-bg); border-color: var(--pr-info-700);
  color: var(--pr-status-pending-fg); }

/* ---- Side-by-side comparison (proposed action vs. bound it crosses) ---- */
.pr-vs { display: grid; gap: var(--pr-space-4); margin: var(--pr-space-4) 0; }
@media (min-width: 40rem) { .pr-vs { grid-template-columns: 1fr 1fr; } }
.pr-vs-panel { border: 1px solid var(--pr-border); border-radius: var(--pr-radius-lg);
  padding: var(--pr-space-4); background: var(--pr-surface); }
.pr-vs-panel.crossed { border-color: var(--pr-danger-700); background: var(--pr-status-escalate-bg); }
.pr-vs-panel .vs-label { font-size: var(--pr-text-xs); text-transform: uppercase;
  letter-spacing: .06em; font-weight: var(--pr-weight-semibold); color: var(--pr-text-muted); }
.pr-vs-panel.crossed .vs-label { color: var(--pr-status-escalate-fg); }
.pr-vs-panel .vs-figure { font-size: var(--pr-text-2xl); font-weight: var(--pr-weight-semibold);
  margin: var(--pr-space-2) 0; font-variant-numeric: tabular-nums; }
.pr-vs-panel .vs-sub { font-size: var(--pr-text-sm); color: var(--pr-text-secondary); }
.pr-vs-panel.crossed .vs-sub { color: var(--pr-status-escalate-fg); }

/* ---- Action bar (operator decision row) ---- */
.pr-actionbar { display: flex; flex-wrap: wrap; gap: var(--pr-space-2);
  padding: var(--pr-space-4) var(--pr-space-5); border-top: 1px solid var(--pr-border); }

/* ---- Forms ---- */
.pr-fieldset { border: 1px solid var(--pr-border); border-radius: var(--pr-radius-lg);
  padding: var(--pr-space-5); margin: 0 0 var(--pr-space-6); }
.pr-fieldset > legend { font-weight: var(--pr-weight-semibold); font-size: var(--pr-text-lg);
  padding: 0 var(--pr-space-2); }
.pr-field { display: flex; flex-direction: column; gap: var(--pr-space-2);
  margin-bottom: var(--pr-space-5); }
.pr-field:last-child { margin-bottom: 0; }
.pr-field > label, .pr-field-label { font-weight: var(--pr-weight-medium); font-size: var(--pr-text-sm); }
.pr-input, .pr-select { font: inherit; min-height: var(--pr-tap-target);
  padding: 0 var(--pr-space-3); border: 1px solid var(--pr-border-strong);
  border-radius: var(--pr-radius-md); background: var(--pr-surface); color: var(--pr-text);
  max-width: 22rem; }
.pr-input:focus-visible, .pr-select:focus-visible {
  outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; }
.pr-input.short { max-width: 9rem; }
.pr-help { font-size: var(--pr-text-sm); color: var(--pr-text-muted); }

/* consequence line — make a bound's effect legible */
.pr-consequence { font-size: var(--pr-text-sm); color: var(--pr-text-secondary);
  display: inline-flex; align-items: baseline; gap: var(--pr-space-2); }
.pr-consequence::before { content: "\2192"; color: var(--pr-status-escalate-fg); font-weight: var(--pr-weight-semibold); }

/* segmented control (single-select register) — accessible radios */
.pr-segmented { display: inline-flex; border: 1px solid var(--pr-border-strong);
  border-radius: var(--pr-radius-md); overflow: hidden; }
.pr-segmented input { position: absolute; opacity: 0; pointer-events: none; }
.pr-segmented label { padding: var(--pr-space-2) var(--pr-space-4); cursor: pointer;
  font-size: var(--pr-text-sm); font-weight: var(--pr-weight-medium); min-height: var(--pr-tap-target);
  display: inline-flex; align-items: center; border-left: 1px solid var(--pr-border); }
.pr-segmented label:first-of-type { border-left: 0; }
.pr-segmented input:checked + label { background: var(--pr-primary-600); color: var(--pr-text-on-primary); }
.pr-segmented input:focus-visible + label { outline: 3px solid var(--pr-focus-ring); outline-offset: -3px; }

/* checkbox row */
.pr-check { display: flex; gap: var(--pr-space-3); align-items: flex-start;
  padding: var(--pr-space-2) 0; }
.pr-check input { width: 1.25rem; height: 1.25rem; margin-top: 2px; flex: none; accent-color: var(--pr-primary-600); }
.pr-check input:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; }
.pr-check .ck-text { font-size: var(--pr-text-sm); }
.pr-check .ck-text .ck-title { font-weight: var(--pr-weight-medium); }

/* ---- Conversation thread (the message exchange, human-readable) ---- */
.pr-thread { list-style: none; margin: 0; padding: var(--pr-space-4) var(--pr-space-5);
  display: flex; flex-direction: column; gap: var(--pr-space-4); }
.pr-msg { background: var(--pr-surface); border: 1px solid var(--pr-border);
  border-left: 3px solid var(--pr-border-strong); border-radius: var(--pr-radius-md);
  padding: var(--pr-space-3) var(--pr-space-4); }
.pr-msg.out { border-left-color: var(--pr-primary-500); }   /* outbound — Propeller */
.pr-msg.in  { border-left-color: var(--pr-slate-400); }     /* inbound — debtor */
.pr-msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--pr-space-2);
  margin-bottom: var(--pr-space-2); }
.pr-msg-head .when { color: var(--pr-text-muted); font-size: var(--pr-text-sm); margin-left: auto;
  font-variant-numeric: tabular-nums; }
.pr-msg-body { font-size: var(--pr-text-sm); line-height: var(--pr-leading-relaxed);
  color: var(--pr-text-secondary); }

/* ---- Textarea ---- */
.pr-textarea { font: inherit; width: 100%; min-height: 8rem; resize: vertical;
  padding: var(--pr-space-3); border: 1px solid var(--pr-border-strong);
  border-radius: var(--pr-radius-md); background: var(--pr-surface); color: var(--pr-text);
  line-height: var(--pr-leading-relaxed); }
.pr-textarea:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; }

/* ---- Metadata chip (neutral, non-status) ---- */
.pr-chip { display: inline-flex; align-items: baseline; gap: var(--pr-space-1);
  background: var(--pr-surface-alt); border: 1px solid var(--pr-border);
  border-radius: var(--pr-radius-full); padding: 2px var(--pr-space-3);
  font-size: var(--pr-text-sm); }
.pr-chip .ck { color: var(--pr-text-muted); }

/* ---- Modal / dialog ---- */
.pr-modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: grid; place-items: center; padding: var(--pr-space-4); z-index: 50; }
.pr-modal { width: min(100%, 36rem); max-height: 90vh; overflow: auto;
  background: var(--pr-surface); border: 1px solid var(--pr-border);
  border-radius: var(--pr-radius-lg); box-shadow: var(--pr-shadow-lg); }
.pr-modal-head { display: flex; align-items: flex-start; gap: var(--pr-space-3);
  padding: var(--pr-space-5) var(--pr-space-5) var(--pr-space-3); }
.pr-modal-head h2 { margin: 0; font-size: var(--pr-text-lg); }
.pr-modal-head .sub { color: var(--pr-text-muted); font-size: var(--pr-text-sm); margin-top: 2px; }
.pr-modal-close { margin-left: auto; flex: none; background: transparent; border: 0;
  cursor: pointer; color: var(--pr-text-muted); font-size: var(--pr-text-xl);
  line-height: 1; min-width: var(--pr-tap-target); min-height: var(--pr-tap-target);
  border-radius: var(--pr-radius-md); }
.pr-modal-close:hover { background: var(--pr-surface-alt); color: var(--pr-text); }
.pr-modal-close:focus-visible { outline: 3px solid var(--pr-focus-ring); outline-offset: 2px; }
.pr-modal-body { padding: 0 var(--pr-space-5) var(--pr-space-5);
  display: flex; flex-direction: column; gap: var(--pr-space-4); }

/* ---- Utility ---- */
.pr-count-pill { background: var(--pr-status-escalate-bg); color: var(--pr-status-escalate-fg);
  border-radius: var(--pr-radius-full); padding: var(--pr-space-1) var(--pr-space-3);
  font-size: var(--pr-text-sm); font-weight: var(--pr-weight-semibold); }
