/* urun built-in component styles — override via --urun-* custom properties */

:root {
  --urun-bg: #ffffff;
  --urun-text: #1a1a2e;
  --urun-border: #e2e8f0;
  --urun-radius: 8px;
  --urun-font: system-ui, -apple-system, sans-serif;

  /* Progress */
  --urun-progress-bg: #e2e8f0;
  --urun-progress-fill: #3b82f6;
  --urun-progress-success: #22c55e;
  --urun-progress-error: #ef4444;
  --urun-progress-height: 8px;

  /* Status */
  --urun-status-thinking: #f59e0b;
  --urun-status-generating: #3b82f6;
  --urun-status-idle: #94a3b8;
  --urun-status-error: #ef4444;
  --urun-status-indicator-size: 8px;

  /* Text stream */
  --urun-cursor-color: #3b82f6;
  --urun-cursor-width: 2px;

  /* Metrics */
  --urun-metric-bg: #f8fafc;
  --urun-metric-label-color: #64748b;
  --urun-metric-value-color: #1a1a2e;
}

/* ProgressCard */
.urun-progress-card {
  font-family: var(--urun-font);
  color: var(--urun-text);
  border: 1px solid var(--urun-border);
  border-radius: var(--urun-radius);
  padding: 12px 16px;
  background: var(--urun-bg);
}

.urun-progress-label {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.urun-progress-bar {
  height: var(--urun-progress-height);
  background: var(--urun-progress-bg);
  border-radius: calc(var(--urun-progress-height) / 2);
  overflow: hidden;
}

.urun-progress-fill {
  height: 100%;
  background: var(--urun-progress-fill);
  border-radius: inherit;
  transition: width 0.3s ease;
}

.urun-progress-card[data-variant='success'] .urun-progress-fill {
  background: var(--urun-progress-success);
}

.urun-progress-card[data-variant='error'] .urun-progress-fill {
  background: var(--urun-progress-error);
}

.urun-progress-text {
  font-size: 0.75rem;
  color: var(--urun-metric-label-color);
  margin-top: 4px;
  text-align: right;
}

/* StatusBadge */
.urun-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--urun-font);
  font-size: 0.875rem;
  color: var(--urun-text);
}

.urun-status-indicator {
  display: inline-block;
  width: var(--urun-status-indicator-size);
  height: var(--urun-status-indicator-size);
  border-radius: 50%;
  background: var(--urun-status-idle);
  flex-shrink: 0;
}

.urun-status-badge[data-state='thinking'] .urun-status-indicator {
  background: var(--urun-status-thinking);
}

.urun-status-badge[data-state='generating'] .urun-status-indicator {
  background: var(--urun-status-generating);
}

.urun-status-badge[data-state='error'] .urun-status-indicator {
  background: var(--urun-status-error);
}

.urun-status-pulse {
  animation: urun-pulse 1.5s ease-in-out infinite;
}

/* TextStream */
.urun-text-stream {
  font-family: var(--urun-font);
  color: var(--urun-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.urun-text-cursor {
  display: inline-block;
  width: var(--urun-cursor-width);
  height: 1em;
  background: var(--urun-cursor-color);
  vertical-align: text-bottom;
  animation: urun-blink 1s step-end infinite;
}

/* ImageFrame */
.urun-image-frame {
  margin: 0;
  border: 1px solid var(--urun-border);
  border-radius: var(--urun-radius);
  overflow: hidden;
  background: var(--urun-bg);
}

.urun-image {
  display: block;
  width: 100%;
  height: auto;
}

.urun-image-caption {
  padding: 8px 12px;
  font-family: var(--urun-font);
  font-size: 0.875rem;
  color: var(--urun-metric-label-color);
  text-align: center;
}

/* MetricsPanel */
.urun-metrics-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  font-family: var(--urun-font);
}

.urun-metric-card {
  background: var(--urun-metric-bg);
  border: 1px solid var(--urun-border);
  border-radius: var(--urun-radius);
  padding: 12px;
  text-align: center;
}

.urun-metric-label {
  font-size: 0.75rem;
  color: var(--urun-metric-label-color);
  margin-bottom: 4px;
}

.urun-metric-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--urun-metric-value-color);
}

/* ComponentRenderer error fallback */
.urun-component-error {
  font-family: var(--urun-font);
  padding: 8px 12px;
  border: 1px solid var(--urun-status-error);
  border-radius: var(--urun-radius);
  background: #fef2f2;
  color: var(--urun-status-error);
  font-size: 0.875rem;
}

/* Animations */
@keyframes urun-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@keyframes urun-blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* UrunVideo — default sizing.
 *
 * video.js wraps the <video> in a `.video-js` div which becomes the rendered
 * box; the component's own props/classes land on the inner <video>, NOT that
 * wrapper. Without explicit sizing the `.video-js` wrapper collapses to a
 * default/zero size inside a flex/relative container, so nothing is visible
 * even though the decoder is fine (this was the prod "black video" bug).
 *
 * Make the whole stack fill its parent so a consumer only has to size the OUTER
 * container (as helios does with an aspect-ratio box) — no per-consumer
 * `videoClassName` required. `data-urun-video` is the component's own wrapper. */
[data-urun-video] {
  width: 100%;
  height: 100%;
}

[data-urun-video] .video-js,
[data-urun-video] .vjs-tech {
  width: 100%;
  height: 100%;
}

/* Letterbox rather than crop/stretch by default; consumers can override the
 * <video> via `videoClassName` (e.g. object-fit: cover). */
[data-urun-video] .vjs-tech {
  object-fit: contain;
}

/* UrunVideo — live mode: keep the video.js poster / loading spinner / big-play
 * layer from staying composited OVER the <video>. On iOS Safari/Chrome that
 * layer stays opaque (black) when srcObject is attached and video.js never
 * sees a "source". Once a live player has started, force these layers gone. */
.urun-video-live.vjs-has-started .vjs-poster,
.urun-video-live.vjs-has-started .vjs-loading-spinner,
.urun-video-live.vjs-has-started .vjs-big-play-button {
  display: none !important;
}

/* Belt-and-braces: live streams never need the spinner/poster covering frames. */
.urun-video-live .vjs-poster {
  background-color: transparent;
}

/* ── Session workbench building blocks ─────────────────────────────────────
 * Unstyled-by-default debug/steer blocks: minimal chrome via CSS custom
 * properties so a consumer can theme with --urun-wb-* or override .urun-*. */
.urun-stream-tail,
.urun-doc-panel,
.urun-control-sender,
.urun-event-spine {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.urun-stream-tail-meta,
.urun-doc-panel-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--urun-wb-muted, #8a8a8a);
}

.urun-stream-tail-log,
.urun-control-sender-log {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
  border-radius: 6px;
  background: var(--urun-wb-log-bg, rgba(0, 0, 0, 0.25));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.urun-stream-tail-time,
.urun-control-sender-time,
.urun-event-spine-time {
  color: var(--urun-wb-muted, #8a8a8a);
}

.urun-doc-panel-snapshot {
  margin: 0;
  padding: 8px;
  max-height: 220px;
  overflow: auto;
  border-radius: 6px;
  background: var(--urun-wb-log-bg, rgba(0, 0, 0, 0.25));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.urun-doc-patch,
.urun-control-sender {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.urun-doc-patch-input {
  width: 100%;
  resize: vertical;
  border-radius: 6px;
  border: 1px solid var(--urun-wb-border, rgba(128, 128, 128, 0.4));
  background: var(--urun-wb-input-bg, transparent);
  color: inherit;
  padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.urun-doc-patch-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.urun-doc-patch-button,
.urun-mic-button {
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--urun-wb-border, rgba(128, 128, 128, 0.4));
  background: var(--urun-wb-accent, #24db49);
  color: var(--urun-wb-accent-fg, #04120a);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}

.urun-doc-patch-button:disabled {
  cursor: default;
  opacity: 0.5;
}

.urun-doc-patch-error,
.urun-mic-error {
  color: var(--urun-wb-danger, #e5484d);
}

.urun-event-spine {
  max-height: 260px;
  overflow: auto;
}

.urun-event-spine-line,
.urun-control-sender-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.urun-event-spine-kind,
.urun-control-sender-dir {
  display: inline-block;
  min-width: 3.5em;
  color: var(--urun-wb-muted, #8a8a8a);
}

/* Session status pill + gate */
.urun-session-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.urun-session-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--urun-wb-muted, #8a8a8a);
}

.urun-session-status-dot[data-phase='live'] {
  background: var(--urun-wb-accent, #24db49);
}
.urun-session-status-dot[data-phase='connecting'],
.urun-session-status-dot[data-phase='provisioning'],
.urun-session-status-dot[data-phase='queued'] {
  background: var(--urun-wb-warn, #ffb224);
}
.urun-session-status-dot[data-phase='error'] {
  background: var(--urun-wb-danger, #e5484d);
}
.urun-session-status-dot[data-phase='expired'] {
  background: var(--urun-wb-warn, #ffb224);
}

.urun-session-status-detail {
  color: var(--urun-wb-muted, #8a8a8a);
}

/* Session length: countdown clock (UrunSessionClock) + terminal surface
 * (UrunSessionEnded). The clock renders nothing without a deadline; state
 * rides data- attributes (data-urgent below the urgent threshold,
 * data-expired at zero) so apps restyle it with plain CSS. */
.urun-session-clock {
  display: inline-flex;
  align-items: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--urun-wb-muted, #8a8a8a);
}
.urun-session-clock[data-urgent] {
  color: var(--urun-wb-danger, #e5484d);
}

.urun-session-ended {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.urun-session-ended-new {
  appearance: none;
  border: 1px solid var(--urun-wb-border, rgba(128, 128, 128, 0.4));
  border-radius: 6px;
  background: var(--urun-wb-accent, #24db49);
  color: #000;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}
.urun-session-ended-new:hover {
  filter: brightness(1.1);
}

/* Scale-to-zero "waking (Ns)" building block (UrunSessionWaking) */
.urun-session-waking {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.urun-session-waking-elapsed {
  color: var(--urun-wb-muted, #8a8a8a);
  font-variant-numeric: tabular-nums;
}

/* ── UrunIdleWarning (attached-but-inert idle primitive) ─────────────────── */
.urun-idle-warning {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
}
.urun-idle-warning-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  padding: 1.5rem 2rem;
  border-radius: 12px;
  background: #111;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  max-width: 90vw;
  text-align: center;
}
.urun-idle-warning-title {
  font-size: 1.1rem;
  font-weight: 600;
}
.urun-idle-warning-copy {
  font-size: 0.9rem;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}
.urun-idle-warning[data-urgent] .urun-idle-warning-copy {
  color: #ff6b6b;
  opacity: 1;
}
.urun-idle-warning-confirm {
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  border: none;
  background: #24db49;
  color: #000;
  font-weight: 600;
  cursor: pointer;
}
.urun-idle-warning-confirm:hover {
  filter: brightness(1.1);
}

/* ── UrunActivationOverlay (>1min first-media activation tolerance) ──────── */
/* Rendered OVER the video surface (or the gate's live window) while a live
   session is still activating a stream — honest staged copy + live elapsed
   counter instead of black video. Cleared by first-media / the element's own
   first decoded frame. Status-only: never intercepts pointer events. */
.urun-session-gate {
  position: relative; /* positioning context for the activation overlay */
}
.urun-activation-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 10;
}
.urun-activation-overlay-card {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  background: #111;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  max-width: 90%;
  text-align: center;
  font-size: 0.9rem;
}
.urun-activation-overlay-elapsed {
  color: var(--urun-wb-muted, #8a8a8a);
  font-variant-numeric: tabular-nums;
}
/* Cold boot is a long honest wait — mark it with the brand accent. */
.urun-activation-overlay[data-state='cold-boot'] .urun-activation-overlay-card {
  border-color: var(--urun-wb-accent, #24db49);
}
/* Degraded = visible warning tone (same urgent color as UrunIdleWarning). */
.urun-activation-overlay[data-state='degraded'] .urun-activation-overlay-copy {
  color: #ff6b6b;
}
.urun-activation-overlay[data-state='degraded'] .urun-activation-overlay-card {
  border-color: #ff6b6b;
}
