/**
 * Floating Panel System
 * =====================
 * Styles for draggable, resizable floating panel windows.
 */

/* ========================================
 * FLOATING PANEL BASE
 * ======================================== */

.floating-panel {
  position: fixed;
  z-index: 1000;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-primary);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4),
              0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  min-width: 250px;
  min-height: 200px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  overflow: hidden;
}

/* Bring focused panel to front */
.floating-panel:focus-within,
.floating-panel--focused {
  z-index: 1001;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5),
              0 6px 16px rgba(0, 0, 0, 0.3),
              0 0 0 2px var(--color-accent-primary);
}

/* ========================================
 * PINNED STATE
 * ======================================== */

.floating-panel--pinned {
  border-color: var(--color-accent-secondary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.floating-panel--pinned .floating-panel__header {
  cursor: default;
  background: linear-gradient(
    135deg,
    var(--color-bg-secondary) 0%,
    var(--color-bg-elevated) 100%
  );
}

.floating-panel--pinned .floating-panel__pin-btn {
  color: var(--color-accent-secondary);
}

/* ========================================
 * MINIMIZED STATE
 * ======================================== */

.floating-panel--minimized {
  display: none;
}

/* ========================================
 * HEADER
 * ======================================== */

.floating-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border-primary);
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}

.floating-panel__header:active {
  cursor: grabbing;
}

.floating-panel__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.floating-panel__title-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.floating-panel__controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.floating-panel__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.floating-panel__btn:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

.floating-panel__btn--close:hover {
  background: var(--color-error);
  color: white;
}

.floating-panel__btn--pin.active {
  color: var(--color-accent-secondary);
}

/* ========================================
 * CONTENT
 * ======================================== */

.floating-panel__content {
  flex: 1;
  overflow: auto;
  padding: 8px;
  min-height: 0;
}

/* Ensure panel content fills available space */
.floating-panel__content > * {
  height: 100%;
}

/* ========================================
 * RESIZE HANDLES
 * ======================================== */

.floating-panel__resize {
  position: absolute;
  z-index: 10;
  background: transparent;
}

/* Edge handles */
.floating-panel__resize--n,
.floating-panel__resize--s {
  height: 8px;
  left: 12px;
  right: 12px;
}

.floating-panel__resize--n {
  top: -4px;
  cursor: ns-resize;
}

.floating-panel__resize--s {
  bottom: -4px;
  cursor: ns-resize;
}

.floating-panel__resize--e,
.floating-panel__resize--w {
  width: 8px;
  top: 12px;
  bottom: 12px;
}

.floating-panel__resize--e {
  right: -4px;
  cursor: ew-resize;
}

.floating-panel__resize--w {
  left: -4px;
  cursor: ew-resize;
}

/* Corner handles */
.floating-panel__resize--ne,
.floating-panel__resize--nw,
.floating-panel__resize--se,
.floating-panel__resize--sw {
  width: 16px;
  height: 16px;
}

.floating-panel__resize--ne {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.floating-panel__resize--nw {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.floating-panel__resize--se {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}

.floating-panel__resize--sw {
  bottom: -4px;
  left: -4px;
  cursor: nesw-resize;
}

/* Visual corner grip indicator */
.floating-panel__resize--se::after {
  content: '';
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: linear-gradient(
    135deg,
    transparent 50%,
    var(--color-text-tertiary) 50%,
    var(--color-text-tertiary) 60%,
    transparent 60%,
    transparent 70%,
    var(--color-text-tertiary) 70%,
    var(--color-text-tertiary) 80%,
    transparent 80%
  );
  opacity: 0.5;
  pointer-events: none;
}

.floating-panel:hover .floating-panel__resize--se::after {
  opacity: 0.8;
}

/* ========================================
 * FLOATING DOCK
 * Taskbar for minimized panels
 * ======================================== */

.floating-dock {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  gap: 4px;
  padding: 6px 12px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
}

/* Hide dock when empty */
.floating-dock:empty {
  display: none;
}

.floating-dock__item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--color-border-primary);
  border-radius: 4px;
  background: var(--color-bg-primary);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.floating-dock__item:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  border-color: var(--color-accent-primary);
}

.floating-dock__item-icon {
  font-size: 14px;
}

.floating-dock__item-title {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
 * FLOATING MANAGER CONTAINER
 * ======================================== */

.floating-panels-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  z-index: 1000;
  pointer-events: none;
}

.floating-panels-container .floating-panel {
  pointer-events: auto;
}

/* ========================================
 * TRANSITIONS & ANIMATIONS
 * ======================================== */

.floating-panel--dragging {
  opacity: 0.9;
  transition: none !important;
}

.floating-panel--resizing {
  transition: none !important;
}

.floating-panel--snap-preview {
  background: var(--color-accent-primary);
  opacity: 0.2;
  pointer-events: none;
}

/* Entrance animation */
@keyframes floating-panel-enter {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.floating-panel--entering {
  animation: floating-panel-enter 0.2s ease-out;
}

/* Exit animation */
@keyframes floating-panel-exit {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

.floating-panel--exiting {
  animation: floating-panel-exit 0.15s ease-in;
  pointer-events: none;
}

/* Minimize animation */
@keyframes floating-panel-minimize {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.5) translateY(100px);
  }
}

.floating-panel--minimizing {
  animation: floating-panel-minimize 0.2s ease-in forwards;
}

/* ========================================
 * TOOLTIP (for panel messages)
 * ======================================== */

.floating-panel__tooltip {
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-primary);
  border-radius: 4px;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  white-space: nowrap;
  z-index: 1002;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.floating-panel__tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--color-bg-elevated);
}

/* ========================================
 * MOBILE: DISABLE FLOATING PANELS
 * ======================================== */

@media (max-width: 768px) {
  .floating-panel,
  .floating-dock,
  .floating-panels-container {
    display: none !important;
  }
}

/* ========================================
 * POP-OUT BUTTON IN SPLIT PANELS
 * ======================================== */

.panel-header__btn--popout {
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.split-panel:hover .panel-header__btn--popout {
  opacity: 1;
}

.panel-header__btn--popout:hover {
  color: var(--color-accent-primary);
}

/* ========================================
 * SNAP-TO-EDGE
 * ======================================== */

/* Snap preview overlay */
.floating-panel__snap-preview {
  position: fixed;
  display: none;
  background: rgba(139, 92, 246, 0.15);
  border: 2px dashed rgba(139, 92, 246, 0.6);
  border-radius: var(--panel-border-radius, 8px);
  pointer-events: none;
  z-index: 9998;
  animation: snap-preview-pulse 1s ease-in-out infinite;
}

@keyframes snap-preview-pulse {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.005);
  }
}

/* Snap preview edge highlights */
.floating-panel__snap-preview[data-edge*="left"] {
  border-left-width: 4px;
  border-left-color: var(--color-accent-primary, #8b5cf6);
}

.floating-panel__snap-preview[data-edge*="right"] {
  border-right-width: 4px;
  border-right-color: var(--color-accent-primary, #8b5cf6);
}

.floating-panel__snap-preview[data-edge*="top"] {
  border-top-width: 4px;
  border-top-color: var(--color-accent-primary, #8b5cf6);
}

.floating-panel__snap-preview[data-edge*="bottom"] {
  border-bottom-width: 4px;
  border-bottom-color: var(--color-accent-primary, #8b5cf6);
}

/* Snapping animation */
.floating-panel--snapping {
  transition: left 0.15s ease-out, top 0.15s ease-out;
}

/* Visual feedback when near snap zone */
.floating-panel--dragging {
  opacity: 0.9;
}
