/* ============================================
   NEURAPHIC WORKERS — ops.css
   Operations pages: approvals, audit, replay, workflows
   All tokens inherit from base.css (--bg, --black, --gray,
   --head, --sans, --green, --amber, --red, --r-*, --s-*).
   ============================================ */

/* ---------- shared ops shell ---------- */
.ops {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--s-6);
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--s-8) clamp(24px, 4vw, 48px);
  min-height: calc(100vh - var(--nav-h));
}
.ops__side {
  position: sticky; top: var(--s-8);
  align-self: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-2);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
.ops__side h6 {
  font-family: var(--head);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--gray);
  text-transform: uppercase;
  margin: var(--s-3) 0 var(--s-1);
}
.ops__side a, .ops__side button.nav {
  display: block;
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--black);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s;
  text-align: left;
  width: 100%;
}
.ops__side a:hover, .ops__side button.nav:hover { background: rgba(19,19,20,0.04); }
.ops__side a[aria-current="page"] { background: var(--black); color: var(--bg); }

.ops__main {
  display: flex; flex-direction: column; gap: var(--s-5);
  min-width: 0;
}
.ops__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-5); flex-wrap: wrap;
}
.ops__head h1 {
  font-size: 28px; letter-spacing: -0.03em; color: var(--black);
}
.ops__head .sub { font-size: 14px; color: var(--gray); margin-top: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--r-md);
  background: #fff; border: 1px solid var(--line);
  color: var(--black); font-weight: 600; font-size: 13px;
  transition: transform .12s, background .15s, border-color .15s;
}
.btn:hover { background: rgba(19,19,20,0.04); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--black); color: var(--bg); border-color: var(--black); }
.btn--primary:hover { background: var(--ink-hover); }
.btn--danger { background: #fff; color: var(--red); border-color: rgba(220,38,38,0.3); }
.btn--danger:hover { background: rgba(220,38,38,0.06); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- filter bar ---------- */
.filters {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: var(--s-3);
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-4);
}
.filters label { font-size: 12px; color: var(--gray); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.filters select, .filters input[type="search"], .filters input[type="date"], .filters input[type="text"] {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 8px 12px; font-size: 13px; color: var(--black); min-width: 140px;
}
.filters input[type="range"] { accent-color: var(--black); width: 140px; }
.filters .group { display: flex; align-items: center; gap: 8px; }
.filters .spacer { flex: 1; }

/* ---------- live badge ---------- */
.live-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; font-family: var(--head);
  text-transform: uppercase; letter-spacing: .08em;
  background: #fff; border: 1px solid var(--line); color: var(--gray);
}
.live-badge .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--gray);
}
.live-badge[data-state="live"] { color: var(--green); border-color: rgba(22,163,74,0.3); }
.live-badge[data-state="live"] .dot { background: var(--green); animation: pulse 1.8s infinite; }
.live-badge[data-state="connecting"] .dot { background: var(--amber); animation: pulse 1s infinite; }
.live-badge[data-state="reconnecting"] { color: var(--amber); border-color: rgba(217,119,6,0.3); }
.live-badge[data-state="reconnecting"] .dot { background: var(--amber); animation: pulse .6s infinite; }
.live-badge[data-state="offline"] { color: var(--red); border-color: rgba(220,38,38,0.3); }
.live-badge[data-state="offline"] .dot { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.45;transform:scale(.8)} }

/* ---------- cards ---------- */
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-5);
}
.card--hover { transition: border-color .15s, transform .15s; }
.card--hover:hover { border-color: rgba(19,19,20,0.18); transform: translateY(-1px); }

/* ========================================================
   PART 1 — APPROVALS
   ======================================================== */
.appr-list { display: flex; flex-direction: column; gap: var(--s-4); }
.appr-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--s-5);
  padding: var(--s-5);
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  transition: border-color .15s, transform .15s;
}
.appr-card:hover { border-color: rgba(19,19,20,0.18); }
.appr-card.is-focused { border-color: var(--black); box-shadow: 0 0 0 3px rgba(19,19,20,0.08); }
.appr-card.is-leaving { opacity: 0; transform: translateX(40px); transition: .25s; }
.appr-card__avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--black); color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--head); font-size: 20px; font-weight: 700;
}
.appr-card__body h3 {
  font-size: 17px; color: var(--black);
  margin-bottom: 2px;
}
.appr-card__meta { font-size: 13px; color: var(--gray); margin-bottom: var(--s-3); }
.appr-card__meta strong { color: var(--black); font-weight: 600; }
.appr-card__preview {
  background: var(--bg); padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); font-size: 13px;
  color: var(--black); line-height: 1.6;
  max-height: 4.8em; overflow: hidden;
  position: relative;
}
.appr-card__preview::after {
  content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 24px;
  background: linear-gradient(transparent, var(--bg));
}
.appr-card__side {
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--s-3);
  min-width: 180px;
}
.appr-card__actions { display: flex; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; font-family: var(--head);
  text-transform: uppercase; letter-spacing: .08em;
  background: rgba(19,19,20,0.06); color: var(--black);
}
.pill--green { background: rgba(22,163,74,0.12); color: var(--green); }
.pill--amber { background: rgba(217,119,6,0.12); color: var(--amber); }
.pill--red { background: rgba(220,38,38,0.12); color: var(--red); }
.pill--gray { background: rgba(107,114,128,0.12); color: var(--gray); }

.cost {
  font-family: var(--head);
  font-size: 20px; font-weight: 700; color: var(--black);
}

/* swipe stack (mobile) */
.swipe-stack {
  display: none;
  position: relative;
  height: 560px;
  margin-top: var(--s-4);
}
.swipe-stack .appr-card {
  position: absolute; inset: 0;
  transition: transform .25s, opacity .25s;
  will-change: transform;
  grid-template-columns: 56px 1fr;
  touch-action: pan-y;
}
.swipe-stack .appr-card__side { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
.swipe-hint {
  display: none; text-align: center;
  font-size: 12px; color: var(--gray);
  font-family: var(--head); text-transform: uppercase; letter-spacing: .1em;
  margin-top: var(--s-4);
}
@media (max-width: 760px) {
  .ops { grid-template-columns: 1fr; padding: var(--s-5) var(--s-4); }
  .ops__side { position: static; flex-direction: row; overflow-x: auto; }
  .appr-list { display: none; }
  .swipe-stack { display: block; }
  .swipe-hint { display: block; }
}

/* drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(540px, 100%);
  background: #fff;
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform .25s;
  z-index: 200;
  display: flex; flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }
.drawer__head {
  padding: var(--s-5); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer__body { padding: var(--s-5); overflow-y: auto; flex: 1; font-size: 13px; }
.drawer__body pre {
  background: var(--bg); padding: var(--s-4); border-radius: var(--r-md);
  overflow-x: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--black); white-space: pre-wrap; word-break: break-word;
}
.scrim {
  position: fixed; inset: 0; background: rgba(19,19,20,0.35);
  opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 150;
}
.scrim.is-open { opacity: 1; pointer-events: auto; }

/* ========================================================
   PART 2 — AUDIT
   ======================================================== */
.audit-wrap { display: flex; flex-direction: column; gap: var(--s-4); }
.audit-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); flex-wrap: wrap;
}
.chain-health {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--gray); font-family: var(--head);
  text-transform: uppercase; letter-spacing: .1em;
}
.chain-health .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gray); }
.chain-health[data-state="ok"] .dot { background: var(--green); box-shadow: 0 0 0 4px rgba(22,163,74,0.15); }
.chain-health[data-state="ok"] { color: var(--green); }
.chain-health[data-state="bad"] .dot { background: var(--red); box-shadow: 0 0 0 4px rgba(220,38,38,0.15); }
.chain-health[data-state="bad"] { color: var(--red); }

.vtable {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden;
}
.vtable__head, .vtable__row {
  display: grid;
  grid-template-columns: 170px 160px 170px 1fr 110px 140px;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-5);
  font-size: 13px;
}
.vtable__head {
  background: var(--bg);
  font-family: var(--head); font-size: 11px;
  color: var(--gray); text-transform: uppercase; letter-spacing: .08em;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}
.vtable__viewport {
  position: relative; overflow-y: auto; height: 620px;
}
.vtable__spacer { position: relative; }
.vtable__row {
  position: absolute; left: 0; right: 0;
  border-bottom: 1px solid var(--line);
  height: 44px;
  cursor: pointer;
  transition: background .1s;
}
.vtable__row:hover { background: rgba(19,19,20,0.03); }
.vtable__row.is-active { background: rgba(19,19,20,0.06); }
.vtable__row .hash {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; color: var(--black);
}
.vtable__row .outcome--ok { color: var(--green); font-weight: 600; }
.vtable__row .outcome--denied { color: var(--red); font-weight: 600; }

/* ========================================================
   PART 3 — REPLAY
   ======================================================== */
.replay {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--s-5);
}
.task-list {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  max-height: 72vh; overflow-y: auto;
}
.task-list__filters { padding: var(--s-4); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.task-list__item {
  padding: var(--s-4); border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background .12s;
}
.task-list__item:hover { background: rgba(19,19,20,0.03); }
.task-list__item.is-active { background: rgba(19,19,20,0.06); }
.task-list__item h4 { font-size: 14px; color: var(--black); margin-bottom: 4px; }
.task-list__item .meta { font-size: 12px; color: var(--gray); }

.replay-pane { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
.replay-controls {
  display: flex; align-items: center; gap: var(--s-3);
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-4);
  flex-wrap: wrap;
}
.replay-controls .speed { display: flex; align-items: center; gap: 8px; }

.timeline {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-6);
  overflow-x: auto;
}
.timeline__track {
  position: relative; min-height: 160px;
  padding: var(--s-6) 0;
}
.timeline__line {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 2px; background: var(--line);
}
.timeline__nodes {
  position: relative;
  display: flex; align-items: center; gap: 24px;
  min-width: max-content;
}
.timeline__node {
  position: relative;
  width: 46px; height: 46px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line);
  display: grid; place-items: center;
  cursor: pointer; transition: transform .15s, border-color .15s;
  font-family: var(--head); font-size: 11px; font-weight: 700;
  color: var(--black);
  flex: 0 0 auto;
}
.timeline__node:hover { transform: scale(1.08); }
.timeline__node.is-active { border-color: var(--black); background: var(--black); color: var(--bg); box-shadow: 0 0 0 4px rgba(19,19,20,0.1); }
.timeline__node.is-played { border-color: var(--black); }
.timeline__node[data-kind="error"] { border-color: var(--red); color: var(--red); }
.timeline__node[data-kind="approval_requested"],
.timeline__node[data-kind="approval_granted"] { border-color: var(--amber); color: var(--amber); }
.timeline__node[data-kind="task_completed"] { border-color: var(--green); color: var(--green); }
.timeline__node .label {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--gray); text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap;
}

.event-panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-5); font-size: 13px;
}
.event-panel h3 { font-size: 16px; color: var(--black); margin-bottom: var(--s-2); }
.event-panel .kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin-bottom: var(--s-3); }
.event-panel .kv dt { font-size: 12px; color: var(--gray); text-transform: uppercase; letter-spacing: .06em; }
.event-panel .kv dd { font-size: 13px; color: var(--black); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

@media (max-width: 960px) {
  .replay { grid-template-columns: 1fr; }
}

/* ========================================================
   PART 4 — WORKFLOWS
   ======================================================== */
.wf-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--s-4);
  min-height: calc(100vh - 160px);
}
.wf-top {
  display: flex; align-items: center; gap: var(--s-3);
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-4);
  flex-wrap: wrap;
}
.wf-top select {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--black); min-width: 240px;
}
.wf-top .spacer { flex: 1; }
.wf-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line);
  font-size: 12px; font-weight: 700; font-family: var(--head);
  text-transform: uppercase; letter-spacing: .08em;
}
.wf-toggle[data-on="true"] { background: rgba(22,163,74,0.12); color: var(--green); border-color: rgba(22,163,74,0.3); }
.wf-toggle[data-on="false"] { color: var(--gray); }

.wf-work { display: grid; grid-template-columns: 220px 1fr 280px; gap: var(--s-4); min-height: 600px; }
.wf-palette, .wf-inspect {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-4); overflow-y: auto;
}
.wf-palette h6, .wf-inspect h6 {
  font-family: var(--head); font-size: 11px; letter-spacing: .12em;
  color: var(--gray); text-transform: uppercase; margin-bottom: var(--s-3);
}
.wf-node-kind {
  display: grid; grid-template-columns: 32px 1fr; gap: 10px;
  padding: 10px; border-radius: var(--r-md);
  border: 1px solid var(--line); margin-bottom: 8px;
  cursor: grab; background: #fff;
  transition: border-color .15s, transform .1s;
}
.wf-node-kind:hover { border-color: var(--black); }
.wf-node-kind:active { cursor: grabbing; transform: scale(.98); }
.wf-node-kind__icon {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: var(--bg);
  display: grid; place-items: center;
  font-family: var(--head); font-weight: 700; font-size: 13px; color: var(--black);
}
.wf-node-kind__name { font-size: 13px; font-weight: 600; color: var(--black); }
.wf-node-kind__desc { font-size: 11px; color: var(--gray); line-height: 1.4; }

.wf-canvas {
  position: relative;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  overflow: hidden;
  background-image:
    radial-gradient(circle, rgba(19,19,20,0.08) 1px, transparent 1px);
  background-size: 20px 20px;
}
.wf-canvas__svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.wf-zoom {
  position: absolute; right: var(--s-4); top: var(--s-4);
  display: flex; flex-direction: column; gap: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 4px;
}
.wf-zoom button {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  display: grid; place-items: center; font-weight: 700; color: var(--black);
}
.wf-zoom button:hover { background: rgba(19,19,20,0.06); }

.wf-node {
  position: absolute;
  min-width: 160px;
  background: #fff; border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px; color: var(--black);
  cursor: grab; user-select: none;
  box-shadow: 0 1px 3px rgba(19,19,20,0.04);
}
.wf-node:hover { border-color: rgba(19,19,20,0.25); }
.wf-node.is-selected { border-color: var(--black); box-shadow: 0 0 0 3px rgba(19,19,20,0.12); }
.wf-node__kind { font-size: 10px; color: var(--gray); text-transform: uppercase; letter-spacing: .08em; font-family: var(--head); font-weight: 700; }
.wf-node__name { font-weight: 600; margin-top: 2px; }
.wf-edge { stroke: var(--gray); stroke-width: 2; fill: none; }
.wf-edge--hot { stroke: var(--black); stroke-width: 3; }

.wf-runs {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s-4);
}
.wf-runs h6 {
  font-family: var(--head); font-size: 11px; letter-spacing: .12em;
  color: var(--gray); text-transform: uppercase; margin-bottom: var(--s-3);
}
.wf-runs__list { display: flex; gap: var(--s-3); overflow-x: auto; }
.wf-run {
  flex: 0 0 auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 10px 14px; min-width: 180px;
  font-size: 12px; color: var(--black);
  cursor: pointer; transition: border-color .15s;
}
.wf-run:hover { border-color: var(--black); }

@media (max-width: 1100px) {
  .wf-work { grid-template-columns: 1fr; }
}

/* ---------- generic ---------- */
.empty {
  padding: var(--s-9);
  text-align: center;
  color: var(--gray);
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  font-size: 14px;
}
.skeleton {
  background: linear-gradient(90deg, rgba(19,19,20,0.04), rgba(19,19,20,0.08), rgba(19,19,20,0.04));
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

.kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--black);
}
