/* ============================================================
   ALLOY — Act 4 Agent Studio macOS simulation (SA-6)
   ------------------------------------------------------------
   Self-contained styling for site/js/agent-studio-sim.js.
   The JS injects a <link> to this file at runtime so the act
   is portable; SA-8 may also add the <link> to index.html head
   (see the agent's final report for the exact tag).

   Two surfaces:
     - The OUTER frame sits natively on the warm cream page
       (#f5f0e8, cinematic-v2 tokens) — no card, no border.
     - The STUDIO WINDOW itself uses a darker control-plane
       surface mirroring packages/dashboard dark theme
       (Stripe-inspired deep navy + indigo accent + JetBrains
       Mono), so it reads as a real macOS app window.

   Visibility rule (matches cinematic-v2): everything is
   visible by default. Motion only enhances. prefers-reduced-
   motion + no-JS both leave the full panel readable.
   ============================================================ */

.studio {
  /* Control-plane dark tokens — scoped so they never leak onto
     the cream page. Sourced from dashboard design-tokens.css
     [data-theme="dark"] (deep navy / indigo / JetBrains Mono). */
  --st-base:        #0a2540;
  --st-raised:      #0f2d4a;
  --st-sunken:      #061325;
  --st-sidebar:     #081b2e;
  --st-inset:       #051018;
  --st-terminal:    #030a12;

  --st-border:      #1a3a5c;
  --st-border-soft: #15304d;
  --st-border-strong:#2a4f73;

  --st-ink:         #e8edf5;
  --st-ink-soft:    #b8c4d4;
  --st-muted:       #7a8fa8;
  --st-dim:         #5a6f88;

  --st-accent:      #7a73ff;   /* indigo — control plane */
  --st-accent-soft: rgba(122, 115, 255, 0.12);
  --st-accent-mut:  rgba(122, 115, 255, 0.22);

  --st-ok:          #3ecf8e;
  --st-ok-soft:     rgba(62, 207, 142, 0.12);
  --st-warn:        #f5a623;
  --st-warn-soft:   rgba(245, 166, 35, 0.12);

  /* Alloy ochre — used sparingly to tie the window to the page. */
  --st-ochre:       #c17f59;

  --st-font-mono:   'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --st-font-body:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --st-font-disp:   'Fraunces', 'Iowan Old Style', Georgia, serif;

  position: relative;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* Caption above the window — lives on the cream page, ochre mono. */
.studio__caption {
  font-family: var(--st-font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--st-ochre);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.studio__caption::before {
  content: '';
  width: 22px;
  height: 1px;
  background: currentColor;
  opacity: 0.7;
}

/* ============================================================
   macOS WINDOW CHROME
   ============================================================ */
.studio-win {
  position: relative;
  border-radius: 12px;
  background: var(--st-base);
  border: 1px solid var(--st-border-strong);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 30px 60px -20px rgba(10, 18, 30, 0.55),
    0 8px 22px -12px rgba(10, 18, 30, 0.4);
  overflow: hidden;
  color: var(--st-ink);
  font-family: var(--st-font-body);
}

/* Title bar with traffic lights */
.studio-win__bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  height: 38px;
  padding: 0 14px;
  background: linear-gradient(180deg, #103057, #0d2742);
  border-bottom: 1px solid var(--st-border);
}

.studio-lights {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.studio-lights span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: block;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.25) inset;
}
.studio-lights .is-close  { background: #ff5f57; }
.studio-lights .is-min    { background: #febc2e; }
.studio-lights .is-max    { background: #28c840; }

.studio-win__title {
  flex: 1;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--st-ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.studio-win__title strong { color: var(--st-ink); font-weight: 600; }

/* balance the traffic-light width so the title stays centred */
.studio-win__spacer { width: 52px; flex-shrink: 0; }

/* ============================================================
   WINDOW BODY — toolbar rail + content grid
   ============================================================ */
.studio-win__body {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 460px;
}

/* Left rail: pipeline stage labels (mono), the scroll-synced index */
.studio-rail {
  background: var(--st-sidebar);
  border-right: 1px solid var(--st-border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.studio-rail__head {
  font-family: var(--st-font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--st-dim);
  padding: 0 8px 10px;
}

.studio-stage {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  font-family: var(--st-font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--st-muted);
  cursor: default;
  position: relative;
  transition: background 0.3s var(--st-ease, ease), color 0.3s ease;
}
.studio-stage__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--st-border-strong);
  flex-shrink: 0;
  transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}
.studio-stage__label { white-space: nowrap; }
.studio-stage__idx {
  margin-left: auto;
  font-size: 0.62rem;
  color: var(--st-dim);
}

/* a stage already passed in the run */
.studio-stage.is-done { color: var(--st-ink-soft); }
.studio-stage.is-done .studio-stage__dot { background: var(--st-ok); }

/* the active stage (scroll-synced highlight) */
.studio-stage.is-active {
  background: var(--st-accent-soft);
  color: var(--st-ink);
}
.studio-stage.is-active .studio-stage__dot {
  background: var(--st-accent);
  box-shadow: 0 0 0 4px var(--st-accent-mut);
  transform: scale(1.05);
}
.studio-stage.is-active .studio-stage__idx { color: var(--st-accent); }

/* Right pane: stacked Agent Studio panels */
.studio-main {
  padding: 16px 18px 18px;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(122, 115, 255, 0.06), transparent 60%),
    var(--st-base);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

/* ---- generic panel ---- */
.studio-panel {
  border: 1px solid var(--st-border);
  border-radius: 10px;
  background: var(--st-raised);
  overflow: hidden;
}
.studio-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--st-border-soft);
  background: rgba(255, 255, 255, 0.015);
}
.studio-panel__title {
  font-family: var(--st-font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--st-muted);
}
.studio-panel__spacer { margin-left: auto; }
.studio-panel__body { padding: 12px 14px; }

/* ---- harness session header ---- */
.studio-session {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}
.studio-session__guild {
  display: flex;
  align-items: center;
  gap: 10px;
}
.studio-session__avatar {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--st-ochre), #8a5536);
  display: grid;
  place-items: center;
  font-family: var(--st-font-disp);
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  flex-shrink: 0;
}
.studio-session__name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--st-ink);
  line-height: 1.2;
}
.studio-session__sub {
  font-size: 0.72rem;
  color: var(--st-muted);
  margin-top: 2px;
}
.studio-session__sub code {
  font-family: var(--st-font-mono);
  color: var(--st-ink-soft);
}

.studio-pill {
  font-family: var(--st-font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--st-border-strong);
  color: var(--st-ink-soft);
  background: var(--st-inset);
  white-space: nowrap;
}
.studio-pill--active {
  color: var(--st-ok);
  background: var(--st-ok-soft);
  border-color: rgba(62, 207, 142, 0.35);
}

.studio-meta {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 6px 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--st-border-soft);
  font-size: 0.74rem;
}
.studio-meta dt {
  font-family: var(--st-font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--st-dim);
  align-self: center;
}
.studio-meta dd {
  margin: 0;
  color: var(--st-ink-soft);
}
.studio-meta dd code {
  font-family: var(--st-font-mono);
  font-size: 0.72rem;
  color: var(--st-ink);
}

/* ---- lane indicator ---- */
.studio-lane {
  display: flex;
  align-items: center;
  gap: 10px;
}
.studio-lane__chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--st-font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid var(--st-warn);
  color: var(--st-warn);
  background: var(--st-warn-soft);
}
.studio-lane__chip::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.studio-lane__note {
  font-size: 0.72rem;
  color: var(--st-muted);
}

/* ---- tool-policy snippet (mono code) ---- */
.studio-code {
  margin: 0;
  font-family: var(--st-font-mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--st-ink-soft);
  background: var(--st-terminal);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  white-space: pre;
  border: 1px solid var(--st-border-soft);
}
.studio-code .tok-key   { color: var(--st-accent); }
.studio-code .tok-str   { color: var(--st-ok); }
.studio-code .tok-warn  { color: var(--st-warn); }
.studio-code .tok-com   { color: var(--st-dim); font-style: italic; }
.studio-code .tok-punc  { color: var(--st-muted); }

/* ---- trace / log stream ---- */
.studio-trace {
  background: var(--st-terminal);
  border-radius: 8px;
  border: 1px solid var(--st-border-soft);
  padding: 6px 0;
  max-height: 188px;
  overflow-y: auto;
  font-family: var(--st-font-mono);
  font-size: 0.7rem;
  line-height: 1.5;
}
.studio-trace__row {
  display: grid;
  grid-template-columns: 64px 86px 1fr;
  gap: 10px;
  padding: 3px 14px;
  color: var(--st-ink-soft);
  border-left: 2px solid transparent;
}
.studio-trace__row.is-active {
  background: var(--st-accent-soft);
  border-left-color: var(--st-accent);
}
.studio-trace__row.is-pending { opacity: 0.45; }
.studio-trace__time { color: var(--st-dim); }
.studio-trace__kind {
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  align-self: center;
}
.studio-trace__kind[data-kind="listen"]      { color: var(--st-muted); }
.studio-trace__kind[data-kind="entitlement"] { color: var(--st-ochre); }
.studio-trace__kind[data-kind="plan"]        { color: var(--st-accent); }
.studio-trace__kind[data-kind="dispatch"]    { color: var(--st-ok); }
.studio-trace__kind[data-kind="trace"]       { color: var(--st-warn); }
.studio-trace__kind[data-kind="output"]      { color: var(--st-accent); }
.studio-trace__msg { color: var(--st-ink-soft); }
.studio-trace__msg b { color: var(--st-ink); font-weight: 600; }
.studio-trace__msg .mono-arrow { color: var(--st-dim); }

/* blinking cursor on the live trace tail */
.studio-trace__caret {
  display: inline-block;
  width: 7px;
  height: 1em;
  vertical-align: -2px;
  background: var(--st-accent);
  margin-left: 4px;
  animation: studioBlink 1.05s steps(2, start) infinite;
}
@keyframes studioBlink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ============================================================
   DISCORD PiP CORNER (lightweight placeholder)
   SA-8: swap .studio-pip__slot contents with a real SA-2
   Discord component (owner harness thread) when available.
   ============================================================ */
.studio-pip {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 210px;
  border-radius: 10px;
  background: #1e1f22;          /* discord dark, placeholder */
  border: 1px solid #2b2d31;
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  z-index: 4;
}
.studio-pip__bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  background: #232428;
  border-bottom: 1px solid #2b2d31;
  font-size: 0.62rem;
  color: #b5bac1;
  font-family: var(--st-font-mono);
  letter-spacing: 0.04em;
}
.studio-pip__bar::before {
  content: '#';
  color: #80848e;
  font-weight: 700;
}
.studio-pip__slot {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.studio-pip__msg { display: flex; gap: 7px; }
.studio-pip__dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, #5865f2, #4752c4);
}
.studio-pip__dot.is-bot {
  background: linear-gradient(135deg, var(--st-ochre), #8a5536);
}
.studio-pip__line { min-width: 0; }
.studio-pip__author {
  font-size: 0.66rem;
  font-weight: 600;
  color: #f2f3f5;
  font-family: var(--st-font-body);
}
.studio-pip__author .tag {
  font-size: 0.5rem;
  background: #5865f2;
  color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: 1px;
  letter-spacing: 0.02em;
}
.studio-pip__text {
  font-size: 0.66rem;
  color: #dbdee1;
  font-family: var(--st-font-body);
  line-height: 1.4;
}
.studio-pip__swap {
  font-family: var(--st-font-mono);
  font-size: 0.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #80848e;
  padding: 0 10px 9px;
}

/* ============================================================
   ENTRANCE MOTION — enhancement only.
   Panels fade/rise in once when JS adds .is-revealed; without
   JS they are already fully visible (rule below in reduced /
   no-anim states). cinematic-v2 owns scroll pinning; we only
   stagger the panel reveal.
   ============================================================ */
.studio.is-anim .studio-panel,
.studio.is-anim .studio-pip {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s var(--st-ease, cubic-bezier(0.16, 1, 0.3, 1)),
              transform 0.6s var(--st-ease, cubic-bezier(0.16, 1, 0.3, 1));
}
.studio.is-anim.is-revealed .studio-panel,
.studio.is-anim.is-revealed .studio-pip {
  opacity: 1;
  transform: translateY(0);
}
.studio.is-anim.is-revealed .studio-panel:nth-child(2) { transition-delay: 0.08s; }
.studio.is-anim.is-revealed .studio-panel:nth-child(3) { transition-delay: 0.16s; }
.studio.is-anim.is-revealed .studio-panel:nth-child(4) { transition-delay: 0.24s; }

/* ============================================================
   RESPONSIVE — stack rail above panels on narrow widths.
   ============================================================ */
@media (max-width: 760px) {
  .studio-win__body { grid-template-columns: 1fr; }
  .studio-rail {
    border-right: 0;
    border-bottom: 1px solid var(--st-border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px;
  }
  .studio-rail__head { width: 100%; padding: 0 6px 6px; }
  .studio-stage { flex: 0 0 auto; padding: 6px 9px; }
  .studio-stage__idx { display: none; }
  .studio-pip {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    margin-top: 4px;
  }
  .studio-trace__row { grid-template-columns: 56px 74px 1fr; }
}

/* ============================================================
   REDUCED MOTION — static, fully visible. No reveal arming,
   no caret blink, no transitions. Active stage still styled.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .studio.is-anim .studio-panel,
  .studio.is-anim .studio-pip {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .studio-trace__caret { animation: none; }
  .studio-stage,
  .studio-stage__dot { transition: none; }
}
