/* ═══════════════════════════════════════════════════════════════
   SPLIT VIEW COMPONENT - Draggable Divider Layout
   ═══════════════════════════════════════════════════════════════
   
   Architecture:
     .split-container           flex parent (direction set by modifier class)
       .split-pane              flex child, ratio via inline style.flex
         (user content)         nest your own scrollable wrapper inside
       .split-divider           drag bar between panes
       .split-pane              second pane

   IMPORTANT — sizing contract:
     • .split-container does NOT set width/height/flex-direction on the base
       class. The element's existing layout (e.g. Tailwind flex-1 flex-col)
       controls sizing. Only the direction modifier (.split-horizontal /
       .split-vertical) overrides flex-direction.
     • overflow:hidden on .split-pane is deliberate — never put overflow-y:auto
       directly on a pane; nest a scrollable child inside instead.
   ═══════════════════════════════════════════════════════════════ */

/* ── Container ────────────────────────────────────────────────── */
.split-container {
  display: flex;
  gap: 0;
  overflow: hidden;
  background: inherit;
  /* NO width / height / flex-direction here — see header comment */
}

.split-container.split-horizontal {
  flex-direction: row;
}

.split-container.split-vertical {
  flex-direction: column;
}

/* ── Pane ─────────────────────────────────────────────────────── */
.split-pane {
  /* flex shorthand overridden at runtime by SplitView.setRatio() */
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;   /* intentional — see header comment */
  position: relative;
  background: inherit;
}

.split-pane.is-collapsed {
  flex: 0 !important;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.split-pane.is-collapsed > * {
  display: none;
}

/* ── Pane content wrapper (created by wrapContent:true) ───────── */
.split-pane-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;  /* CRITICAL: Allow flex shrinking below content size */
  min-width: 0;   /* Also for horizontal layout */
  -webkit-overflow-scrolling: touch;
}

.split-pane-content.scrollable {
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateZ(0);   /* GPU-accelerated scroll */
}

/* ── Draggable Divider ────────────────────────────────────────── */
.split-divider {
  position: relative;
  background: transparent;
  user-select: none;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: none;
  z-index: 10;
  transition: background-color 0.15s ease;
}

/* Horizontal (side-by-side panes) */
.split-container.split-horizontal > .split-divider {
  cursor: col-resize;
  width: 6px;
  height: auto;
}

/* Vertical (top-bottom panes) */
.split-container.split-vertical > .split-divider {
  cursor: row-resize;
  width: auto;
  height: 6px;
}

/* Divider visual indicator */
.split-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 1px;
  opacity: 0.5;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.split-container.split-horizontal > .split-divider::before {
  width: 2px;
  height: 24px;
  background: #cbd5e1;
}

.split-container.split-vertical > .split-divider::before {
  width: 24px;
  height: 2px;
  background: #cbd5e1;
}

/* Hover */
.split-divider:hover {
  background-color: rgba(59, 130, 246, 0.06);
}
.split-divider:hover::before {
  opacity: 1;
  background: #3b82f6;
}

/* Dragging */
.split-divider.is-dragging {
  background-color: rgba(59, 130, 246, 0.10);
}
.split-divider.is-dragging::before {
  background: #2563eb;
  opacity: 1;
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.35);
  transition: none;
}

/* ── Drag Overlay — blocks iframes from stealing mouse events ── */
.split-drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: transparent;
  /* cursor is set by JS based on split direction */
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .split-container.split-horizontal {
    flex-direction: column !important;
  }

  .split-container.split-horizontal > .split-divider {
    width: auto;
    height: 6px;
    cursor: row-resize;
  }

  .split-container.split-horizontal > .split-divider::before {
    width: 24px;
    height: 2px;
  }
}

/* ── Collapse Button (Optional) ───────────────────────────────── */
.split-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(0, 0, 0, 0.02);
  gap: 0.5rem;
}

.dark .split-pane-header {
  border-bottom-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
}

.split-pane-title {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  margin: 0;
}

.split-pane-collapse-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  background: transparent;
  color: #64748b;
  transition: all 0.2s ease;
  padding: 0;
}

.dark .split-pane-collapse-btn {
  color: #94a3b8;
}

.split-pane-collapse-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.split-pane-collapse-btn svg {
  width: 18px;
  height: 18px;
}

/* ── Accessibility ────────────────────────────────────────────── */
.split-divider:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

.split-divider:focus-visible::after {
  content: attr(data-help);
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
}
