.windows-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.snap-preview {
  position: absolute;
  top: 8px;
  bottom: 84px;
  border-radius: 14px;
  background: rgba(10, 132, 255, 0.22);
  border: 2px solid rgba(10, 132, 255, 0.72);
  backdrop-filter: blur(8px);
  z-index: 15;
  pointer-events: none;
  transition: all 0.14s var(--ease-spring);
}

.app-window {
  position: absolute;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-window);
  background: var(--surface-app);
  backdrop-filter: blur(32px) saturate(180%);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-window-inactive);
  overflow: hidden;
  transition: box-shadow 0.2s ease, opacity 0.2s ease, transform 0.24s var(--ease-spring);
  will-change: transform, left, top, width, height;
}

.app-window.focused {
  box-shadow: var(--shadow-window), inset 0 1px 0 var(--glass-highlight);
}

.app-window.opening {
  animation: windowOpen 0.24s var(--ease-spring);
}

.app-window.minimized {
  opacity: 0;
  transform: scale(0.75) translateY(140px);
  pointer-events: none;
}

.app-window.snapping {
  transition: left 0.22s var(--ease-spring), top 0.22s var(--ease-spring), width 0.22s var(--ease-spring), height 0.22s var(--ease-spring);
}

/* Titlebar */
.window-titlebar {
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--divider);
  background: var(--glass-bg-subtle);
  cursor: grab;
  touch-action: none;
}

.window-titlebar:active {
  cursor: grabbing;
}

.window-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
}

.traffic-btn {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.traffic-btn::after {
  content: "";
  position: absolute;
  inset: -7px;
}

.traffic-btn:hover {
  transform: scale(1.1);
}

.traffic-close {
  background: #ff5f57;
}
.traffic-min {
  background: #febc2e;
}
.traffic-max {
  background: #28c840;
}

.traffic-glyph {
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  color: rgba(0, 0, 0, 0.68);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.window-controls:hover .traffic-glyph {
  opacity: 1;
}

.window-title {
  position: absolute;
  left: 88px;
  right: 88px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.window-actions-right {
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 2;
}

.window-snap-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.window-snap-btn:hover {
  background: var(--glass-bg-subtle);
  color: var(--text-primary);
}

.window-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Resize Handles (8-way + touch friendly corners) */
.resize-handle {
  position: absolute;
  z-index: 5;
  touch-action: none;
}

.resize-n { top: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.resize-s { bottom: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.resize-e { right: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.resize-w { left: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.resize-ne { top: -4px; right: -4px; width: 16px; height: 16px; cursor: nesw-resize; }
.resize-nw { top: -4px; left: -4px; width: 16px; height: 16px; cursor: nwse-resize; }
.resize-se { bottom: -4px; right: -4px; width: 20px; height: 20px; cursor: nwse-resize; }
.resize-sw { bottom: -4px; left: -4px; width: 16px; height: 16px; cursor: nesw-resize; }

.resize-se::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  border-bottom-right-radius: 2px;
  opacity: 0.5;
}

@keyframes windowOpen {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 720px) {
  .window-titlebar {
    height: 44px;
  }
  .traffic-btn {
    width: 15px;
    height: 15px;
  }
  .window-snap-btn {
    display: none;
  }
  .resize-se {
    width: 26px;
    height: 26px;
  }
}
