/*
 * Bodylet AI: window chrome and the remote screen frame
 *
 *   <section class="bl-window">
 *     <header class="bl-window__bar">
 *       <span class="bl-window__dots" aria-hidden="true"><i></i><i></i><i></i></span>
 *       <span class="bl-window__title">DEV-WIN-01</span>
 *       <span class="bl-window__meta"> … pills … </span>
 *       <span class="bl-window__actions"> … buttons … </span>
 *     </header>
 *     <div class="bl-window__body"> … </div>
 *   </section>
 *
 * A window with a side panel puts both in .bl-window__split:
 *   <div class="bl-window__split"> <div class="bl-window__main">…</div> <aside class="bl-window__side">…</aside> </div>
 *
 * A window takes the scheme of the page. Its frame and bar are
 * --bl-window-bg, a step off the body of a terminal or code block inside it
 * (--bl-code-bg): near-black under a darker body on dark, a faint tint
 * around a white body on light. A remote screen (.bl-screen) keeps the dark
 * scheme in both.
 */

.bl-window {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--bl-border-strong);
  border-radius: var(--bl-radius-lg);
  background: var(--bl-window-bg);
  box-shadow: var(--bl-highlight), var(--bl-shadow-2);
}

.bl-window--float {
  box-shadow: var(--bl-highlight), var(--bl-shadow-3);
}

.bl-window__bar {
  display: flex;
  flex: none;
  flex-wrap: wrap;            /* in a narrow window the actions take a second row */
  align-items: center;
  gap: var(--bl-space-2) var(--bl-space-3);
  min-height: 3.25rem;
  padding: var(--bl-space-2) var(--bl-space-3) var(--bl-space-2) var(--bl-space-4);
  border-bottom: 1px solid var(--bl-border);
}

.bl-window__dots {
  display: inline-flex;
  flex: none;
  gap: var(--bl-space-2);
  margin-right: var(--bl-space-1);
}

.bl-window__dots i {
  width: 0.6875rem;
  height: 0.6875rem;
  border-radius: 50%;
  background: var(--bl-chrome-close);
}

.bl-window__dots i:nth-child(2) {
  background: var(--bl-chrome-minimize);
}

.bl-window__dots i:nth-child(3) {
  background: var(--bl-chrome-zoom);
}

.bl-window__title {
  display: inline-flex;
  align-items: center;
  gap: var(--bl-space-2);
  min-width: 0;
  overflow: hidden;
  color: var(--bl-text);
  font-size: var(--bl-text-md);
  font-weight: var(--bl-weight-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bl-window__title .bl-icon {
  width: 1rem;
  height: 1rem;
  color: var(--bl-text-2);
}

.bl-window__title--muted {
  color: var(--bl-text-2);
  font-weight: var(--bl-weight-regular);
}

.bl-window__meta {
  display: inline-flex;
  align-items: center;
  gap: var(--bl-space-2);
  min-width: 0;
}

.bl-window__actions {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--bl-space-2);
  margin-left: auto;
}

.bl-window__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.bl-window__body > .bl-term,
.bl-window__body > .bl-code {
  flex: 1;
}

.bl-window__body--pad {
  padding: var(--bl-space-4);
}

.bl-window__split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  flex: 1;
  min-height: 0;
}

.bl-window__main {
  min-width: 0;
  padding: var(--bl-space-2);
}

.bl-window__side {
  display: flex;
  flex-direction: column;
  gap: var(--bl-space-4);
  min-width: 0;
  padding: var(--bl-space-4);
}

.bl-window__side > .bl-btn:last-child {
  margin-top: auto;
}

@media (max-width: 860px) {
  .bl-window__split {
    grid-template-columns: minmax(0, 1fr);
  }

  .bl-window__side {
    padding-top: var(--bl-space-2);
  }
}

/* ── Remote screen ──────────────────────────────────────────────────────── */
/*
 *   <figure class="bl-screen bl-screen--agent">
 *     <img class="bl-screen__frame" src="/sessions/…/frame.png" alt="Desktop of DEV-WIN-01" width="1280" height="720">
 *     <span class="bl-screen__tag">Agent in control</span>
 *   </figure>
 *
 * The colored edge says who holds the input lock: --agent (lime) or --human (blue).
 * --paused dims the frame (emergency stop, disconnected).
 */

.bl-screen {
  --_edge: transparent;
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--bl-radius-md);
  background: var(--bl-black);
  box-shadow: inset 0 0 0 1px var(--_edge);
  isolation: isolate;
  /* Lets overlays be placed in cqw: 100cqw wide, 56.25cqw tall. */
  container-type: inline-size;
}

.bl-screen--agent {
  --_edge: var(--bl-accent-line-strong);
}

.bl-screen--human {
  --_edge: var(--bl-human);
}

.bl-screen__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bl-screen--paused .bl-screen__frame {
  filter: grayscale(1) brightness(0.45);
}

.bl-screen__tag {
  position: absolute;
  top: var(--bl-space-3);
  left: var(--bl-space-3);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 1.5rem;
  padding: 0 0.625rem;
  border-radius: var(--bl-radius-pill);
  background: rgba(7, 10, 8, 0.78);
  box-shadow: 0 0 0 1px var(--_edge);
  color: var(--bl-text);
  font-size: var(--bl-text-xs);
  font-weight: var(--bl-weight-semibold);
  line-height: 1;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.bl-screen__tag::before {
  content: "";
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--bl-text-3);
}

.bl-screen--agent .bl-screen__tag::before {
  background: var(--bl-agent);
}

.bl-screen--human .bl-screen__tag::before {
  background: var(--bl-human);
}

/* A pointer with a name tag: where the agent (or the human) is acting. */
.bl-screen__cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  color: var(--bl-agent);
  pointer-events: none;
  will-change: transform;
}

.bl-screen__cursor svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: currentColor;
  stroke: var(--bl-black);
  stroke-width: 1.2;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.bl-screen__cursor span {
  margin: 0.875rem 0 0 -0.125rem;
  padding: 0.1875rem 0.4375rem;
  border-radius: 0.25rem 0.625rem 0.625rem 0.625rem;
  background: currentColor;
  font-family: var(--bl-font-mono);
  font-size: var(--bl-text-2xs);
  font-weight: var(--bl-weight-medium);
  line-height: 1.2;
  white-space: nowrap;
}

.bl-screen__cursor span b {
  color: var(--bl-text-on-accent);
  font-weight: inherit;
}

.bl-screen__cursor--human {
  color: var(--bl-human);
}
