/* Desktop Stage: a stable, read-only companion pane beside the main canvas. */
@media (min-width: 1051px) {
  #app.app:has(#stage:not([hidden])) {
    display: grid !important;
    grid-template-columns: 232px minmax(0, 1fr) 8px minmax(300px, min(var(--flowlo-stage-width, 360px), 44vw)) !important;
    align-items: stretch;
  }

  #app.app:has(#stage:not([hidden])) > .shell-main {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
  }

  #stage.stage-preview:not([hidden]) {
    display: flex !important;
    grid-column: 4;
    grid-row: 1;
    width: auto;
    max-width: none;
    min-width: 0;
    min-height: 0;
    height: 100dvh;
    overflow: hidden;
    flex-direction: column;
    gap: 0;
    padding: 15px 16px 13px;
    border-left: 1px solid var(--line);
    background: var(--surface);
  }

  #stage.stage-preview[hidden] {
    display: none !important;
  }

  .stage-resizer:not([hidden]) {
    display: block;
    grid-column: 3;
    grid-row: 1;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    touch-action: none;
    outline: 0;
    position: relative;
    z-index: 2;
  }

  .stage-resizer::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 3px;
    width: 1px;
    background: var(--line);
    transition: background .15s, width .15s, left .15s;
  }

  .stage-resizer:hover::after,
  .stage-resizer:focus-visible::after {
    left: 2px;
    width: 3px;
    background: var(--accent);
  }

  body.stage-resizing,
  body.stage-resizing * {
    cursor: col-resize !important;
    user-select: none !important;
  }
}

.stage-preview .stage-head {
  flex: 0 0 auto;
  min-height: 51px;
  align-items: flex-start;
  padding: 2px 0 12px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.stage-preview .stage-head > div {
  min-width: 0;
}

.stage-preview .stage-head small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .1em;
}

.stage-preview .stage-head h3 {
  max-width: 100%;
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-preview .stage-head .icon {
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: -4px -5px 0 8px;
  border-radius: 8px;
  color: var(--muted);
}

.stage-preview .stage-head .icon:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.stage-preview .stage-note,
.stage-preview .stage-feed,
.stage-preview .stage-board {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 28%, transparent) transparent;
}

.stage-preview .stage-note {
  padding: 13px 8px 20px 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.stage-preview .stage-note h1,
.stage-preview .stage-note h2,
.stage-preview .stage-note h3,
.stage-preview .stage-note h4 {
  margin: 1em 0 .5em !important;
  font-size: 1.3em !important;
  line-height: 1.3 !important;
}

.stage-preview .stage-note p {
  margin: 0 0 .8em !important;
  font-size: 1em !important;
  line-height: 1.55 !important;
}

.stage-preview .stage-note img,
.stage-preview .stage-note video,
.stage-preview .stage-note table,
.stage-preview .stage-note iframe {
  max-width: 100% !important;
}

.stage-preview .stage-note iframe {
  pointer-events: none;
}

.stage-preview .stage-feed {
  display: block;
  padding: 7px 6px 16px 0;
}

.stage-preview .stage-flow-entry {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.stage-preview .stage-flow-entry:last-child {
  border-bottom: 0;
}

.stage-preview .stage-flow-entry > div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.stage-preview .stage-flow-entry header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stage-preview .stage-flow-entry header small {
  color: var(--muted);
  font-size: 10px;
}

.stage-preview .stage-flow-entry aside {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

.stage-preview .stage-flow-entry aside button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  color: var(--muted);
}

.stage-preview .stage-flow-entry aside button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.stage-preview .stage-flow-entry aside .material-symbols-rounded {
  font-size: 17px;
}

.stage-preview .stage-flow-entry > div > span {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.stage-preview .stage-feed > button {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  margin: 0;
  padding: 9px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}

.stage-preview .stage-feed > button:hover {
  color: var(--accent);
}

.stage-preview .stage-feed > button.done {
  color: var(--muted);
  text-decoration: line-through;
}

.stage-preview .stage-board {
  padding: 12px 6px 18px 0;
}

.stage-preview .stage-open {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 40px;
  margin-top: auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
}

.stage-preview .stage-open:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (max-width: 1050px) {
  #app.app:has(#stage:not([hidden])) {
    grid-template-columns: 232px minmax(0, 1fr) !important;
  }

  #stage.stage-preview,
  .stage-resizer {
    display: none !important;
  }

  .canvas-head-actions [data-stage],
  [data-stage-voice] {
    display: none !important;
  }
}

[data-theme="dark"] .stage-preview .stage-flow-entry aside button:hover,
[data-theme="dark"] .stage-preview .stage-feed > button:hover,
[data-theme="dark"] .stage-preview .stage-open:hover {
  background: var(--accent-soft);
}
