/* ════════════════════════════════════════════════════════════════════
 * styles/agent-ui.css — Platform Masters panel
 *
 * Liquid-glass, no fixed accent. Uses the platform's frosted-overlay
 * variables where available; falls back to safe defaults so the panel
 * still works if loaded in isolation.
 *
 * Mode-scoping note: this stylesheet adds NEW classes that don't exist
 * elsewhere in the platform. It does NOT touch any shared selectors
 * (.input-bar, .input-row, #prompt, .send-btn, etc.). No body.in-
 * story-mode / body:not(.in-story-mode) guards required — the agent
 * panel is mode-agnostic by design.
 * ════════════════════════════════════════════════════════════════════ */

.soj-agent-panel {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}
.soj-agent-panel.hidden { display: none !important; }
.soj-agent-panel [hidden] { display: none !important; }   /* scoped attribute-trap defence */

.soj-agent-scrim {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.55);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}

.soj-agent-card {
  position: relative;
  width: min(720px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: rgba(20, 22, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 18px;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: saturate(160%) blur(24px);
  -webkit-backdrop-filter: saturate(160%) blur(24px);
  color: rgba(255, 255, 255, 0.92);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
}

.soj-agent-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.soj-agent-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.005em;
}
.soj-agent-x {
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}
.soj-agent-x:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.soj-agent-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.soj-agent-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
}
.soj-foot-spacer { flex: 1; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.soj-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.92);
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
  user-select: none;
}
.soj-btn:hover  { background: rgba(255, 255, 255, 0.10); border-color: rgba(255, 255, 255, 0.18); }
.soj-btn:active { transform: translateY(1px); }
.soj-btn-primary {
  background: rgba(255, 255, 255, 0.92);
  color: #0f1218;
  border-color: rgba(255, 255, 255, 0.92);
}
.soj-btn-primary:hover { background: #fff; }
.soj-btn-secondary { background: transparent; }
.soj-btn-danger {
  background: rgba(220, 70, 70, 0.14);
  border-color: rgba(220, 70, 70, 0.32);
  color: rgba(255, 200, 200, 0.95);
}
.soj-btn-danger:hover { background: rgba(220, 70, 70, 0.22); }

/* ── Roster grid ──────────────────────────────────────────────────── */
.soj-master-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.soj-master-card {
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.soj-master-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
}
.soj-master-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}
.soj-master-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  opacity: 0.7;
}
.soj-master-coins {
  background: rgba(255, 255, 255, 0.10);
  padding: 2px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.soj-master-phase { letter-spacing: 0.04em; text-transform: uppercase; font-size: 11px; }

/* ── Brief composer ───────────────────────────────────────────────── */
.soj-brief-composer { display: flex; flex-direction: column; gap: 12px; }
.soj-brief-label    { font-size: 13px; opacity: 0.85; }
.soj-brief-input {
  width: 100%;
  resize: vertical;
  font: inherit;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.10);
  outline: none;
}
.soj-brief-input.small { rows: 2; }
.soj-brief-input:focus { border-color: rgba(255, 255, 255, 0.32); background: rgba(255, 255, 255, 0.07); }
.soj-brief-advanced {
  font-size: 13px;
  border-top: 1px dashed rgba(255, 255, 255, 0.10);
  padding-top: 10px;
}
.soj-brief-advanced summary { cursor: pointer; opacity: 0.8; }
.soj-brief-advanced summary:hover { opacity: 1; }
.soj-brief-help { font-size: 12px; opacity: 0.65; margin: 8px 0; }
.soj-brief-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 0; }

.soj-cost-pill {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

.soj-agent-hint {
  font-size: 12px;
  opacity: 0.7;
  width: 100%;
  text-align: center;
}

/* ── Recent runs ─────────────────────────────────────────────────── */
.soj-recent-runs-wrap {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.soj-section-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
  margin-bottom: 10px;
}
.soj-recent-runs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.soj-recent-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  background: transparent;
  transition: background 0.12s ease;
  font-size: 13px;
}
.soj-recent-row:hover { background: rgba(255, 255, 255, 0.05); }
.soj-recent-row .soj-orb { width: 9px; height: 9px; flex: 0 0 9px; }
.soj-recent-name {
  flex: 0 0 auto;
  font-weight: 600;
  opacity: 0.9;
  white-space: nowrap;
  max-width: 36%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.soj-recent-snippet {
  flex: 1;
  opacity: 0.65;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}
.soj-recent-when {
  flex: 0 0 auto;
  opacity: 0.5;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ── Run card ─────────────────────────────────────────────────────── */
.soj-run-card { display: flex; flex-direction: column; gap: 12px; }
.soj-run-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 6px;
}
.soj-run-status-label { font-size: 14px; font-weight: 600; }
.soj-run-coins {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
.soj-run-brief {
  font-size: 14px;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px 14px;
  border-radius: 10px;
  white-space: pre-wrap;
}
.soj-run-goal {
  font-size: 12px;
  opacity: 0.85;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  border-left: 2px solid rgba(255, 255, 255, 0.20);
}

/* Orbs */
.soj-orb {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 0 10px currentColor;
}
.soj-orb-queued    { background: rgba(180, 180, 200, 0.85); }
.soj-orb-running   { background: rgba(120, 200, 255, 0.95); animation: sojPulse 1.4s ease-in-out infinite; }
.soj-orb-paused    { background: rgba(255, 200, 80, 0.95); }
.soj-orb-completed { background: rgba(120, 230, 150, 0.95); }
.soj-orb-failed    { background: rgba(255, 110, 110, 0.95); }
.soj-orb-cancelled { background: rgba(180, 180, 180, 0.7); }
/* Fallback states so a status without its own rule never renders an invisible
   dot: `idle` (mapStatusToOrb default) and `awaiting_approval` (Command Center). */
.soj-orb-idle      { background: rgba(180, 180, 200, 0.55); }
.soj-orb-awaiting_approval { background: rgba(255, 200, 80, 0.95); }
@keyframes sojPulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.25); opacity: 0.75;}
}

/* Milestones */
.soj-milestones { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.soj-milestone {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  animation: sojSlideIn 0.25s ease-out;
}
.soj-milestone-stage {
  flex: 0 0 auto;
  opacity: 0.55;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-top: 2px;
  min-width: 60px;
}
.soj-milestone-msg { flex: 1; }
@keyframes sojSlideIn {
  from { transform: translateY(-4px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* Output */
.soj-run-output {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
}
.soj-output-summary { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.soj-output-next { margin-top: 10px; font-size: 12px; opacity: 0.75; }
.soj-output-json {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  max-height: 360px;
  overflow: auto;
}

/* Pending + error */
.soj-run-pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 36px 12px;
  opacity: 0.8;
}
.soj-spinner {
  width: 28px; height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.18);
  border-top-color: rgba(255,255,255,0.85);
  animation: sojSpin 0.9s linear infinite;
}
@keyframes sojSpin { to { transform: rotate(360deg); } }

.soj-run-error {
  background: rgba(220, 70, 70, 0.10);
  border: 1px solid rgba(220, 70, 70, 0.32);
  border-radius: 12px;
  padding: 14px 16px;
}
.soj-run-error-title { font-weight: 600; margin-bottom: 6px; }
.soj-run-error-detail { font-family: ui-monospace, monospace; font-size: 12px; opacity: 0.85; word-break: break-all; }

/* Guide input */
.soj-guide-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.10);
  outline: none;
  font: inherit;
}
.soj-guide-input:focus { border-color: rgba(255, 255, 255, 0.32); }

/* Toast */
.soj-agent-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 9999;
  background: rgba(20, 22, 28, 0.96);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.soj-agent-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* When the agent panel is open, prevent body scroll behind it. */
body.soj-agent-open { overflow: hidden; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .soj-orb-running, .soj-spinner, .soj-milestone { animation: none; }
}

/* ── Floating launcher ───────────────────────────────────────────── */
/* The persistent CTA that opens the Masters panel from anywhere on
   the platform. Bottom-right by default — K can reposition via
   SOJ.edits.set('agent-launcher', 'bottom', '24px') etc. */
.soj-agent-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 8500;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(20, 22, 28, 0.72);
  color: rgba(255, 255, 255, 0.95);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  box-shadow:
    0 12px 36px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
.soj-agent-launcher:hover {
  background: rgba(28, 30, 38, 0.86);
  border-color: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
  box-shadow:
    0 16px 44px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.10);
}
.soj-agent-launcher:active { transform: translateY(0); }
.soj-launcher-orb {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 35% 30%, rgba(180, 220, 255, 0.95), rgba(80, 120, 220, 0.6) 60%, rgba(40, 60, 140, 0.0) 70%),
    radial-gradient(circle at 70% 70%, rgba(255, 220, 180, 0.7),  rgba(220, 120, 80, 0.4) 60%, transparent 70%);
  box-shadow: 0 0 14px rgba(120, 180, 255, 0.45);
  animation: sojLauncherPulse 3.6s ease-in-out infinite;
}
@keyframes sojLauncherPulse {
  0%, 100% { transform: scale(1);    filter: brightness(1); }
  50%      { transform: scale(1.08); filter: brightness(1.15); }
}
.soj-launcher-label { white-space: nowrap; }

/* Hide the launcher while the panel itself is open — the panel is the
   visible affordance at that point. */
body.soj-agent-open .soj-agent-launcher { display: none; }

/* Opt-out hook: any surface that wants to suppress the launcher (story
   mode, full-screen generation, etc.) can add body.no-soj-agent-launcher. */
body.no-soj-agent-launcher .soj-agent-launcher { display: none; }

/* Mobile sizing */
@media (max-width: 640px) {
  .soj-agent-launcher { right: 14px; bottom: 14px; padding: 9px 14px 9px 11px; font-size: 12px; }
}

/* ── The Council (mixture-of-agents) picker ───────────────────────── */
.soj-master-card.is-premium { position: relative; }
.soj-master-premium {
  font-size: 9px; letter-spacing: .06em; text-transform: uppercase;
  padding: 1px 6px; margin-left: 6px; border-radius: 999px; vertical-align: middle;
  background: linear-gradient(135deg, rgba(255,210,120,.22), rgba(180,140,255,.22));
  border: 1px solid rgba(255,255,255,.18); color: rgba(255,255,255,.82);
}
.soj-council-pick {
  margin: 12px 0 4px; padding: 12px; border-radius: 14px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08);
}
.soj-council-pick__head { font-size: 13px; font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.soj-council-pick__hint { font-size: 11px; font-weight: 400; opacity: .6; }
.soj-council-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.soj-council-opt {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 10px;
  background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.07); cursor: pointer;
  font-size: 12px; transition: background .15s, border-color .15s;
}
.soj-council-opt:hover { background: rgba(255,255,255,.06); }
.soj-council-opt input { accent-color: #b48cff; }
.soj-council-opt__name { flex: 1; }
.soj-council-opt__fam { font-size: 10px; opacity: .5; }
.soj-council-agg { display: block; margin-top: 10px; font-size: 12px; opacity: .85; }
.soj-council-agg__sel {
  margin-left: 6px; padding: 4px 8px; border-radius: 8px; font-size: 12px;
  background: rgba(0,0,0,.25); color: inherit; border: 1px solid rgba(255,255,255,.12);
}
.soj-council-pick__note { font-size: 11px; opacity: .55; margin: 9px 0 0; line-height: 1.4; }
.soj-cost-pill.is-invalid { opacity: .6; }

/* ── Pay-as-it-works: spend cap + live meter ─────────────────────── */
.soj-brief-meter-note {
  font-size: 12px; line-height: 1.5; opacity: .7; margin: 12px 2px 0;
}
.soj-cap-field {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px;
  opacity: .85; margin-right: 10px; white-space: nowrap;
}
.soj-cap-input {
  width: 72px; padding: 5px 8px; border-radius: 8px; font-size: 12px;
  background: rgba(0,0,0,.25); color: inherit; border: 1px solid rgba(255,255,255,.14);
}
.soj-cap-input::placeholder { opacity: .45; }
/* Live meter in the run card */
.soj-meter {
  position: relative; display: inline-flex; align-items: center; justify-content: flex-end;
  min-width: 130px; height: 22px; margin-left: auto; padding: 0 10px; border-radius: 999px;
  overflow: hidden; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.10);
  font-variant-numeric: tabular-nums;
}
.soj-meter-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: linear-gradient(90deg, rgba(120,200,160,.30), rgba(120,200,160,.5));
  transition: width .4s ease;
}
.soj-meter.is-near .soj-meter-fill {
  background: linear-gradient(90deg, rgba(255,180,90,.35), rgba(255,140,90,.6));
}
.soj-meter-label { position: relative; z-index: 1; font-size: 11px; font-weight: 600; }
.soj-meter--nocap { background: rgba(255,255,255,.04); }
