/*
 * agent-fluid-ambient.css — AmbientStream right rail
 *
 * 300px right-side panel mounted INSIDE #agentLayout, hidden below 1600px
 * and while it has no active content.
 * Three vertically-stacked sections:
 *   1. AlarmBanner — pending approvals (sticky top, brand-pink accent)
 *   2. WorkingNowFeed — live agent status balloons (FIFO max-3 + overflow pill)
 *   3. RecentlyLearnedCards — memory receipts (0..3)
 *
 * Reuses existing Netscape design tokens from styles.css / agent-fluid.css.
 * Color tokens used here, NO new colors introduced:
 *   --canvas, --surface, --surface-hover, --card, --hairline, --hairline-strong
 *   --fg, --fg-strong, --fg-muted, --fg-faint
 *   --brand (#ff1bbd ≈ brand pink), --brand-soft (rgba pink)
 *   --state-thinking-* (amber), --state-done-* (green), --state-review-* (oxblood),
 *   --state-block-* (oxblood-deep)
 *
 * Mount: agent-fluid-ambient.js inserts
 *   <aside id="agentAmbient" class="agent-fluid-ambient"> into #agentLayout.
 *
 * Constraints (from the build brief):
 *   - DO NOT touch the Netscape chrome
 *   - DO NOT introduce new color tokens
 *   - 300px wide, hidden <1600px or when empty
 *   - Inside #agentLab only — never escape the agent panel
 */

/* ============================================================================
   Layout host — the rail is a real grid column in #agentLayout. The JS keeps
   it hidden until there is pending approval, active work, or memory context.
   Below 1600px the main chat gets the width back; ambient events still render
   in the main transcript where appropriate.
   ============================================================================ */

#agentLab .agent-fluid-ambient {
  position: relative;
  width: 300px;
  min-width: 280px;
  height: auto;
  min-height: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
  border-left: 1px solid var(--hairline);
  font-family: var(--font-ui);
  color: var(--fg);
  overflow: hidden;
  box-shadow: inset 1px 0 0 var(--hairline);
}

#agentLab .agent-fluid-ambient[hidden] {
  display: none !important;
}

/* Below 1600px the rail is hidden so chat and drafts keep usable width. */
@media (max-width: 1599px) {
  #agentLab .agent-fluid-ambient {
    display: none !important;
  }
}

/* ============================================================================
   Section heading reused by all 3 stacked sections.
   ============================================================================ */

#agentLab .agent-fluid-ambient__section {
  display: flex;
  flex-direction: column;
  padding: 12px 14px 14px;
  border-bottom: 1px solid var(--hairline);
  min-height: 0;
}

#agentLab .agent-fluid-ambient__section:last-child {
  border-bottom: none;
}

#agentLab .agent-fluid-ambient__heading {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#agentLab .agent-fluid-ambient__heading-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  font-size: 9px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  color: var(--fg-muted);
}

/* ============================================================================
   1. AlarmBanner — pending approvals
   ============================================================================ */

#agentLab .agent-fluid-ambient__alarms {
  position: sticky;
  top: 0;
  background: var(--canvas);
  z-index: 1;
  min-height: 120px;
  max-height: 180px;
  flex-shrink: 0;
}

#agentLab .agent-fluid-ambient__alarms[data-state="empty"] .agent-fluid-ambient__alarm-empty {
  display: flex;
}

#agentLab .agent-fluid-ambient__alarms[data-state="active"] {
  background: linear-gradient(180deg, var(--brand-soft), transparent 75%);
  border-bottom-color: var(--hairline-strong);
}

#agentLab .agent-fluid-ambient__alarm-empty {
  display: none;
  align-items: center;
  font-size: 12px;
  color: var(--fg-muted);
  padding: 8px 0;
  letter-spacing: 0.01em;
}

#agentLab .agent-fluid-ambient__alarm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

#agentLab .agent-fluid-ambient__alarm {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--card);
  font-size: 12px;
  color: var(--fg-strong);
}

#agentLab .agent-fluid-ambient__alarm-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

#agentLab .agent-fluid-ambient__alarm-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#agentLab .agent-fluid-ambient__alarm-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--fg-strong);
  letter-spacing: 0.01em;
}

#agentLab .agent-fluid-ambient__alarm-summary {
  font-size: 11px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#agentLab .agent-fluid-ambient__alarm-approve {
  flex-shrink: 0;
  appearance: none;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-standard),
              border-color var(--motion-fast) var(--ease-standard);
}

#agentLab .agent-fluid-ambient__alarm-approve:hover {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
}

/* ============================================================================
   2. WorkingNowFeed — live agent status balloons
   ============================================================================ */

#agentLab .agent-fluid-ambient__working {
  min-height: 140px;
  max-height: 160px;
  flex-shrink: 0;
}

#agentLab .agent-fluid-ambient__working-empty {
  font-size: 12px;
  color: var(--fg-muted);
  padding: 4px 0;
}

#agentLab .agent-fluid-ambient__balloons {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#agentLab .agent-fluid-ambient__balloon {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--card);
  font-size: 11px;
  transition: opacity 200ms var(--ease-standard);
}

#agentLab .agent-fluid-ambient__balloon[data-fading="true"] {
  opacity: 0;
}

#agentLab .agent-fluid-ambient__balloon-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--fg-muted);
  /* Pulse animation reused across colors via currentColor swap. */
  animation: agent-fluid-ambient-pulse 1.6s var(--ease-standard) infinite;
}

#agentLab .agent-fluid-ambient__balloon-name {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  white-space: nowrap;
}

#agentLab .agent-fluid-ambient__balloon-task {
  font-size: 11px;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

/* State color coding — reuses --state-* tokens, no new colors. */
#agentLab .agent-fluid-ambient__balloon[data-state="thinking"] .agent-fluid-ambient__balloon-dot {
  background: var(--state-thinking-dot);
  box-shadow: 0 0 0 2px var(--state-thinking-bg);
}
#agentLab .agent-fluid-ambient__balloon[data-state="executing"] .agent-fluid-ambient__balloon-dot {
  background: var(--state-review-dot);
  box-shadow: 0 0 0 2px var(--state-review-bg);
}
#agentLab .agent-fluid-ambient__balloon[data-state="waiting_approval"] .agent-fluid-ambient__balloon-dot {
  background: var(--state-thinking-dot);
  box-shadow: 0 0 0 2px var(--brand-soft);
}
#agentLab .agent-fluid-ambient__balloon[data-state="blocked"] .agent-fluid-ambient__balloon-dot {
  background: var(--state-block-dot);
  box-shadow: 0 0 0 2px var(--state-block-bg);
  animation: none;
}
#agentLab .agent-fluid-ambient__balloon[data-state="completed"] .agent-fluid-ambient__balloon-dot {
  background: var(--state-done-dot);
  box-shadow: 0 0 0 2px var(--state-done-bg);
  animation: none;
}
#agentLab .agent-fluid-ambient__balloon[data-state="idle"] .agent-fluid-ambient__balloon-dot {
  background: var(--fg-faint);
  animation: none;
}

#agentLab .agent-fluid-ambient__balloon-overflow {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 8px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
}

/* Pulse animation — gentle scale. Disabled for completed / blocked / idle. */
@keyframes agent-fluid-ambient-pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.3); opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
  #agentLab .agent-fluid-ambient__balloon-dot { animation: none !important; }
}

/* ============================================================================
   3. RecentlyLearnedCards — memory receipts
   ============================================================================ */

#agentLab .agent-fluid-ambient__memory {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#agentLab .agent-fluid-ambient__memory-empty {
  font-size: 12px;
  color: var(--fg-muted);
  padding: 4px 0;
}

#agentLab .agent-fluid-ambient__memory-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#agentLab .agent-fluid-ambient__memory-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 8px;
}

#agentLab .agent-fluid-ambient__memory-label {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
}

#agentLab .agent-fluid-ambient__memory-body {
  font-size: 12px;
  color: var(--fg-strong);
  line-height: 1.4;
}

#agentLab .agent-fluid-ambient__memory-edit {
  align-self: flex-start;
  font-size: 11px;
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: border-color var(--motion-fast) var(--ease-standard);
}

#agentLab .agent-fluid-ambient__memory-edit:hover {
  border-bottom-color: var(--brand);
}
