:root {
  --bp-z: 20000;
  --bp-window-bg: rgba(255, 255, 255, 0.98);
  --bp-window-border: rgba(17, 24, 39, 0.10);
  --bp-toolbar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 249, 252, 0.96));
  --bp-text: #18212f;
  --bp-subtle: #607086;
  --bp-shadow:
    0 20px 60px rgba(15, 23, 42, 0.16),
    0 8px 24px rgba(15, 23, 42, 0.10),
    0 2px 8px rgba(15, 23, 42, 0.06);
  --bp-shadow-drag:
    0 28px 80px rgba(15, 23, 42, 0.22),
    0 12px 32px rgba(15, 23, 42, 0.14);
  --bp-radius: 18px;
  --bp-toolbar-h: 54px;
}

/* full-screen container, but NON-blocking */
.board-popout-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--bp-z);

  /* no dark screen, no blur */
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;

  /* crucial: allow clicking through the whole screen */
  pointer-events: none;
}

/* floating window only */
.board-popout-window {
  position: fixed;
  top: 72px;
  right: 28px;
  width: min(1100px, calc(100vw - 56px));
  height: min(76vh, 820px);
  min-width: 420px;
  min-height: 320px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);

  display: flex;
  flex-direction: column;
  overflow: hidden;

  background: var(--bp-window-bg);
  color: var(--bp-text);
  border: 1px solid var(--bp-window-border);
  border-radius: var(--bp-radius);
  box-shadow: var(--bp-shadow);

  will-change: transform, width, height, left, top;
  transform: translateZ(0);
  backface-visibility: hidden;
  contain: layout paint style;
  isolation: isolate;

  transition:
    box-shadow 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;

  /* crucial: window itself remains interactive */
  pointer-events: auto;
}

.board-popout-toolbar {
  height: var(--bp-toolbar-h);
  min-height: var(--bp-toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px 0 16px;

  background: var(--bp-toolbar-bg);
  border-bottom: 1px solid rgba(17, 24, 39, 0.08);

  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  position: relative;
  z-index: 3;
}

.board-popout-toolbar:active {
  cursor: grabbing;
}

.board-popout-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--bp-text);
}

.board-popout-close {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--bp-subtle);
  cursor: pointer;
  transition:
    background-color 140ms ease,
    color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.board-popout-close:hover {
  background: rgba(220, 38, 38, 0.10);
  color: #b91c1c;
}

.board-popout-close:active {
  transform: scale(0.96);
}

.board-popout-close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
  background: rgba(59, 130, 246, 0.08);
}

.board-popout-close span,
.board-popout-close::before,
.board-popout-close::after {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  content: "";
  transform-origin: center;
}

.board-popout-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.board-popout-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.board-popout-close span {
  display: none;
}

.board-popout-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}

.board-popout-iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.board-popout-iframe-shield {
  position: absolute;
  inset: var(--bp-toolbar-h) 0 0 0;
  z-index: 4;
  pointer-events: none;
  background: transparent;
}

.board-popout-window.is-dragging .board-popout-iframe-shield,
.board-popout-window.is-resizing .board-popout-iframe-shield,
.board-popout-dragging .board-popout-iframe-shield {
  pointer-events: auto;
}

.board-popout-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 34px;
  height: 34px;
  z-index: 5;
  cursor: nwse-resize;
  touch-action: none;
  border-bottom-right-radius: var(--bp-radius);
  background: transparent;
}

.board-popout-resize::before {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 14px;
  height: 14px;
  opacity: 0.6;
  background:
    linear-gradient(135deg, transparent 0 46%, rgba(96, 112, 134, 0.42) 46% 52%, transparent 52% 100%),
    linear-gradient(135deg, transparent 0 62%, rgba(96, 112, 134, 0.55) 62% 68%, transparent 68% 100%),
    linear-gradient(135deg, transparent 0 78%, rgba(96, 112, 134, 0.70) 78% 84%, transparent 84% 100%);
  border-radius: 2px;
  transition: opacity 140ms ease, transform 140ms ease;
}

.board-popout-resize:hover::before {
  opacity: 0.95;
  transform: scale(1.04);
}

.board-popout-window.is-dragging,
.board-popout-window.is-resizing {
  box-shadow: var(--bp-shadow-drag);
  transition: none;
  border-color: rgba(37, 99, 235, 0.16);
}

.board-popout-window.is-dragging .board-popout-toolbar {
  cursor: grabbing;
}

.board-popout-window.is-dragging::after,
.board-popout-window.is-resizing::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.10);
}

@media (max-width: 900px) {
  .board-popout-window {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    height: calc(100vh - 24px);
    max-width: none;
    max-height: none;
    min-width: 0;
    border-radius: 16px;
  }
}

@media (max-width: 560px) {
  .board-popout-window {
    top: 8px;
    right: 8px;
    left: 8px;
    bottom: 8px;
    height: auto;
    min-height: 0;
    border-radius: 14px;
  }

  .board-popout-toolbar {
    height: 50px;
    min-height: 50px;
  }

  .board-popout-iframe-shield {
    inset: 50px 0 0 0;
  }
}