/* Windows 98 Window Styles */

.win98-window {
  position: absolute;
  background-color: var(--win98-window-bg);
  border: 2px solid;
  border-color: var(--win98-button-highlight) var(--win98-button-shadow) var(--win98-button-shadow) var(--win98-button-highlight);
  box-shadow: 2px 2px 0 0 var(--win98-button-dark-shadow);
  min-width: 200px;
  min-height: 150px;
}

/* Window titlebar */
.win98-window-titlebar {
  height: 18px;
  background-color: var(--win98-title-inactive);
  color: var(--win98-title-text-inactive);
  display: flex;
  align-items: center;
  padding: 0 2px;
  cursor: move;
  user-select: none;
}

.win98-window.active .win98-window-titlebar {
  background-color: var(--win98-title-active);
  color: var(--win98-title-text-active);
}

.win98-window-titlebar-icon {
  width: 16px;
  height: 16px;
  margin-right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.win98-window-titlebar-icon img {
  width: 16px;
  height: 16px;
}

.win98-window-titlebar-text {
  flex-grow: 1;
  font-weight: bold;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win98-window-titlebar-controls {
  display: flex;
}

/* Window control buttons */
.win98-window-button {
  width: 16px;
  height: 14px;
  margin-left: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--win98-button-face);
  border: 1px solid;
  border-color: var(--win98-button-highlight) var(--win98-button-shadow) var(--win98-button-shadow) var(--win98-button-highlight);
  cursor: pointer;
}

.win98-window-button:active {
  border-color: var(--win98-button-shadow) var(--win98-button-highlight) var(--win98-button-highlight) var(--win98-button-shadow);
}

.win98-window-button.minimize::after {
  content: '';
  width: 8px;
  height: 2px;
  background-color: var(--win98-text);
  position: absolute;
  bottom: 3px;
}

.win98-window-button.maximize::after {
  content: '';
  width: 8px;
  height: 8px;
  border: 1px solid var(--win98-text);
  border-top-width: 2px;
  background-color: transparent;
  position: absolute;
}

.win98-window-button.close::after {
  content: '×';
  font-size: 12px;
  line-height: 12px;
  position: absolute;
}

/* Window content */
.win98-window-content {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  background-color: var(--win98-window-bg);
  padding: 2px;
}

/* Window resize handle */
.win98-window-resize-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  bottom: 0;
  right: 0;
  cursor: nwse-resize;
  z-index: 1000;
  background-color: transparent;
}

.win98-window-resize-handle::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 3px;
  height: 3px;
  box-shadow: 
    3px 0 0 0 var(--win98-button-shadow),
    6px 0 0 0 var(--win98-button-shadow),
    0 3px 0 0 var(--win98-button-shadow),
    3px 3px 0 0 var(--win98-button-shadow),
    6px 3px 0 0 var(--win98-button-shadow),
    0 6px 0 0 var(--win98-button-shadow),
    3px 6px 0 0 var(--win98-button-shadow),
    6px 6px 0 0 var(--win98-button-shadow);
}

/* jQuery UI specific styles */
.ui-resizable-handle {
  position: absolute;
  display: block;
  background-image: none !important;
}

.ui-resizable-se {
  cursor: nwse-resize;
  width: 16px !important;
  height: 16px !important;
  right: 0 !important;
  bottom: 0 !important;
  background-color: transparent !important;
}

/* Hide default jQuery UI handle */
.ui-icon-gripsmall-diagonal-se {
  background-image: none !important;
}

/* Active resize handle */
.win98-window.resizing .win98-window-resize-handle::after,
.win98-window.ui-resizable-resizing .win98-window-resize-handle::after {
  box-shadow: 
    3px 0 0 0 var(--win98-button-dark-shadow),
    6px 0 0 0 var(--win98-button-dark-shadow),
    0 3px 0 0 var(--win98-button-dark-shadow),
    3px 3px 0 0 var(--win98-button-dark-shadow),
    6px 3px 0 0 var(--win98-button-dark-shadow),
    0 6px 0 0 var(--win98-button-dark-shadow),
    3px 6px 0 0 var(--win98-button-dark-shadow),
    6px 6px 0 0 var(--win98-button-dark-shadow);
}

/* Maximized window */
.win98-window.maximized {
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: calc(100% - 28px) !important; /* Subtract taskbar height */
  border-width: 0;
  box-shadow: none;
}

/* Dragging states */
.win98-window.dragging {
  opacity: 0.8;
  z-index: 9999 !important;
  transition: none !important;
  will-change: left, top;
}

.win98-window-titlebar:active {
  cursor: move;
}

.win98-window {
  transition: left 0.01s, top 0.01s;
}

.win98-window.resizing {
  transition: none !important;
  will-change: width, height;
}

/* Prevent text selection during drag */
.win98-window-titlebar * {
  pointer-events: none;
}

.win98-window-button {
  pointer-events: auto;
}

/* Responsive design for windows */
@media (max-width: 640px) {
  .win98-window {
    min-width: 150px;
    min-height: 100px;
  }
  
  .win98-window.maximized {
    height: calc(100% - 24px) !important; /* Smaller taskbar on mobile */
  }
  
  /* Larger touch targets on mobile */
  .win98-window-titlebar {
    height: 22px;
    padding: 0 4px;
  }
  
  .win98-window-button {
    width: 20px;
    height: 18px;
  }
  
  .win98-window-content {
    top: 22px;
  }
}

/* Enhanced Resize Handles */
.win98-resize-handle {
  position: absolute;
  background-color: transparent;
  z-index: 1001;
  pointer-events: auto;
}

/* Corner resize handles */
.win98-resize-handle.corner {
  width: 8px;
  height: 8px;
}

.win98-resize-handle.corner.nw {
  top: 0;
  left: 0;
  cursor: nw-resize;
}

.win98-resize-handle.corner.ne {
  top: 0;
  right: 0;
  cursor: ne-resize;
}

.win98-resize-handle.corner.sw {
  bottom: 0;
  left: 0;
  cursor: sw-resize;
}

.win98-resize-handle.corner.se {
  bottom: 0;
  right: 0;
  cursor: se-resize;
}

/* Side resize handles */
.win98-resize-handle.side.n {
  top: 0;
  left: 8px;
  right: 8px;
  height: 4px;
  cursor: n-resize;
}

.win98-resize-handle.side.s {
  bottom: 0;
  left: 8px;
  right: 8px;
  height: 4px;
  cursor: s-resize;
}

.win98-resize-handle.side.e {
  top: 8px;
  bottom: 8px;
  right: 0;
  width: 4px;
  cursor: e-resize;
}

.win98-resize-handle.side.w {
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 4px;
  cursor: w-resize;
}

/* Visual feedback for resize handles */
.win98-resize-handle:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

/* Debug: Make resize handles visible for testing */
.win98-resize-handle {
  background-color: rgba(255, 0, 0, 0.1) !important;
  border: 1px solid rgba(255, 0, 0, 0.3);
}

.win98-window.resizing .win98-resize-handle {
  background-color: rgba(0, 0, 0, 0.2);
}

/* Resize preview indicators */
.win98-resize-handle.corner::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(45deg, transparent 30%, var(--win98-button-shadow) 30%, var(--win98-button-shadow) 70%, transparent 70%),
    linear-gradient(-45deg, transparent 30%, var(--win98-button-shadow) 30%, var(--win98-button-shadow) 70%, transparent 70%);
  background-size: 2px 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

.win98-resize-handle.corner:hover::after {
  opacity: 0.5;
}

/* Enhanced resize feedback */
.win98-window.resizing {
  box-shadow: 
    2px 2px 0 0 var(--win98-button-dark-shadow),
    0 0 0 1px var(--win98-title-active);
}

/* Resize constraints visual feedback */
.win98-window[data-at-min-width="true"] .win98-resize-handle.side.w,
.win98-window[data-at-min-width="true"] .win98-resize-handle.corner.nw,
.win98-window[data-at-min-width="true"] .win98-resize-handle.corner.sw {
  cursor: not-allowed;
  background-color: rgba(255, 0, 0, 0.1);
}

.win98-window[data-at-min-height="true"] .win98-resize-handle.side.n,
.win98-window[data-at-min-height="true"] .win98-resize-handle.corner.nw,
.win98-window[data-at-min-height="true"] .win98-resize-handle.corner.ne {
  cursor: not-allowed;
  background-color: rgba(255, 0, 0, 0.1);
}

/* Smooth resize animations */
.win98-window:not(.resizing) {
  transition: width 0.1s ease-out, height 0.1s ease-out, left 0.1s ease-out, top 0.1s ease-out;
}

/* Aspect ratio preservation indicator */
.win98-window.preserve-aspect-ratio {
  outline: 1px dashed var(--win98-title-active);
  outline-offset: -1px;
}

/* Mobile responsive resize handles */
@media (max-width: 640px) {
  .win98-resize-handle.corner {
    width: 12px;
    height: 12px;
  }
  
  .win98-resize-handle.side.n,
  .win98-resize-handle.side.s {
    height: 8px;
  }
  
  .win98-resize-handle.side.e,
  .win98-resize-handle.side.w {
    width: 8px;
  }
}