/* Side-panel viewer — two stacked right-hand panes.
   - viewer pane: slides in when a data-viewer link is clicked
   - session pane: slides in when a citation inside the preview is escalated
     via postMessage (see preview.js), so we can keep the research artifact
     and the conversation side by side.

   Sizing logic (wide screens only):
     viewer alone            → viewer 40vw, body margin-right 40vw
     viewer + session open   → viewer 30vw at right:32vw, session 32vw, body margin-right 62vw
   On narrow screens both panes overlay at 100vw; the session pane wins. */

:root {
  --viewer-w: 40vw;
  --viewer-w-compact: 30vw;
  --session-w: 32vw;
}

aside.viewer,
aside.session-pane {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  background: var(--bg, #fafaf7);
  border-left: 1px solid var(--line, #e6e4dc);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease-out, right 0.2s ease-out, width 0.2s ease-out;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
}

aside.viewer { width: var(--viewer-w); }
aside.session-pane { width: var(--session-w); z-index: 101; }

body.viewer-open aside.viewer { transform: translateX(0); }
body.session-open aside.session-pane { transform: translateX(0); }

/* When both panes are open, shrink the viewer and push it left by the
   session pane's width so the two sit shoulder-to-shoulder. */
@media (min-width: 1400px) {
  body.viewer-open.session-open aside.viewer {
    width: var(--viewer-w-compact);
    right: var(--session-w);
  }
}

/* On wide screens push the main cockpit content left so everything stays
   visible and independently scrollable. Below 1100px the panes overlay. */
body { transition: margin-right 0.2s ease-out; }
@media (min-width: 1100px) {
  body.viewer-open { margin-right: var(--viewer-w); }
}
@media (min-width: 1400px) {
  body.viewer-open.session-open {
    margin-right: calc(var(--viewer-w-compact) + var(--session-w));
  }
}

/* Narrow-screen overlay: the more-specific pane wins. */
@media (max-width: 1099px) {
  aside.viewer,
  aside.session-pane { width: 100vw; }
}

aside.viewer > header,
aside.session-pane > header {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line, #e6e4dc);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--muted, #6a6a66);
  background: var(--soft, #f3f1e8);
  flex-shrink: 0;
}
aside.session-pane > header {
  /* Subtle visual distinction so you know which pane is which at a glance. */
  background: #eef2ef;
}
aside.viewer > header .title,
aside.session-pane > header .title {
  flex: 1 1 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
aside.viewer > header .pop-out,
aside.viewer > header button.close,
aside.session-pane > header .pop-out,
aside.session-pane > header button.close {
  background: transparent;
  border: 1px solid var(--line, #e6e4dc);
  color: var(--muted, #6a6a66);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.3;
  text-decoration: none;
  font-family: inherit;
}
aside.viewer > header .pop-out:hover,
aside.viewer > header button.close:hover,
aside.session-pane > header .pop-out:hover,
aside.session-pane > header button.close:hover {
  color: var(--ink, #1d1d1b);
  border-color: var(--accent, #1f6f4a);
}
aside.viewer > header .pop-out:not([href]),
aside.session-pane > header .pop-out:not([href]) {
  opacity: 0.4;
  pointer-events: none;
}
aside.viewer > iframe,
aside.session-pane > iframe {
  flex: 1 1 0;
  border: 0;
  width: 100%;
  background: var(--bg, #fafaf7);
}

/* Citation / ref links styled to look like inline refs in cockpit cards. */
a.src-link,
a.prose-fileref {
  color: var(--accent, #1f6f4a);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
a.src-link:hover,
a.prose-fileref:hover {
  border-bottom-style: solid;
}

/* Drag-to-resize handle on the left edge of each pane. Straddles the border
   so the cursor-change zone is generous without widening the visible gap. */
aside.viewer > .resize-handle,
aside.session-pane > .resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  width: 6px;
  cursor: col-resize;
  background: transparent;
  z-index: 102;
  touch-action: none;
}
aside.viewer > .resize-handle:hover,
aside.session-pane > .resize-handle:hover {
  background: var(--accent, #1f6f4a);
  opacity: 0.5;
}
body.resizing {
  cursor: col-resize;
  user-select: none;
}
/* Kill transitions during drag so the pane follows the pointer instantly. */
body.resizing,
body.resizing aside.viewer,
body.resizing aside.session-pane {
  transition: none;
}
body.resizing aside.viewer > .resize-handle,
body.resizing aside.session-pane > .resize-handle {
  background: var(--accent, #1f6f4a);
  opacity: 0.7;
}
/* Iframes would otherwise capture pointermove once the cursor crossed into
   them; pointer capture on the handle covers most browsers, this is belt-
   and-suspenders. */
body.resizing aside.viewer > iframe,
body.resizing aside.session-pane > iframe {
  pointer-events: none;
}
/* Below 1100px both panes overlay at 100vw; resizing stops making sense. */
@media (max-width: 1099px) {
  aside.viewer > .resize-handle,
  aside.session-pane > .resize-handle { display: none; }
}
